diff options
Diffstat (limited to 'src/pkg/runtime/windows/mem.c')
-rw-r--r-- | src/pkg/runtime/windows/mem.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/pkg/runtime/windows/mem.c b/src/pkg/runtime/windows/mem.c index ba89887ea..19d11ce8d 100644 --- a/src/pkg/runtime/windows/mem.c +++ b/src/pkg/runtime/windows/mem.c @@ -15,16 +15,6 @@ enum { PAGE_EXECUTE_READWRITE = 0x40, }; -static void -abort(int8 *name) -{ - uintptr errno; - - errno = (uintptr)runtime·stdcall(runtime·GetLastError, 0); - runtime·printf("%s failed with errno=%d\n", name, errno); - runtime·throw(name); -} - #pragma dynimport runtime·VirtualAlloc VirtualAlloc "kernel32.dll" #pragma dynimport runtime·VirtualFree VirtualFree "kernel32.dll" extern void *runtime·VirtualAlloc; @@ -33,12 +23,8 @@ extern void *runtime·VirtualFree; void* runtime·SysAlloc(uintptr n) { - void *v; - - v = runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); - if(v == 0) - abort("VirtualAlloc"); - return v; + mstats.sys += n; + return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); } void @@ -53,12 +39,25 @@ runtime·SysFree(void *v, uintptr n) { uintptr r; + mstats.sys -= n; r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE); if(r == 0) - abort("VirtualFree"); + runtime·throw("runtime: failed to release pages"); +} + +void* +runtime·SysReserve(void *v, uintptr n) +{ + return runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_RESERVE, 0); } void -runtime·SysMemInit(void) +runtime·SysMap(void *v, uintptr n) { + void *p; + + mstats.sys += n; + p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if(p != v) + runtime·throw("runtime: cannot map pages in arena address space"); } |