]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: write sigsetstack for Darwin, fix sigaction arg
authorIan Lance Taylor <iant@golang.org>
Thu, 17 Dec 2015 22:49:34 +0000 (14:49 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 18 Dec 2015 20:56:10 +0000 (20:56 +0000)
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/18015
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/runtime/defs_darwin.go
src/runtime/defs_darwin_386.go
src/runtime/defs_darwin_amd64.go
src/runtime/defs_darwin_arm.go
src/runtime/defs_darwin_arm64.go
src/runtime/os1_darwin.go
src/runtime/os_darwin.go

index 722013ba968581f218e6d0752643fb55e0f00db3..78df4e7ac88570c829a7d16da65629dbd860619d 100644 (file)
@@ -152,7 +152,7 @@ type StackT C.struct_sigaltstack
 type Sighandler C.union___sigaction_u
 
 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 Siginfo C.siginfo_t
 type Timeval C.struct_timeval
index e051301207db75ac284eb5c46af21e7c53a34554..1a5967b24ba8ebe41346a058596c112d8afec395 100644 (file)
@@ -167,6 +167,12 @@ type sigactiont struct {
        sa_flags      int32
 }
 
+type usigactiont struct {
+       __sigaction_u [4]byte
+       sa_mask       uint32
+       sa_flags      int32
+}
+
 type siginfo struct {
        si_signo  int32
        si_errno  int32
index d9d9fc551662ba80bde86d9601b2e593b5c2c07c..a4ab090d51d36ec2af5c1fff7b8445f5f06bf3ad 100644 (file)
@@ -168,6 +168,12 @@ type sigactiont struct {
        sa_flags      int32
 }
 
+type usigactiont struct {
+       __sigaction_u [8]byte
+       sa_mask       uint32
+       sa_flags      int32
+}
+
 type siginfo struct {
        si_signo  int32
        si_errno  int32
index b53336c1b46185bc129b509bca54f8f04360ba68..3f8dbbf25457a1e2e59b8768ed0b7c9fdecef2cd 100644 (file)
@@ -169,6 +169,12 @@ type sigactiont struct {
        sa_flags      int32
 }
 
+type usigactiont struct {
+       __sigaction_u [4]byte
+       sa_mask       uint32
+       sa_flags      int32
+}
+
 type siginfo struct {
        si_signo  int32
        si_errno  int32
index 3cc77c10662895e1d8a607b1baaf0380157d44fd..c25a41b749f73398e5d981b25e8bac30f9355ca7 100644 (file)
@@ -168,6 +168,12 @@ type sigactiont struct {
        sa_flags      int32
 }
 
+type usigactiont struct {
+       __sigaction_u [8]byte
+       sa_mask       uint32
+       sa_flags      int32
+}
+
 type siginfo struct {
        si_signo  int32
        si_errno  int32
index e0bfaa9f77fcd32a1a911be84cea271474db91d3..831533235dc951b71dc74224dc78a37d677cedd5 100644 (file)
@@ -444,7 +444,6 @@ func memlimit() uintptr {
 
 func setsig(i int32, fn uintptr, restart bool) {
        var sa sigactiont
-       memclr(unsafe.Pointer(&sa), unsafe.Sizeof(sa))
        sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK
        if restart {
                sa.sa_flags |= _SA_RESTART
@@ -456,12 +455,22 @@ func setsig(i int32, fn uintptr, restart bool) {
 }
 
 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 {
-       var sa sigactiont
-       memclr(unsafe.Pointer(&sa), unsafe.Sizeof(sa))
+       var sa usigactiont
        sigaction(uint32(i), nil, &sa)
        return *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u))
 }
index 75a6eebb70284651f9ed256cb1b3c6453ae1d912..b8257768ac3488f0e576d463f5455aebac15e672 100644 (file)
@@ -27,7 +27,7 @@ func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, nds
 func sigprocmask(how uint32, new, old *sigset)
 
 //go:noescape
-func sigaction(mode uint32, new, old *sigactiont)
+func sigaction(mode uint32, new *sigactiont, old *usigactiont)
 
 //go:noescape
 func sigaltstack(new, old *stackt)