"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sljit/sljitExecAllocator.c" between
pcre2-10.35.tar.bz2 and pcre2-10.36.tar.bz2

About: The PCRE2 library implements Perl compatible regular expression pattern matching. New future PCRE version with revised API.

sljitExecAllocator.c  (pcre2-10.35.tar.bz2):sljitExecAllocator.c  (pcre2-10.36.tar.bz2)
skipping to change at line 75 skipping to change at line 75
/* System (OS) functions */ /* System (OS) functions */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* 64 KByte. */ /* 64 KByte. */
#define CHUNK_SIZE 0x10000 #define CHUNK_SIZE 0x10000
/* /*
alloc_chunk / free_chunk : alloc_chunk / free_chunk :
* allocate executable system memory chunks * allocate executable system memory chunks
* the size is always divisible by CHUNK_SIZE * the size is always divisible by CHUNK_SIZE
allocator_grab_lock / allocator_release_lock : SLJIT_ALLOCATOR_LOCK / SLJIT_ALLOCATOR_UNLOCK :
* make the allocator thread safe * provided as part of sljitUtils
* can be empty if the OS (or the application) does not support threading
* only the allocator requires this lock, sljit is fully thread safe * only the allocator requires this lock, sljit is fully thread safe
as it only uses local variables as it only uses local variables
*/ */
#ifdef _WIN32 #ifdef _WIN32
static SLJIT_INLINE void* alloc_chunk(sljit_uw size) static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
{ {
return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_RE ADWRITE); return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_RE ADWRITE);
} }
static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size) static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)
{ {
SLJIT_UNUSED_ARG(size); SLJIT_UNUSED_ARG(size);
VirtualFree(chunk, 0, MEM_RELEASE); VirtualFree(chunk, 0, MEM_RELEASE);
} }
#else #else
#ifdef __APPLE__ #ifdef __APPLE__
#ifdef MAP_ANON
/* Configures TARGET_OS_OSX when appropriate */ /* Configures TARGET_OS_OSX when appropriate */
#include <TargetConditionals.h> #include <TargetConditionals.h>
#if TARGET_OS_OSX && defined(MAP_JIT) #if TARGET_OS_OSX && defined(MAP_JIT)
#include <sys/utsname.h> #include <sys/utsname.h>
#endif /* TARGET_OS_OSX && MAP_JIT */ #endif /* TARGET_OS_OSX && MAP_JIT */
#ifdef MAP_JIT #ifdef MAP_JIT
/*
On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a
version where it's OK to have more than one JIT block.
On non-macOS systems, returns MAP_JIT if it is defined.
*/
static SLJIT_INLINE int get_map_jit_flag() static SLJIT_INLINE int get_map_jit_flag()
{ {
/* On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a v
ersion
of macOS where it's OK to have more than one JIT block.
On non-macOS systems, returns MAP_JIT if it is defined. */
#if TARGET_OS_OSX #if TARGET_OS_OSX
sljit_sw page_size = get_page_alignment() + 1;
void *ptr;
static int map_jit_flag = -1; static int map_jit_flag = -1;
/* The following code is thread safe because multiple initialization /*
sets map_jit_flag to the same value and the code has no side-effects. The following code is thread safe because multiple initialization
Changing the kernel version witout system restart is (very) unlikely. sets map_jit_flag to the same value and the code has no side-effects.
*/ Changing the kernel version witout system restart is (very) unlikely.
*/
if (map_jit_flag == -1) { if (map_jit_flag == -1) {
struct utsname name; struct utsname name;
map_jit_flag = 0; map_jit_flag = 0;
uname(&name); uname(&name);
/* Kernel version for 10.14.0 (Mojave) */ /* Kernel version for 10.14.0 (Mojave) */
if (atoi(name.release) >= 18) { if (atoi(name.release) >= 18) {
/* Only use MAP_JIT if a hardened runtime is used, becaus e MAP_JIT is incompatible with fork(). */ /* Only use MAP_JIT if a hardened runtime is used */
/* mirroring page size detection from sljit_allocate_stac ptr = mmap(NULL, page_size, PROT_WRITE | PROT_EXEC, MAP_P
k */ RIVATE | MAP_ANON, -1, 0);
long page_size = sysconf(_SC_PAGESIZE);
/* Should never happen */
if (page_size < 0)
page_size = 4096;
void *ptr = mmap(NULL, page_size, PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (ptr == MAP_FAILED) { if (ptr == MAP_FAILED) {
map_jit_flag = MAP_JIT; map_jit_flag = MAP_JIT;
} else { } else {
munmap(ptr, page_size); munmap(ptr, page_size);
} }
} }
} }
return map_jit_flag; return map_jit_flag;
#else /* !TARGET_OS_OSX */ #else /* !TARGET_OS_OSX */
return MAP_JIT; return MAP_JIT;
#endif /* TARGET_OS_OSX */ #endif /* TARGET_OS_OSX */
} }
#endif /* MAP_JIT */ #endif /* MAP_JIT */
#endif /* MAP_ANON */
#endif /* __APPLE__ */ #endif /* __APPLE__ */
static SLJIT_INLINE void* alloc_chunk(sljit_uw size) static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
{ {
void *retval; void *retval;
const int prot = PROT_READ | PROT_WRITE | PROT_EXEC; const int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
#ifdef MAP_ANON #ifdef MAP_ANON
int flags = MAP_PRIVATE | MAP_ANON; int flags = MAP_PRIVATE | MAP_ANON;
#ifdef MAP_JIT #ifdef MAP_JIT
flags |= get_map_jit_flag(); flags |= get_map_jit_flag();
#endif #endif
retval = mmap(NULL, size, prot, flags, -1, 0); retval = mmap(NULL, size, prot, flags, -1, 0);
#else /* !MAP_ANON */ #else /* !MAP_ANON */
if (dev_zero < 0) { if (SLJIT_UNLIKELY((dev_zero < 0) && open_dev_zero()))
if (open_dev_zero()) return NULL;
return NULL;
}
retval = mmap(NULL, size, prot, MAP_PRIVATE, dev_zero, 0); retval = mmap(NULL, size, prot, MAP_PRIVATE, dev_zero, 0);
#endif /* MAP_ANON */ #endif /* MAP_ANON */
if (retval == MAP_FAILED) if (retval == MAP_FAILED)
retval = NULL; retval = NULL;
else { else {
if (mprotect(retval, size, prot) < 0) { if (mprotect(retval, size, prot) < 0) {
munmap(retval, size); munmap(retval, size);
retval = NULL; retval = NULL;
} }
skipping to change at line 256 skipping to change at line 255
} }
} }
SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size)
{ {
struct block_header *header; struct block_header *header;
struct block_header *next_header; struct block_header *next_header;
struct free_block *free_block; struct free_block *free_block;
sljit_uw chunk_size; sljit_uw chunk_size;
allocator_grab_lock(); SLJIT_ALLOCATOR_LOCK();
if (size < (64 - sizeof(struct block_header))) if (size < (64 - sizeof(struct block_header)))
size = (64 - sizeof(struct block_header)); size = (64 - sizeof(struct block_header));
size = ALIGN_SIZE(size); size = ALIGN_SIZE(size);
free_block = free_blocks; free_block = free_blocks;
while (free_block) { while (free_block) {
if (free_block->size >= size) { if (free_block->size >= size) {
chunk_size = free_block->size; chunk_size = free_block->size;
if (chunk_size > size + 64) { if (chunk_size > size + 64) {
/* We just cut a block from the end of the free b lock. */ /* We just cut a block from the end of the free b lock. */
skipping to change at line 280 skipping to change at line 279
header->prev_size = chunk_size; header->prev_size = chunk_size;
AS_BLOCK_HEADER(header, size)->prev_size = size; AS_BLOCK_HEADER(header, size)->prev_size = size;
} }
else { else {
sljit_remove_free_block(free_block); sljit_remove_free_block(free_block);
header = (struct block_header*)free_block; header = (struct block_header*)free_block;
size = chunk_size; size = chunk_size;
} }
allocated_size += size; allocated_size += size;
header->size = size; header->size = size;
allocator_release_lock(); SLJIT_ALLOCATOR_UNLOCK();
return MEM_START(header); return MEM_START(header);
} }
free_block = free_block->next; free_block = free_block->next;
} }
chunk_size = (size + sizeof(struct block_header) + CHUNK_SIZE - 1) & CHUN K_MASK; chunk_size = (size + sizeof(struct block_header) + CHUNK_SIZE - 1) & CHUN K_MASK;
header = (struct block_header*)alloc_chunk(chunk_size); header = (struct block_header*)alloc_chunk(chunk_size);
if (!header) { if (!header) {
allocator_release_lock(); SLJIT_ALLOCATOR_UNLOCK();
return NULL; return NULL;
} }
chunk_size -= sizeof(struct block_header); chunk_size -= sizeof(struct block_header);
total_size += chunk_size; total_size += chunk_size;
header->prev_size = 0; header->prev_size = 0;
if (chunk_size > size + 64) { if (chunk_size > size + 64) {
/* Cut the allocated space into a free and a used block. */ /* Cut the allocated space into a free and a used block. */
allocated_size += size; allocated_size += size;
skipping to change at line 316 skipping to change at line 315
next_header = AS_BLOCK_HEADER(free_block, chunk_size); next_header = AS_BLOCK_HEADER(free_block, chunk_size);
} }
else { else {
/* All space belongs to this allocation. */ /* All space belongs to this allocation. */
allocated_size += chunk_size; allocated_size += chunk_size;
header->size = chunk_size; header->size = chunk_size;
next_header = AS_BLOCK_HEADER(header, chunk_size); next_header = AS_BLOCK_HEADER(header, chunk_size);
} }
next_header->size = 1; next_header->size = 1;
next_header->prev_size = chunk_size; next_header->prev_size = chunk_size;
allocator_release_lock(); SLJIT_ALLOCATOR_UNLOCK();
return MEM_START(header); return MEM_START(header);
} }
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr) SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr)
{ {
struct block_header *header; struct block_header *header;
struct free_block* free_block; struct free_block* free_block;
allocator_grab_lock(); SLJIT_ALLOCATOR_LOCK();
header = AS_BLOCK_HEADER(ptr, -(sljit_sw)sizeof(struct block_header)); header = AS_BLOCK_HEADER(ptr, -(sljit_sw)sizeof(struct block_header));
allocated_size -= header->size; allocated_size -= header->size;
/* Connecting free blocks together if possible. */ /* Connecting free blocks together if possible. */
/* If header->prev_size == 0, free_block will equal to header. /* If header->prev_size == 0, free_block will equal to header.
In this case, free_block->header.size will be > 0. */ In this case, free_block->header.size will be > 0. */
free_block = AS_FREE_BLOCK(header, -(sljit_sw)header->prev_size); free_block = AS_FREE_BLOCK(header, -(sljit_sw)header->prev_size);
if (SLJIT_UNLIKELY(!free_block->header.size)) { if (SLJIT_UNLIKELY(!free_block->header.size)) {
free_block->size += header->size; free_block->size += header->size;
skipping to change at line 362 skipping to change at line 361
/* The whole chunk is free. */ /* The whole chunk is free. */
if (SLJIT_UNLIKELY(!free_block->header.prev_size && header->size == 1)) { if (SLJIT_UNLIKELY(!free_block->header.prev_size && header->size == 1)) {
/* If this block is freed, we still have (allocated_size / 2) fre e space. */ /* If this block is freed, we still have (allocated_size / 2) fre e space. */
if (total_size - free_block->size > (allocated_size * 3 / 2)) { if (total_size - free_block->size > (allocated_size * 3 / 2)) {
total_size -= free_block->size; total_size -= free_block->size;
sljit_remove_free_block(free_block); sljit_remove_free_block(free_block);
free_chunk(free_block, free_block->size + sizeof(struct b lock_header)); free_chunk(free_block, free_block->size + sizeof(struct b lock_header));
} }
} }
allocator_release_lock(); SLJIT_ALLOCATOR_UNLOCK();
} }
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void) SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void)
{ {
struct free_block* free_block; struct free_block* free_block;
struct free_block* next_free_block; struct free_block* next_free_block;
allocator_grab_lock(); SLJIT_ALLOCATOR_LOCK();
free_block = free_blocks; free_block = free_blocks;
while (free_block) { while (free_block) {
next_free_block = free_block->next; next_free_block = free_block->next;
if (!free_block->header.prev_size && if (!free_block->header.prev_size &&
AS_BLOCK_HEADER(free_block, free_block->size)->si ze == 1) { AS_BLOCK_HEADER(free_block, free_block->size)->si ze == 1) {
total_size -= free_block->size; total_size -= free_block->size;
sljit_remove_free_block(free_block); sljit_remove_free_block(free_block);
free_chunk(free_block, free_block->size + sizeof(struct b lock_header)); free_chunk(free_block, free_block->size + sizeof(struct b lock_header));
} }
free_block = next_free_block; free_block = next_free_block;
} }
SLJIT_ASSERT((total_size && free_blocks) || (!total_size && !free_blocks) ); SLJIT_ASSERT((total_size && free_blocks) || (!total_size && !free_blocks) );
allocator_release_lock(); SLJIT_ALLOCATOR_UNLOCK();
} }
 End of changes. 18 change blocks. 
34 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)