github.com/aloncn/graphics-go@v0.0.1/src/runtime/signal_darwin.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  }
    48  
    49  //go:noescape
    50  func sigreturn(ctx unsafe.Pointer, infostyle uint32)
    51  
    52  //go:nosplit
    53  //go:nowritebarrierrec
    54  func sigtrampgo(fn uintptr, infostyle, sig uint32, info *siginfo, ctx unsafe.Pointer) {
    55  	if sigfwdgo(sig, info, ctx) {
    56  		sigreturn(ctx, infostyle)
    57  		return
    58  	}
    59  	g := getg()
    60  	if g == nil {
    61  		badsignal(uintptr(sig))
    62  		sigreturn(ctx, infostyle)
    63  		return
    64  	}
    65  
    66  	// If some non-Go code called sigaltstack, adjust.
    67  	sp := uintptr(unsafe.Pointer(&sig))
    68  	if sp < g.m.gsignal.stack.lo || sp >= g.m.gsignal.stack.hi {
    69  		var st stackt
    70  		sigaltstack(nil, &st)
    71  		if st.ss_flags&_SS_DISABLE != 0 {
    72  			setg(nil)
    73  			cgocallback(unsafe.Pointer(funcPC(noSignalStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig))
    74  		}
    75  		stsp := uintptr(unsafe.Pointer(st.ss_sp))
    76  		if sp < stsp || sp >= stsp+st.ss_size {
    77  			setg(nil)
    78  			cgocallback(unsafe.Pointer(funcPC(sigNotOnStack)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig))
    79  		}
    80  		g.m.gsignal.stack.lo = stsp
    81  		g.m.gsignal.stack.hi = stsp + st.ss_size
    82  		g.m.gsignal.stackguard0 = stsp + _StackGuard
    83  		g.m.gsignal.stackguard1 = stsp + _StackGuard
    84  		g.m.gsignal.stackAlloc = st.ss_size
    85  		g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig))
    86  	}
    87  
    88  	setg(g.m.gsignal)
    89  	c := &sigctxt{info, ctx}
    90  	c.fixsigcode(sig)
    91  	sighandler(sig, info, ctx, g)
    92  	setg(g)
    93  	sigreturn(ctx, infostyle)
    94  }