diff --git a/src/pkg/runtime/mem_darwin.c b/src/pkg/runtime/mem_darwin.c index fe99c1aff15..47fe2a525ff 100644 --- a/src/pkg/runtime/mem_darwin.c +++ b/src/pkg/runtime/mem_darwin.c @@ -44,7 +44,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_dragonfly.c b/src/pkg/runtime/mem_dragonfly.c index f19a39950b2..ada820c2de8 100644 --- a/src/pkg/runtime/mem_dragonfly.c +++ b/src/pkg/runtime/mem_dragonfly.c @@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_freebsd.c b/src/pkg/runtime/mem_freebsd.c index b8895567d21..1d6024013b8 100644 --- a/src/pkg/runtime/mem_freebsd.c +++ b/src/pkg/runtime/mem_freebsd.c @@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_linux.c b/src/pkg/runtime/mem_linux.c index bab05011ff1..2ead204101f 100644 --- a/src/pkg/runtime/mem_linux.c +++ b/src/pkg/runtime/mem_linux.c @@ -95,7 +95,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_nacl.c b/src/pkg/runtime/mem_nacl.c index b3cf91d7f0e..c743259cc06 100644 --- a/src/pkg/runtime/mem_nacl.c +++ b/src/pkg/runtime/mem_nacl.c @@ -56,7 +56,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_netbsd.c b/src/pkg/runtime/mem_netbsd.c index 5ad7937d0f2..ed0a0583699 100644 --- a/src/pkg/runtime/mem_netbsd.c +++ b/src/pkg/runtime/mem_netbsd.c @@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_openbsd.c b/src/pkg/runtime/mem_openbsd.c index 5ad7937d0f2..ed0a0583699 100644 --- a/src/pkg/runtime/mem_openbsd.c +++ b/src/pkg/runtime/mem_openbsd.c @@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_solaris.c b/src/pkg/runtime/mem_solaris.c index 2379cdff9f8..f82a25b0312 100644 --- a/src/pkg/runtime/mem_solaris.c +++ b/src/pkg/runtime/mem_solaris.c @@ -49,7 +49,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - runtime·mmap(v, n, PROT_NONE, 0, -1, 0); + runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); } void* diff --git a/src/pkg/runtime/mem_windows.c b/src/pkg/runtime/mem_windows.c index 3c6fef60cff..c0820082599 100644 --- a/src/pkg/runtime/mem_windows.c +++ b/src/pkg/runtime/mem_windows.c @@ -66,11 +66,8 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat) void runtime·SysFault(void *v, uintptr n) { - uintptr r, old; - - r = (uintptr)runtime·stdcall(runtime·VirtualProtect, 4, v, n, (uintptr)PAGE_NOACCESS, &old); - if(r == 0) - runtime·throw("runtime: failed to protect pages"); + // SysUnused makes the memory inaccessible and prevents its reuse + runtime·SysUnused(v, n); } void*