@@ -90,6 +90,10 @@ extern "C"
9090
9191#endif // __APPLE__
9292
93+ #ifdef __HAIKU__
94+ #include < OS.h>
95+ #endif // __HAIKU__
96+
9397#ifdef __linux__
9498#include < sys/syscall.h> // __NR_membarrier
9599// Ensure __NR_membarrier is defined for portable builds.
@@ -572,7 +576,11 @@ static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags,
572576 }
573577
574578 size_t alignedSize = size + (alignment - OS_PAGE_SIZE);
575- void * pRetVal = mmap (nullptr , alignedSize, PROT_NONE, MAP_ANON | MAP_PRIVATE | hugePagesFlag, -1 , 0 );
579+ int mmapFlags = MAP_ANON | MAP_PRIVATE | hugePagesFlag;
580+ #ifdef __HAIKU__
581+ mmapFlags |= MAP_NORESERVE;
582+ #endif
583+ void * pRetVal = mmap (nullptr , alignedSize, PROT_NONE, mmapFlags, -1 , 0 );
576584
577585 if (pRetVal != MAP_FAILED)
578586 {
@@ -721,7 +729,11 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size)
721729 // that much more clear to the operating system that we no
722730 // longer need these pages. Also, GC depends on re-committed pages to
723731 // be zeroed-out.
724- bool bRetVal = mmap (address, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1 , 0 ) != MAP_FAILED;
732+ int mmapFlags = MAP_FIXED | MAP_ANON | MAP_PRIVATE;
733+ #ifdef TARGET_HAIKU
734+ mmapFlags |= MAP_NORESERVE;
735+ #endif
736+ bool bRetVal = mmap (address, size, PROT_NONE, mmapFlags, -1 , 0 ) != MAP_FAILED;
725737
726738#ifdef MADV_DONTDUMP
727739 if (bRetVal)
@@ -1022,7 +1034,7 @@ static uint64_t GetMemorySizeMultiplier(char units)
10221034 return 1 ;
10231035}
10241036
1025- #ifndef __APPLE__
1037+ #if !defined( __APPLE__) && !defined(__HAIKU__)
10261038// Try to read the MemAvailable entry from /proc/meminfo.
10271039// Return true if the /proc/meminfo existed, the entry was present and we were able to parse it.
10281040static bool ReadMemAvailable (uint64_t * memAvailable)
@@ -1055,7 +1067,7 @@ static bool ReadMemAvailable(uint64_t* memAvailable)
10551067
10561068 return foundMemAvailable;
10571069}
1058- #endif // __APPLE__
1070+ #endif // !defined( __APPLE__) && !defined(__HAIKU__)
10591071
10601072// Get size of the largest cache on the processor die
10611073// Parameters:
@@ -1284,6 +1296,12 @@ uint64_t GetAvailablePhysicalMemory()
12841296 sysctlbyname (" vm.stats.vm.v_free_count" , &free_count, &sz, NULL , 0 );
12851297
12861298 available = (inactive_count + laundry_count + free_count) * sysconf (_SC_PAGESIZE);
1299+ #elif defined(__HAIKU__)
1300+ system_info info;
1301+ if (get_system_info (&info) == B_OK)
1302+ {
1303+ available = info.free_memory ;
1304+ }
12871305#else // Linux
12881306 static volatile bool tryReadMemInfo = true ;
12891307
0 commit comments