github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/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 *s, G *gp)
    30  {
    31  	bool crash;
    32  	Ureg *ureg;
    33  	uintptr *sp;
    34  	SigTab *sig, *nsig;
    35  	int32 len, i;
    36  
    37  	if(!s)
    38  		return NCONT;
    39  			
    40  	len = runtime·findnull((byte*)s);
    41  	if(len <= 4 || runtime·mcmp((byte*)s, (byte*)"sys:", 4) != 0)
    42  		return NDFLT;
    43  
    44  	nsig = nil;
    45  	sig = runtime·sigtab;
    46  	for(i=0; i < NSIG; i++) {
    47  		if(runtime·strstr((byte*)s, (byte*)sig->name)) {
    48  			nsig = sig;
    49  			break;
    50  		}
    51  		sig++;
    52  	}
    53  
    54  	if(nsig == nil)
    55  		return NDFLT;
    56  
    57  	ureg = v;
    58  	if(nsig->flags & SigPanic) {
    59  		if(gp == nil || m->notesig == 0)
    60  			goto Throw;
    61  
    62  		// Save error string from sigtramp's stack,
    63  		// into gsignal->sigcode0, so we can reliably
    64  		// access it from the panic routines.
    65  		if(len > ERRMAX)
    66  			len = ERRMAX;
    67  		runtime·memmove((void*)m->notesig, (void*)s, len);
    68  
    69  		gp->sig = i;
    70  		gp->sigpc = ureg->pc;
    71  
    72  		// Only push runtime·sigpanic if ureg->pc != 0.
    73  		// If ureg->pc == 0, probably panicked because of a
    74  		// call to a nil func.  Not pushing that onto sp will
    75  		// make the trace look like a call to runtime·sigpanic instead.
    76  		// (Otherwise the trace will end at runtime·sigpanic and we
    77  		// won't get to see who faulted.)
    78  		if(ureg->pc != 0) {
    79  			sp = (uintptr*)ureg->sp;
    80  			*--sp = ureg->pc;
    81  			ureg->sp = (uint32)sp;
    82  		}
    83  		ureg->pc = (uintptr)runtime·sigpanic;
    84  		return NCONT;
    85  	}
    86  
    87  	if(!(nsig->flags & SigThrow))
    88  		return NDFLT;
    89  
    90  Throw:
    91  	runtime·startpanic();
    92  
    93  	runtime·printf("%s\n", s);
    94  	runtime·printf("PC=%X\n", ureg->pc);
    95  	runtime·printf("\n");
    96  
    97  	if(runtime·gotraceback(&crash)) {
    98  		runtime·traceback((void*)ureg->pc, (void*)ureg->sp, 0, gp);
    99  		runtime·tracebackothers(gp);
   100  		runtime·dumpregs(ureg);
   101  	}
   102  	
   103  	if(crash)
   104  		runtime·crash();
   105  
   106  	runtime·goexitsall("");
   107  	runtime·exits(s);
   108  
   109  	return 0;
   110  }
   111  
   112  
   113  void
   114  runtime·sigenable(uint32 sig)
   115  {
   116  	USED(sig);
   117  }
   118  
   119  void
   120  runtime·sigdisable(uint32 sig)
   121  {
   122  	USED(sig);
   123  }
   124  
   125  void
   126  runtime·resetcpuprofiler(int32 hz)
   127  {
   128  	// TODO: Enable profiling interrupts.
   129  	
   130  	m->profilehz = hz;
   131  }