Skip to content

Commit

Permalink
prefix cs_ to global variables to avoid link problems (capstone-engin…
Browse files Browse the repository at this point in the history
…e#1108)

* prefix cs_ to global variables to avoid link problems

* force Capstone to be build using MT

* fix identation
  • Loading branch information
illera88 authored and aquynh committed Mar 29, 2018
1 parent 3a6ccaf commit 5c30212
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ option(CAPSTONE_X86_REDUCE "x86 with reduce instruction sets to minimize library
option(CAPSTONE_X86_ATT_DISABLE "Disable x86 AT&T syntax" OFF)
option(CAPSTONE_OSXKERNEL_SUPPORT "Support to embed Capstone into OS X Kernel extensions" OFF)

if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif ()

enable_testing()

if (CAPSTONE_BUILD_DIET)
Expand Down
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void AArch64_enable(void)
{
arch_init[CS_ARCH_ARM64] = init;
arch_option[CS_ARCH_ARM64] = option;
cs_arch_init[CS_ARCH_ARM64] = init;
cs_arch_option[CS_ARCH_ARM64] = option;

// support this arch
all_arch |= (1 << CS_ARCH_ARM64);
Expand Down
4 changes: 2 additions & 2 deletions arch/ARM/ARMModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void ARM_enable(void)
{
arch_init[CS_ARCH_ARM] = init;
arch_option[CS_ARCH_ARM] = option;
cs_arch_init[CS_ARCH_ARM] = init;
cs_arch_option[CS_ARCH_ARM] = option;

// support this arch
all_arch |= (1 << CS_ARCH_ARM);
Expand Down
4 changes: 2 additions & 2 deletions arch/M680X/M680XModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void M680X_enable(void)
{
arch_init[CS_ARCH_M680X] = init;
arch_option[CS_ARCH_M680X] = option;
cs_arch_init[CS_ARCH_M680X] = init;
cs_arch_option[CS_ARCH_M680X] = option;

// support this arch
all_arch |= (1 << CS_ARCH_M680X);
Expand Down
4 changes: 2 additions & 2 deletions arch/M68K/M68KModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void M68K_enable(void)
{
arch_init[CS_ARCH_M68K] = init;
arch_option[CS_ARCH_M68K] = option;
cs_arch_init[CS_ARCH_M68K] = init;
cs_arch_option[CS_ARCH_M68K] = option;

// support this arch
all_arch |= (1 << CS_ARCH_M68K);
Expand Down
4 changes: 2 additions & 2 deletions arch/Mips/MipsModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void Mips_enable(void)
{
arch_init[CS_ARCH_MIPS] = init;
arch_option[CS_ARCH_MIPS] = option;
cs_arch_init[CS_ARCH_MIPS] = init;
cs_arch_option[CS_ARCH_MIPS] = option;

// support this arch
all_arch |= (1 << CS_ARCH_MIPS);
Expand Down
4 changes: 2 additions & 2 deletions arch/PowerPC/PPCModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void PPC_enable(void)
{
arch_init[CS_ARCH_PPC] = init;
arch_option[CS_ARCH_PPC] = option;
cs_arch_init[CS_ARCH_PPC] = init;
cs_arch_option[CS_ARCH_PPC] = option;

// support this arch
all_arch |= (1 << CS_ARCH_PPC);
Expand Down
4 changes: 2 additions & 2 deletions arch/Sparc/SparcModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void Sparc_enable(void)
{
arch_init[CS_ARCH_SPARC] = init;
arch_option[CS_ARCH_SPARC] = option;
cs_arch_init[CS_ARCH_SPARC] = init;
cs_arch_option[CS_ARCH_SPARC] = option;

// support this arch
all_arch |= (1 << CS_ARCH_SPARC);
Expand Down
4 changes: 2 additions & 2 deletions arch/SystemZ/SystemZModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void SystemZ_enable(void)
{
arch_init[CS_ARCH_SYSZ] = init;
arch_option[CS_ARCH_SYSZ] = option;
cs_arch_init[CS_ARCH_SYSZ] = init;
cs_arch_option[CS_ARCH_SYSZ] = option;

// support this arch
all_arch |= (1 << CS_ARCH_SYSZ);
Expand Down
4 changes: 2 additions & 2 deletions arch/TMS320C64x/TMS320C64xModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void TMS320C64x_enable(void)
{
arch_init[CS_ARCH_TMS320C64X] = init;
arch_option[CS_ARCH_TMS320C64X] = option;
cs_arch_init[CS_ARCH_TMS320C64X] = init;
cs_arch_option[CS_ARCH_TMS320C64X] = option;

all_arch |= (1 << CS_ARCH_TMS320C64X);
}
Expand Down
4 changes: 2 additions & 2 deletions arch/X86/X86Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void X86_enable(void)
{
arch_init[CS_ARCH_X86] = init;
arch_option[CS_ARCH_X86] = option;
cs_arch_init[CS_ARCH_X86] = init;
cs_arch_option[CS_ARCH_X86] = option;

// support this arch
all_arch |= (1 << CS_ARCH_X86);
Expand Down
4 changes: 2 additions & 2 deletions arch/XCore/XCoreModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)

void XCore_enable(void)
{
arch_init[CS_ARCH_XCORE] = init;
arch_option[CS_ARCH_XCORE] = option;
cs_arch_init[CS_ARCH_XCORE] = init;
cs_arch_option[CS_ARCH_XCORE] = option;

// support this arch
all_arch |= (1 << CS_ARCH_XCORE);
Expand Down
12 changes: 6 additions & 6 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
#define SKIPDATA_MNEM NULL
#endif

cs_err (*arch_init[MAX_ARCH])(cs_struct *) = { NULL };
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };
cs_err (*cs_arch_init[MAX_ARCH])(cs_struct *) = { NULL };
cs_err (*cs_arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
void (*cs_arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };

extern void ARM_enable(void);
extern void AArch64_enable(void);
Expand Down Expand Up @@ -275,7 +275,7 @@ cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)

archs_enable();

if (arch < CS_ARCH_MAX && arch_init[arch]) {
if (arch < CS_ARCH_MAX && cs_arch_init[arch]) {
ud = cs_mem_calloc(1, sizeof(*ud));
if (!ud) {
// memory insufficient
Expand All @@ -292,7 +292,7 @@ cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
// default skipdata setup
ud->skipdata_setup.mnemonic = SKIPDATA_MNEM;

err = arch_init[ud->arch](ud);
err = cs_arch_init[ud->arch](ud);
if (err) {
cs_mem_free(ud);
*handle = 0;
Expand Down Expand Up @@ -560,7 +560,7 @@ cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
return CS_ERR_OK;
}

return arch_option[handle->arch](handle, type, value);
return cs_arch_option[handle->arch](handle, type, value);
}

// generate @op_str for data instruction of SKIPDATA
Expand Down
4 changes: 2 additions & 2 deletions cs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ struct cs_struct {
#define MAX_ARCH CS_ARCH_MAX

// constructor initialization for all archs
extern cs_err (*arch_init[MAX_ARCH]) (cs_struct *);
extern cs_err (*cs_arch_init[MAX_ARCH]) (cs_struct *);

// support cs_option() for all archs
extern cs_err (*arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);
extern cs_err (*cs_arch_option[MAX_ARCH]) (cs_struct*, cs_opt_type, size_t value);

extern unsigned int all_arch;

Expand Down

0 comments on commit 5c30212

Please sign in to comment.