From 69614c0d0e05787c8203bdc364c3293e1cf5094a Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 5 Dec 2019 14:41:24 -0500 Subject: [PATCH] runtime: give useful failure message on mlock failure Currently, we're ignoring failures to mlock signal stacks in the workaround for #35777. This means if your mlock limit is low, you'll instead get random memory corruption, which seems like the wrong trade-off. This CL checks for mlock failures and panics with useful guidance. Updates #35777. Change-Id: I15f02d3a1fceade79f6ca717500ca5b86d5bd570 Reviewed-on: https://go-review.googlesource.com/c/go/+/210098 Run-TryBot: Austin Clements Reviewed-by: Brad Fitzpatrick Reviewed-by: Cherry Zhang Reviewed-by: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/runtime/os_linux_amd64.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runtime/os_linux_amd64.go b/src/runtime/os_linux_amd64.go index 21e4790c53..cbfcf2e40a 100644 --- a/src/runtime/os_linux_amd64.go +++ b/src/runtime/os_linux_amd64.go @@ -59,5 +59,13 @@ func osArchInit() { } func mlockGsignal(gsignal *g) { - mlock(gsignal.stack.hi-physPageSize, physPageSize) + if err := mlock(gsignal.stack.hi-physPageSize, physPageSize); err < 0 { + printlock() + println("runtime: mlock of signal stack failed:", -err) + if err == -_ENOMEM { + println("runtime: increase the mlock limit (ulimit -l) or") + } + println("runtime: update your kernel to 5.4.2 or later") + throw("mlock failed") + } } -- 2.50.0