mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: preserve signal stack when calling Go on C thread
When calling a Go function on a C thread, if the C thread already has an alternate signal stack, use that signal stack instead of installing a new one. Update #9896. Change-Id: I62aa3a6a4a1dc4040fca050757299c8e6736987c Reviewed-on: https://go-review.googlesource.com/18108 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
62c280ac1c
commit
a7cad52e04
11 changed files with 383 additions and 14 deletions
|
|
@ -152,7 +152,22 @@ func sigblock() {
|
|||
func minit() {
|
||||
// Initialize signal handling.
|
||||
_g_ := getg()
|
||||
signalstack(&_g_.m.gsignal.stack)
|
||||
|
||||
var st stackt
|
||||
sigaltstack(nil, &st)
|
||||
if st.ss_flags&_SS_DISABLE != 0 {
|
||||
signalstack(&_g_.m.gsignal.stack)
|
||||
_g_.m.newSigstack = true
|
||||
} else {
|
||||
// Use existing signal stack.
|
||||
stsp := uintptr(unsafe.Pointer(st.ss_sp))
|
||||
_g_.m.gsignal.stack.lo = stsp
|
||||
_g_.m.gsignal.stack.hi = stsp + st.ss_size
|
||||
_g_.m.gsignal.stackguard0 = stsp + _StackGuard
|
||||
_g_.m.gsignal.stackguard1 = stsp + _StackGuard
|
||||
_g_.m.gsignal.stackAlloc = st.ss_size
|
||||
_g_.m.newSigstack = false
|
||||
}
|
||||
|
||||
// restore signal mask from m.sigmask and unblock essential signals
|
||||
nmask := _g_.m.sigmask
|
||||
|
|
@ -167,7 +182,9 @@ func minit() {
|
|||
// Called from dropm to undo the effect of an minit.
|
||||
//go:nosplit
|
||||
func unminit() {
|
||||
signalstack(nil)
|
||||
if getg().m.newSigstack {
|
||||
signalstack(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// Mach IPC, to get at semaphores
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue