OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "defs_GOOS_GOARCH.h" | 6 #include "defs_GOOS_GOARCH.h" |
7 #include "os_GOOS.h" | 7 #include "os_GOOS.h" |
8 #include "signal_unix.h" | 8 #include "signal_unix.h" |
9 #include "stack.h" | 9 #include "stack.h" |
10 #include "../../cmd/ld/textflag.h" | 10 #include "../../cmd/ld/textflag.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 extern void runtime·sigtramp(void); | 242 extern void runtime·sigtramp(void); |
243 | 243 |
244 typedef struct sigaction { | 244 typedef struct sigaction { |
245 union { | 245 union { |
246 void (*__sa_handler)(int32); | 246 void (*__sa_handler)(int32); |
247 void (*__sa_sigaction)(int32, Siginfo*, void *); | 247 void (*__sa_sigaction)(int32, Siginfo*, void *); |
248 } __sigaction_u; /* signal handler */ | 248 } __sigaction_u; /* signal handler */ |
249 int32 sa_flags; /* see signal options below */ | 249 int32 sa_flags; /* see signal options below */ |
250 Sigset sa_mask; /* signal mask to apply */ | 250 Sigset sa_mask; /* signal mask to apply */ |
251 } Sigaction; | 251 } SigactionT; |
252 | 252 |
253 void | 253 void |
254 runtime·setsig(int32 i, GoSighandler *fn, bool restart) | 254 runtime·setsig(int32 i, GoSighandler *fn, bool restart) |
255 { | 255 { |
256 » Sigaction sa; | 256 » SigactionT sa; |
257 | 257 |
258 runtime·memclr((byte*)&sa, sizeof sa); | 258 runtime·memclr((byte*)&sa, sizeof sa); |
259 sa.sa_flags = SA_SIGINFO|SA_ONSTACK; | 259 sa.sa_flags = SA_SIGINFO|SA_ONSTACK; |
260 if(restart) | 260 if(restart) |
261 sa.sa_flags |= SA_RESTART; | 261 sa.sa_flags |= SA_RESTART; |
262 sa.sa_mask.__bits[0] = ~(uint32)0; | 262 sa.sa_mask.__bits[0] = ~(uint32)0; |
263 sa.sa_mask.__bits[1] = ~(uint32)0; | 263 sa.sa_mask.__bits[1] = ~(uint32)0; |
264 sa.sa_mask.__bits[2] = ~(uint32)0; | 264 sa.sa_mask.__bits[2] = ~(uint32)0; |
265 sa.sa_mask.__bits[3] = ~(uint32)0; | 265 sa.sa_mask.__bits[3] = ~(uint32)0; |
266 if(fn == runtime·sighandler) | 266 if(fn == runtime·sighandler) |
267 fn = (void*)runtime·sigtramp; | 267 fn = (void*)runtime·sigtramp; |
268 sa.__sigaction_u.__sa_sigaction = (void*)fn; | 268 sa.__sigaction_u.__sa_sigaction = (void*)fn; |
269 runtime·sigaction(i, &sa, nil); | 269 runtime·sigaction(i, &sa, nil); |
270 } | 270 } |
271 | 271 |
272 GoSighandler* | 272 GoSighandler* |
273 runtime·getsig(int32 i) | 273 runtime·getsig(int32 i) |
274 { | 274 { |
275 » Sigaction sa; | 275 » SigactionT sa; |
276 | 276 |
277 runtime·memclr((byte*)&sa, sizeof sa); | 277 runtime·memclr((byte*)&sa, sizeof sa); |
278 runtime·sigaction(i, nil, &sa); | 278 runtime·sigaction(i, nil, &sa); |
279 if((void*)sa.__sigaction_u.__sa_sigaction == runtime·sigtramp) | 279 if((void*)sa.__sigaction_u.__sa_sigaction == runtime·sigtramp) |
280 return runtime·sighandler; | 280 return runtime·sighandler; |
281 return (void*)sa.__sigaction_u.__sa_sigaction; | 281 return (void*)sa.__sigaction_u.__sa_sigaction; |
282 } | 282 } |
283 | 283 |
284 void | 284 void |
285 runtime·signalstack(byte *p, int32 n) | 285 runtime·signalstack(byte *p, int32 n) |
286 { | 286 { |
287 StackT st; | 287 StackT st; |
288 | 288 |
289 st.ss_sp = (void*)p; | 289 st.ss_sp = (void*)p; |
290 st.ss_size = n; | 290 st.ss_size = n; |
291 st.ss_flags = 0; | 291 st.ss_flags = 0; |
292 if(p == nil) | 292 if(p == nil) |
293 st.ss_flags = SS_DISABLE; | 293 st.ss_flags = SS_DISABLE; |
294 runtime·sigaltstack(&st, nil); | 294 runtime·sigaltstack(&st, nil); |
295 } | 295 } |
296 | 296 |
297 void | 297 void |
298 runtime·unblocksignals(void) | 298 runtime·unblocksignals(void) |
299 { | 299 { |
300 runtime·sigprocmask(&sigset_none, nil); | 300 runtime·sigprocmask(&sigset_none, nil); |
301 } | 301 } |
OLD | NEW |