[MLton-commit] r5815

Matthew Fluet fluet at mlton.org
Thu Aug 2 15:09:30 PDT 2007


32-bit systems with more than 4GB physical memory might overflow the
GC_totalRam computation (yielding actual total RAM `mod` 4GB).  So,
compute at uintmax_t and return min of actual total RAM and SIZE_MAX;
we can't return more than the virtual address space allows.


----------------------------------------------------------------------

U   mlton/trunk/runtime/platform/sysconf.c

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/platform/sysconf.c
===================================================================
--- mlton/trunk/runtime/platform/sysconf.c	2007-08-02 20:03:40 UTC (rev 5814)
+++ mlton/trunk/runtime/platform/sysconf.c	2007-08-02 22:09:29 UTC (rev 5815)
@@ -1,14 +1,21 @@
 size_t GC_pageSize (void) {
-  long int tmp;
+  long int pageSize;
 
-  tmp = sysconf (_SC_PAGESIZE);
-  return (size_t)tmp;
+  pageSize = sysconf (_SC_PAGESIZE);
+  return (size_t)pageSize;
 }
 
 size_t GC_totalRam (void) {
   size_t pageSize = GC_pageSize ();
-  long int tmp;
+  long int physPages;
+  uintmax_t totalRam;
 
-  tmp = sysconf (_SC_PHYS_PAGES);
-  return pageSize * (size_t)tmp;
+  physPages = sysconf (_SC_PHYS_PAGES);
+  totalRam = (uintmax_t)pageSize * (uintmax_t)physPages;
+  if (sizeof(size_t) >= sizeof(uintmax_t)) {
+    return (uintmax_t)totalRam;
+  } else {
+    totalRam = min(totalRam, (uintmax_t)SIZE_MAX);
+    return (size_t)totalRam;
+  }
 }




More information about the MLton-commit mailing list