--- src/lj_alloc.c | 27 +++++++++++++++++++++++++++ src/lj_arch.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/lj_alloc.c b/src/lj_alloc.c index facccee..f405e1c 100644 --- a/src/lj_alloc.c +++ b/src/lj_alloc.c @@ -194,6 +194,33 @@ static LJ_AINLINE void *CALL_MMAP(size_t size) return ptr; } +#elif defined(__DragonFly__) + +#define MMAP_REGION_START ((uintptr_t)0x1000) +#define MMAP_REGION_END ((uintptr_t)0x80000000) + +static LJ_AINLINE void *CALL_MMAP(size_t size) +{ + int olderr = errno; + /* Hint for next allocation. Doesn't need to be thread-safe. */ + static uintptr_t alloc_hint = MMAP_REGION_START; + int retry = 0; + for (;;) { + void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0); + if ((uintptr_t)p >= 0 && (uintptr_t)p + size < MMAP_REGION_END) { + alloc_hint = (uintptr_t)p + size; + errno = olderr; + return p; + } + if (p != CMFAIL) munmap(p, size); + if (retry) break; + retry = 1; + alloc_hint += 0x100000; + } + errno = olderr; + return CMFAIL; +} + #elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__) /* OSX and FreeBSD mmap() use a naive first-fit linear search. diff --git a/src/lj_arch.h b/src/lj_arch.h index f04da3b..afc5888 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -67,6 +67,7 @@ #elif defined(__MACH__) && defined(__APPLE__) #define LUAJIT_OS LUAJIT_OS_OSX #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__DragonFly__) || \ defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__) #define LUAJIT_OS LUAJIT_OS_BSD #elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__) -- 2.1.0 --nextPart1904913.vajSqoPxc0--