Source file src/runtime/os3_plan9.go

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

View as plain text