github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/runtime/signal_openbsd.go (about)

     1  // Copyright 2009 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  package runtime
     6  
     7  import "unsafe"
     8  
     9  type sigTabT struct {
    10  	flags int32
    11  	name  string
    12  }
    13  
    14  var sigtable = [...]sigTabT{
    15  	/*  0 */ {0, "SIGNONE: no trap"},
    16  	/*  1 */ {_SigNotify + _SigKill, "SIGHUP: terminal line hangup"},
    17  	/*  2 */ {_SigNotify + _SigKill, "SIGINT: interrupt"},
    18  	/*  3 */ {_SigNotify + _SigThrow, "SIGQUIT: quit"},
    19  	/*  4 */ {_SigThrow + _SigUnblock, "SIGILL: illegal instruction"},
    20  	/*  5 */ {_SigThrow + _SigUnblock, "SIGTRAP: trace trap"},
    21  	/*  6 */ {_SigNotify + _SigThrow, "SIGABRT: abort"},
    22  	/*  7 */ {_SigThrow, "SIGEMT: emulate instruction executed"},
    23  	/*  8 */ {_SigPanic + _SigUnblock, "SIGFPE: floating-point exception"},
    24  	/*  9 */ {0, "SIGKILL: kill"},
    25  	/* 10 */ {_SigPanic + _SigUnblock, "SIGBUS: bus error"},
    26  	/* 11 */ {_SigPanic + _SigUnblock, "SIGSEGV: segmentation violation"},
    27  	/* 12 */ {_SigThrow, "SIGSYS: bad system call"},
    28  	/* 13 */ {_SigNotify, "SIGPIPE: write to broken pipe"},
    29  	/* 14 */ {_SigNotify, "SIGALRM: alarm clock"},
    30  	/* 15 */ {_SigNotify + _SigKill, "SIGTERM: termination"},
    31  	/* 16 */ {_SigNotify, "SIGURG: urgent condition on socket"},
    32  	/* 17 */ {0, "SIGSTOP: stop"},
    33  	/* 18 */ {_SigNotify + _SigDefault, "SIGTSTP: keyboard stop"},
    34  	/* 19 */ {_SigNotify + _SigDefault, "SIGCONT: continue after stop"},
    35  	/* 20 */ {_SigNotify + _SigUnblock, "SIGCHLD: child status has changed"},
    36  	/* 21 */ {_SigNotify + _SigDefault, "SIGTTIN: background read from tty"},
    37  	/* 22 */ {_SigNotify + _SigDefault, "SIGTTOU: background write to tty"},
    38  	/* 23 */ {_SigNotify, "SIGIO: i/o now possible"},
    39  	/* 24 */ {_SigNotify, "SIGXCPU: cpu limit exceeded"},
    40  	/* 25 */ {_SigNotify, "SIGXFSZ: file size limit exceeded"},
    41  	/* 26 */ {_SigNotify, "SIGVTALRM: virtual alarm clock"},
    42  	/* 27 */ {_SigNotify + _SigUnblock, "SIGPROF: profiling alarm clock"},
    43  	/* 28 */ {_SigNotify, "SIGWINCH: window size change"},
    44  	/* 29 */ {_SigNotify, "SIGINFO: status request from keyboard"},
    45  	/* 30 */ {_SigNotify, "SIGUSR1: user-defined signal 1"},
    46  	/* 31 */ {_SigNotify, "SIGUSR2: user-defined signal 2"},
    47  	/* 32 */ {_SigNotify, "SIGTHR: reserved"},
    48  }
    49  
    50  //go:nosplit
    51  //go:nowritebarrierrec
    52  func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
    53  	if sigfwdgo(sig, info, ctx) {
    54  		return
    55  	}
    56  	g := getg()
    57  	if g == nil {
    58  		badsignal(uintptr(sig), &sigctxt{info, ctx})
    59  		return
    60  	}
    61  
    62  	// If some non-Go code called sigaltstack, adjust.
    63  	sp := uintptr(unsafe.Pointer(&sig))
    64  	if sp < g.m.gsignal.stack.lo || sp >= g.m.gsignal.stack.hi {
    65  		var st stackt
    66  		sigaltstack(nil, &st)
    67  		if st.ss_flags&_SS_DISABLE != 0 {
    68  			setg(nil)
    69  			cgocallback(unsafe.Pointer(funcPC(noSignalStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig), 0)
    70  		}
    71  		stsp := uintptr(unsafe.Pointer(st.ss_sp))
    72  		if sp < stsp || sp >= stsp+st.ss_size {
    73  			setg(nil)
    74  			cgocallback(unsafe.Pointer(funcPC(sigNotOnStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig), 0)
    75  		}
    76  		g.m.gsignal.stack.lo = stsp
    77  		g.m.gsignal.stack.hi = stsp + st.ss_size
    78  		g.m.gsignal.stackguard0 = stsp + _StackGuard
    79  		g.m.gsignal.stackguard1 = stsp + _StackGuard
    80  		g.m.gsignal.stackAlloc = st.ss_size
    81  		g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig))
    82  	}
    83  
    84  	setg(g.m.gsignal)
    85  	sighandler(sig, info, ctx, g)
    86  	setg(g)
    87  }