mirror of
https://github.com/golang/go
synced 2024-11-26 00:57:56 -07:00
runtime: fix SysFree to really free memory on Windows
Fixes #1294. R=golang-dev, PeterGo, iant CC=golang-dev https://golang.org/cl/3271041
This commit is contained in:
parent
86cdbfb5eb
commit
4e69976a60
@ -15,10 +15,25 @@ enum {
|
|||||||
PAGE_EXECUTE_READWRITE = 0x40,
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
runtime·SysAlloc(uintptr n)
|
runtime·SysAlloc(uintptr n)
|
||||||
{
|
{
|
||||||
return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
void *v;
|
||||||
|
|
||||||
|
v = runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||||
|
if(v == 0)
|
||||||
|
abort("VirtualAlloc");
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -31,7 +46,11 @@ runtime·SysUnused(void *v, uintptr n)
|
|||||||
void
|
void
|
||||||
runtime·SysFree(void *v, uintptr n)
|
runtime·SysFree(void *v, uintptr n)
|
||||||
{
|
{
|
||||||
runtime·stdcall(runtime·VirtualFree, 3, v, n, MEM_RELEASE);
|
uintptr r;
|
||||||
|
|
||||||
|
r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE);
|
||||||
|
if(r == 0)
|
||||||
|
abort("VirtualFree");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user