1 // Copyright 2016 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.
5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
13 // Functions for gccgo to support signal handling. In the gc runtime
14 // these are written in OS-specific files and in assembler.
17 func sigaction(signum
uint32, act
*_sigaction
, oact
*_sigaction
) int32
20 func sigprocmask(how
int32, set
*sigset
, oldset
*sigset
) int32
23 func sigfillset(set
*sigset
) int32
26 func sigemptyset(set
*sigset
) int32
29 func c_sigaddset(set
*sigset
, signum
uint32) int32
32 func c_sigdelset(set
*sigset
, signum
uint32) int32
35 func sigaltstack(ss
*_stack_t
, oss
*_stack_t
) int32
38 func raise(sig
uint32) int32
44 func kill(pid _pid_t
, sig
uint32) int32
47 func setitimer(which
int32, new *_itimerval
, old
*_itimerval
) int32
59 func (c
*sigctxt
) sigcode() uint64 {
61 // This can happen on Solaris 10. We don't know the
62 // code, just avoid a misleading value.
65 return uint64(c
.info
.si_code
)
69 //go:nowritebarrierrec
70 func setsig(i
uint32, fn
uintptr) {
72 sa
.sa_flags
= _SA_SIGINFO | _SA_RESTART
74 // For gccgo we do not set SA_ONSTACK for a signal that can
75 // cause a panic. Instead, we trust that the split stack has
76 // enough room to start the signal handler. This is because
77 // otherwise we have no good way to switch back to the
78 // original stack before panicing.
79 if sigtable
[i
].flags
&_SigPanic
== 0 {
80 sa
.sa_flags |
= _SA_ONSTACK
83 sigfillset((*sigset
)(unsafe
.Pointer(&sa
.sa_mask
)))
84 setSigactionHandler(&sa
, fn
)
85 sigaction(i
, &sa
, nil)
89 //go:nowritebarrierrec
90 func setsigstack(i
uint32) {
92 sigaction(i
, nil, &sa
)
93 handler
:= getSigactionHandler(&sa
)
94 if handler
== 0 || handler
== _SIG_DFL || handler
== _SIG_IGN || sa
.sa_flags
&_SA_ONSTACK
!= 0 {
97 if sigtable
[i
].flags
&_SigPanic
!= 0 {
100 sa
.sa_flags |
= _SA_ONSTACK
101 sigaction(i
, &sa
, nil)
105 //go:nowritebarrierrec
106 func getsig(i
uint32) uintptr {
108 if sigaction(i
, nil, &sa
) < 0 {
109 // On GNU/Linux glibc rejects attempts to call
110 // sigaction with signal 32 (SIGCANCEL) or 33 (SIGSETXID).
111 if GOOS
== "linux" && (i
== 32 || i
== 33) {
114 throw("sigaction read failure")
116 return getSigactionHandler(&sa
)
119 func signalstack(p unsafe
.Pointer
, n
uintptr)
122 //go:nowritebarrierrec
123 func raiseproc(sig
uint32) {
128 //go:nowritebarrierrec
129 func sigfwd(fn
uintptr, sig
uint32, info
*_siginfo_t
, ctx unsafe
.Pointer
) {
130 f1
:= &[1]uintptr{fn
}
131 f2
:= *(*func(uint32, *_siginfo_t
, unsafe
.Pointer
))(unsafe
.Pointer(&f1
))
136 //go:nowritebarrierrec
137 func sigaddset(mask
*sigset
, i
int) {
138 c_sigaddset(mask
, uint32(i
))
141 func sigdelset(mask
*sigset
, i
int) {
142 c_sigdelset(mask
, uint32(i
))