Commit c2f28de7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: change from rt_sigaction to sigaction

This normalizes the Linux code to act like other targets. The size
argument to the rt_sigaction system call is pushed to a single
function, sysSigaction.

This is intended as a simplification step for CL 93875 for #14327.

Change-Id: I594788e235f0da20e16e8a028e27ac8c883907c4
Reviewed-on: https://go-review.googlesource.com/99077
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
parent d8c9ef9e
...@@ -17,7 +17,7 @@ var _cgo_sigaction unsafe.Pointer ...@@ -17,7 +17,7 @@ var _cgo_sigaction unsafe.Pointer
//go:nosplit //go:nosplit
//go:nowritebarrierrec //go:nowritebarrierrec
func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 { func sigaction(sig uint32, new, old *sigactiont) {
// The runtime package is explicitly blacklisted from sanitizer // The runtime package is explicitly blacklisted from sanitizer
// instrumentation in racewalk.go, but we might be calling into instrumented C // instrumentation in racewalk.go, but we might be calling into instrumented C
// functions here — so we need the pointer parameters to be properly marked. // functions here — so we need the pointer parameters to be properly marked.
...@@ -28,10 +28,8 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 { ...@@ -28,10 +28,8 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 {
msanwrite(unsafe.Pointer(new), unsafe.Sizeof(*new)) msanwrite(unsafe.Pointer(new), unsafe.Sizeof(*new))
} }
var ret int32
if _cgo_sigaction == nil || inForkedChild { if _cgo_sigaction == nil || inForkedChild {
ret = sysSigaction(sig, new, old, size) sysSigaction(sig, new, old)
} else { } else {
// We need to call _cgo_sigaction, which means we need a big enough stack // We need to call _cgo_sigaction, which means we need a big enough stack
// for C. To complicate matters, we may be in libpreinit (before the // for C. To complicate matters, we may be in libpreinit (before the
...@@ -39,17 +37,19 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 { ...@@ -39,17 +37,19 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 {
// the current thread in transition between goroutines, or with the g0 // the current thread in transition between goroutines, or with the g0
// system stack already in use). // system stack already in use).
var ret int32
g := getg() g := getg()
sp := uintptr(unsafe.Pointer(&sig)) sp := uintptr(unsafe.Pointer(&sig))
switch { switch {
case g == nil: case g == nil:
// No g: we're on a C stack or a signal stack. // No g: we're on a C stack or a signal stack.
ret = callCgoSigaction(sig, new, old) ret = callCgoSigaction(uintptr(sig), new, old)
case sp < g.stack.lo || sp >= g.stack.hi: case sp < g.stack.lo || sp >= g.stack.hi:
// We're no longer on g's stack, so we must be handling a signal. It's // We're no longer on g's stack, so we must be handling a signal. It's
// possible that we interrupted the thread during a transition between g // possible that we interrupted the thread during a transition between g
// and g0, so we should stay on the current stack to avoid corrupting g0. // and g0, so we should stay on the current stack to avoid corrupting g0.
ret = callCgoSigaction(sig, new, old) ret = callCgoSigaction(uintptr(sig), new, old)
default: default:
// We're running on g's stack, so either we're not in a signal handler or // We're running on g's stack, so either we're not in a signal handler or
// the signal handler has set the correct g. If we're on gsignal or g0, // the signal handler has set the correct g. If we're on gsignal or g0,
...@@ -60,7 +60,7 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 { ...@@ -60,7 +60,7 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 {
// that's ok: we'll be running on a fresh, clean system stack so the stack // that's ok: we'll be running on a fresh, clean system stack so the stack
// check will always succeed anyway. // check will always succeed anyway.
systemstack(func() { systemstack(func() {
ret = callCgoSigaction(sig, new, old) ret = callCgoSigaction(uintptr(sig), new, old)
}) })
} }
...@@ -69,20 +69,15 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 { ...@@ -69,20 +69,15 @@ func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32 {
// libc reserves certain signals — normally 32-33 — for pthreads, and // libc reserves certain signals — normally 32-33 — for pthreads, and
// returns EINVAL for sigaction calls on those signals. If we get EINVAL, // returns EINVAL for sigaction calls on those signals. If we get EINVAL,
// fall back to making the syscall directly. // fall back to making the syscall directly.
ret = sysSigaction(sig, new, old, size) sysSigaction(sig, new, old)
} }
} }
if msanenabled && old != nil && ret == 0 { if msanenabled && old != nil {
msanread(unsafe.Pointer(old), unsafe.Sizeof(*old)) msanread(unsafe.Pointer(old), unsafe.Sizeof(*old))
} }
return ret
} }
// sysSigaction calls the rt_sigaction system call. It is implemented in assembly.
//go:noescape
func sysSigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
// callCgoSigaction calls the sigaction function in the runtime/cgo package // callCgoSigaction calls the sigaction function in the runtime/cgo package
// using the GCC calling convention. It is implemented in assembly. // using the GCC calling convention. It is implemented in assembly.
//go:noescape //go:noescape
......
...@@ -378,28 +378,26 @@ func setsig(i uint32, fn uintptr) { ...@@ -378,28 +378,26 @@ func setsig(i uint32, fn uintptr) {
} }
} }
sa.sa_handler = fn sa.sa_handler = fn
rt_sigaction(uintptr(i), &sa, nil, unsafe.Sizeof(sa.sa_mask)) sigaction(i, &sa, nil)
} }
//go:nosplit //go:nosplit
//go:nowritebarrierrec //go:nowritebarrierrec
func setsigstack(i uint32) { func setsigstack(i uint32) {
var sa sigactiont var sa sigactiont
rt_sigaction(uintptr(i), nil, &sa, unsafe.Sizeof(sa.sa_mask)) sigaction(i, nil, &sa)
if sa.sa_flags&_SA_ONSTACK != 0 { if sa.sa_flags&_SA_ONSTACK != 0 {
return return
} }
sa.sa_flags |= _SA_ONSTACK sa.sa_flags |= _SA_ONSTACK
rt_sigaction(uintptr(i), &sa, nil, unsafe.Sizeof(sa.sa_mask)) sigaction(i, &sa, nil)
} }
//go:nosplit //go:nosplit
//go:nowritebarrierrec //go:nowritebarrierrec
func getsig(i uint32) uintptr { func getsig(i uint32) uintptr {
var sa sigactiont var sa sigactiont
if rt_sigaction(uintptr(i), nil, &sa, unsafe.Sizeof(sa.sa_mask)) != 0 { sigaction(i, nil, &sa)
throw("rt_sigaction read failure")
}
return sa.sa_handler return sa.sa_handler
} }
...@@ -411,3 +409,15 @@ func setSignalstackSP(s *stackt, sp uintptr) { ...@@ -411,3 +409,15 @@ func setSignalstackSP(s *stackt, sp uintptr) {
func (c *sigctxt) fixsigcode(sig uint32) { func (c *sigctxt) fixsigcode(sig uint32) {
} }
// sysSigaction calls the rt_sigaction system call.
//go:nosplit
func sysSigaction(sig uint32, new, old *sigactiont) {
if rt_sigaction(uintptr(sig), new, old, unsafe.Sizeof(sigactiont{}.sa_mask)) != 0 {
throw("sigaction failed")
}
}
// rt_sigaction is implemented in assembly.
//go:noescape
func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
package runtime package runtime
// rt_sigaction calls the rt_sigaction system call. It is implemented in assembly. // This version is used on Linux systems on which we don't use cgo to
//go:noescape // call the C version of sigaction.
func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
//go:nosplit
//go:nowritebarrierrec
func sigaction(sig uint32, new, old *sigactiont) {
sysSigaction(sig, new, old)
}
...@@ -287,7 +287,7 @@ TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0-28 ...@@ -287,7 +287,7 @@ TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0-28
MOVL $0xf1, 0xf1 // crash MOVL $0xf1, 0xf1 // crash
RET RET
TEXT runtime·sysSigaction(SB),NOSPLIT,$0-36 TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-36
MOVQ sig+0(FP), DI MOVQ sig+0(FP), DI
MOVQ new+8(FP), SI MOVQ new+8(FP), SI
MOVQ old+16(FP), DX MOVQ old+16(FP), DX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment