do not use constructor to enable archs, so code is more portable. suggested by Alex Ionescu
This commit is contained in:
parent
a580d92e05
commit
c272e9d000
|
@ -35,7 +35,7 @@ static void destroy(cs_struct *handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) __init_arm64__()
|
void AArch64_enable(void)
|
||||||
{
|
{
|
||||||
arch_init[CS_ARCH_ARM64] = init;
|
arch_init[CS_ARCH_ARM64] = init;
|
||||||
arch_option[CS_ARCH_ARM64] = option;
|
arch_option[CS_ARCH_ARM64] = option;
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#include "ARMInstPrinter.h"
|
#include "ARMInstPrinter.h"
|
||||||
#include "mapping.h"
|
#include "mapping.h"
|
||||||
|
|
||||||
void enable_arm() {};
|
|
||||||
|
|
||||||
static cs_err init(cs_struct *ud)
|
static cs_err init(cs_struct *ud)
|
||||||
{
|
{
|
||||||
MCRegisterInfo *mri = cs_mem_malloc(sizeof(*mri));
|
MCRegisterInfo *mri = cs_mem_malloc(sizeof(*mri));
|
||||||
|
@ -48,7 +46,7 @@ static void destroy(cs_struct *handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) __init_arm__()
|
void ARM_enable(void)
|
||||||
{
|
{
|
||||||
arch_init[CS_ARCH_ARM] = init;
|
arch_init[CS_ARCH_ARM] = init;
|
||||||
arch_option[CS_ARCH_ARM] = option;
|
arch_option[CS_ARCH_ARM] = option;
|
||||||
|
|
|
@ -46,7 +46,7 @@ static void destroy(cs_struct *handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) __init_mips__()
|
void Mips_enable(void)
|
||||||
{
|
{
|
||||||
arch_init[CS_ARCH_MIPS] = init;
|
arch_init[CS_ARCH_MIPS] = init;
|
||||||
arch_option[CS_ARCH_MIPS] = option;
|
arch_option[CS_ARCH_MIPS] = option;
|
||||||
|
|
|
@ -39,7 +39,7 @@ static void destroy(cs_struct *handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) __init_mips__()
|
void PPC_enable(void)
|
||||||
{
|
{
|
||||||
arch_init[CS_ARCH_PPC] = init;
|
arch_init[CS_ARCH_PPC] = init;
|
||||||
arch_option[CS_ARCH_PPC] = option;
|
arch_option[CS_ARCH_PPC] = option;
|
||||||
|
|
|
@ -50,7 +50,7 @@ static void destroy(cs_struct *handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) __init_x86__()
|
void X86_enable(void)
|
||||||
{
|
{
|
||||||
arch_init[CS_ARCH_X86] = init;
|
arch_init[CS_ARCH_X86] = init;
|
||||||
arch_option[CS_ARCH_X86] = option;
|
arch_option[CS_ARCH_X86] = option;
|
||||||
|
|
32
cs.c
32
cs.c
|
@ -14,30 +14,36 @@ cs_err (*arch_init[MAX_ARCH])(cs_struct *) = { NULL };
|
||||||
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
|
cs_err (*arch_option[MAX_ARCH]) (cs_struct *, cs_opt_type, size_t value) = { NULL };
|
||||||
void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };
|
void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL };
|
||||||
|
|
||||||
// we need this trick to enable module constructors in static lib
|
extern void ARM_enable(void);
|
||||||
extern void enable_arm();
|
extern void AArch64_enable(void);
|
||||||
extern void enable_arm64();
|
extern void Mips_enable(void);
|
||||||
extern void enable_mips();
|
extern void X86_enable(void);
|
||||||
extern void enable_x86();
|
extern void PPC_enable(void);
|
||||||
extern void enable_powerpc();
|
|
||||||
|
|
||||||
void enable_construct()
|
static void archs_enable(void)
|
||||||
{
|
{
|
||||||
|
static bool initialized = false;
|
||||||
|
|
||||||
|
if (initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
#ifdef CAPSTONE_HAS_ARM
|
#ifdef CAPSTONE_HAS_ARM
|
||||||
enable_arm();
|
ARM_enable();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CAPSTONE_HAS_ARM64
|
#ifdef CAPSTONE_HAS_ARM64
|
||||||
enable_arm64();
|
AArch64_enable();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CAPSTONE_HAS_MIPS
|
#ifdef CAPSTONE_HAS_MIPS
|
||||||
enable_mips();
|
Mips_enable();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CAPSTONE_HAS_X86
|
#ifdef CAPSTONE_HAS_X86
|
||||||
enable_x86();
|
X86_enable();
|
||||||
#endif
|
#endif
|
||||||
#ifdef CAPSTONE_HAS_POWERPC
|
#ifdef CAPSTONE_HAS_POWERPC
|
||||||
enable_powerpc();
|
PPC_enable();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int all_arch = 0;
|
unsigned int all_arch = 0;
|
||||||
|
@ -119,6 +125,8 @@ cs_err cs_open(cs_arch arch, cs_mode mode, csh *handle)
|
||||||
// with cs_option(CS_OPT_MEM)
|
// with cs_option(CS_OPT_MEM)
|
||||||
return CS_ERR_MEMSETUP;
|
return CS_ERR_MEMSETUP;
|
||||||
|
|
||||||
|
archs_enable();
|
||||||
|
|
||||||
if (arch < CS_ARCH_MAX && arch_init[arch]) {
|
if (arch < CS_ARCH_MAX && arch_init[arch]) {
|
||||||
cs_struct *ud;
|
cs_struct *ud;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue