Massive patch for the first months work adding System FC to GHC #35
[ghc-hetmet.git] / rts / win32 / OSMem.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The University of Glasgow 2006
4  *
5  * OS-specific memory management
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #include <windows.h>
10 #include "Rts.h"
11 #include "OSMem.h"
12
13 lnat getPageSize (void)
14 {
15     static lnat pagesize = 0;
16     if (pagesize) {
17         return pagesize;
18     } else {
19         SYSTEM_INFO sSysInfo;
20         GetSystemInfo(&sSysInfo);
21         pagesize = sSysInfo.dwPageSize;
22         return pagesize;
23     }
24 }
25
26 void setExecutable (void *p, lnat len, rtsBool exec)
27 {
28     DWORD dwOldProtect = 0;
29     if (VirtualProtect (p, len, 
30                         exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, 
31                         &dwOldProtect) == 0)
32     {
33         barf("makeExecutable: failed to protect 0x%p; error=%lu; old protection: %lu\n",
34              p, (unsigned long)GetLastError(), (unsigned long)dwOldProtect);
35     }
36 }