@@ -91,6 +91,10 @@ extern "C"
9191
9292#endif // __APPLE__
9393
94+ #ifdef __HAIKU__
95+ #include < OS.h>
96+ #endif // __HAIKU__
97+
9498#ifdef __linux__
9599#include < sys/syscall.h> // __NR_membarrier
96100// Ensure __NR_membarrier is defined for portable builds.
@@ -527,7 +531,11 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
527531 }
528532
529533 size_t alignedSize = size + (alignment - OS_PAGE_SIZE);
530- void * pRetVal = mmap (nullptr , alignedSize, PROT_NONE, MAP_ANON | MAP_PRIVATE | hugePagesFlag, -1 , 0 );
534+ int mmapFlags = MAP_ANON | MAP_PRIVATE | hugePagesFlag;
535+ #ifdef __HAIKU__
536+ mmapFlags |= MAP_NORESERVE;
537+ #endif
538+ void * pRetVal = mmap (nullptr , alignedSize, PROT_NONE, mmapFlags, -1 , 0 );
531539
532540 if (pRetVal != MAP_FAILED)
533541 {
@@ -661,7 +669,11 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size)
661669 // that much more clear to the operating system that we no
662670 // longer need these pages. Also, GC depends on re-committed pages to
663671 // be zeroed-out.
664- bool bRetVal = mmap (address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1 , 0 ) != MAP_FAILED;
672+ int mmapFlags = MAP_FIXED | MAP_ANON | MAP_PRIVATE;
673+ #ifdef TARGET_HAIKU
674+ mmapFlags |= MAP_NORESERVE;
675+ #endif
676+ bool bRetVal = mmap (address, size, PROT_NONE, mmapFlags, -1 , 0 ) != MAP_FAILED;
665677
666678#ifdef MADV_DONTDUMP
667679 if (bRetVal)
@@ -955,7 +967,7 @@ static uint64_t GetMemorySizeMultiplier(char units)
955967 return 1 ;
956968}
957969
958- #ifndef __APPLE__
970+ #if !defined( __APPLE__) && !defined(__HAIKU__)
959971// Try to read the MemAvailable entry from /proc/meminfo.
960972// Return true if the /proc/meminfo existed, the entry was present and we were able to parse it.
961973static bool ReadMemAvailable (uint64_t * memAvailable)
@@ -988,7 +1000,7 @@ static bool ReadMemAvailable(uint64_t* memAvailable)
9881000
9891001 return foundMemAvailable;
9901002}
991- #endif // __APPLE__
1003+ #endif // !defined( __APPLE__) && !defined(__HAIKU__)
9921004
9931005// Get size of the largest cache on the processor die
9941006// Parameters:
@@ -1189,15 +1201,21 @@ uint64_t GetAvailablePhysicalMemory()
11891201#elif defined(__FreeBSD__)
11901202 size_t inactive_count = 0 , laundry_count = 0 , free_count = 0 ;
11911203 size_t sz = sizeof (inactive_count);
1192- sysctlbyname (" vm.stats.vm.v_inactive_count" , &inactive_count, &sz, NULL , 0 );
1204+ sysctlbyname (" vm.stats.vm.v_inactive_count" , &inactive_count, &sz, NULL , 0 );
11931205
11941206 sz = sizeof (laundry_count);
1195- sysctlbyname (" vm.stats.vm.v_laundry_count" , &laundry_count, &sz, NULL , 0 );
1207+ sysctlbyname (" vm.stats.vm.v_laundry_count" , &laundry_count, &sz, NULL , 0 );
11961208
11971209 sz = sizeof (free_count);
11981210 sysctlbyname (" vm.stats.vm.v_free_count" , &free_count, &sz, NULL , 0 );
11991211
12001212 available = (inactive_count + laundry_count + free_count) * sysconf (_SC_PAGESIZE);
1213+ #elif defined(__HAIKU__)
1214+ system_info info;
1215+ if (get_system_info (&info) == B_OK)
1216+ {
1217+ available = info.free_memory ;
1218+ }
12011219#else // Linux
12021220 static volatile bool tryReadMemInfo = true ;
12031221
0 commit comments