Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/os3_plan9.go

Documentation: runtime

     1  // Copyright 2010 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 (
     8  	"runtime/internal/sys"
     9  	"unsafe"
    10  )
    11  
    12  // May run during STW, so write barriers are not allowed.
    13  //
    14  //go:nowritebarrierrec
    15  func sighandler(_ureg *ureg, note *byte, gp *g) int {
    16  	_g_ := getg()
    17  	var t sigTabT
    18  	var docrash bool
    19  	var sig int
    20  	var flags int
    21  	var level int32
    22  
    23  	c := &sigctxt{_ureg}
    24  	notestr := gostringnocopy(note)
    25  
    26  	// The kernel will never pass us a nil note or ureg so we probably
    27  	// made a mistake somewhere in sigtramp.
    28  	if _ureg == nil || note == nil {
    29  		print("sighandler: ureg ", _ureg, " note ", note, "\n")
    30  		goto Throw
    31  	}
    32  	// Check that the note is no more than ERRMAX bytes (including
    33  	// the trailing NUL). We should never receive a longer note.
    34  	if len(notestr) > _ERRMAX-1 {
    35  		print("sighandler: note is longer than ERRMAX\n")
    36  		goto Throw
    37  	}
    38  	if isAbortPC(c.pc()) {
    39  		// Never turn abort into a panic.
    40  		goto Throw
    41  	}
    42  	// See if the note matches one of the patterns in sigtab.
    43  	// Notes that do not match any pattern can be handled at a higher
    44  	// level by the program but will otherwise be ignored.
    45  	flags = _SigNotify
    46  	for sig, t = range sigtable {
    47  		if hasPrefix(notestr, t.name) {
    48  			flags = t.flags
    49  			break
    50  		}
    51  	}
    52  	if flags&_SigPanic != 0 && gp.throwsplit {
    53  		// We can't safely sigpanic because it may grow the
    54  		// stack. Abort in the signal handler instead.
    55  		flags = (flags &^ _SigPanic) | _SigThrow
    56  	}
    57  	if flags&_SigGoExit != 0 {
    58  		exits((*byte)(add(unsafe.Pointer(note), 9))) // Strip "go: exit " prefix.
    59  	}
    60  	if flags&_SigPanic != 0 {
    61  		// Copy the error string from sigtramp's stack into m->notesig so
    62  		// we can reliably access it from the panic routines.
    63  		memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1))
    64  		gp.sig = uint32(sig)
    65  		gp.sigpc = c.pc()
    66  
    67  		pc := c.pc()
    68  		sp := c.sp()
    69  
    70  		// If we don't recognize the PC as code
    71  		// but we do recognize the top pointer on the stack as code,
    72  		// then assume this was a call to non-code and treat like
    73  		// pc == 0, to make unwinding show the context.
    74  		if pc != 0 && !findfunc(pc).valid() && findfunc(*(*uintptr)(unsafe.Pointer(sp))).valid() {
    75  			pc = 0
    76  		}
    77  
    78  		// IF LR exists, sigpanictramp must save it to the stack
    79  		// before entry to sigpanic so that panics in leaf
    80  		// functions are correctly handled. This will smash
    81  		// the stack frame but we're not going back there
    82  		// anyway.
    83  		if usesLR {
    84  			c.savelr(c.lr())
    85  		}
    86  
    87  		// If PC == 0, probably panicked because of a call to a nil func.
    88  		// Not faking that as the return address will make the trace look like a call
    89  		// to sigpanic instead. (Otherwise the trace will end at
    90  		// sigpanic and we won't get to see who faulted).
    91  		if pc != 0 {
    92  			if usesLR {
    93  				c.setlr(pc)
    94  			} else {
    95  				sp -= sys.PtrSize
    96  				*(*uintptr)(unsafe.Pointer(sp)) = pc
    97  				c.setsp(sp)
    98  			}
    99  		}
   100  		if usesLR {
   101  			c.setpc(funcPC(sigpanictramp))
   102  		} else {
   103  			c.setpc(funcPC(sigpanic0))
   104  		}
   105  		return _NCONT
   106  	}
   107  	if flags&_SigNotify != 0 {
   108  		if ignoredNote(note) {
   109  			return _NCONT
   110  		}
   111  		if sendNote(note) {
   112  			return _NCONT
   113  		}
   114  	}
   115  	if flags&_SigKill != 0 {
   116  		goto Exit
   117  	}
   118  	if flags&_SigThrow == 0 {
   119  		return _NCONT
   120  	}
   121  Throw:
   122  	_g_.m.throwing = 1
   123  	_g_.m.caughtsig.set(gp)
   124  	startpanic_m()
   125  	print(notestr, "\n")
   126  	print("PC=", hex(c.pc()), "\n")
   127  	print("\n")
   128  	level, _, docrash = gotraceback()
   129  	if level > 0 {
   130  		goroutineheader(gp)
   131  		tracebacktrap(c.pc(), c.sp(), c.lr(), gp)
   132  		tracebackothers(gp)
   133  		print("\n")
   134  		dumpregs(_ureg)
   135  	}
   136  	if docrash {
   137  		crash()
   138  	}
   139  Exit:
   140  	goexitsall(note)
   141  	exits(note)
   142  	return _NDFLT // not reached
   143  }
   144  
   145  func sigenable(sig uint32) {
   146  }
   147  
   148  func sigdisable(sig uint32) {
   149  }
   150  
   151  func sigignore(sig uint32) {
   152  }
   153  
   154  func setProcessCPUProfiler(hz int32) {
   155  }
   156  
   157  func setThreadCPUProfiler(hz int32) {
   158  	// TODO: Enable profiling interrupts.
   159  	getg().m.profilehz = hz
   160  }
   161  
   162  // gsignalStack is unused on Plan 9.
   163  type gsignalStack struct{}
   164  

View as plain text