github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/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 throw("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 if t.flags&_SigSetStack != 0 { 41 setsigstack(i) 42 continue 43 } 44 45 t.flags |= _SigHandling 46 setsig(i, funcPC(sighandler), true) 47 } 48 } 49 50 func sigenable(sig uint32) { 51 if sig >= uint32(len(sigtable)) { 52 return 53 } 54 55 t := &sigtable[sig] 56 if t.flags&_SigNotify != 0 && t.flags&_SigHandling == 0 { 57 t.flags |= _SigHandling 58 if getsig(int32(sig)) == _SIG_IGN { 59 t.flags |= _SigIgnored 60 } 61 setsig(int32(sig), funcPC(sighandler), true) 62 } 63 } 64 65 func sigdisable(sig uint32) { 66 if sig >= uint32(len(sigtable)) { 67 return 68 } 69 70 t := &sigtable[sig] 71 if t.flags&_SigNotify != 0 && t.flags&_SigHandling != 0 { 72 t.flags &^= _SigHandling 73 if t.flags&_SigIgnored != 0 { 74 setsig(int32(sig), _SIG_IGN, true) 75 } else { 76 setsig(int32(sig), _SIG_DFL, true) 77 } 78 } 79 } 80 81 func resetcpuprofiler(hz int32) { 82 var it itimerval 83 if hz == 0 { 84 setitimer(_ITIMER_PROF, &it, nil) 85 } else { 86 it.it_interval.tv_sec = 0 87 it.it_interval.set_usec(1000000 / hz) 88 it.it_value = it.it_interval 89 setitimer(_ITIMER_PROF, &it, nil) 90 } 91 _g_ := getg() 92 _g_.m.profilehz = hz 93 } 94 95 func sigpipe() { 96 setsig(_SIGPIPE, _SIG_DFL, false) 97 raise(_SIGPIPE) 98 } 99 100 func crash() { 101 if GOOS == "darwin" { 102 // OS X core dumps are linear dumps of the mapped memory, 103 // from the first virtual byte to the last, with zeros in the gaps. 104 // Because of the way we arrange the address space on 64-bit systems, 105 // this means the OS X core file will be >128 GB and even on a zippy 106 // workstation can take OS X well over an hour to write (uninterruptible). 107 // Save users from making that mistake. 108 if ptrSize == 8 { 109 return 110 } 111 } 112 113 unblocksignals() 114 setsig(_SIGABRT, _SIG_DFL, false) 115 raise(_SIGABRT) 116 }