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

runtime: write sigsetstack for Darwin, fix sigaction arg

It turns out that the second argument for sigaction on Darwin has a
different type than the first argument.  The second argument is the user
visible sigaction struct, and does not have the sa_tramp field.

I base this on
  http://www.opensource.apple.com/source/Libc/Libc-1081.1.3/sys/sigaction.c
not to mention actual testing.

While I was at it I removed a useless memclr in setsig, a relic of the C
code.

This CL is Darwin-specific changes.  The tests for this CL are in
https://golang.org/cl/17903 .

Change-Id: I61fe305c72311df6a589b49ad7b6e49b6960ca24
Reviewed-on: https://go-review.googlesource.com/18015Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent e5ef5d46
...@@ -152,7 +152,7 @@ type StackT C.struct_sigaltstack ...@@ -152,7 +152,7 @@ type StackT C.struct_sigaltstack
type Sighandler C.union___sigaction_u type Sighandler C.union___sigaction_u
type Sigaction C.struct___sigaction // used in syscalls type Sigaction C.struct___sigaction // used in syscalls
// type Sigaction C.struct_sigaction // used by the C library type Usigaction C.struct_sigaction // used by sigaction second argument
type Sigval C.union_sigval type Sigval C.union_sigval
type Siginfo C.siginfo_t type Siginfo C.siginfo_t
type Timeval C.struct_timeval type Timeval C.struct_timeval
......
...@@ -167,6 +167,12 @@ type sigactiont struct { ...@@ -167,6 +167,12 @@ type sigactiont struct {
sa_flags int32 sa_flags int32
} }
type usigactiont struct {
__sigaction_u [4]byte
sa_mask uint32
sa_flags int32
}
type siginfo struct { type siginfo struct {
si_signo int32 si_signo int32
si_errno int32 si_errno int32
......
...@@ -168,6 +168,12 @@ type sigactiont struct { ...@@ -168,6 +168,12 @@ type sigactiont struct {
sa_flags int32 sa_flags int32
} }
type usigactiont struct {
__sigaction_u [8]byte
sa_mask uint32
sa_flags int32
}
type siginfo struct { type siginfo struct {
si_signo int32 si_signo int32
si_errno int32 si_errno int32
......
...@@ -169,6 +169,12 @@ type sigactiont struct { ...@@ -169,6 +169,12 @@ type sigactiont struct {
sa_flags int32 sa_flags int32
} }
type usigactiont struct {
__sigaction_u [4]byte
sa_mask uint32
sa_flags int32
}
type siginfo struct { type siginfo struct {
si_signo int32 si_signo int32
si_errno int32 si_errno int32
......
...@@ -168,6 +168,12 @@ type sigactiont struct { ...@@ -168,6 +168,12 @@ type sigactiont struct {
sa_flags int32 sa_flags int32
} }
type usigactiont struct {
__sigaction_u [8]byte
sa_mask uint32
sa_flags int32
}
type siginfo struct { type siginfo struct {
si_signo int32 si_signo int32
si_errno int32 si_errno int32
......
...@@ -444,7 +444,6 @@ func memlimit() uintptr { ...@@ -444,7 +444,6 @@ func memlimit() uintptr {
func setsig(i int32, fn uintptr, restart bool) { func setsig(i int32, fn uintptr, restart bool) {
var sa sigactiont var sa sigactiont
memclr(unsafe.Pointer(&sa), unsafe.Sizeof(sa))
sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK
if restart { if restart {
sa.sa_flags |= _SA_RESTART sa.sa_flags |= _SA_RESTART
...@@ -456,12 +455,22 @@ func setsig(i int32, fn uintptr, restart bool) { ...@@ -456,12 +455,22 @@ func setsig(i int32, fn uintptr, restart bool) {
} }
func setsigstack(i int32) { func setsigstack(i int32) {
throw("setsigstack") var osa usigactiont
sigaction(uint32(i), nil, &osa)
handler := *(*uintptr)(unsafe.Pointer(&osa.__sigaction_u))
if handler == 0 || handler == _SIG_DFL || handler == _SIG_IGN || osa.sa_flags&_SA_ONSTACK != 0 {
return
}
var sa sigactiont
*(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) = handler
sa.sa_tramp = unsafe.Pointer(funcPC(sigtramp))
sa.sa_mask = osa.sa_mask
sa.sa_flags = osa.sa_flags | _SA_ONSTACK
sigaction(uint32(i), &sa, nil)
} }
func getsig(i int32) uintptr { func getsig(i int32) uintptr {
var sa sigactiont var sa usigactiont
memclr(unsafe.Pointer(&sa), unsafe.Sizeof(sa))
sigaction(uint32(i), nil, &sa) sigaction(uint32(i), nil, &sa)
return *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) return *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u))
} }
......
...@@ -27,7 +27,7 @@ func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, nds ...@@ -27,7 +27,7 @@ func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, nds
func sigprocmask(how uint32, new, old *sigset) func sigprocmask(how uint32, new, old *sigset)
//go:noescape //go:noescape
func sigaction(mode uint32, new, old *sigactiont) func sigaction(mode uint32, new *sigactiont, old *usigactiont)
//go:noescape //go:noescape
func sigaltstack(new, old *stackt) func sigaltstack(new, old *stackt)
......
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