mirror of
https://github.com/golang/go
synced 2024-11-12 05:40:22 -07:00
split rt1.c into signal.c and thread.c.
move out of arch-specific directory: only os-specific. rm sys_types.h (unused). TBR=r OCL=26681 CL=26681
This commit is contained in:
parent
878822f355
commit
8ee041dc24
@ -32,12 +32,13 @@ OFILES=\
|
||||
rune.$O\
|
||||
runtime.$O\
|
||||
rt0.$O\
|
||||
rt1.$O\
|
||||
sema.$O\
|
||||
sema_go.$O\
|
||||
signal.$O\
|
||||
string.$O\
|
||||
symtab.$O\
|
||||
sys.$O\
|
||||
thread.$O\
|
||||
traceback.$O\
|
||||
|
||||
OS_H=$(GOARCH)_$(GOOS).h
|
||||
|
258
src/runtime/darwin/signal.c
Normal file
258
src/runtime/darwin/signal.c
Normal file
@ -0,0 +1,258 @@
|
||||
// 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"
|
||||
|
||||
typedef uint64 __uint64_t;
|
||||
|
||||
/* From /usr/include/mach/i386/_structs.h */
|
||||
#define _STRUCT_X86_THREAD_STATE64 struct __darwin_x86_thread_state64
|
||||
_STRUCT_X86_THREAD_STATE64
|
||||
{
|
||||
__uint64_t __rax;
|
||||
__uint64_t __rbx;
|
||||
__uint64_t __rcx;
|
||||
__uint64_t __rdx;
|
||||
__uint64_t __rdi;
|
||||
__uint64_t __rsi;
|
||||
__uint64_t __rbp;
|
||||
__uint64_t __rsp;
|
||||
__uint64_t __r8;
|
||||
__uint64_t __r9;
|
||||
__uint64_t __r10;
|
||||
__uint64_t __r11;
|
||||
__uint64_t __r12;
|
||||
__uint64_t __r13;
|
||||
__uint64_t __r14;
|
||||
__uint64_t __r15;
|
||||
__uint64_t __rip;
|
||||
__uint64_t __rflags;
|
||||
__uint64_t __cs;
|
||||
__uint64_t __fs;
|
||||
__uint64_t __gs;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
print_thread_state(_STRUCT_X86_THREAD_STATE64* ss)
|
||||
{
|
||||
prints("\nrax "); sys·printhex(ss->__rax);
|
||||
prints("\nrbx "); sys·printhex(ss->__rbx);
|
||||
prints("\nrcx "); sys·printhex(ss->__rcx);
|
||||
prints("\nrdx "); sys·printhex(ss->__rdx);
|
||||
prints("\nrdi "); sys·printhex(ss->__rdi);
|
||||
prints("\nrsi "); sys·printhex(ss->__rsi);
|
||||
prints("\nrbp "); sys·printhex(ss->__rbp);
|
||||
prints("\nrsp "); sys·printhex(ss->__rsp);
|
||||
prints("\nr8 "); sys·printhex(ss->__r8 );
|
||||
prints("\nr9 "); sys·printhex(ss->__r9 );
|
||||
prints("\nr10 "); sys·printhex(ss->__r10);
|
||||
prints("\nr11 "); sys·printhex(ss->__r11);
|
||||
prints("\nr12 "); sys·printhex(ss->__r12);
|
||||
prints("\nr13 "); sys·printhex(ss->__r13);
|
||||
prints("\nr14 "); sys·printhex(ss->__r14);
|
||||
prints("\nr15 "); sys·printhex(ss->__r15);
|
||||
prints("\nrip "); sys·printhex(ss->__rip);
|
||||
prints("\nrflags "); sys·printhex(ss->__rflags);
|
||||
prints("\ncs "); sys·printhex(ss->__cs);
|
||||
prints("\nfs "); sys·printhex(ss->__fs);
|
||||
prints("\ngs "); sys·printhex(ss->__gs);
|
||||
prints("\n");
|
||||
}
|
||||
|
||||
|
||||
/* Code generated via: g++ -m64 gen_signals_support.cc && a.out */
|
||||
|
||||
static void *adr_at(void *ptr, int32 offs) {
|
||||
return (void *)((uint8 *)ptr + offs);
|
||||
}
|
||||
|
||||
static void *ptr_at(void *ptr, int32 offs) {
|
||||
return *(void **)((uint8 *)ptr + offs);
|
||||
}
|
||||
|
||||
typedef void ucontext_t;
|
||||
typedef void _STRUCT_MCONTEXT64;
|
||||
typedef void _STRUCT_X86_EXCEPTION_STATE64;
|
||||
typedef void _STRUCT_X86_FLOAT_STATE64;
|
||||
|
||||
static _STRUCT_MCONTEXT64 *get_uc_mcontext(ucontext_t *ptr) {
|
||||
return (_STRUCT_MCONTEXT64 *)ptr_at(ptr, 48);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_EXCEPTION_STATE64 *get___es(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_EXCEPTION_STATE64 *)adr_at(ptr, 0);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_THREAD_STATE64 *get___ss(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_THREAD_STATE64 *)adr_at(ptr, 16);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_FLOAT_STATE64 *get___fs(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_FLOAT_STATE64 *)adr_at(ptr, 184);
|
||||
}
|
||||
|
||||
/* End of generated code */
|
||||
|
||||
|
||||
/*
|
||||
* This assembler routine takes the args from registers, puts them on the stack,
|
||||
* and calls the registered handler.
|
||||
*/
|
||||
extern void sigtramp(void);
|
||||
/*
|
||||
* Rudimentary reverse-engineered definition of signal interface.
|
||||
* You'd think it would be documented.
|
||||
*/
|
||||
struct siginfo {
|
||||
int32 si_signo; /* signal number */
|
||||
int32 si_errno; /* errno association */
|
||||
int32 si_code; /* signal code */
|
||||
int32 si_pid; /* sending process */
|
||||
int32 si_uid; /* sender's ruid */
|
||||
int32 si_status; /* exit value */
|
||||
void *si_addr; /* faulting address */
|
||||
/* more stuff here */
|
||||
};
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int32, struct siginfo*, void*); // actual handler
|
||||
void (*sa_trampoline)(void); // assembly trampoline
|
||||
uint32 sa_mask; // signal mask during handler
|
||||
int32 sa_flags; // flags below
|
||||
};
|
||||
|
||||
void
|
||||
sighandler(int32 sig, struct siginfo *info, void *context)
|
||||
{
|
||||
if(panicking) // traceback already printed
|
||||
sys_Exit(2);
|
||||
panicking = 1;
|
||||
|
||||
_STRUCT_MCONTEXT64 *uc_mcontext = get_uc_mcontext(context);
|
||||
_STRUCT_X86_THREAD_STATE64 *ss = get___ss(uc_mcontext);
|
||||
|
||||
if(sig < 0 || sig >= NSIG){
|
||||
prints("Signal ");
|
||||
sys·printint(sig);
|
||||
}else{
|
||||
prints(sigtab[sig].name);
|
||||
}
|
||||
|
||||
prints("\nFaulting address: "); sys·printpointer(info->si_addr);
|
||||
prints("\npc: "); sys·printhex(ss->__rip);
|
||||
prints("\n\n");
|
||||
|
||||
if(gotraceback()){
|
||||
traceback((void *)ss->__rip, (void *)ss->__rsp, (void*)ss->__r15);
|
||||
tracebackothers((void*)ss->__r15);
|
||||
print_thread_state(ss);
|
||||
}
|
||||
|
||||
sys_Exit(2);
|
||||
}
|
||||
|
||||
void
|
||||
sigignore(int32, struct siginfo*, void*)
|
||||
{
|
||||
}
|
||||
|
||||
struct stack_t {
|
||||
byte *sp;
|
||||
int64 size;
|
||||
int32 flags;
|
||||
};
|
||||
|
||||
void
|
||||
signalstack(byte *p, int32 n)
|
||||
{
|
||||
struct stack_t st;
|
||||
|
||||
st.sp = p;
|
||||
st.size = n;
|
||||
st.flags = 0;
|
||||
sigaltstack(&st, nil);
|
||||
}
|
||||
|
||||
void sigaction(int64, void*, void*);
|
||||
|
||||
enum {
|
||||
SA_SIGINFO = 0x40,
|
||||
SA_RESTART = 0x02,
|
||||
SA_ONSTACK = 0x01,
|
||||
SA_USERTRAMP = 0x100,
|
||||
SA_64REGSET = 0x200,
|
||||
};
|
||||
|
||||
void
|
||||
initsig(void)
|
||||
{
|
||||
int32 i;
|
||||
static struct sigaction sa;
|
||||
|
||||
sa.sa_flags |= SA_SIGINFO|SA_ONSTACK;
|
||||
sa.sa_mask = 0; // 0xFFFFFFFFU;
|
||||
sa.sa_trampoline = sigtramp;
|
||||
for(i = 0; i<NSIG; i++) {
|
||||
if(sigtab[i].flags) {
|
||||
if(sigtab[i].flags & SigCatch) {
|
||||
sa.sa_handler = sighandler;
|
||||
} else {
|
||||
sa.sa_handler = sigignore;
|
||||
}
|
||||
if(sigtab[i].flags & SigRestart)
|
||||
sa.sa_flags |= SA_RESTART;
|
||||
else
|
||||
sa.sa_flags &= ~SA_RESTART;
|
||||
sigaction(i, &sa, nil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unimplemented(int8 *name)
|
||||
{
|
||||
prints(name);
|
||||
prints(" not implemented\n");
|
||||
*(int32*)1231 = 1231;
|
||||
}
|
||||
|
||||
// Thread-safe allocation of a semaphore.
|
||||
// Psema points at a kernel semaphore key.
|
||||
// It starts out zero, meaning no semaphore.
|
||||
// Fill it in, being careful of others calling initsema
|
||||
// simultaneously.
|
||||
static void
|
||||
initsema(uint32 *psema)
|
||||
{
|
||||
uint32 sema;
|
||||
|
||||
if(*psema != 0) // already have one
|
||||
return;
|
||||
|
||||
sema = mach_semcreate();
|
||||
if(!cas(psema, 0, sema)){
|
||||
// Someone else filled it in. Use theirs.
|
||||
mach_semdestroy(sema);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Atomic add and return new value.
|
||||
static uint32
|
||||
xadd(uint32 volatile *val, int32 delta)
|
||||
{
|
||||
uint32 oval, nval;
|
||||
|
||||
for(;;){
|
||||
oval = *val;
|
||||
nval = oval + delta;
|
||||
if(cas(val, oval, nval))
|
||||
return nval;
|
||||
}
|
||||
}
|
||||
|
@ -4,213 +4,6 @@
|
||||
|
||||
#include "runtime.h"
|
||||
#include "defs.h"
|
||||
#include "signals.h"
|
||||
|
||||
typedef uint64 __uint64_t;
|
||||
|
||||
/* From /usr/include/mach/i386/_structs.h */
|
||||
#define _STRUCT_X86_THREAD_STATE64 struct __darwin_x86_thread_state64
|
||||
_STRUCT_X86_THREAD_STATE64
|
||||
{
|
||||
__uint64_t __rax;
|
||||
__uint64_t __rbx;
|
||||
__uint64_t __rcx;
|
||||
__uint64_t __rdx;
|
||||
__uint64_t __rdi;
|
||||
__uint64_t __rsi;
|
||||
__uint64_t __rbp;
|
||||
__uint64_t __rsp;
|
||||
__uint64_t __r8;
|
||||
__uint64_t __r9;
|
||||
__uint64_t __r10;
|
||||
__uint64_t __r11;
|
||||
__uint64_t __r12;
|
||||
__uint64_t __r13;
|
||||
__uint64_t __r14;
|
||||
__uint64_t __r15;
|
||||
__uint64_t __rip;
|
||||
__uint64_t __rflags;
|
||||
__uint64_t __cs;
|
||||
__uint64_t __fs;
|
||||
__uint64_t __gs;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
print_thread_state(_STRUCT_X86_THREAD_STATE64* ss)
|
||||
{
|
||||
prints("\nrax "); sys·printhex(ss->__rax);
|
||||
prints("\nrbx "); sys·printhex(ss->__rbx);
|
||||
prints("\nrcx "); sys·printhex(ss->__rcx);
|
||||
prints("\nrdx "); sys·printhex(ss->__rdx);
|
||||
prints("\nrdi "); sys·printhex(ss->__rdi);
|
||||
prints("\nrsi "); sys·printhex(ss->__rsi);
|
||||
prints("\nrbp "); sys·printhex(ss->__rbp);
|
||||
prints("\nrsp "); sys·printhex(ss->__rsp);
|
||||
prints("\nr8 "); sys·printhex(ss->__r8 );
|
||||
prints("\nr9 "); sys·printhex(ss->__r9 );
|
||||
prints("\nr10 "); sys·printhex(ss->__r10);
|
||||
prints("\nr11 "); sys·printhex(ss->__r11);
|
||||
prints("\nr12 "); sys·printhex(ss->__r12);
|
||||
prints("\nr13 "); sys·printhex(ss->__r13);
|
||||
prints("\nr14 "); sys·printhex(ss->__r14);
|
||||
prints("\nr15 "); sys·printhex(ss->__r15);
|
||||
prints("\nrip "); sys·printhex(ss->__rip);
|
||||
prints("\nrflags "); sys·printhex(ss->__rflags);
|
||||
prints("\ncs "); sys·printhex(ss->__cs);
|
||||
prints("\nfs "); sys·printhex(ss->__fs);
|
||||
prints("\ngs "); sys·printhex(ss->__gs);
|
||||
prints("\n");
|
||||
}
|
||||
|
||||
|
||||
/* Code generated via: g++ -m64 gen_signals_support.cc && a.out */
|
||||
|
||||
static void *adr_at(void *ptr, int32 offs) {
|
||||
return (void *)((uint8 *)ptr + offs);
|
||||
}
|
||||
|
||||
static void *ptr_at(void *ptr, int32 offs) {
|
||||
return *(void **)((uint8 *)ptr + offs);
|
||||
}
|
||||
|
||||
typedef void ucontext_t;
|
||||
typedef void _STRUCT_MCONTEXT64;
|
||||
typedef void _STRUCT_X86_EXCEPTION_STATE64;
|
||||
typedef void _STRUCT_X86_FLOAT_STATE64;
|
||||
|
||||
static _STRUCT_MCONTEXT64 *get_uc_mcontext(ucontext_t *ptr) {
|
||||
return (_STRUCT_MCONTEXT64 *)ptr_at(ptr, 48);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_EXCEPTION_STATE64 *get___es(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_EXCEPTION_STATE64 *)adr_at(ptr, 0);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_THREAD_STATE64 *get___ss(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_THREAD_STATE64 *)adr_at(ptr, 16);
|
||||
}
|
||||
|
||||
static _STRUCT_X86_FLOAT_STATE64 *get___fs(_STRUCT_MCONTEXT64 *ptr) {
|
||||
return (_STRUCT_X86_FLOAT_STATE64 *)adr_at(ptr, 184);
|
||||
}
|
||||
|
||||
/* End of generated code */
|
||||
|
||||
|
||||
/*
|
||||
* This assembler routine takes the args from registers, puts them on the stack,
|
||||
* and calls the registered handler.
|
||||
*/
|
||||
extern void sigtramp(void);
|
||||
/*
|
||||
* Rudimentary reverse-engineered definition of signal interface.
|
||||
* You'd think it would be documented.
|
||||
*/
|
||||
struct siginfo {
|
||||
int32 si_signo; /* signal number */
|
||||
int32 si_errno; /* errno association */
|
||||
int32 si_code; /* signal code */
|
||||
int32 si_pid; /* sending process */
|
||||
int32 si_uid; /* sender's ruid */
|
||||
int32 si_status; /* exit value */
|
||||
void *si_addr; /* faulting address */
|
||||
/* more stuff here */
|
||||
};
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int32, struct siginfo*, void*); // actual handler
|
||||
void (*sa_trampoline)(void); // assembly trampoline
|
||||
uint32 sa_mask; // signal mask during handler
|
||||
int32 sa_flags; // flags below
|
||||
};
|
||||
|
||||
void
|
||||
sighandler(int32 sig, struct siginfo *info, void *context)
|
||||
{
|
||||
if(panicking) // traceback already printed
|
||||
sys_Exit(2);
|
||||
panicking = 1;
|
||||
|
||||
_STRUCT_MCONTEXT64 *uc_mcontext = get_uc_mcontext(context);
|
||||
_STRUCT_X86_THREAD_STATE64 *ss = get___ss(uc_mcontext);
|
||||
|
||||
if(sig < 0 || sig >= NSIG){
|
||||
prints("Signal ");
|
||||
sys·printint(sig);
|
||||
}else{
|
||||
prints(sigtab[sig].name);
|
||||
}
|
||||
|
||||
prints("\nFaulting address: "); sys·printpointer(info->si_addr);
|
||||
prints("\npc: "); sys·printhex(ss->__rip);
|
||||
prints("\n\n");
|
||||
|
||||
if(gotraceback()){
|
||||
traceback((void *)ss->__rip, (void *)ss->__rsp, (void*)ss->__r15);
|
||||
tracebackothers((void*)ss->__r15);
|
||||
print_thread_state(ss);
|
||||
}
|
||||
|
||||
sys_Exit(2);
|
||||
}
|
||||
|
||||
void
|
||||
sigignore(int32, struct siginfo*, void*)
|
||||
{
|
||||
}
|
||||
|
||||
struct stack_t {
|
||||
byte *sp;
|
||||
int64 size;
|
||||
int32 flags;
|
||||
};
|
||||
|
||||
void
|
||||
signalstack(byte *p, int32 n)
|
||||
{
|
||||
struct stack_t st;
|
||||
|
||||
st.sp = p;
|
||||
st.size = n;
|
||||
st.flags = 0;
|
||||
sigaltstack(&st, nil);
|
||||
}
|
||||
|
||||
void sigaction(int64, void*, void*);
|
||||
|
||||
enum {
|
||||
SA_SIGINFO = 0x40,
|
||||
SA_RESTART = 0x02,
|
||||
SA_ONSTACK = 0x01,
|
||||
SA_USERTRAMP = 0x100,
|
||||
SA_64REGSET = 0x200,
|
||||
};
|
||||
|
||||
void
|
||||
initsig(void)
|
||||
{
|
||||
int32 i;
|
||||
static struct sigaction sa;
|
||||
|
||||
sa.sa_flags |= SA_SIGINFO|SA_ONSTACK;
|
||||
sa.sa_mask = 0; // 0xFFFFFFFFU;
|
||||
sa.sa_trampoline = sigtramp;
|
||||
for(i = 0; i<NSIG; i++) {
|
||||
if(sigtab[i].flags) {
|
||||
if(sigtab[i].flags & SigCatch) {
|
||||
sa.sa_handler = sighandler;
|
||||
} else {
|
||||
sa.sa_handler = sigignore;
|
||||
}
|
||||
if(sigtab[i].flags & SigRestart)
|
||||
sa.sa_flags |= SA_RESTART;
|
||||
else
|
||||
sa.sa_flags &= ~SA_RESTART;
|
||||
sigaction(i, &sa, nil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unimplemented(int8 *name)
|
214
src/runtime/linux/signal.c
Normal file
214
src/runtime/linux/signal.c
Normal file
@ -0,0 +1,214 @@
|
||||
// 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"
|
||||
|
||||
/* From /usr/include/asm-x86_64/sigcontext.h */
|
||||
struct _fpstate {
|
||||
uint16 cwd;
|
||||
uint16 swd;
|
||||
uint16 twd; /* Note this is not the same as the 32bit/x87/FSAVE twd */
|
||||
uint16 fop;
|
||||
uint64 rip;
|
||||
uint32 rdp;
|
||||
uint32 mxcsr;
|
||||
uint32 mxcsr_mask;
|
||||
uint32 st_space[32]; /* 8*16 bytes for each FP-reg */
|
||||
uint32 xmm_space[64]; /* 16*16 bytes for each XMM-reg */
|
||||
uint32 reserved2[24];
|
||||
};
|
||||
|
||||
struct sigcontext {
|
||||
uint64 r8;
|
||||
uint64 r9;
|
||||
uint64 r10;
|
||||
uint64 r11;
|
||||
uint64 r12;
|
||||
uint64 r13;
|
||||
uint64 r14;
|
||||
uint64 r15;
|
||||
uint64 rdi;
|
||||
uint64 rsi;
|
||||
uint64 rbp;
|
||||
uint64 rbx;
|
||||
uint64 rdx;
|
||||
uint64 rax;
|
||||
uint64 rcx;
|
||||
uint64 rsp;
|
||||
uint64 rip;
|
||||
uint64 eflags; /* RFLAGS */
|
||||
uint16 cs;
|
||||
uint16 gs;
|
||||
uint16 fs;
|
||||
uint16 __pad0;
|
||||
uint64 err;
|
||||
uint64 trapno;
|
||||
uint64 oldmask;
|
||||
uint64 cr2;
|
||||
struct _fpstate *fpstate; /* zero when no FPU context */
|
||||
uint64 reserved1[8];
|
||||
};
|
||||
|
||||
|
||||
/* From /usr/include/asm-x86_64/signal.h */
|
||||
typedef struct sigaltstack {
|
||||
void /*__user*/ *ss_sp;
|
||||
int32 ss_flags;
|
||||
uint64 ss_size;
|
||||
} stack_t;
|
||||
|
||||
typedef uint64 sigset_t;
|
||||
|
||||
|
||||
/* From /usr/include/asm-x86_64/ucontext.h */
|
||||
struct ucontext {
|
||||
uint64 uc_flags;
|
||||
struct ucontext *uc_link;
|
||||
stack_t uc_stack;
|
||||
struct sigcontext uc_mcontext;
|
||||
sigset_t uc_sigmask; /* mask last for extensibility */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
print_sigcontext(struct sigcontext *sc)
|
||||
{
|
||||
prints("\nrax "); sys·printhex(sc->rax);
|
||||
prints("\nrbx "); sys·printhex(sc->rbx);
|
||||
prints("\nrcx "); sys·printhex(sc->rcx);
|
||||
prints("\nrdx "); sys·printhex(sc->rdx);
|
||||
prints("\nrdi "); sys·printhex(sc->rdi);
|
||||
prints("\nrsi "); sys·printhex(sc->rsi);
|
||||
prints("\nrbp "); sys·printhex(sc->rbp);
|
||||
prints("\nrsp "); sys·printhex(sc->rsp);
|
||||
prints("\nr8 "); sys·printhex(sc->r8 );
|
||||
prints("\nr9 "); sys·printhex(sc->r9 );
|
||||
prints("\nr10 "); sys·printhex(sc->r10);
|
||||
prints("\nr11 "); sys·printhex(sc->r11);
|
||||
prints("\nr12 "); sys·printhex(sc->r12);
|
||||
prints("\nr13 "); sys·printhex(sc->r13);
|
||||
prints("\nr14 "); sys·printhex(sc->r14);
|
||||
prints("\nr15 "); sys·printhex(sc->r15);
|
||||
prints("\nrip "); sys·printhex(sc->rip);
|
||||
prints("\nrflags "); sys·printhex(sc->eflags);
|
||||
prints("\ncs "); sys·printhex(sc->cs);
|
||||
prints("\nfs "); sys·printhex(sc->fs);
|
||||
prints("\ngs "); sys·printhex(sc->gs);
|
||||
prints("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
/*
|
||||
* Rudimentary reverse-engineered definition of signal interface.
|
||||
* You'd think it would be documented.
|
||||
*/
|
||||
/* From /usr/include/bits/siginfo.h */
|
||||
struct siginfo {
|
||||
int32 si_signo; /* signal number */
|
||||
int32 si_errno; /* errno association */
|
||||
int32 si_code; /* signal code */
|
||||
int32 si_status; /* exit value */
|
||||
void *si_addr; /* faulting address */
|
||||
/* more stuff here */
|
||||
};
|
||||
|
||||
// This is a struct sigaction from /usr/include/asm/signal.h
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int32, struct siginfo*, void*);
|
||||
uint64 sa_flags;
|
||||
void (*sa_restorer)(void);
|
||||
uint64 sa_mask;
|
||||
};
|
||||
|
||||
void
|
||||
sighandler(int32 sig, struct siginfo* info, void** context)
|
||||
{
|
||||
if(panicking) // traceback already printed
|
||||
sys_Exit(2);
|
||||
|
||||
struct sigcontext *sc = &(((struct ucontext *)context)->uc_mcontext);
|
||||
|
||||
if(sig < 0 || sig >= NSIG){
|
||||
prints("Signal ");
|
||||
sys·printint(sig);
|
||||
}else{
|
||||
prints(sigtab[sig].name);
|
||||
}
|
||||
|
||||
prints("\nFaulting address: "); sys·printpointer(info->si_addr);
|
||||
prints("\npc: "); sys·printhex(sc->rip);
|
||||
prints("\n\n");
|
||||
|
||||
if(gotraceback()){
|
||||
traceback((void *)sc->rip, (void *)sc->rsp, (void *)sc->r15);
|
||||
tracebackothers((void*)sc->r15);
|
||||
print_sigcontext(sc);
|
||||
}
|
||||
|
||||
sys·Breakpoint();
|
||||
sys_Exit(2);
|
||||
}
|
||||
|
||||
struct stack_t {
|
||||
void *sp;
|
||||
int32 flags;
|
||||
int32 pad;
|
||||
int64 size;
|
||||
};
|
||||
|
||||
void
|
||||
signalstack(byte *p, int32 n)
|
||||
{
|
||||
struct stack_t st;
|
||||
|
||||
st.sp = p;
|
||||
st.size = n;
|
||||
st.pad = 0;
|
||||
st.flags = 0;
|
||||
sigaltstack(&st, nil);
|
||||
}
|
||||
|
||||
void rt_sigaction(int64, void*, void*, uint64);
|
||||
|
||||
enum {
|
||||
SA_RESTART = 0x10000000,
|
||||
SA_ONSTACK = 0x08000000,
|
||||
SA_RESTORER = 0x04000000,
|
||||
SA_SIGINFO = 0x00000004,
|
||||
};
|
||||
|
||||
void
|
||||
initsig(void)
|
||||
{
|
||||
static struct sigaction sa;
|
||||
|
||||
int32 i;
|
||||
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
|
||||
sa.sa_mask = 0xFFFFFFFFFFFFFFFFULL;
|
||||
sa.sa_restorer = (void*)sigreturn;
|
||||
for(i = 0; i<NSIG; i++) {
|
||||
if(sigtab[i].flags) {
|
||||
if(sigtab[i].flags & SigCatch)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,215 +3,8 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "runtime.h"
|
||||
#include "amd64_linux.h"
|
||||
#include "signals_linux.h"
|
||||
|
||||
/* From /usr/include/asm-x86_64/sigcontext.h */
|
||||
struct _fpstate {
|
||||
uint16 cwd;
|
||||
uint16 swd;
|
||||
uint16 twd; /* Note this is not the same as the 32bit/x87/FSAVE twd */
|
||||
uint16 fop;
|
||||
uint64 rip;
|
||||
uint32 rdp;
|
||||
uint32 mxcsr;
|
||||
uint32 mxcsr_mask;
|
||||
uint32 st_space[32]; /* 8*16 bytes for each FP-reg */
|
||||
uint32 xmm_space[64]; /* 16*16 bytes for each XMM-reg */
|
||||
uint32 reserved2[24];
|
||||
};
|
||||
|
||||
struct sigcontext {
|
||||
uint64 r8;
|
||||
uint64 r9;
|
||||
uint64 r10;
|
||||
uint64 r11;
|
||||
uint64 r12;
|
||||
uint64 r13;
|
||||
uint64 r14;
|
||||
uint64 r15;
|
||||
uint64 rdi;
|
||||
uint64 rsi;
|
||||
uint64 rbp;
|
||||
uint64 rbx;
|
||||
uint64 rdx;
|
||||
uint64 rax;
|
||||
uint64 rcx;
|
||||
uint64 rsp;
|
||||
uint64 rip;
|
||||
uint64 eflags; /* RFLAGS */
|
||||
uint16 cs;
|
||||
uint16 gs;
|
||||
uint16 fs;
|
||||
uint16 __pad0;
|
||||
uint64 err;
|
||||
uint64 trapno;
|
||||
uint64 oldmask;
|
||||
uint64 cr2;
|
||||
struct _fpstate *fpstate; /* zero when no FPU context */
|
||||
uint64 reserved1[8];
|
||||
};
|
||||
|
||||
|
||||
/* From /usr/include/asm-x86_64/signal.h */
|
||||
typedef struct sigaltstack {
|
||||
void /*__user*/ *ss_sp;
|
||||
int32 ss_flags;
|
||||
uint64 ss_size;
|
||||
} stack_t;
|
||||
|
||||
typedef uint64 sigset_t;
|
||||
|
||||
|
||||
/* From /usr/include/asm-x86_64/ucontext.h */
|
||||
struct ucontext {
|
||||
uint64 uc_flags;
|
||||
struct ucontext *uc_link;
|
||||
stack_t uc_stack;
|
||||
struct sigcontext uc_mcontext;
|
||||
sigset_t uc_sigmask; /* mask last for extensibility */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
print_sigcontext(struct sigcontext *sc)
|
||||
{
|
||||
prints("\nrax "); sys·printhex(sc->rax);
|
||||
prints("\nrbx "); sys·printhex(sc->rbx);
|
||||
prints("\nrcx "); sys·printhex(sc->rcx);
|
||||
prints("\nrdx "); sys·printhex(sc->rdx);
|
||||
prints("\nrdi "); sys·printhex(sc->rdi);
|
||||
prints("\nrsi "); sys·printhex(sc->rsi);
|
||||
prints("\nrbp "); sys·printhex(sc->rbp);
|
||||
prints("\nrsp "); sys·printhex(sc->rsp);
|
||||
prints("\nr8 "); sys·printhex(sc->r8 );
|
||||
prints("\nr9 "); sys·printhex(sc->r9 );
|
||||
prints("\nr10 "); sys·printhex(sc->r10);
|
||||
prints("\nr11 "); sys·printhex(sc->r11);
|
||||
prints("\nr12 "); sys·printhex(sc->r12);
|
||||
prints("\nr13 "); sys·printhex(sc->r13);
|
||||
prints("\nr14 "); sys·printhex(sc->r14);
|
||||
prints("\nr15 "); sys·printhex(sc->r15);
|
||||
prints("\nrip "); sys·printhex(sc->rip);
|
||||
prints("\nrflags "); sys·printhex(sc->eflags);
|
||||
prints("\ncs "); sys·printhex(sc->cs);
|
||||
prints("\nfs "); sys·printhex(sc->fs);
|
||||
prints("\ngs "); sys·printhex(sc->gs);
|
||||
prints("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
/*
|
||||
* Rudimentary reverse-engineered definition of signal interface.
|
||||
* You'd think it would be documented.
|
||||
*/
|
||||
/* From /usr/include/bits/siginfo.h */
|
||||
struct siginfo {
|
||||
int32 si_signo; /* signal number */
|
||||
int32 si_errno; /* errno association */
|
||||
int32 si_code; /* signal code */
|
||||
int32 si_status; /* exit value */
|
||||
void *si_addr; /* faulting address */
|
||||
/* more stuff here */
|
||||
};
|
||||
|
||||
// This is a struct sigaction from /usr/include/asm/signal.h
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int32, struct siginfo*, void*);
|
||||
uint64 sa_flags;
|
||||
void (*sa_restorer)(void);
|
||||
uint64 sa_mask;
|
||||
};
|
||||
|
||||
void
|
||||
sighandler(int32 sig, struct siginfo* info, void** context)
|
||||
{
|
||||
if(panicking) // traceback already printed
|
||||
sys_Exit(2);
|
||||
|
||||
struct sigcontext *sc = &(((struct ucontext *)context)->uc_mcontext);
|
||||
|
||||
if(sig < 0 || sig >= NSIG){
|
||||
prints("Signal ");
|
||||
sys·printint(sig);
|
||||
}else{
|
||||
prints(sigtab[sig].name);
|
||||
}
|
||||
|
||||
prints("\nFaulting address: "); sys·printpointer(info->si_addr);
|
||||
prints("\npc: "); sys·printhex(sc->rip);
|
||||
prints("\n\n");
|
||||
|
||||
if(gotraceback()){
|
||||
traceback((void *)sc->rip, (void *)sc->rsp, (void *)sc->r15);
|
||||
tracebackothers((void*)sc->r15);
|
||||
print_sigcontext(sc);
|
||||
}
|
||||
|
||||
sys·Breakpoint();
|
||||
sys_Exit(2);
|
||||
}
|
||||
|
||||
struct stack_t {
|
||||
void *sp;
|
||||
int32 flags;
|
||||
int32 pad;
|
||||
int64 size;
|
||||
};
|
||||
|
||||
void
|
||||
signalstack(byte *p, int32 n)
|
||||
{
|
||||
struct stack_t st;
|
||||
|
||||
st.sp = p;
|
||||
st.size = n;
|
||||
st.pad = 0;
|
||||
st.flags = 0;
|
||||
sigaltstack(&st, nil);
|
||||
}
|
||||
|
||||
void rt_sigaction(int64, void*, void*, uint64);
|
||||
|
||||
enum {
|
||||
SA_RESTART = 0x10000000,
|
||||
SA_ONSTACK = 0x08000000,
|
||||
SA_RESTORER = 0x04000000,
|
||||
SA_SIGINFO = 0x00000004,
|
||||
};
|
||||
|
||||
void
|
||||
initsig(void)
|
||||
{
|
||||
static struct sigaction sa;
|
||||
|
||||
int32 i;
|
||||
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
|
||||
sa.sa_mask = 0xFFFFFFFFFFFFFFFFULL;
|
||||
sa.sa_restorer = (void*)sigreturn;
|
||||
for(i = 0; i<NSIG; i++) {
|
||||
if(sigtab[i].flags) {
|
||||
if(sigtab[i].flags & SigCatch)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "defs.h"
|
||||
#include "signals.h"
|
||||
|
||||
// Linux futex.
|
||||
//
|
@ -1,13 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifdef amd64_linux
|
||||
#include "amd64_linux.h"
|
||||
#else
|
||||
#ifdef amd64_darwin
|
||||
#include "amd64_darwin.h"
|
||||
#else
|
||||
You_need_to_write_the_syscall_header
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user