Skip to content

Commit

Permalink
applied a new versiono of the patch for DragonFlyBSD compatibility fr…
Browse files Browse the repository at this point in the history
…om lhmwzy in #2.
  • Loading branch information
agentzh authored and fsfod committed Feb 17, 2018
1 parent ad3b824 commit 7be13bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/lj_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ static int CALL_MUNMAP(void *ptr, size_t size)
#define LJ_ALLOC_MMAP_PROBE_LINEAR 5

#define LJ_ALLOC_MMAP_PROBE_LOWER ((uintptr_t)0x4000)
#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;
}


/* No point in a giant ifdef mess. Just try to open /dev/urandom.
** It doesn't really matter if this fails, since we get some ASLR bits from
Expand Down
3 changes: 1 addition & 2 deletions src/lj_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
#elif defined(__MACH__) && defined(__APPLE__)
#define LUAJIT_OS LUAJIT_OS_OSX
#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__DragonFly__)) && !defined(__ORBIS__)
defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__) || defined(__DragonFly__)
#define LUAJIT_OS LUAJIT_OS_BSD
#elif (defined(__sun__) && defined(__svr4__)) || defined(__HAIKU__)
#define LUAJIT_OS LUAJIT_OS_POSIX
Expand Down

0 comments on commit 7be13bc

Please sign in to comment.