replace stgMallocBytesRWX() with our own allocator
[ghc-hetmet.git] / rts / win32 / OSMem.c
diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c
new file mode 100644 (file)
index 0000000..fe69a34
--- /dev/null
@@ -0,0 +1,34 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The University of Glasgow 2006
+ *
+ * OS-specific memory management
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include <windows.h>
+
+lnat getPageSize (void)
+{
+    static lnat pagesize = 0;
+    if (pagesize) {
+       return pagesize;
+    } else {
+       SYSTEM_INFO sSysInfo;
+       GetSystemInfo(&sSysInfo);
+       pagesize = sSysInfo.dwPageSize;
+       return pagesize;
+    }
+}
+
+void setExecutable (void *p, lnat len, rtsBool exec)
+{
+    DWORD dwOldProtect = 0;
+    if (VirtualProtect (addr, len, 
+                       exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, 
+                       &dwOldProtect) == 0)
+    {
+       barf("makeExecutable: failed to protect 0x%p; error=%lu; old protection: %lu\n",
+            addr, (unsigned long)GetLastError(), (unsigned long)dwOldProtect);
+    }
+}