Skip to content

Commit 8017ace

Browse files
Elias Naurianlancetaylor
Elias Naur
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent eeb64b7 commit 8017ace

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/runtime/os1_openbsd.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func mpreinit(mp *m) {
149149
}
150150

151151
func msigsave(mp *m) {
152+
smask := (*uint32)(unsafe.Pointer(&mp.sigmask))
153+
if unsafe.Sizeof(*smask) > unsafe.Sizeof(mp.sigmask) {
154+
throw("insufficient storage for signal mask")
155+
}
156+
*smask = sigprocmask(_SIG_BLOCK, 0)
152157
}
153158

154159
// Called to initialize a new m (including the bootstrap m).
@@ -161,11 +166,22 @@ func minit() {
161166

162167
// Initialize signal handling
163168
signalstack((*byte)(unsafe.Pointer(_g_.m.gsignal.stack.lo)), 32*1024)
164-
sigprocmask(_SIG_SETMASK, sigset_none)
169+
170+
// restore signal mask from m.sigmask and unblock essential signals
171+
nmask := *(*uint32)(unsafe.Pointer(&_g_.m.sigmask))
172+
for i := range sigtable {
173+
if sigtable[i].flags&_SigUnblock != 0 {
174+
nmask &^= 1 << (uint32(i) - 1)
175+
}
176+
}
177+
sigprocmask(_SIG_SETMASK, nmask)
165178
}
166179

167180
// Called from dropm to undo the effect of an minit.
168181
func unminit() {
182+
_g_ := getg()
183+
smask := *(*uint32)(unsafe.Pointer(&_g_.m.sigmask))
184+
sigprocmask(_SIG_SETMASK, smask)
169185
signalstack(nil, 0)
170186
}
171187

0 commit comments

Comments
 (0)