diff --git a/Makefile b/Makefile index a2015927..ad9e8a84 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,11 @@ RANLIB ?= $(CROSS)ranlib STRIP ?= $(CROSS)strip CFLAGS += -fPIC -O3 -Wall -Iinclude + +ifeq ($(USE_SYS_DYN_MEM),yes) +CFLAGS += -DUSE_SYS_DYN_MEM +endif + LDFLAGS += -shared PREFIX ?= /usr diff --git a/config.mk b/config.mk index da094d77..e9c73b36 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,9 @@ +# Comment out the line below 'USE_SYS_DYN_MEM = yes' if you do not want to use +# system's malloc()/calloc()/realloc()/free() for internal dynamic memory management. +# NOTE: in that case, your program must specify your own malloc/calloc/realloc/free +# functions with cs_option(), using CS_OPT_MEM option type. +USE_SYS_DYN_MEM = yes + # Specify which archs you want to compile in CAPSTONE_ARCHS = diff --git a/cs.c b/cs.c index 76cab6a9..284d31e9 100644 --- a/cs.c +++ b/cs.c @@ -16,10 +16,17 @@ void (*arch_destroy[MAX_ARCH]) (cs_struct *) = { NULL }; unsigned int all_arch = 0; +#ifdef USE_SYS_DYN_MEM malloc_t my_malloc = malloc; calloc_t my_calloc = calloc; realloc_t my_realloc = realloc; free_t my_free = free; +#else +malloc_t my_malloc = NULL; +calloc_t my_calloc = NULL; +realloc_t my_realloc = NULL; +free_t my_free = NULL; +#endif unsigned int cs_version(int *major, int *minor) {