1 // Copyright 2012 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
11 #include "signal_unix.h"
13 extern SigTab runtime_sigtab
[];
21 // First call: basic setup.
22 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++) {
23 t
= &runtime_sigtab
[i
];
24 if((t
->flags
== 0) || (t
->flags
& SigDefault
))
27 t
->fwdsig
= runtime_getsig(i
);
29 // For some signals, we respect an inherited SIG_IGN handler
30 // rather than insist on installing our own default handler.
31 // Even these signals can be fetched using the os/signal package.
35 if(t
->fwdsig
== GO_SIG_IGN
) {
40 t
->flags
|= SigHandling
;
41 runtime_setsig(i
, runtime_sighandler
, true);
46 runtime_sigenable(uint32 sig
)
52 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++) {
53 if(runtime_sigtab
[i
].sig
== (int32
)sig
) {
54 t
= &runtime_sigtab
[i
];
62 if((t
->flags
& SigNotify
) && !(t
->flags
& SigHandling
)) {
63 t
->flags
|= SigHandling
;
64 t
->fwdsig
= runtime_getsig(i
);
65 runtime_setsig(i
, runtime_sighandler
, true);
70 runtime_sigdisable(uint32 sig
)
76 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++) {
77 if(runtime_sigtab
[i
].sig
== (int32
)sig
) {
78 t
= &runtime_sigtab
[i
];
86 if((sig
== SIGHUP
|| sig
== SIGINT
) && t
->fwdsig
== GO_SIG_IGN
) {
87 t
->flags
&= ~SigHandling
;
88 runtime_setsig(i
, t
->fwdsig
, true);
93 runtime_sigignore(uint32 sig
)
99 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++) {
100 if(runtime_sigtab
[i
].sig
== (int32
)sig
) {
101 t
= &runtime_sigtab
[i
];
109 if((t
->flags
& SigNotify
) != 0) {
110 t
->flags
&= ~SigHandling
;
111 runtime_setsig(i
, GO_SIG_IGN
, true);
116 runtime_resetcpuprofiler(int32 hz
)
120 runtime_memclr((byte
*)&it
, sizeof it
);
122 runtime_setitimer(ITIMER_PROF
, &it
, nil
);
124 it
.it_interval
.tv_sec
= 0;
125 it
.it_interval
.tv_usec
= 1000000 / hz
;
126 it
.it_value
= it
.it_interval
;
127 runtime_setitimer(ITIMER_PROF
, &it
, nil
);
129 runtime_m()->profilehz
= hz
;
133 runtime_unblocksignals(void)
135 sigset_t sigset_none
;
136 sigemptyset(&sigset_none
);
137 pthread_sigmask(SIG_SETMASK
, &sigset_none
, nil
);
146 // OS X core dumps are linear dumps of the mapped memory,
147 // from the first virtual byte to the last, with zeros in the gaps.
148 // Because of the way we arrange the address space on 64-bit systems,
149 // this means the OS X core file will be >128 GB and even on a zippy
150 // workstation can take OS X well over an hour to write (uninterruptible).
151 // Save users from making that mistake.
152 if(sizeof(void*) == 8)
156 runtime_unblocksignals();
157 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++)
158 if(runtime_sigtab
[i
].sig
== SIGABRT
)
160 runtime_setsig(i
, GO_SIG_DFL
, false);
161 runtime_raise(SIGABRT
);
165 runtime_raise(int32 sig
)