1
0
mirror of https://github.com/golang/go synced 2024-11-15 03:30:37 -07:00
go/src/pkg/runtime/linux/arm/signal.c
Russ Cox 6c196015e0 runtime: various arm fixes
* correct symbol table size
  * do not reorder functions in output
  * traceback
  * signal handling
  * use same code for go + defer
  * handle leaf functions in symbol table

R=kaib, dpx
CC=golang-dev
https://golang.org/cl/884041
2010-04-05 12:51:09 -07:00

128 lines
2.8 KiB
C

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "runtime.h"
#include "defs.h"
#include "signals.h"
#include "os.h"
void
dumpregs(Sigcontext *r)
{
printf("trap %x\n", r->trap_no);
printf("error %x\n", r->error_code);
printf("oldmask %x\n", r->oldmask);
printf("r0 %x\n", r->arm_r0);
printf("r1 %x\n", r->arm_r1);
printf("r2 %x\n", r->arm_r2);
printf("r3 %x\n", r->arm_r3);
printf("r4 %x\n", r->arm_r4);
printf("r5 %x\n", r->arm_r5);
printf("r6 %x\n", r->arm_r6);
printf("r7 %x\n", r->arm_r7);
printf("r8 %x\n", r->arm_r8);
printf("r9 %x\n", r->arm_r9);
printf("r10 %x\n", r->arm_r10);
printf("fp %x\n", r->arm_fp);
printf("ip %x\n", r->arm_ip);
printf("sp %x\n", r->arm_sp);
printf("lr %x\n", r->arm_lr);
printf("pc %x\n", r->arm_pc);
printf("cpsr %x\n", r->arm_cpsr);
printf("fault %x\n", r->fault_address);
}
/*
* This assembler routine takes the args from registers, puts them on the stack,
* and calls sighandler().
*/
extern void sigtramp(void);
extern void sigignore(void); // just returns
extern void sigreturn(void); // calls sigreturn
String
signame(int32 sig)
{
if(sig < 0 || sig >= NSIG)
return emptystring;
return gostring((byte*)sigtab[sig].name);
}
void
sighandler(int32 sig, Siginfo *info, void *context)
{
Ucontext *uc;
Sigcontext *sc;
if(sigtab[sig].flags & SigQueue) {
if(sigsend(sig) || (sigtab[sig].flags & SigIgnore))
return;
exit(2); // SIGINT, SIGTERM, etc
}
if(panicking) // traceback already printed
exit(2);
panicking = 1;
if(sig < 0 || sig >= NSIG)
printf("Signal %d\n", sig);
else
printf("%s\n", sigtab[sig].name);
uc = context;
sc = &uc->uc_mcontext;
printf("Faulting address: %p\n", sc->fault_address);
printf("PC=%x\n", sc->arm_pc);
printf("\n");
if(gotraceback()){
traceback((void*)sc->arm_pc, (void*)sc->arm_sp, (void*)sc->arm_lr, m->curg);
tracebackothers(m->curg);
printf("\n");
dumpregs(sc);
}
// breakpoint();
exit(2);
}
void
signalstack(byte *p, int32 n)
{
Sigaltstack st;
st.ss_sp = p;
st.ss_size = n;
st.ss_flags = 0;
sigaltstack(&st, nil);
}
void
initsig(void)
{
static Sigaction sa;
siginit();
int32 i;
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
sa.sa_mask.sig[0] = 0xFFFFFFFF;
sa.sa_mask.sig[1] = 0xFFFFFFFF;
sa.sa_restorer = (void*)sigreturn;
for(i = 0; i<NSIG; i++) {
if(sigtab[i].flags) {
if(sigtab[i].flags & (SigCatch | SigQueue))
sa.sa_handler = (void*)sigtramp;
else
sa.sa_handler = (void*)sigignore;
if(sigtab[i].flags & SigRestart)
sa.sa_flags |= SA_RESTART;
else
sa.sa_flags &= ~SA_RESTART;
rt_sigaction(i, &sa, nil, 8);
}
}
}