Commit 048692e5 authored by Russ Cox's avatar Russ Cox

runtime: fix Windows SysUsed

Same fix as for SysUnused.
Fixes #8038.

LGTM=iant, alex.brainman
R=golang-codereviews, iant, alex.brainman
CC=golang-codereviews
https://golang.org/cl/147820043
parent 54245cba
...@@ -68,10 +68,22 @@ void ...@@ -68,10 +68,22 @@ void
runtime·SysUsed(void *v, uintptr n) runtime·SysUsed(void *v, uintptr n)
{ {
void *r; void *r;
uintptr small;
r = runtime·stdcall4(runtime·VirtualAlloc, (uintptr)v, n, MEM_COMMIT, PAGE_READWRITE); r = runtime·stdcall4(runtime·VirtualAlloc, (uintptr)v, n, MEM_COMMIT, PAGE_READWRITE);
if(r != v) if(r != v)
runtime·throw("runtime: failed to commit pages"); runtime·throw("runtime: failed to commit pages");
// Commit failed. See SysUnused.
while(n > 0) {
small = n;
while(small >= 4096 && runtime·stdcall4(runtime·VirtualAlloc, (uintptr)v, small, MEM_COMMIT, PAGE_READWRITE) == nil)
small = (small / 2) & ~(4096-1);
if(small < 4096)
runtime·throw("runtime: failed to decommit pages");
v = (byte*)v + small;
n -= small;
}
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment