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 // For some signals, we respect an inherited SIG_IGN handler
28 // rather than insist on installing our own default handler.
29 // Even these signals can be fetched using the os/signal package.
33 if(runtime_getsig(i
) == GO_SIG_IGN
) {
34 t
->flags
= SigNotify
| SigIgnored
;
39 t
->flags
|= SigHandling
;
40 runtime_setsig(i
, runtime_sighandler
, true);
45 runtime_sigenable(uint32 sig
)
51 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++) {
52 if(runtime_sigtab
[i
].sig
== (int32
)sig
) {
53 t
= &runtime_sigtab
[i
];
61 if((t
->flags
& SigNotify
) && !(t
->flags
& SigHandling
)) {
62 t
->flags
|= SigHandling
;
63 if(runtime_getsig(i
) == GO_SIG_IGN
)
64 t
->flags
|= SigIgnored
;
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((t
->flags
& SigNotify
) && (t
->flags
& SigHandling
)) {
87 t
->flags
&= ~SigHandling
;
88 if(t
->flags
& SigIgnored
)
89 runtime_setsig(i
, GO_SIG_IGN
, true);
91 runtime_setsig(i
, GO_SIG_DFL
, true);
96 runtime_resetcpuprofiler(int32 hz
)
100 runtime_memclr((byte
*)&it
, sizeof it
);
102 runtime_setitimer(ITIMER_PROF
, &it
, nil
);
104 it
.it_interval
.tv_sec
= 0;
105 it
.it_interval
.tv_usec
= 1000000 / hz
;
106 it
.it_value
= it
.it_interval
;
107 runtime_setitimer(ITIMER_PROF
, &it
, nil
);
109 runtime_m()->profilehz
= hz
;
117 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++)
118 if(runtime_sigtab
[i
].sig
== SIGPIPE
)
120 runtime_setsig(i
, GO_SIG_DFL
, false);
121 runtime_raise(SIGPIPE
);
125 runtime_unblocksignals(void)
127 sigset_t sigset_none
;
128 sigemptyset(&sigset_none
);
129 pthread_sigmask(SIG_SETMASK
, &sigset_none
, nil
);
138 // OS X core dumps are linear dumps of the mapped memory,
139 // from the first virtual byte to the last, with zeros in the gaps.
140 // Because of the way we arrange the address space on 64-bit systems,
141 // this means the OS X core file will be >128 GB and even on a zippy
142 // workstation can take OS X well over an hour to write (uninterruptible).
143 // Save users from making that mistake.
144 if(sizeof(void*) == 8)
148 runtime_unblocksignals();
149 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++)
150 if(runtime_sigtab
[i
].sig
== SIGABRT
)
152 runtime_setsig(i
, GO_SIG_DFL
, false);
153 runtime_raise(SIGABRT
);
157 runtime_raise(int32 sig
)