-static u64
-get_avail_memory(void)
-{
-#ifdef __WIN32__
- u64 phys_bytes = win32_get_avail_memory();
- if (phys_bytes == 0)
- goto default_size;
- return phys_bytes;
-#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
- long page_size = sysconf(_SC_PAGESIZE);
- long num_pages = sysconf(_SC_PHYS_PAGES);
- if (page_size <= 0 || num_pages <= 0)
- goto default_size;
- return ((u64)page_size * (u64)num_pages);
-#else
- int mib[2] = {CTL_HW, HW_MEMSIZE};
- u64 memsize;
- size_t len = sizeof(memsize);
- if (sysctl(mib, ARRAY_LEN(mib), &memsize, &len, NULL, 0) < 0 || len != 8)
- goto default_size;
- return memsize;
-#endif
-
-default_size:
- WARNING("Failed to determine available memory; assuming 1 GiB");
- return 1ULL << 30;
-}