aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-07-18 11:14:28 -0400
committerAustin Clements <austin@google.com>2017-07-21 01:00:33 +0000
commitfa3c5173a5ab4d011cf77ab9775e677d2a9682ea (patch)
treee9e690087a3d4a5e8fb0a7e0c3590dd7a49fb9b5
parent2abd8aebc3cae9c5f4e31d6ab963a2ec77f27c7c (diff)
downloadgo-fa3c5173a5ab4d011cf77ab9775e677d2a9682ea.tar.gz
go-fa3c5173a5ab4d011cf77ab9775e677d2a9682ea.zip
runtime: improve out-of-memory message when VirtualAlloc fails
Fixes #19514. Change-Id: I93600d5c3d11ecab5a47dd4cd55ed3aea05e221e Reviewed-on: https://go-review.googlesource.com/49611 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/runtime/mem_windows.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/runtime/mem_windows.go b/src/runtime/mem_windows.go
index 2c338c8a8c..c37c82ab67 100644
--- a/src/runtime/mem_windows.go
+++ b/src/runtime/mem_windows.go
@@ -16,6 +16,9 @@ const (
_PAGE_READWRITE = 0x0004
_PAGE_NOACCESS = 0x0001
+
+ _ERROR_NOT_ENOUGH_MEMORY = 8
+ _ERROR_COMMITMENT_LIMIT = 1455
)
// Don't split the stack as this function may be invoked without a valid G,
@@ -112,7 +115,13 @@ func sysMap(v unsafe.Pointer, n uintptr, reserved bool, sysStat *uint64) {
mSysStatInc(sysStat, n)
p := stdcall4(_VirtualAlloc, uintptr(v), n, _MEM_COMMIT, _PAGE_READWRITE)
if p != uintptr(v) {
- print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", getlasterror(), "\n")
- throw("runtime: cannot map pages in arena address space")
+ errno := getlasterror()
+ print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", errno, "\n")
+ switch errno {
+ case _ERROR_NOT_ENOUGH_MEMORY, _ERROR_COMMITMENT_LIMIT:
+ throw("out of memory")
+ default:
+ throw("runtime: cannot map pages in arena address space")
+ }
}
}