//go:nosplit
//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
// instrumentation in racewalk.go, but we might be calling into instrumented C
// functions here — so we need the pointer parameters to be properly marked.
msanwrite(unsafe.Pointer(new), unsafe.Sizeof(*new))
}
- var ret int32
-
if _cgo_sigaction == nil || inForkedChild {
- ret = sysSigaction(sig, new, old, size)
+ sysSigaction(sig, new, old)
} else {
// 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
// the current thread in transition between goroutines, or with the g0
// system stack already in use).
+ var ret int32
+
g := getg()
sp := uintptr(unsafe.Pointer(&sig))
switch {
case g == nil:
// 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:
// 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
// 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:
// 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,
// that's ok: we'll be running on a fresh, clean system stack so the stack
// check will always succeed anyway.
systemstack(func() {
- ret = callCgoSigaction(sig, new, old)
+ ret = callCgoSigaction(uintptr(sig), new, old)
})
}
// libc reserves certain signals — normally 32-33 — for pthreads, and
// returns EINVAL for sigaction calls on those signals. If we get EINVAL,
// 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))
}
- 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
// using the GCC calling convention. It is implemented in assembly.
//go:noescape
}
}
sa.sa_handler = fn
- rt_sigaction(uintptr(i), &sa, nil, unsafe.Sizeof(sa.sa_mask))
+ sigaction(i, &sa, nil)
}
//go:nosplit
//go:nowritebarrierrec
func setsigstack(i uint32) {
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 {
return
}
sa.sa_flags |= _SA_ONSTACK
- rt_sigaction(uintptr(i), &sa, nil, unsafe.Sizeof(sa.sa_mask))
+ sigaction(i, &sa, nil)
}
//go:nosplit
//go:nowritebarrierrec
func getsig(i uint32) uintptr {
var sa sigactiont
- if rt_sigaction(uintptr(i), nil, &sa, unsafe.Sizeof(sa.sa_mask)) != 0 {
- throw("rt_sigaction read failure")
- }
+ sigaction(i, nil, &sa)
return sa.sa_handler
}
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