summaryrefslogtreecommitdiff
path: root/sljit
diff options
context:
space:
mode:
authorzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2014-09-30 06:35:20 +0000
committerzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2014-09-30 06:35:20 +0000
commite88f39765748aaca498cdc4e936ba1825d0c75b0 (patch)
tree2ee55e6c7c3689c321f2f6fab48b0455bc4d7f2f /sljit
parent68dfb979bd99c518fa96c9ee2883a66a73672177 (diff)
downloadpcre-e88f39765748aaca498cdc4e936ba1825d0c75b0.tar.gz
Support custom memory allocators in the JIT compiler.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1507 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'sljit')
-rw-r--r--sljit/sljitConfigInternal.h4
-rw-r--r--sljit/sljitLir.c40
-rw-r--r--sljit/sljitLir.h25
-rw-r--r--sljit/sljitNativeARM_32.c6
-rw-r--r--sljit/sljitNativeX86_common.c1
-rw-r--r--sljit/sljitUtils.c10
6 files changed, 50 insertions, 36 deletions
diff --git a/sljit/sljitConfigInternal.h b/sljit/sljitConfigInternal.h
index 52c8f61..01a5329 100644
--- a/sljit/sljitConfigInternal.h
+++ b/sljit/sljitConfigInternal.h
@@ -203,11 +203,11 @@
*/
#ifndef SLJIT_MALLOC
-#define SLJIT_MALLOC(size) malloc(size)
+#define SLJIT_MALLOC(size, allocator_data) malloc(size)
#endif
#ifndef SLJIT_FREE
-#define SLJIT_FREE(ptr) free(ptr)
+#define SLJIT_FREE(ptr, allocator_data) free(ptr)
#endif
#ifndef SLJIT_MEMMOVE
diff --git a/sljit/sljitLir.c b/sljit/sljitLir.c
index 89a93e2..f0b3947 100644
--- a/sljit/sljitLir.c
+++ b/sljit/sljitLir.c
@@ -325,9 +325,9 @@ static sljit_si compiler_initialized = 0;
static void init_compiler(void);
#endif
-SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
+SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
{
- struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler));
+ struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
if (!compiler)
return NULL;
SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
@@ -349,15 +349,16 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
/* Only the non-zero members must be set. */
compiler->error = SLJIT_SUCCESS;
- compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
- compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
+ compiler->allocator_data = allocator_data;
+ compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
+ compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
if (!compiler->buf || !compiler->abuf) {
if (compiler->buf)
- SLJIT_FREE(compiler->buf);
+ SLJIT_FREE(compiler->buf, allocator_data);
if (compiler->abuf)
- SLJIT_FREE(compiler->abuf);
- SLJIT_FREE(compiler);
+ SLJIT_FREE(compiler->abuf, allocator_data);
+ SLJIT_FREE(compiler, allocator_data);
return NULL;
}
@@ -377,11 +378,12 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
#endif
#if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
- compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw) + CPOOL_SIZE * sizeof(sljit_ub));
+ compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
+ + CPOOL_SIZE * sizeof(sljit_ub), allocator_data);
if (!compiler->cpool) {
- SLJIT_FREE(compiler->buf);
- SLJIT_FREE(compiler->abuf);
- SLJIT_FREE(compiler);
+ SLJIT_FREE(compiler->buf, allocator_data);
+ SLJIT_FREE(compiler->abuf, allocator_data);
+ SLJIT_FREE(compiler, allocator_data);
return NULL;
}
compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE);
@@ -410,25 +412,27 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compile
{
struct sljit_memory_fragment *buf;
struct sljit_memory_fragment *curr;
+ void *allocator_data = compiler->allocator_data;
+ SLJIT_UNUSED_ARG(allocator_data);
buf = compiler->buf;
while (buf) {
curr = buf;
buf = buf->next;
- SLJIT_FREE(curr);
+ SLJIT_FREE(curr, allocator_data);
}
buf = compiler->abuf;
while (buf) {
curr = buf;
buf = buf->next;
- SLJIT_FREE(curr);
+ SLJIT_FREE(curr, allocator_data);
}
#if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
- SLJIT_FREE(compiler->cpool);
+ SLJIT_FREE(compiler->cpool, allocator_data);
#endif
- SLJIT_FREE(compiler);
+ SLJIT_FREE(compiler, allocator_data);
}
#if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
@@ -484,7 +488,7 @@ static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
compiler->buf->used_size += size;
return ret;
}
- new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
+ new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
PTR_FAIL_IF_NULL(new_frag);
new_frag->next = compiler->buf;
compiler->buf = new_frag;
@@ -503,7 +507,7 @@ static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
compiler->abuf->used_size += size;
return ret;
}
- new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
+ new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
PTR_FAIL_IF_NULL(new_frag);
new_frag->next = compiler->abuf;
compiler->abuf = new_frag;
@@ -547,6 +551,7 @@ static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
{
+ SLJIT_UNUSED_ARG(args);
SLJIT_UNUSED_ARG(local_size);
compiler->options = options;
@@ -563,6 +568,7 @@ static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
{
+ SLJIT_UNUSED_ARG(args);
SLJIT_UNUSED_ARG(local_size);
compiler->options = options;
diff --git a/sljit/sljitLir.h b/sljit/sljitLir.h
index e13713f..229e04f 100644
--- a/sljit/sljitLir.h
+++ b/sljit/sljitLir.h
@@ -307,6 +307,7 @@ struct sljit_compiler {
struct sljit_jump *last_jump;
struct sljit_const *last_const;
+ void *allocator_data;
struct sljit_memory_fragment *buf;
struct sljit_memory_fragment *abuf;
@@ -409,11 +410,16 @@ struct sljit_compiler {
/* Main functions */
/* --------------------------------------------------------------------- */
-/* Creates an sljit compiler.
+/* Creates an sljit compiler. The allocator_data is required by some
+ custom memory managers. This pointer is passed to SLJIT_MALLOC
+ and SLJIT_FREE macros. Most allocators (including the default
+ one) ignores this value, and it is recommended to pass NULL
+ as a dummy value for allocator_data.
+
Returns NULL if failed. */
-SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void);
+SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data);
-/* Free everything except the compiled machine code. */
+/* Frees everything except the compiled machine code. */
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);
/* Returns the current error code. If an error is occurred, future sljit
@@ -1095,7 +1101,7 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_consta
/* --------------------------------------------------------------------- */
#define SLJIT_MAJOR_VERSION 0
-#define SLJIT_MINOR_VERSION 92
+#define SLJIT_MINOR_VERSION 93
/* Get the human readable name of the platform. Can be useful on platforms
like ARM, where ARM and Thumb2 functions can be mixed, and
@@ -1141,10 +1147,11 @@ struct sljit_stack {
};
/* Returns NULL if unsuccessful.
- Note: limit and max_limit contains the size for stack allocation
- Note: the top field is initialized to base. */
-SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit);
-SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack);
+ Note: limit and max_limit contains the size for stack allocation.
+ Note: the top field is initialized to base.
+ Note: see sljit_create_compiler for the explanation of allocator_data. */
+SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit, void *allocator_data);
+SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack *stack, void *allocator_data);
/* Can be used to increase (allocate) or decrease (free) the memory area.
Returns with a non-zero value if unsuccessful. If new_limit is greater than
@@ -1152,7 +1159,7 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* st
since the growth ratio can be added to the current limit, and sljit_stack_resize
will do all the necessary checks. The fields of the stack are not changed if
sljit_stack_resize fails. */
-SLJIT_API_FUNC_ATTRIBUTE sljit_sw SLJIT_CALL sljit_stack_resize(struct sljit_stack* stack, sljit_uw new_limit);
+SLJIT_API_FUNC_ATTRIBUTE sljit_sw SLJIT_CALL sljit_stack_resize(struct sljit_stack *stack, sljit_uw new_limit);
#endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */
diff --git a/sljit/sljitNativeARM_32.c b/sljit/sljitNativeARM_32.c
index a7a6198..81f200d 100644
--- a/sljit/sljitNativeARM_32.c
+++ b/sljit/sljitNativeARM_32.c
@@ -337,7 +337,7 @@ static SLJIT_INLINE sljit_si resolve_const_pool_index(struct future_patch **firs
prev_patch->next = curr_patch->next;
else
*first_patch = curr_patch->next;
- SLJIT_FREE(curr_patch);
+ SLJIT_FREE(curr_patch, compiler->allocator_data);
break;
}
prev_patch = curr_patch;
@@ -347,12 +347,12 @@ static SLJIT_INLINE sljit_si resolve_const_pool_index(struct future_patch **firs
if (value >= 0) {
if ((sljit_uw)value > cpool_current_index) {
- curr_patch = (struct future_patch*)SLJIT_MALLOC(sizeof(struct future_patch));
+ curr_patch = (struct future_patch*)SLJIT_MALLOC(sizeof(struct future_patch), compiler->allocator_data);
if (!curr_patch) {
while (*first_patch) {
curr_patch = *first_patch;
*first_patch = (*first_patch)->next;
- SLJIT_FREE(curr_patch);
+ SLJIT_FREE(curr_patch, compiler->allocator_data);
}
return SLJIT_ERR_ALLOC_FAILED;
}
diff --git a/sljit/sljitNativeX86_common.c b/sljit/sljitNativeX86_common.c
index 7717e95..22a163f 100644
--- a/sljit/sljitNativeX86_common.c
+++ b/sljit/sljitNativeX86_common.c
@@ -2661,6 +2661,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *com
CHECK_ERROR();
CHECK(check_sljit_emit_op_flags(compiler, op, dst, dstw, src, srcw, type));
+ SLJIT_UNUSED_ARG(srcw);
if (dst == SLJIT_UNUSED)
return SLJIT_SUCCESS;
diff --git a/sljit/sljitUtils.c b/sljit/sljitUtils.c
index b29b403..3f12bb7 100644
--- a/sljit/sljitUtils.c
+++ b/sljit/sljitUtils.c
@@ -200,7 +200,7 @@ static SLJIT_INLINE sljit_si open_dev_zero(void)
/* Planning to make it even more clever in the future. */
static sljit_sw sljit_page_align = 0;
-SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit)
+SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit, void *allocator_data)
{
struct sljit_stack *stack;
union {
@@ -232,7 +232,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj
/* Align limit and max_limit. */
max_limit = (max_limit + sljit_page_align) & ~sljit_page_align;
- stack = (struct sljit_stack*)SLJIT_MALLOC(sizeof(struct sljit_stack));
+ stack = (struct sljit_stack*)SLJIT_MALLOC(sizeof(struct sljit_stack), allocator_data);
if (!stack)
return NULL;
@@ -262,7 +262,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj
base.ptr = mmap(NULL, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero, 0);
#endif
if (base.ptr == MAP_FAILED) {
- SLJIT_FREE(stack);
+ SLJIT_FREE(stack, allocator_data);
return NULL;
}
stack->base = base.uw;
@@ -275,14 +275,14 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj
#undef PAGE_ALIGN
-SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack)
+SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack, void *allocator_data)
{
#ifdef _WIN32
VirtualFree((void*)stack->base, 0, MEM_RELEASE);
#else
munmap((void*)stack->base, stack->max_limit - stack->base);
#endif
- SLJIT_FREE(stack);
+ SLJIT_FREE(stack, allocator_data);
}
SLJIT_API_FUNC_ATTRIBUTE sljit_sw SLJIT_CALL sljit_stack_resize(struct sljit_stack* stack, sljit_uw new_limit)