summaryrefslogtreecommitdiff
path: root/www/webkit2-gtk3/files/patch-Source_WTF_wtf_RAMSize.cpp
blob: 8c6b00de1d48c87f45b582e88ee967e05b3dbe47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--- Source/WTF/wtf/RAMSize.cpp.orig	2021-09-22 23:29:42 UTC
+++ Source/WTF/wtf/RAMSize.cpp
@@ -35,6 +35,8 @@
 #include <sys/sysinfo.h>
 #elif OS(UNIX)
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
 #endif // OS(LINUX) || OS(UNIX)
 #else
 #include <bmalloc/bmalloc.h>
@@ -56,14 +58,18 @@ static size_t computeRAMSize()
         return ramSizeGuess;
     return status.ullTotalPhys;
 #elif USE(SYSTEM_MALLOC)
-#if OS(LINUX) || OS(FREEBSD)
+#if OS(LINUX)
     struct sysinfo si;
     sysinfo(&si);
     return si.totalram * si.mem_unit;
 #elif OS(UNIX)
-    long pages = sysconf(_SC_PHYS_PAGES);
-    long pageSize = sysconf(_SC_PAGE_SIZE);
-    return pages * pageSize;
+    size_t physmem, len;
+    int mib[2] = { CTL_HW, HW_PHYSMEM };
+    if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0
+	&& len == sizeof(physmem))
+	return physmem;
+    else
+	return 512 * MB; // guess
 #else
 #error "Missing a platform specific way of determining the available RAM"
 #endif // OS(LINUX) || OS(FREEBSD) || OS(UNIX)