Merge branch 'next' of https://github.com/aquynh/capstone into next
diff --git a/arch/X86/X86GenAsmWriter1.inc b/arch/X86/X86GenAsmWriter1.inc
index 491ce3d..46c2f16 100644
--- a/arch/X86/X86GenAsmWriter1.inc
+++ b/arch/X86/X86GenAsmWriter1.inc
@@ -20484,6 +20484,8 @@
#ifdef PRINT_ALIAS_INSTR
#undef PRINT_ALIAS_INSTR
+#ifndef CAPSTONE_DIET
+
static void printCustomAliasOperand(MCInst *MI, unsigned OpIdx,
unsigned PrintMethodIdx, SStream *OS)
{
@@ -20573,4 +20575,6 @@
return tmp;
}
+#endif
+
#endif // PRINT_ALIAS_INSTR
diff --git a/arch/X86/X86GenAsmWriter1_reduce.inc b/arch/X86/X86GenAsmWriter1_reduce.inc
index f0c9e45..9dd4fb8 100644
--- a/arch/X86/X86GenAsmWriter1_reduce.inc
+++ b/arch/X86/X86GenAsmWriter1_reduce.inc
@@ -4575,6 +4575,8 @@
#ifdef PRINT_ALIAS_INSTR
#undef PRINT_ALIAS_INSTR
+#ifndef CAPSTONE_DIET
+
static void printCustomAliasOperand(MCInst *MI, unsigned OpIdx,
unsigned PrintMethodIdx, SStream *OS)
{
@@ -4646,4 +4648,6 @@
return tmp;
}
+#endif
+
#endif // PRINT_ALIAS_INSTR
diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c
index 57778a7..5ea5835 100644
--- a/arch/X86/X86IntelInstPrinter.c
+++ b/arch/X86/X86IntelInstPrinter.c
@@ -720,11 +720,16 @@
printMemOffset(MI, OpNo, O);
}
+#ifndef CAPSTONE_DIET
static char *printAliasInstr(MCInst *MI, SStream *OS, void *info);
+#endif
static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI);
+
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
{
+#ifndef CAPSTONE_DIET
char *mnem;
+#endif
x86_reg reg, reg2;
enum cs_ac_type access1, access2;
@@ -734,11 +739,13 @@
return;
}
+#ifndef CAPSTONE_DIET
// Try to print any aliases first.
mnem = printAliasInstr(MI, O, Info);
if (mnem)
cs_mem_free(mnem);
else
+#endif
printInstruction(MI, O, Info);
reg = X86_insn_reg_intel(MCInst_getOpcode(MI), &access1);
diff --git a/arch/X86/X86Mapping.c b/arch/X86/X86Mapping.c
index 85f8b77..fe295d7 100644
--- a/arch/X86/X86Mapping.c
+++ b/arch/X86/X86Mapping.c
@@ -4,7 +4,9 @@
#ifdef CAPSTONE_HAS_X86
#include <string.h>
+#ifndef CAPSTONE_HAS_OSXKERNEL
#include <stdlib.h>
+#endif
#include "X86Mapping.h"
#include "X86DisassemblerDecoder.h"
@@ -3128,6 +3130,7 @@
// given MCInst's id, find out if this insn is valid for BND prefix
// BND prefix is valid for CALL/JMP/RET
+#ifndef CAPSTONE_DIET
static bool valid_bnd(cs_struct *h, unsigned int opcode)
{
unsigned int id;
@@ -3170,6 +3173,7 @@
// not found
return false;
}
+#endif
// given MCInst's id, find out if this insn is valid for REP prefix
static bool valid_rep(cs_struct *h, unsigned int opcode)
diff --git a/cs.c b/cs.c
index 19c65c7..82f9efe 100644
--- a/cs.c
+++ b/cs.c
@@ -45,7 +45,11 @@
#endif
// default SKIPDATA mnemonic
+#ifndef CAPSTONE_DIET
#define SKIPDATA_MNEM ".byte"
+#else // No printing is available in diet mode
+#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 };
@@ -552,6 +556,7 @@
}
// generate @op_str for data instruction of SKIPDATA
+#ifndef CAPSTONE_DIET
static void skipdata_opstr(char *opstr, const uint8_t *buffer, size_t size)
{
char *p = opstr;
@@ -580,6 +585,7 @@
available -= len;
}
}
+#endif
// dynamicly allocate memory to contain disasm insn
// NOTE: caller must free() the allocated memory itself to avoid memory leaking
@@ -708,9 +714,14 @@
insn_cache->address = offset;
insn_cache->size = (uint16_t)skipdata_bytes;
memcpy(insn_cache->bytes, buffer, skipdata_bytes);
+#ifdef CAPSTONE_DIET
+ insn_cache->mnemonic[0] = '\0';
+ insn_cache->op_str[0] = '\0';
+#else
strncpy(insn_cache->mnemonic, handle->skipdata_setup.mnemonic,
sizeof(insn_cache->mnemonic) - 1);
skipdata_opstr(insn_cache->op_str, buffer, skipdata_bytes);
+#endif
insn_cache->detail = NULL;
next_offset = skipdata_bytes;
@@ -912,10 +923,15 @@
insn->id = 0; // invalid ID for this "data" instruction
insn->address = *address;
insn->size = (uint16_t)skipdata_bytes;
+#ifdef CAPSTONE_DIET
+ insn->mnemonic[0] = '\0';
+ insn->op_str[0] = '\0';
+#else
memcpy(insn->bytes, *code, skipdata_bytes);
strncpy(insn->mnemonic, handle->skipdata_setup.mnemonic,
sizeof(insn->mnemonic) - 1);
skipdata_opstr(insn->op_str, *code, skipdata_bytes);
+#endif
*code += skipdata_bytes;
*size -= skipdata_bytes;
diff --git a/include/capstone/capstone.h b/include/capstone/capstone.h
index f3e9c5e..fc06307 100644
--- a/include/capstone/capstone.h
+++ b/include/capstone/capstone.h
@@ -30,9 +30,9 @@
#endif
#else
#define CAPSTONE_API
-#ifdef __GNUC__
+#if defined(__GNUC__) && !defined(CAPSTONE_STATIC)
#define CAPSTONE_EXPORT __attribute__((visibility("default")))
-#else
+#else // defined(CAPSTONE_STATIC)
#define CAPSTONE_EXPORT
#endif
#endif
diff --git a/include/capstone/platform.h b/include/capstone/platform.h
index 4c5de08..7427b42 100644
--- a/include/capstone/platform.h
+++ b/include/capstone/platform.h
@@ -62,6 +62,11 @@
#define UINT64_MAX 0xffffffffffffffffui64
#endif // defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE))
+#ifdef CAPSTONE_HAS_OSXKERNEL
+// this system has stdint.h
+#include <stdint.h>
+#endif
+
#define __PRI_8_LENGTH_MODIFIER__ "hh"
#define __PRI_64_LENGTH_MODIFIER__ "ll"