OK,I apply the fllowing patch and works fine.
the patch is from John Marino@DrgonFlyBSD
It works under LuaJIT-2.0.2 and LuaJit 2.1
---
lj_arch.h.org 2014-02-14 16:32:03.125932000 +0000
+++ lj_arch.h 2014-02-14 16:32:34.725951000 +0000
@@ -67,7 +67,7 @@
#elif defined(__MACH__) && defined(__APPLE__)
#define LUAJIT_OS LUAJIT_OS_OSX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
- defined(__NetBSD__) || defined(__OpenBSD__)
+ defined(__NetBSD__) || defined(__OpenBSD__)|| defined(__DragonFly__)
#define LUAJIT_OS LUAJIT_OS_BSD
#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
#define LUAJIT_OS LUAJIT_OS_POSIX
---
lj_alloc.c.org 2014-02-14 16:33:19.015979000 +0000
+++ lj_alloc.c 2014-02-14 16:32:50.225961000 +0000
@@ -188,6 +188,33 @@
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 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__sun__)
/* OSX and FreeBSD mmap() use a naive first-fit linear search.