From 8017ace496f5a21bcd55377e250e325f8ba11d45 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 23 May 2015 11:26:22 +0200 Subject: [PATCH] runtime: don't always block all signals on OpenBSD Implement the changes from CL 10173 on OpenBSD. Change-Id: I2db1cd8141fd392a34753a1b8113e2e0401173b9 Reviewed-on: https://go-review.googlesource.com/10342 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/os1_openbsd.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/runtime/os1_openbsd.go b/src/runtime/os1_openbsd.go index 98af545f7f..5ccf642468 100644 --- a/src/runtime/os1_openbsd.go +++ b/src/runtime/os1_openbsd.go @@ -149,6 +149,11 @@ func mpreinit(mp *m) { } func msigsave(mp *m) { + smask := (*uint32)(unsafe.Pointer(&mp.sigmask)) + if unsafe.Sizeof(*smask) > unsafe.Sizeof(mp.sigmask) { + throw("insufficient storage for signal mask") + } + *smask = sigprocmask(_SIG_BLOCK, 0) } // Called to initialize a new m (including the bootstrap m). @@ -161,11 +166,22 @@ func minit() { // Initialize signal handling signalstack((*byte)(unsafe.Pointer(_g_.m.gsignal.stack.lo)), 32*1024) - sigprocmask(_SIG_SETMASK, sigset_none) + + // restore signal mask from m.sigmask and unblock essential signals + nmask := *(*uint32)(unsafe.Pointer(&_g_.m.sigmask)) + for i := range sigtable { + if sigtable[i].flags&_SigUnblock != 0 { + nmask &^= 1 << (uint32(i) - 1) + } + } + sigprocmask(_SIG_SETMASK, nmask) } // Called from dropm to undo the effect of an minit. func unminit() { + _g_ := getg() + smask := *(*uint32)(unsafe.Pointer(&_g_.m.sigmask)) + sigprocmask(_SIG_SETMASK, smask) signalstack(nil, 0) }