github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/os_plan9_386.c (about)

     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  #include "runtime.h"
     6  #include "defs_GOOS_GOARCH.h"
     7  #include "os_GOOS.h"
     8  #include "signals_GOOS.h"
     9  
    10  void
    11  runtime·dumpregs(Ureg *u)
    12  {
    13  	runtime·printf("ax	%x\n", u->ax);
    14  	runtime·printf("bx	%x\n", u->bx);
    15  	runtime·printf("cx	%x\n", u->cx);
    16  	runtime·printf("dx	%x\n", u->dx);
    17  	runtime·printf("di	%x\n", u->di);
    18  	runtime·printf("si	%x\n", u->si);
    19  	runtime·printf("bp	%x\n", u->bp);
    20  	runtime·printf("sp	%x\n", u->sp);
    21  	runtime·printf("pc	%x\n", u->pc);
    22  	runtime·printf("flags	%x\n", u->flags);
    23  	runtime·printf("cs	%x\n", u->cs);
    24  	runtime·printf("fs	%x\n", u->fs);
    25  	runtime·printf("gs	%x\n", u->gs);
    26  }
    27  
    28  int32
    29  runtime·sighandler(void *v, int8 *note, G *gp)
    30  {
    31  	uintptr *sp;
    32  	SigTab *t;
    33  	bool crash;
    34  	Ureg *ureg;
    35  	intgo len, n;
    36  	int32 sig, flags;
    37  
    38  	ureg = (Ureg*)v;
    39  
    40  	// The kernel will never pass us a nil note or ureg so we probably
    41  	// made a mistake somewhere in runtime·sigtramp.
    42  	if(ureg == nil || note == nil) {
    43  		runtime·printf("sighandler: ureg %p note %p\n", ureg, note);
    44  		goto Throw;
    45  	}
    46  
    47  	// Check that the note is no more than ERRMAX bytes (including
    48  	// the trailing NUL). We should never receive a longer note.
    49  	len = runtime·findnull((byte*)note);
    50  	if(len > ERRMAX-1) {
    51  		runtime·printf("sighandler: note is longer than ERRMAX\n");
    52  		goto Throw;
    53  	}
    54  
    55  	// See if the note matches one of the patterns in runtime·sigtab.
    56  	// Notes that do not match any pattern can be handled at a higher
    57  	// level by the program but will otherwise be ignored.
    58  	flags = SigNotify;
    59  	for(sig = 0; sig < nelem(runtime·sigtab); sig++) {
    60  		t = &runtime·sigtab[sig];
    61  		n = runtime·findnull((byte*)t->name);
    62  		if(len < n)
    63  			continue;
    64  		if(runtime·strncmp((byte*)note, (byte*)t->name, n) == 0) {
    65  			flags = t->flags;
    66  			break;
    67  		}
    68  	}
    69  
    70  	if(flags & SigGoExit)
    71  		runtime·exits(note+9); // Strip "go: exit " prefix.
    72  
    73  	if(flags & SigPanic) {
    74  		// Copy the error string from sigtramp's stack into m->notesig so
    75  		// we can reliably access it from the panic routines.
    76  		runtime·memmove(g->m->notesig, note, len+1);
    77  
    78  		gp->sig = sig;
    79  		gp->sigpc = ureg->pc;
    80  
    81  		// Only push runtime·sigpanic if PC != 0.
    82  		//
    83  		// If PC == 0, probably panicked because of a call to a nil func.
    84  		// Not pushing that onto SP will make the trace look like a call
    85  		// to runtime·sigpanic instead. (Otherwise the trace will end at
    86  		// runtime·sigpanic and we won't get to see who faulted).
    87  		if(ureg->pc != 0) {
    88  			sp = (uintptr*)ureg->sp;
    89  			*--sp = ureg->pc;
    90  			ureg->sp = (uint32)sp;
    91  		}
    92  		ureg->pc = (uintptr)runtime·sigpanic;
    93  		return NCONT;
    94  	}
    95  
    96  	if(flags & SigNotify) {
    97  		// TODO(ality): See if os/signal wants it.
    98  		//if(runtime·sigsend(...))
    99  		//	return NCONT;
   100  	}
   101  	if(flags & SigKill)
   102  		goto Exit;
   103  	if(!(flags & SigThrow))
   104  		return NCONT;
   105  
   106  Throw:
   107  	g->m->throwing = 1;
   108  	g->m->caughtsig = gp;
   109  	runtime·startpanic();
   110  
   111  	runtime·printf("%s\n", note);
   112  	runtime·printf("PC=%x\n", ureg->pc);
   113  	runtime·printf("\n");
   114  
   115  	if(runtime·gotraceback(&crash)) {
   116  		runtime·goroutineheader(gp);
   117  		runtime·traceback(ureg->pc, ureg->sp, 0, gp);
   118  		runtime·tracebackothers(gp);
   119  		runtime·printf("\n");
   120  		runtime·dumpregs(ureg);
   121  	}
   122  	
   123  	if(crash)
   124  		runtime·crash();
   125  
   126  Exit:
   127  	runtime·goexitsall(note);
   128  	runtime·exits(note);
   129  	return NDFLT; // not reached
   130  }
   131  
   132  void
   133  runtime·sigenable(uint32 sig)
   134  {
   135  	USED(sig);
   136  }
   137  
   138  void
   139  runtime·sigdisable(uint32 sig)
   140  {
   141  	USED(sig);
   142  }
   143  
   144  void
   145  runtime·resetcpuprofiler(int32 hz)
   146  {
   147  	// TODO: Enable profiling interrupts.
   148  	
   149  	g->m->profilehz = hz;
   150  }