Commit 8dee8729 authored by Russ Cox's avatar Russ Cox

runtime: os-specific types and code for setitimer

R=r
CC=golang-dev
https://golang.org/cl/4273097
parent ccdbb8a6
...@@ -89,6 +89,9 @@ enum { ...@@ -89,6 +89,9 @@ enum {
BUS_OBJERR = 0x3, BUS_OBJERR = 0x3,
SEGV_MAPERR = 0x1, SEGV_MAPERR = 0x1,
SEGV_ACCERR = 0x2, SEGV_ACCERR = 0x2,
ITIMER_REAL = 0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
}; };
// Types // Types
...@@ -139,14 +142,14 @@ struct StackT { ...@@ -139,14 +142,14 @@ struct StackT {
typedef union Sighandler Sighandler; typedef union Sighandler Sighandler;
union Sighandler { union Sighandler {
void *__sa_handler; uint32 __sa_handler;
void *__sa_sigaction; uint32 __sa_sigaction;
}; };
typedef struct Sigaction Sigaction; typedef struct Sigaction Sigaction;
struct Sigaction { struct Sigaction {
Sighandler __sigaction_u; Sighandler __sigaction_u;
void *sa_tramp; uint32 sa_tramp;
uint32 sa_mask; uint32 sa_mask;
int32 sa_flags; int32 sa_flags;
}; };
...@@ -171,14 +174,26 @@ struct Siginfo { ...@@ -171,14 +174,26 @@ struct Siginfo {
uint32 __pad[7]; uint32 __pad[7];
}; };
typedef struct Timeval Timeval;
struct Timeval {
int32 tv_sec;
int32 tv_usec;
};
typedef struct Itimerval Itimerval;
struct Itimerval {
Timeval it_interval;
Timeval it_value;
};
typedef struct FPControl FPControl; typedef struct FPControl FPControl;
struct FPControl { struct FPControl {
byte pad0[2]; byte pad_godefs_0[2];
}; };
typedef struct FPStatus FPStatus; typedef struct FPStatus FPStatus;
struct FPStatus { struct FPStatus {
byte pad0[2]; byte pad_godefs_0[2];
}; };
typedef struct RegMMST RegMMST; typedef struct RegMMST RegMMST;
...@@ -214,7 +229,7 @@ struct Regs { ...@@ -214,7 +229,7 @@ struct Regs {
typedef struct FloatState FloatState; typedef struct FloatState FloatState;
struct FloatState { struct FloatState {
int32 fpu_reserved[2]; uint64 fpu_reserved;
FPControl fpu_fcw; FPControl fpu_fcw;
FPStatus fpu_fsw; FPStatus fpu_fsw;
uint8 fpu_ftw; uint8 fpu_ftw;
...@@ -267,7 +282,7 @@ struct Ucontext { ...@@ -267,7 +282,7 @@ struct Ucontext {
int32 uc_onstack; int32 uc_onstack;
uint32 uc_sigmask; uint32 uc_sigmask;
StackT uc_stack; StackT uc_stack;
Ucontext *uc_link; uint32 uc_link;
uint32 uc_mcsize; uint32 uc_mcsize;
Mcontext *uc_mcontext; Mcontext *uc_mcontext;
}; };
......
...@@ -45,6 +45,11 @@ TEXT runtime·munmap(SB),7,$0 ...@@ -45,6 +45,11 @@ TEXT runtime·munmap(SB),7,$0
CALL runtime·notok(SB) CALL runtime·notok(SB)
RET RET
TEXT runtime·setitimer(SB),7,$0
MOVL $83, AX
INT $0x80
RET
// void gettime(int64 *sec, int32 *usec) // void gettime(int64 *sec, int32 *usec)
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
LEAL 12(SP), AX // must be non-nil, unused LEAL 12(SP), AX // must be non-nil, unused
......
...@@ -89,6 +89,9 @@ enum { ...@@ -89,6 +89,9 @@ enum {
BUS_OBJERR = 0x3, BUS_OBJERR = 0x3,
SEGV_MAPERR = 0x1, SEGV_MAPERR = 0x1,
SEGV_ACCERR = 0x2, SEGV_ACCERR = 0x2,
ITIMER_REAL = 0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
}; };
// Types // Types
...@@ -135,19 +138,19 @@ struct StackT { ...@@ -135,19 +138,19 @@ struct StackT {
void *ss_sp; void *ss_sp;
uint64 ss_size; uint64 ss_size;
int32 ss_flags; int32 ss_flags;
byte pad0[4]; byte pad_godefs_0[4];
}; };
typedef union Sighandler Sighandler; typedef union Sighandler Sighandler;
union Sighandler { union Sighandler {
void *__sa_handler; uint64 __sa_handler;
void *__sa_sigaction; uint64 __sa_sigaction;
}; };
typedef struct Sigaction Sigaction; typedef struct Sigaction Sigaction;
struct Sigaction { struct Sigaction {
Sighandler __sigaction_u; Sighandler __sigaction_u;
void *sa_tramp; uint64 sa_tramp;
uint32 sa_mask; uint32 sa_mask;
int32 sa_flags; int32 sa_flags;
}; };
...@@ -172,14 +175,27 @@ struct Siginfo { ...@@ -172,14 +175,27 @@ struct Siginfo {
uint64 __pad[7]; uint64 __pad[7];
}; };
typedef struct Timeval Timeval;
struct Timeval {
int64 tv_sec;
int32 tv_usec;
byte pad_godefs_0[4];
};
typedef struct Itimerval Itimerval;
struct Itimerval {
Timeval it_interval;
Timeval it_value;
};
typedef struct FPControl FPControl; typedef struct FPControl FPControl;
struct FPControl { struct FPControl {
byte pad0[2]; byte pad_godefs_0[2];
}; };
typedef struct FPStatus FPStatus; typedef struct FPStatus FPStatus;
struct FPStatus { struct FPStatus {
byte pad0[2]; byte pad_godefs_0[2];
}; };
typedef struct RegMMST RegMMST; typedef struct RegMMST RegMMST;
...@@ -220,7 +236,7 @@ struct Regs { ...@@ -220,7 +236,7 @@ struct Regs {
typedef struct FloatState FloatState; typedef struct FloatState FloatState;
struct FloatState { struct FloatState {
int32 fpu_reserved[2]; uint64 fpu_reserved;
FPControl fpu_fcw; FPControl fpu_fcw;
FPStatus fpu_fsw; FPStatus fpu_fsw;
uint8 fpu_ftw; uint8 fpu_ftw;
...@@ -274,7 +290,7 @@ struct Mcontext { ...@@ -274,7 +290,7 @@ struct Mcontext {
ExceptionState es; ExceptionState es;
Regs ss; Regs ss;
FloatState fs; FloatState fs;
byte pad0[4]; byte pad_godefs_0[4];
}; };
typedef struct Ucontext Ucontext; typedef struct Ucontext Ucontext;
...@@ -282,7 +298,7 @@ struct Ucontext { ...@@ -282,7 +298,7 @@ struct Ucontext {
int32 uc_onstack; int32 uc_onstack;
uint32 uc_sigmask; uint32 uc_sigmask;
StackT uc_stack; StackT uc_stack;
Ucontext *uc_link; uint64 uc_link;
uint64 uc_mcsize; uint64 uc_mcsize;
Mcontext *uc_mcontext; Mcontext *uc_mcontext;
}; };
......
...@@ -38,11 +38,19 @@ TEXT runtime·write(SB),7,$0 ...@@ -38,11 +38,19 @@ TEXT runtime·write(SB),7,$0
SYSCALL SYSCALL
RET RET
TEXT runtime·setitimer(SB), 7, $0
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVL $(0x2000000+83), AX // syscall entry
SYSCALL
RET
// void gettime(int64 *sec, int32 *usec) // void gettime(int64 *sec, int32 *usec)
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVQ SP, DI // must be non-nil, unused MOVQ SP, DI // must be non-nil, unused
MOVQ $0, SI MOVQ $0, SI
MOVQ $(0x2000000+116), AX MOVL $(0x2000000+116), AX
SYSCALL SYSCALL
MOVQ sec+0(FP), DI MOVQ sec+0(FP), DI
MOVQ AX, (DI) MOVQ AX, (DI)
......
...@@ -116,6 +116,10 @@ enum { ...@@ -116,6 +116,10 @@ enum {
$SEGV_MAPERR = SEGV_MAPERR, $SEGV_MAPERR = SEGV_MAPERR,
$SEGV_ACCERR = SEGV_ACCERR, $SEGV_ACCERR = SEGV_ACCERR,
$ITIMER_REAL = ITIMER_REAL,
$ITIMER_VIRTUAL = ITIMER_VIRTUAL,
$ITIMER_PROF = ITIMER_PROF,
}; };
typedef mach_msg_body_t $MachBody; typedef mach_msg_body_t $MachBody;
...@@ -130,6 +134,8 @@ typedef struct __sigaction $Sigaction; // used in syscalls ...@@ -130,6 +134,8 @@ typedef struct __sigaction $Sigaction; // used in syscalls
// typedef struct sigaction $Sigaction; // used by the C library // typedef struct sigaction $Sigaction; // used by the C library
typedef union sigval $Sigval; typedef union sigval $Sigval;
typedef siginfo_t $Siginfo; typedef siginfo_t $Siginfo;
typedef struct timeval $Timeval;
typedef struct itimerval $Itimerval;
typedef struct fp_control $FPControl; typedef struct fp_control $FPControl;
typedef struct fp_status $FPStatus; typedef struct fp_status $FPStatus;
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
#define SIG_DFL ((void*)0)
#define SIG_IGN ((void*)1)
int32 runtime·bsdthread_create(void*, M*, G*, void(*)(void)); int32 runtime·bsdthread_create(void*, M*, G*, void(*)(void));
void runtime·bsdthread_register(void); void runtime·bsdthread_register(void);
int32 runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32); int32 runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32);
...@@ -23,3 +26,4 @@ struct StackT; ...@@ -23,3 +26,4 @@ struct StackT;
void runtime·sigaltstack(struct StackT*, struct StackT*); void runtime·sigaltstack(struct StackT*, struct StackT*);
void runtime·sigtramp(void); void runtime·sigtramp(void);
void runtime·sigpanic(void); void runtime·sigpanic(void);
void runtime·setitimer(int32, Itimerval*, Itimerval*);
...@@ -87,6 +87,11 @@ TEXT runtime·munmap(SB),7,$-4 ...@@ -87,6 +87,11 @@ TEXT runtime·munmap(SB),7,$-4
CALL runtime·notok(SB) CALL runtime·notok(SB)
RET RET
TEXT runtime·setitimer(SB), 7, $-4
MOVL $83, AX
INT $0x80
RET
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVL $116, AX MOVL $116, AX
LEAL 12(SP), BX LEAL 12(SP), BX
......
...@@ -65,6 +65,14 @@ TEXT runtime·write(SB),7,$-8 ...@@ -65,6 +65,14 @@ TEXT runtime·write(SB),7,$-8
SYSCALL SYSCALL
RET RET
TEXT runtime·setitimer(SB), 7, $-8
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVL $83, AX
SYSCALL
RET
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVL $116, AX MOVL $116, AX
LEAQ 8(SP), DI LEAQ 8(SP), DI
......
...@@ -86,6 +86,10 @@ enum { ...@@ -86,6 +86,10 @@ enum {
$SEGV_MAPERR = SEGV_MAPERR, $SEGV_MAPERR = SEGV_MAPERR,
$SEGV_ACCERR = SEGV_ACCERR, $SEGV_ACCERR = SEGV_ACCERR,
$ITIMER_REAL = ITIMER_REAL,
$ITIMER_VIRTUAL = ITIMER_VIRTUAL,
$ITIMER_PROF = ITIMER_PROF,
}; };
typedef struct rtprio $Rtprio; typedef struct rtprio $Rtprio;
...@@ -99,3 +103,4 @@ typedef siginfo_t $Siginfo; ...@@ -99,3 +103,4 @@ typedef siginfo_t $Siginfo;
typedef mcontext_t $Mcontext; typedef mcontext_t $Mcontext;
typedef ucontext_t $Ucontext; typedef ucontext_t $Ucontext;
typedef struct itimerval $Itimerval;
#define SIG_DFL ((void*)0)
#define SIG_IGN ((void*)1)
int32 runtime·thr_new(ThrParam*, int32); int32 runtime·thr_new(ThrParam*, int32);
void runtime·sigpanic(void); void runtime·sigpanic(void);
void runtime·sigaltstack(Sigaltstack*, Sigaltstack*); void runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
struct sigaction; struct sigaction;
void runtime·sigaction(int32, struct sigaction*, struct sigaction*); void runtime·sigaction(int32, struct sigaction*, struct sigaction*);
void runtiem·setitimerval(int32, Itimerval*, Itimerval*);
...@@ -58,6 +58,9 @@ enum { ...@@ -58,6 +58,9 @@ enum {
BUS_OBJERR = 0x3, BUS_OBJERR = 0x3,
SEGV_MAPERR = 0x1, SEGV_MAPERR = 0x1,
SEGV_ACCERR = 0x2, SEGV_ACCERR = 0x2,
ITIMER_REAL = 0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
}; };
// Types // Types
...@@ -98,7 +101,8 @@ struct Fpstate { ...@@ -98,7 +101,8 @@ struct Fpstate {
uint32 reserved; uint32 reserved;
Fpxreg _fxsr_st[8]; Fpxreg _fxsr_st[8];
Xmmreg _xmm[8]; Xmmreg _xmm[8];
uint32 padding[56]; uint32 padding1[44];
byte Pad_godefs_0[48];
}; };
typedef struct Timespec Timespec; typedef struct Timespec Timespec;
...@@ -176,4 +180,10 @@ struct Ucontext { ...@@ -176,4 +180,10 @@ struct Ucontext {
Sigcontext uc_mcontext; Sigcontext uc_mcontext;
uint32 uc_sigmask; uint32 uc_sigmask;
}; };
typedef struct Itimerval Itimerval;
struct Itimerval {
Timeval it_interval;
Timeval it_value;
};
#pragma pack off #pragma pack off
...@@ -30,6 +30,15 @@ TEXT runtime·write(SB),7,$0 ...@@ -30,6 +30,15 @@ TEXT runtime·write(SB),7,$0
INT $0x80 INT $0x80
RET RET
TEXT runtime·setitimer(SB),7,$0-24
MOVL $104, AX // syscall - setitimer
MOVL 4(SP), BX
MOVL 8(SP), CX
MOVL 12(SP), DX
INT $0x80
RET
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVL $78, AX // syscall - gettimeofday MOVL $78, AX // syscall - gettimeofday
LEAL 8(SP), BX LEAL 8(SP), BX
......
...@@ -58,6 +58,9 @@ enum { ...@@ -58,6 +58,9 @@ enum {
BUS_OBJERR = 0x3, BUS_OBJERR = 0x3,
SEGV_MAPERR = 0x1, SEGV_MAPERR = 0x1,
SEGV_ACCERR = 0x2, SEGV_ACCERR = 0x2,
ITIMER_REAL = 0,
ITIMER_VIRTUAL = 0x1,
ITIMER_PROF = 0x2,
}; };
// Types // Types
...@@ -88,9 +91,15 @@ struct Siginfo { ...@@ -88,9 +91,15 @@ struct Siginfo {
int32 si_signo; int32 si_signo;
int32 si_errno; int32 si_errno;
int32 si_code; int32 si_code;
byte pad0[4]; byte pad_godefs_0[4];
byte _sifields[112]; byte _sifields[112];
}; };
typedef struct Itimerval Itimerval;
struct Itimerval {
Timeval it_interval;
Timeval it_value;
};
#pragma pack off #pragma pack off
// godefs -f -m64 defs1.c // godefs -f -m64 defs1.c
...@@ -170,7 +179,7 @@ typedef struct Sigaltstack Sigaltstack; ...@@ -170,7 +179,7 @@ typedef struct Sigaltstack Sigaltstack;
struct Sigaltstack { struct Sigaltstack {
void *ss_sp; void *ss_sp;
int32 ss_flags; int32 ss_flags;
byte pad0[4]; byte pad_godefs_0[4];
uint64 ss_size; uint64 ss_size;
}; };
......
...@@ -36,6 +36,14 @@ TEXT runtime·write(SB),7,$0-24 ...@@ -36,6 +36,14 @@ TEXT runtime·write(SB),7,$0-24
SYSCALL SYSCALL
RET RET
TEXT runtime·setitimer(SB),7,$0-24
MOVL 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVL $38, AX // syscall entry
SYSCALL
RET
TEXT runtime·gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
LEAQ 8(SP), DI LEAQ 8(SP), DI
MOVQ $0, SI MOVQ $0, SI
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define SYS_futex (SYS_BASE + 240) #define SYS_futex (SYS_BASE + 240)
#define SYS_exit_group (SYS_BASE + 248) #define SYS_exit_group (SYS_BASE + 248)
#define SYS_munmap (SYS_BASE + 91) #define SYS_munmap (SYS_BASE + 91)
#define SYS_setitimer (SYS_BASE + 104)
#define ARM_BASE (SYS_BASE + 0x0f0000) #define ARM_BASE (SYS_BASE + 0x0f0000)
#define SYS_ARM_cacheflush (ARM_BASE + 2) #define SYS_ARM_cacheflush (ARM_BASE + 2)
...@@ -72,6 +73,14 @@ TEXT runtime·munmap(SB),7,$0 ...@@ -72,6 +73,14 @@ TEXT runtime·munmap(SB),7,$0
SWI $0 SWI $0
RET RET
TEXT runtime·getitimer(SB),7,$0
MOVW 0(FP), R0
MOVW 4(FP), R1
MOWW 8(FP), R2
MOVW $SYS_setitimer, R7
SWI $0
RET
TEXT runtime·gettime(SB),7,$32 TEXT runtime·gettime(SB),7,$32
/* dummy version - return 0,0 */ /* dummy version - return 0,0 */
MOVW $0, R1 MOVW $0, R1
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
// headers for things like ucontext_t, so that happens in // headers for things like ucontext_t, so that happens in
// a separate file, defs1.c. // a separate file, defs1.c.
#include <asm/posix_types.h>
#define size_t __kernel_size_t
#include <asm/signal.h> #include <asm/signal.h>
#include <asm/siginfo.h> #include <asm/siginfo.h>
#include <asm/mman.h> #include <asm/mman.h>
...@@ -80,9 +82,14 @@ enum { ...@@ -80,9 +82,14 @@ enum {
$SEGV_MAPERR = SEGV_MAPERR, $SEGV_MAPERR = SEGV_MAPERR,
$SEGV_ACCERR = SEGV_ACCERR, $SEGV_ACCERR = SEGV_ACCERR,
$ITIMER_REAL = ITIMER_REAL,
$ITIMER_VIRTUAL = ITIMER_VIRTUAL,
$ITIMER_PROF = ITIMER_PROF,
}; };
typedef struct timespec $Timespec; typedef struct timespec $Timespec;
typedef struct timeval $Timeval; typedef struct timeval $Timeval;
typedef struct sigaction $Sigaction; typedef struct sigaction $Sigaction;
typedef siginfo_t $Siginfo; typedef siginfo_t $Siginfo;
typedef struct itimerval $Itimerval;
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
-f -I/home/rsc/pub/linux-2.6/arch/x86/include \ -f -I/home/rsc/pub/linux-2.6/arch/x86/include \
-f -I/home/rsc/pub/linux-2.6/include \ -f -I/home/rsc/pub/linux-2.6/include \
-f -D_LOOSE_KERNEL_NAMES \ -f -D_LOOSE_KERNEL_NAMES \
-f -D__ARCH_SI_UID_T=__kernel_uid32_t \ -f -D__ARCH_SI_UID_T'='__kernel_uid32_t \
defs2.c >386/defs.h defs2.c >386/defs.h
* The asm header tricks we have to use for Linux on amd64 * The asm header tricks we have to use for Linux on amd64
...@@ -100,6 +100,10 @@ enum { ...@@ -100,6 +100,10 @@ enum {
$SEGV_MAPERR = SEGV_MAPERR, $SEGV_MAPERR = SEGV_MAPERR,
$SEGV_ACCERR = SEGV_ACCERR, $SEGV_ACCERR = SEGV_ACCERR,
$ITIMER_REAL = ITIMER_REAL,
$ITIMER_VIRTUAL = ITIMER_VIRTUAL,
$ITIMER_PROF = ITIMER_PROF,
}; };
typedef struct _fpreg $Fpreg; typedef struct _fpreg $Fpreg;
...@@ -113,4 +117,4 @@ typedef siginfo_t $Siginfo; ...@@ -113,4 +117,4 @@ typedef siginfo_t $Siginfo;
typedef struct sigaltstack $Sigaltstack; typedef struct sigaltstack $Sigaltstack;
typedef struct sigcontext $Sigcontext; typedef struct sigcontext $Sigcontext;
typedef struct ucontext $Ucontext; typedef struct ucontext $Ucontext;
typedef struct itimerval $Itimerval;
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
#define SIG_DFL ((void*)0)
#define SIG_IGN ((void*)1)
// Linux-specific system calls // Linux-specific system calls
int32 runtime·futex(uint32*, int32, uint32, Timespec*, uint32*, uint32); int32 runtime·futex(uint32*, int32, uint32, Timespec*, uint32*, uint32);
int32 runtime·clone(int32, void*, M*, G*, void(*)(void)); int32 runtime·clone(int32, void*, M*, G*, void(*)(void));
...@@ -11,3 +14,4 @@ void runtime·rt_sigaction(uintptr, struct Sigaction*, void*, uintptr); ...@@ -11,3 +14,4 @@ void runtime·rt_sigaction(uintptr, struct Sigaction*, void*, uintptr);
void runtime·sigaltstack(Sigaltstack*, Sigaltstack*); void runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
void runtime·sigpanic(void); void runtime·sigpanic(void);
void runtime·setitimer(int32, Itimerval*, Itimerval*);
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