提交 66fb9763 编写于 作者: B bellard

basic signal handling


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@41 c046a42c-6fe2-441c-8c8c-71466251a162
上级 1b6b029e
......@@ -36,7 +36,7 @@ LDFLAGS+=-p
main.o: CFLAGS+=-p
endif
OBJS= elfload.o main.o thunk.o syscall.o libgemu.a
OBJS= elfload.o main.o thunk.o syscall.o signal.o libgemu.a
LIBOBJS+=translate-i386.o op-i386.o exec-i386.o
# NOTE: the disassembler code is only needed for debugging
......
- asynchronous signal interrupt / clear synchronous signal handling
- add eflags restore in emulator
- finish signal handing (fp87 state)
- verify thread support (clone() and various locks)
- signals
- optimize translated cache chaining (DLL PLT-like system)
- vm86 syscall support
- overrides/16bit for string ops
......
......@@ -81,10 +81,6 @@ int cpu_x86_inl(int addr)
return 0;
}
/* default linux values for the selectors */
#define __USER_CS (0x23)
#define __USER_DS (0x2B)
void write_dt(void *ptr, unsigned long addr, unsigned long limit,
int seg32_bit)
{
......@@ -135,6 +131,7 @@ void cpu_loop(struct CPUX86State *env)
(long)pc, err);
abort();
}
process_pending_signals(env);
}
}
......@@ -199,6 +196,7 @@ int main(int argc, char **argv)
target_set_brk((char *)info->brk);
syscall_init();
signal_init();
env = cpu_x86_init();
......
......@@ -3,6 +3,12 @@
#include "thunk.h"
#ifdef TARGET_I386
/* default linux values for the selectors */
#define __USER_CS (0x23)
#define __USER_DS (0x2B)
struct target_pt_regs {
long ebx;
long ecx;
......@@ -21,6 +27,8 @@ struct target_pt_regs {
int xss;
};
#endif
/* This struct is used to hold certain information about the image.
* Basically, it replicates in user space what would be certain
* task_struct fields in the kernel
......@@ -53,5 +61,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
struct CPUX86State;
void cpu_loop(struct CPUX86State *env);
void process_pending_signals(void *cpu_env);
void signal_init(void);
#endif
此差异已折叠。
......@@ -75,12 +75,18 @@
#include "syscall-i386.h"
#endif
void host_to_target_siginfo(target_siginfo_t *tinfo, siginfo_t *info);
void target_to_host_siginfo(siginfo_t *info, target_siginfo_t *tinfo);
long do_sigreturn(CPUX86State *env);
long do_rt_sigreturn(CPUX86State *env);
#define __NR_sys_uname __NR_uname
#define __NR_sys_getcwd1 __NR_getcwd
#define __NR_sys_statfs __NR_statfs
#define __NR_sys_fstatfs __NR_fstatfs
#define __NR_sys_getdents __NR_getdents
#define __NR_sys_getdents64 __NR_getdents64
#define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
#ifdef __NR_gettid
_syscall0(int, gettid)
......@@ -97,6 +103,9 @@ _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
loff_t *, res, uint, wh);
_syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf)
_syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf)
_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
extern int personality(int);
static inline long get_errno(long ret)
{
......@@ -199,18 +208,18 @@ static inline void host_to_target_fds(target_long *target_fds,
#endif
}
/* XXX: incorrect for some archs */
static void host_to_target_old_sigset(target_ulong *old_sigset,
const sigset_t *sigset)
static inline void target_to_host_timeval(struct timeval *tv,
struct target_timeval *target_tv)
{
*old_sigset = tswap32(*(unsigned long *)sigset & 0xffffffff);
tv->tv_sec = tswapl(target_tv->tv_sec);
tv->tv_usec = tswapl(target_tv->tv_usec);
}
static void target_to_host_old_sigset(sigset_t *sigset,
const target_ulong *old_sigset)
static inline void host_to_target_timeval(struct target_timeval *target_tv,
struct timeval *tv)
{
sigemptyset(sigset);
*(unsigned long *)sigset = tswapl(*old_sigset);
target_tv->tv_sec = tswapl(tv->tv_sec);
target_tv->tv_usec = tswapl(tv->tv_usec);
}
......@@ -1042,28 +1051,195 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
ret = get_errno(setsid());
break;
case TARGET_NR_sigaction:
#if 1
{
ret = 0;
struct target_old_sigaction *old_act = (void *)arg2;
struct target_old_sigaction *old_oact = (void *)arg3;
struct target_sigaction act, oact, *pact;
if (old_act) {
act._sa_handler = old_act->_sa_handler;
target_siginitset(&act.sa_mask, old_act->sa_mask);
act.sa_flags = old_act->sa_flags;
act.sa_restorer = old_act->sa_restorer;
pact = &act;
} else {
pact = NULL;
}
ret = get_errno(do_sigaction(arg1, pact, &oact));
if (!is_error(ret) && old_oact) {
old_oact->_sa_handler = oact._sa_handler;
old_oact->sa_mask = oact.sa_mask.sig[0];
old_oact->sa_flags = oact.sa_flags;
old_oact->sa_restorer = oact.sa_restorer;
}
}
break;
#else
goto unimplemented;
#endif
case TARGET_NR_rt_sigaction:
ret = get_errno(do_sigaction(arg1, (void *)arg2, (void *)arg3));
break;
case TARGET_NR_sgetmask:
goto unimplemented;
{
sigset_t cur_set;
target_ulong target_set;
sigprocmask(0, NULL, &cur_set);
host_to_target_old_sigset(&target_set, &cur_set);
ret = target_set;
}
break;
case TARGET_NR_ssetmask:
goto unimplemented;
{
sigset_t set, oset, cur_set;
target_ulong target_set = arg1;
sigprocmask(0, NULL, &cur_set);
target_to_host_old_sigset(&set, &target_set);
sigorset(&set, &set, &cur_set);
sigprocmask(SIG_SETMASK, &set, &oset);
host_to_target_old_sigset(&target_set, &oset);
ret = target_set;
}
break;
case TARGET_NR_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
target_ulong *pset = (void *)arg2, *poldset = (void *)arg3;
if (pset) {
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
break;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
break;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
break;
default:
ret = -EINVAL;
goto fail;
}
target_to_host_old_sigset(&set, pset);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
}
ret = get_errno(sigprocmask(arg1, set_ptr, &oldset));
if (!is_error(ret) && poldset) {
host_to_target_old_sigset(poldset, &oldset);
}
}
break;
case TARGET_NR_rt_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
target_sigset_t *pset = (void *)arg2;
target_sigset_t *poldset = (void *)arg3;
if (pset) {
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
break;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
break;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
break;
default:
ret = -EINVAL;
goto fail;
}
target_to_host_sigset(&set, pset);
set_ptr = &set;
} else {
how = 0;
set_ptr = NULL;
}
ret = get_errno(sigprocmask(how, set_ptr, &oldset));
if (!is_error(ret) && poldset) {
host_to_target_sigset(poldset, &oldset);
}
}
break;
case TARGET_NR_sigpending:
{
sigset_t set;
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
host_to_target_old_sigset((target_ulong *)arg1, &set);
}
}
break;
case TARGET_NR_rt_sigpending:
{
sigset_t set;
ret = get_errno(sigpending(&set));
if (!is_error(ret)) {
host_to_target_sigset((target_sigset_t *)arg1, &set);
}
}
break;
case TARGET_NR_sigsuspend:
{
sigset_t set;
target_to_host_old_sigset(&set, (target_ulong *)arg1);
ret = get_errno(sigsuspend(&set));
}
break;
case TARGET_NR_rt_sigsuspend:
{
sigset_t set;
target_to_host_sigset(&set, (target_sigset_t *)arg1);
ret = get_errno(sigsuspend(&set));
}
break;
case TARGET_NR_rt_sigtimedwait:
{
target_sigset_t *target_set = (void *)arg1;
target_siginfo_t *target_uinfo = (void *)arg2;
struct target_timespec *target_uts = (void *)arg3;
sigset_t set;
struct timespec uts, *puts;
siginfo_t uinfo;
target_to_host_sigset(&set, target_set);
if (target_uts) {
puts = &uts;
puts->tv_sec = tswapl(target_uts->tv_sec);
puts->tv_nsec = tswapl(target_uts->tv_nsec);
} else {
puts = NULL;
}
ret = get_errno(sigtimedwait(&set, &uinfo, puts));
if (!is_error(ret) && target_uinfo) {
host_to_target_siginfo(target_uinfo, &uinfo);
}
}
break;
case TARGET_NR_rt_sigqueueinfo:
{
siginfo_t uinfo;
target_to_host_siginfo(&uinfo, (target_siginfo_t *)arg3);
ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
}
break;
case TARGET_NR_sigreturn:
/* NOTE: ret is eax, so not transcoding must be done */
ret = do_sigreturn(cpu_env);
break;
case TARGET_NR_rt_sigreturn:
/* NOTE: ret is eax, so not transcoding must be done */
ret = do_rt_sigreturn(cpu_env);
break;
case TARGET_NR_setreuid:
ret = get_errno(setreuid(arg1, arg2));
break;
case TARGET_NR_setregid:
ret = get_errno(setregid(arg1, arg2));
break;
case TARGET_NR_sigsuspend:
goto unimplemented;
case TARGET_NR_sigpending:
goto unimplemented;
case TARGET_NR_sethostname:
ret = get_errno(sethostname((const char *)arg1, arg2));
break;
......@@ -1190,9 +1366,43 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
case TARGET_NR_syslog:
goto unimplemented;
case TARGET_NR_setitimer:
goto unimplemented;
{
struct target_itimerval *target_value = (void *)arg2;
struct target_itimerval *target_ovalue = (void *)arg3;
struct itimerval value, ovalue, *pvalue;
if (target_value) {
pvalue = &value;
target_to_host_timeval(&pvalue->it_interval,
&target_value->it_interval);
target_to_host_timeval(&pvalue->it_value,
&target_value->it_value);
} else {
pvalue = NULL;
}
ret = get_errno(setitimer(arg1, pvalue, &ovalue));
if (!is_error(ret) && target_ovalue) {
host_to_target_timeval(&target_ovalue->it_interval,
&ovalue.it_interval);
host_to_target_timeval(&target_ovalue->it_value,
&ovalue.it_value);
}
}
break;
case TARGET_NR_getitimer:
goto unimplemented;
{
struct target_itimerval *target_value = (void *)arg2;
struct itimerval value;
ret = get_errno(getitimer(arg1, &value));
if (!is_error(ret) && target_value) {
host_to_target_timeval(&target_value->it_interval,
&value.it_interval);
host_to_target_timeval(&target_value->it_value,
&value.it_value);
}
}
break;
case TARGET_NR_stat:
ret = get_errno(stat((const char *)arg1, &st));
goto do_stat;
......@@ -1279,8 +1489,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
case TARGET_NR_fsync:
ret = get_errno(fsync(arg1));
break;
case TARGET_NR_sigreturn:
goto unimplemented;
case TARGET_NR_clone:
ret = get_errno(do_fork(cpu_env, arg1, arg2));
break;
......@@ -1301,39 +1509,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
case TARGET_NR_mprotect:
ret = get_errno(mprotect((void *)arg1, arg2, arg3));
break;
case TARGET_NR_sigprocmask:
{
int how = arg1;
sigset_t set, oldset, *set_ptr;
target_ulong *pset = (void *)arg2, *poldset = (void *)arg3;
switch(how) {
case TARGET_SIG_BLOCK:
how = SIG_BLOCK;
break;
case TARGET_SIG_UNBLOCK:
how = SIG_UNBLOCK;
break;
case TARGET_SIG_SETMASK:
how = SIG_SETMASK;
break;
default:
ret = -EINVAL;
goto fail;
}
if (pset) {
target_to_host_old_sigset(&set, pset);
set_ptr = &set;
} else {
set_ptr = NULL;
}
ret = get_errno(sigprocmask(arg1, set_ptr, &oldset));
if (!is_error(ret) && poldset) {
host_to_target_old_sigset(poldset, &oldset);
}
}
break;
case TARGET_NR_create_module:
case TARGET_NR_init_module:
case TARGET_NR_delete_module:
......@@ -1516,13 +1691,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
case TARGET_NR_setresgid:
case TARGET_NR_getresgid:
case TARGET_NR_prctl:
case TARGET_NR_rt_sigreturn:
case TARGET_NR_rt_sigaction:
case TARGET_NR_rt_sigprocmask:
case TARGET_NR_rt_sigpending:
case TARGET_NR_rt_sigtimedwait:
case TARGET_NR_rt_sigqueueinfo:
case TARGET_NR_rt_sigsuspend:
case TARGET_NR_pread:
case TARGET_NR_pwrite:
goto unimplemented;
......
......@@ -29,6 +29,11 @@ struct target_timespec {
target_long tv_nsec;
};
struct target_itimerval {
struct target_timeval it_interval;
struct target_timeval it_value;
};
struct target_iovec {
target_long iov_base; /* Starting address */
target_long iov_len; /* Number of bytes */
......@@ -113,6 +118,38 @@ typedef struct {
target_ulong sig[TARGET_NSIG_WORDS];
} target_sigset_t;
#ifdef BSWAP_NEEDED
static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
{
int i;
for(i = 0;i < TARGET_NSIG_WORDS; i++)
d->sig[i] = tswapl(s->sig[i]);
}
#else
static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s)
{
*d = *s;
}
#endif
static inline void target_siginitset(target_sigset_t *d, target_ulong set)
{
int i;
d->sig[0] = set;
for(i = 1;i < TARGET_NSIG_WORDS; i++)
d->sig[i] = 0;
}
void host_to_target_sigset(target_sigset_t *d, sigset_t *s);
void target_to_host_sigset(sigset_t *d, target_sigset_t *s);
void host_to_target_old_sigset(target_ulong *old_sigset,
const sigset_t *sigset);
void target_to_host_old_sigset(sigset_t *sigset,
const target_ulong *old_sigset);
struct target_sigaction;
int do_sigaction(int sig, const struct target_sigaction *act,
struct target_sigaction *oact);
/* Networking ioctls */
#define TARGET_SIOCADDRT 0x890B /* add routing table entry */
#define TARGET_SIOCDELRT 0x890C /* delete routing table entry */
......
/*
* i386 micro operations (included several times to generate
* different operand sizes)
*
* Copyright (c) 2003 Fabrice Bellard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define DATA_BITS (1 << (3 + SHIFT))
#define SHIFT_MASK (DATA_BITS - 1)
......
......@@ -302,20 +302,59 @@ struct target_stat64 {
unsigned long long st_ino;
};
typedef unsigned long old_sigset_t; /* at least 32 bits */
#define TARGET_SA_NOCLDSTOP 0x00000001
#define TARGET_SA_NOCLDWAIT 0x00000002 /* not supported yet */
#define TARGET_SA_SIGINFO 0x00000004
#define TARGET_SA_ONSTACK 0x08000000
#define TARGET_SA_RESTART 0x10000000
#define TARGET_SA_NODEFER 0x40000000
#define TARGET_SA_RESETHAND 0x80000000
#define TARGET_SA_RESTORER 0x04000000
#define TARGET_SIGHUP 1
#define TARGET_SIGINT 2
#define TARGET_SIGQUIT 3
#define TARGET_SIGILL 4
#define TARGET_SIGTRAP 5
#define TARGET_SIGABRT 6
#define TARGET_SIGIOT 6
#define TARGET_SIGBUS 7
#define TARGET_SIGFPE 8
#define TARGET_SIGKILL 9
#define TARGET_SIGUSR1 10
#define TARGET_SIGSEGV 11
#define TARGET_SIGUSR2 12
#define TARGET_SIGPIPE 13
#define TARGET_SIGALRM 14
#define TARGET_SIGTERM 15
#define TARGET_SIGSTKFLT 16
#define TARGET_SIGCHLD 17
#define TARGET_SIGCONT 18
#define TARGET_SIGSTOP 19
#define TARGET_SIGTSTP 20
#define TARGET_SIGTTIN 21
#define TARGET_SIGTTOU 22
#define TARGET_SIGURG 23
#define TARGET_SIGXCPU 24
#define TARGET_SIGXFSZ 25
#define TARGET_SIGVTALRM 26
#define TARGET_SIGPROF 27
#define TARGET_SIGWINCH 28
#define TARGET_SIGIO 29
#define TARGET_SIGRTMIN 32
struct target_old_sigaction {
target_ulong _sa_handler;
target_ulong sa_mask;
target_ulong sa_flags;
void (*sa_restorer)(void);
target_ulong sa_restorer;
};
struct target_sigaction {
target_ulong _sa_handler;
target_sigset_t sa_mask;
target_ulong sa_flags;
target_ulong sa_restorer;
target_sigset_t sa_mask;
};
typedef union target_sigval {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册