Skip to content

Commit

Permalink
compatible with FreeBSD mmap()
Browse files Browse the repository at this point in the history
FreeBSD mmap() requires MAP_FIXED to map to desired address.
  • Loading branch information
Dieken authored Oct 27, 2024
1 parent ecf2995 commit 52bca4d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/memoryUnix.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void* allocateJITMemory(usqInt desiredSize, usqInt desiredPosition){
#else
int additionalFlags = 0;
#endif

if (desiredPosition) additionalFlags |= MAP_FIXED;

logDebug("Trying to allocate JIT memory in %p\n", (void* )desiredBaseAddressAligned);

Expand All @@ -123,6 +125,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize, usqInt desiredBaseA
char *heap = 0;
sqInt heapSize = 0;
sqInt heapLimit = 0;
int additionalFlags = desiredBaseAddress ? MAP_FIXED : 0;

pageSize = getpagesize();
pageMask = ~(pageSize - 1);
Expand All @@ -142,7 +145,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize, usqInt desiredBaseA
(void* )desiredBaseAddressAligned);

while ((!heap) && (heapLimit >= minHeapSize)) {
if (MAP_FAILED == (heap = mmap((void*) desiredBaseAddressAligned, heapLimit, MAP_PROT, MAP_FLAGS, devZero, 0))) {
if (MAP_FAILED == (heap = mmap((void*) desiredBaseAddressAligned, heapLimit, MAP_PROT, MAP_FLAGS | additionalFlags, devZero, 0))) {
heap = 0;
heapLimit = valign(heapLimit / 4 * 3);
}
Expand Down

0 comments on commit 52bca4d

Please sign in to comment.