OSMem.c 876 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
/* -----------------------------------------------------------------------------
 *
 * (c) The University of Glasgow 2006
 *
 * OS-specific memory management
 *
 * ---------------------------------------------------------------------------*/

#include <windows.h>
simonmar@microsoft.com's avatar
simonmar@microsoft.com committed
10 11
#include "Rts.h"
#include "OSMem.h"
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

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;
simonmar@microsoft.com's avatar
simonmar@microsoft.com committed
29
    if (VirtualProtect (p, len, 
30 31 32 33
			exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, 
			&dwOldProtect) == 0)
    {
	barf("makeExecutable: failed to protect 0x%p; error=%lu; old protection: %lu\n",
simonmar@microsoft.com's avatar
simonmar@microsoft.com committed
34
	     p, (unsigned long)GetLastError(), (unsigned long)dwOldProtect);
35 36
    }
}