Commit 209865be authored by Russ Cox's avatar Russ Cox

convert Linux to auto-generated defs.h

TBR=r
OCL=26686
CL=26688
parent 08cfcd1d
...@@ -64,6 +64,7 @@ sighandler(int32 sig, Siginfo *info, void *context) ...@@ -64,6 +64,7 @@ sighandler(int32 sig, Siginfo *info, void *context)
dumpregs(r); dumpregs(r);
} }
sys·Breakpoint();
sys_Exit(2); sys_Exit(2);
} }
......
/* // godefs -f -m64 defs.c
* System structs for Linux, amd64
*/ // MACHINE GENERATED - DO NOT EDIT.
typedef uint64 dev_t; // Constants
typedef uint64 ino_t; enum {
typedef uint32 mode_t; PROT_NONE = 0,
typedef uint64 nlink_t; PROT_READ = 0x1,
typedef uint32 uid_t; PROT_WRITE = 0x2,
typedef uint32 gid_t; PROT_EXEC = 0x4,
typedef int64 off_t; MAP_ANON = 0x20,
typedef int64 blksize_t; MAP_PRIVATE = 0x2,
typedef int64 blkcnt_t; SA_RESTART = 0x10000000,
typedef int64 time_t; SA_ONSTACK = 0x8000000,
SA_RESTORER = 0x4000000,
struct timespec { SA_SIGINFO = 0x4,
time_t tv_sec; };
// Types
#pragma pack on
typedef struct Timespec Timespec;
struct Timespec {
int64 tv_sec;
int64 tv_nsec; int64 tv_nsec;
}; };
struct timeval { typedef struct Timeval Timeval;
time_t tv_sec; struct Timeval {
int64 tv_sec;
int64 tv_usec; int64 tv_usec;
}; };
struct stat { typedef struct Sigaction Sigaction;
dev_t st_dev; /* ID of device containing file */ struct Sigaction {
ino_t st_ino; /* inode number */ void *sa_handler;
nlink_t st_nlink; /* number of hard links */ uint64 sa_flags;
mode_t st_mode; /* protection */ void *sa_restorer;
uid_t st_uid; /* user ID of owner */ uint64 sa_mask;
gid_t st_gid; /* group ID of owner */ };
int32 pad0;
dev_t st_rdev; /* device ID (if special file) */ typedef struct Siginfo Siginfo;
off_t st_size; /* total size, in bytes */ struct Siginfo {
blksize_t st_blksize; /* blocksize for filesystem I/O */ int32 si_signo;
blkcnt_t st_blocks; /* number of blocks allocated */ int32 si_errno;
struct timespec st_atime; /* time of last access */ int32 si_code;
struct timespec st_mtime; /* time of last modification */ byte pad0[4];
struct timespec st_ctime; /* time of last status change */ byte _sifields[112];
}; };
#pragma pack off
// godefs -f -m64 defs1.c
// MACHINE GENERATED - DO NOT EDIT.
#define O_CREAT 0100 // Constants
// Linux-specific system calls // Types
int64 futex(uint32*, int32, uint32, struct timespec*, uint32*, uint32); #pragma pack on
int64 clone(int32, void*, M*, G*, void(*)(void));
typedef struct Usigset Usigset;
struct Usigset {
uint64 __val[16];
};
typedef struct Fpxreg Fpxreg;
struct Fpxreg {
uint16 significand[4];
uint16 exponent;
uint16 padding[3];
};
typedef struct Xmmreg Xmmreg;
struct Xmmreg {
uint32 element[4];
};
typedef struct Fpstate Fpstate;
struct Fpstate {
uint16 cwd;
uint16 swd;
uint16 ftw;
uint16 fop;
uint64 rip;
uint64 rdp;
uint32 mxcsr;
uint32 mxcr_mask;
Fpxreg _st[8];
Xmmreg _xmm[16];
uint32 padding[24];
};
typedef struct Fpxreg1 Fpxreg1;
struct Fpxreg1 {
uint16 significand[4];
uint16 exponent;
uint16 padding[3];
};
typedef struct Xmmreg1 Xmmreg1;
struct Xmmreg1 {
uint32 element[4];
};
typedef struct Fpstate1 Fpstate1;
struct Fpstate1 {
uint16 cwd;
uint16 swd;
uint16 ftw;
uint16 fop;
uint64 rip;
uint64 rdp;
uint32 mxcsr;
uint32 mxcr_mask;
Fpxreg1 _st[8];
Xmmreg1 _xmm[16];
uint32 padding[24];
};
typedef struct Sigaltstack Sigaltstack;
struct Sigaltstack {
void *ss_sp;
int32 ss_flags;
byte pad0[4];
uint64 ss_size;
};
typedef struct Mcontext Mcontext;
struct Mcontext {
int64 gregs[23];
Fpstate *fpregs;
uint64 __reserved1[8];
};
typedef struct Ucontext Ucontext;
struct Ucontext {
uint64 uc_flags;
Ucontext *uc_link;
Sigaltstack uc_stack;
Mcontext uc_mcontext;
Usigset uc_sigmask;
Fpstate __fpregs_mem;
};
typedef struct Sigcontext Sigcontext;
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;
uint16 cs;
uint16 gs;
uint16 fs;
uint16 __pad0;
uint64 err;
uint64 trapno;
uint64 oldmask;
uint64 cr2;
Fpstate1 *fpstate;
uint64 __reserved1[8];
};
#pragma pack off
// 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.
/*
* Input to godefs
godefs -f -m64 defs.c >amd64/defs.h
godefs -f -m64 defs1.c >>amd64/defs.h
godefs defs.c >386/defs.h
godefs defs1.c >>386/defs.h
*/
// Linux glibc and Linux kernel define different and conflicting
// definitions for struct sigaction, struct timespec, etc.
// We want the kernel ones, which are in the asm/* headers.
// But then we'd get conflicts when we include the system
// headers for things like ucontext_t, so that happens in
// a separate file, defs1.c.
#include <asm/signal.h>
#include <asm/siginfo.h>
#include <asm/mman.h>
enum {
$PROT_NONE = PROT_NONE,
$PROT_READ = PROT_READ,
$PROT_WRITE = PROT_WRITE,
$PROT_EXEC = PROT_EXEC,
$MAP_ANON = MAP_ANONYMOUS,
$MAP_PRIVATE = MAP_PRIVATE,
$SA_RESTART = SA_RESTART,
$SA_ONSTACK = SA_ONSTACK,
$SA_RESTORER = SA_RESTORER,
$SA_SIGINFO = SA_SIGINFO,
};
typedef struct timespec $Timespec;
typedef struct timeval $Timeval;
typedef struct sigaction $Sigaction;
typedef siginfo_t $Siginfo;
// 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.
/*
* Input to godefs
godefs -f -m64 defs.c >amd64/defs.h
godefs -f -m64 defs1.c >>amd64/defs.h
godefs defs.c >386/defs.h
godefs defs1.c >>386/defs.h
*/
#include <ucontext.h>
typedef __sigset_t $Usigset;
typedef struct _libc_fpxreg $Fpxreg;
typedef struct _libc_xmmreg $Xmmreg;
typedef struct _libc_fpstate $Fpstate;
typedef struct _fpxreg $Fpxreg1;
typedef struct _xmmreg $Xmmreg1;
typedef struct _fpstate $Fpstate1;
typedef struct sigaltstack $Sigaltstack;
typedef mcontext_t $Mcontext;
typedef ucontext_t $Ucontext;
typedef struct sigcontext $Sigcontext;
// 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.
// Linux-specific system calls
int64 futex(uint32*, int32, uint32, Timespec*, uint32*, uint32);
int64 clone(int32, void*, M*, G*, void(*)(void));
struct Sigaction;
void rt_sigaction(int64, struct Sigaction*, void*, uint64);
...@@ -5,102 +5,34 @@ ...@@ -5,102 +5,34 @@
#include "runtime.h" #include "runtime.h"
#include "defs.h" #include "defs.h"
#include "signals.h" #include "signals.h"
#include "os.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 void
print_sigcontext(struct sigcontext *sc) dumpregs(Sigcontext *r)
{ {
prints("\nrax "); sys·printhex(sc->rax); printf("rax %X\n", r->rax);
prints("\nrbx "); sys·printhex(sc->rbx); printf("rbx %X\n", r->rbx);
prints("\nrcx "); sys·printhex(sc->rcx); printf("rcx %X\n", r->rcx);
prints("\nrdx "); sys·printhex(sc->rdx); printf("rdx %X\n", r->rdx);
prints("\nrdi "); sys·printhex(sc->rdi); printf("rdi %X\n", r->rdi);
prints("\nrsi "); sys·printhex(sc->rsi); printf("rsi %X\n", r->rsi);
prints("\nrbp "); sys·printhex(sc->rbp); printf("rbp %X\n", r->rbp);
prints("\nrsp "); sys·printhex(sc->rsp); printf("rsp %X\n", r->rsp);
prints("\nr8 "); sys·printhex(sc->r8 ); printf("r8 %X\n", r->r8 );
prints("\nr9 "); sys·printhex(sc->r9 ); printf("r9 %X\n", r->r9 );
prints("\nr10 "); sys·printhex(sc->r10); printf("r10 %X\n", r->r10);
prints("\nr11 "); sys·printhex(sc->r11); printf("r11 %X\n", r->r11);
prints("\nr12 "); sys·printhex(sc->r12); printf("r12 %X\n", r->r12);
prints("\nr13 "); sys·printhex(sc->r13); printf("r13 %X\n", r->r13);
prints("\nr14 "); sys·printhex(sc->r14); printf("r14 %X\n", r->r14);
prints("\nr15 "); sys·printhex(sc->r15); printf("r15 %X\n", r->r15);
prints("\nrip "); sys·printhex(sc->rip); printf("rip %X\n", r->rip);
prints("\nrflags "); sys·printhex(sc->eflags); printf("rflags %X\n", r->eflags);
prints("\ncs "); sys·printhex(sc->cs); printf("cs %X\n", (uint64)r->cs);
prints("\nfs "); sys·printhex(sc->fs); printf("fs %X\n", (uint64)r->fs);
prints("\ngs "); sys·printhex(sc->gs); printf("gs %X\n", (uint64)r->gs);
prints("\n");
} }
/* /*
* This assembler routine takes the args from registers, puts them on the stack, * This assembler routine takes the args from registers, puts them on the stack,
* and calls sighandler(). * and calls sighandler().
...@@ -109,89 +41,54 @@ extern void sigtramp(void); ...@@ -109,89 +41,54 @@ extern void sigtramp(void);
extern void sigignore(void); // just returns extern void sigignore(void); // just returns
extern void sigreturn(void); // calls sigreturn 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 void
sighandler(int32 sig, struct siginfo* info, void** context) sighandler(int32 sig, Siginfo* info, void* context)
{ {
Ucontext *uc;
Mcontext *mc;
Sigcontext *sc;
if(panicking) // traceback already printed if(panicking) // traceback already printed
sys_Exit(2); sys_Exit(2);
struct sigcontext *sc = &(((struct ucontext *)context)->uc_mcontext); uc = context;
mc = &uc->uc_mcontext;
sc = (Sigcontext*)mc; // same layout, more conveient names
if(sig < 0 || sig >= NSIG){ if(sig < 0 || sig >= NSIG)
prints("Signal "); printf("Signal %d\n", sig);
sys·printint(sig); else
}else{ printf("%s\n", sigtab[sig].name);
prints(sigtab[sig].name);
}
prints("\nFaulting address: "); sys·printpointer(info->si_addr); printf("Faulting address: %p\n", *(void**)info->_sifields);
prints("\npc: "); sys·printhex(sc->rip); printf("PC=%X\n", sc->rip);
prints("\n\n"); printf("\n");
if(gotraceback()){ if(gotraceback()){
traceback((void *)sc->rip, (void *)sc->rsp, (void *)sc->r15); traceback((void*)sc->rip, (void*)sc->rsp, (void*)sc->r15);
tracebackothers((void*)sc->r15); tracebackothers((void*)sc->r15);
print_sigcontext(sc); dumpregs(sc);
} }
sys·Breakpoint(); sys·Breakpoint();
sys_Exit(2); sys_Exit(2);
} }
struct stack_t {
void *sp;
int32 flags;
int32 pad;
int64 size;
};
void void
signalstack(byte *p, int32 n) signalstack(byte *p, int32 n)
{ {
struct stack_t st; Sigaltstack st;
st.sp = p; st.ss_sp = p;
st.size = n; st.ss_size = n;
st.pad = 0; st.ss_flags = 0;
st.flags = 0;
sigaltstack(&st, nil); sigaltstack(&st, nil);
} }
void rt_sigaction(int64, void*, void*, uint64);
enum {
SA_RESTART = 0x10000000,
SA_ONSTACK = 0x08000000,
SA_RESTORER = 0x04000000,
SA_SIGINFO = 0x00000004,
};
void void
initsig(void) initsig(void)
{ {
static struct sigaction sa; static Sigaction sa;
int32 i; int32 i;
sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER; sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "runtime.h" #include "runtime.h"
#include "defs.h" #include "defs.h"
#include "signals.h" #include "signals.h"
#include "os.h"
// Linux futex. // Linux futex.
// //
...@@ -24,12 +25,12 @@ enum ...@@ -24,12 +25,12 @@ enum
EAGAIN = 11, EAGAIN = 11,
}; };
// TODO(rsc) I tried using 1<<40 here but futex woke up (-ETIMEDOUT). // TODO(rsc): I tried using 1<<40 here but futex woke up (-ETIMEDOUT).
// I wonder if the timespec that gets to the kernel // I wonder if the timespec that gets to the kernel
// actually has two 32-bit numbers in it, so tha // actually has two 32-bit numbers in it, so that
// a 64-bit 1<<40 ends up being 0 seconds, // a 64-bit 1<<40 ends up being 0 seconds,
// 1<<8 nanoseconds. // 1<<8 nanoseconds.
static struct timespec longtime = static Timespec longtime =
{ {
1<<30, // 34 years 1<<30, // 34 years
0 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment