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 openbsd netbsd
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
);
130 // OS X core dumps are linear dumps of the mapped memory,
131 // from the first virtual byte to the last, with zeros in the gaps.
132 // Because of the way we arrange the address space on 64-bit systems,
133 // this means the OS X core file will be >128 GB and even on a zippy
134 // workstation can take OS X well over an hour to write (uninterruptible).
135 // Save users from making that mistake.
136 if(sizeof(void*) == 8)
140 for(i
= 0; runtime_sigtab
[i
].sig
!= -1; i
++)
141 if(runtime_sigtab
[i
].sig
== SIGABRT
)
143 runtime_setsig(i
, GO_SIG_DFL
, false);
144 runtime_raise(SIGABRT
);
148 runtime_raise(int32 sig
)