fe69a341e828108ae78d53e177ccc3bd78a42765
[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
11 lnat getPageSize (void)
12 {
13     static lnat pagesize = 0;
14     if (pagesize) {
15         return pagesize;
16     } else {
17         SYSTEM_INFO sSysInfo;
18         GetSystemInfo(&sSysInfo);
19         pagesize = sSysInfo.dwPageSize;
20         return pagesize;
21     }
22 }
23
24 void setExecutable (void *p, lnat len, rtsBool exec)
25 {
26     DWORD dwOldProtect = 0;
27     if (VirtualProtect (addr, len, 
28                         exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, 
29                         &dwOldProtect) == 0)
30     {
31         barf("makeExecutable: failed to protect 0x%p; error=%lu; old protection: %lu\n",
32              addr, (unsigned long)GetLastError(), (unsigned long)dwOldProtect);
33     }
34 }