Skip to content

Commit fa3c517

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 2abd8ae commit fa3c517

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/runtime/mem_windows.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const (
1616

1717
_PAGE_READWRITE = 0x0004
1818
_PAGE_NOACCESS = 0x0001
19+
20+
_ERROR_NOT_ENOUGH_MEMORY = 8
21+
_ERROR_COMMITMENT_LIMIT = 1455
1922
)
2023

2124
// 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) {
112115
mSysStatInc(sysStat, n)
113116
p := stdcall4(_VirtualAlloc, uintptr(v), n, _MEM_COMMIT, _PAGE_READWRITE)
114117
if p != uintptr(v) {
115-
print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", getlasterror(), "\n")
116-
throw("runtime: cannot map pages in arena address space")
118+
errno := getlasterror()
119+
print("runtime: VirtualAlloc of ", n, " bytes failed with errno=", errno, "\n")
120+
switch errno {
121+
case _ERROR_NOT_ENOUGH_MEMORY, _ERROR_COMMITMENT_LIMIT:
122+
throw("out of memory")
123+
default:
124+
throw("runtime: cannot map pages in arena address space")
125+
}
117126
}
118127
}

0 commit comments

Comments
 (0)