]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/runtime/signal_unix.go
runtime/cgo: store M for C-created thread in pthread key
[gostls13.git] / src / runtime / signal_unix.go
index c401fc1b7a572ba95f10c6ad5833c1799ac6bec0..026a503eb1a6ba1cf9f3853baaa4d3d60bc19f63 100644 (file)
@@ -435,7 +435,7 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
        c := &sigctxt{info, ctx}
        gp := sigFetchG(c)
        setg(gp)
-       if gp == nil {
+       if gp == nil || (gp.m != nil && gp.m.isExtraInC) {
                if sig == _SIGPROF {
                        // Some platforms (Linux) have per-thread timers, which we use in
                        // combination with the process-wide timer. Avoid double-counting.
@@ -458,7 +458,18 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
                        return
                }
                c.fixsigcode(sig)
+               // Set g to nil here and badsignal will use g0 by needm.
+               // TODO: reuse the current m here by using the gsignal and adjustSignalStack,
+               // since the current g maybe a normal goroutine and actually running on the signal stack,
+               // it may hit stack split that is not expected here.
+               if gp != nil {
+                       setg(nil)
+               }
                badsignal(uintptr(sig), c)
+               // Restore g
+               if gp != nil {
+                       setg(gp)
+               }
                return
        }
 
@@ -1121,8 +1132,9 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
        //   (1) we weren't in VDSO page,
        //   (2) we were in a goroutine (i.e., m.curg != nil), and
        //   (3) we weren't in CGO.
+       //   (4) we weren't in dropped extra m.
        gp := sigFetchG(c)
-       if gp != nil && gp.m != nil && gp.m.curg != nil && !gp.m.incgo {
+       if gp != nil && gp.m != nil && gp.m.curg != nil && !gp.m.isExtraInC && !gp.m.incgo {
                return false
        }