summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/windows/mem.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
committerOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
commit758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch)
tree6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/runtime/windows/mem.c
parent3e45412327a2654a77944249962b3652e6142299 (diff)
downloadgolang-upstream/2011-02-01.1.tar.gz
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/runtime/windows/mem.c')
-rw-r--r--src/pkg/runtime/windows/mem.c35
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");
}