github.com/aloncn/graphics-go@v0.0.1/src/runtime/signal_sigtramp.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build dragonfly linux netbsd 6 7 package runtime 8 9 import "unsafe" 10 11 // Continuation of the (assembly) sigtramp() logic. 12 // This may be called with the world stopped. 13 //go:nosplit 14 //go:nowritebarrierrec 15 func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) { 16 if sigfwdgo(sig, info, ctx) { 17 return 18 } 19 g := getg() 20 if g == nil { 21 badsignal(uintptr(sig)) 22 return 23 } 24 25 // If some non-Go code called sigaltstack, adjust. 26 sp := uintptr(unsafe.Pointer(&sig)) 27 if sp < g.m.gsignal.stack.lo || sp >= g.m.gsignal.stack.hi { 28 var st sigaltstackt 29 sigaltstack(nil, &st) 30 if st.ss_flags&_SS_DISABLE != 0 { 31 setg(nil) 32 cgocallback(unsafe.Pointer(funcPC(noSignalStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig)) 33 } 34 stsp := uintptr(unsafe.Pointer(st.ss_sp)) 35 if sp < stsp || sp >= stsp+st.ss_size { 36 setg(nil) 37 cgocallback(unsafe.Pointer(funcPC(sigNotOnStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig)) 38 } 39 g.m.gsignal.stack.lo = stsp 40 g.m.gsignal.stack.hi = stsp + st.ss_size 41 g.m.gsignal.stackguard0 = stsp + _StackGuard 42 g.m.gsignal.stackguard1 = stsp + _StackGuard 43 g.m.gsignal.stackAlloc = st.ss_size 44 g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig)) 45 } 46 47 setg(g.m.gsignal) 48 sighandler(sig, info, ctx, g) 49 setg(g) 50 }