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