github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/runtime/signal1_unix.go (about) 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. 4 5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 7 package runtime 8 9 const ( 10 _SIG_DFL uintptr = 0 11 _SIG_IGN uintptr = 1 12 ) 13 14 func initsig() { 15 // _NSIG is the number of signals on this operating system. 16 // sigtable should describe what to do for all the possible signals. 17 if len(sigtable) != _NSIG { 18 print("runtime: len(sigtable)=", len(sigtable), " _NSIG=", _NSIG, "\n") 19 gothrow("initsig") 20 } 21 22 // First call: basic setup. 23 for i := int32(0); i < _NSIG; i++ { 24 t := &sigtable[i] 25 if t.flags == 0 || t.flags&_SigDefault != 0 { 26 continue 27 } 28 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. 32 switch i { 33 case _SIGHUP, _SIGINT: 34 if getsig(i) == _SIG_IGN { 35 t.flags = _SigNotify | _SigIgnored 36 continue 37 } 38 } 39 40 t.flags |= _SigHandling 41 setsig(i, funcPC(sighandler), true) 42 } 43 } 44 45 func sigenable(sig uint32) { 46 if sig >= uint32(len(sigtable)) { 47 return 48 } 49 50 t := &sigtable[sig] 51 if t.flags&_SigNotify != 0 && t.flags&_SigHandling == 0 { 52 t.flags |= _SigHandling 53 if getsig(int32(sig)) == _SIG_IGN { 54 t.flags |= _SigIgnored 55 } 56 setsig(int32(sig), funcPC(sighandler), true) 57 } 58 } 59 60 func sigdisable(sig uint32) { 61 if sig >= uint32(len(sigtable)) { 62 return 63 } 64 65 t := &sigtable[sig] 66 if t.flags&_SigNotify != 0 && t.flags&_SigHandling != 0 { 67 t.flags &^= _SigHandling 68 if t.flags&_SigIgnored != 0 { 69 setsig(int32(sig), _SIG_IGN, true) 70 } else { 71 setsig(int32(sig), _SIG_DFL, true) 72 } 73 } 74 } 75 76 func resetcpuprofiler(hz int32) { 77 var it itimerval 78 if hz == 0 { 79 setitimer(_ITIMER_PROF, &it, nil) 80 } else { 81 it.it_interval.tv_sec = 0 82 it.it_interval.set_usec(1000000 / hz) 83 it.it_value = it.it_interval 84 setitimer(_ITIMER_PROF, &it, nil) 85 } 86 _g_ := getg() 87 _g_.m.profilehz = hz 88 } 89 90 func sigpipe() { 91 setsig(_SIGPIPE, _SIG_DFL, false) 92 raise(_SIGPIPE) 93 } 94 95 func crash() { 96 if GOOS == "darwin" { 97 // OS X core dumps are linear dumps of the mapped memory, 98 // from the first virtual byte to the last, with zeros in the gaps. 99 // Because of the way we arrange the address space on 64-bit systems, 100 // this means the OS X core file will be >128 GB and even on a zippy 101 // workstation can take OS X well over an hour to write (uninterruptible). 102 // Save users from making that mistake. 103 if ptrSize == 8 { 104 return 105 } 106 } 107 108 unblocksignals() 109 setsig(_SIGABRT, _SIG_DFL, false) 110 raise(_SIGABRT) 111 }