aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linux-user/main.c88
-rw-r--r--linux-user/qemu.h26
-rw-r--r--linux-user/signal.c257
-rw-r--r--linux-user/syscall.c6
4 files changed, 204 insertions, 173 deletions
diff --git a/linux-user/main.c b/linux-user/main.c
index 640b7fe775..21c2d3ba08 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -230,7 +230,7 @@ void cpu_loop(CPUX86State *env)
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case EXCP0D_GPF:
/* XXX: potential problem if ABI32 */
@@ -244,7 +244,7 @@ void cpu_loop(CPUX86State *env)
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP0E_PAGE:
@@ -255,7 +255,7 @@ void cpu_loop(CPUX86State *env)
else
info.si_code = TARGET_SEGV_ACCERR;
info._sifields._sigfault._addr = env->cr[2];
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case EXCP00_DIVZ:
#ifndef TARGET_X86_64
@@ -269,7 +269,7 @@ void cpu_loop(CPUX86State *env)
info.si_errno = 0;
info.si_code = TARGET_FPE_INTDIV;
info._sifields._sigfault._addr = env->eip;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP01_SSTP:
@@ -289,7 +289,7 @@ void cpu_loop(CPUX86State *env)
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
}
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP04_INTO:
@@ -304,7 +304,7 @@ void cpu_loop(CPUX86State *env)
info.si_errno = 0;
info.si_code = TARGET_SI_KERNEL;
info._sifields._sigfault._addr = 0;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP06_ILLOP:
@@ -312,7 +312,7 @@ void cpu_loop(CPUX86State *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->eip;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
@@ -327,7 +327,7 @@ void cpu_loop(CPUX86State *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -441,7 +441,7 @@ void cpu_loop(CPUARMState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->regs[15];
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
} else if (rc < 0) { /* FP exception */
int arm_fpe=0;
@@ -472,7 +472,7 @@ void cpu_loop(CPUARMState *env)
if (arm_fpe & BIT_IOC) info.si_code = TARGET_FPE_FLTINV;
info._sifields._sigfault._addr = env->regs[15];
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
} else {
env->regs[15] += 4;
}
@@ -584,7 +584,7 @@ void cpu_loop(CPUARMState *env)
/* XXX: check env->error_code */
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = addr;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP_DEBUG:
@@ -597,7 +597,7 @@ void cpu_loop(CPUARMState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -780,7 +780,7 @@ void cpu_loop (CPUSPARCState *env)
/* XXX: check env->error_code */
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->mmuregs[4];
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
#else
@@ -801,7 +801,7 @@ void cpu_loop (CPUSPARCState *env)
info._sifields._sigfault._addr = env->dmmuregs[4];
else
info._sifields._sigfault._addr = env->tsptr->tpc;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
#ifndef TARGET_ABI32
@@ -828,7 +828,7 @@ void cpu_loop (CPUSPARCState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -949,7 +949,7 @@ void cpu_loop(CPUPPCState *env)
break;
}
info._sifields._sigfault._addr = env->nip;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_ISI: /* Instruction storage exception */
EXCP_DUMP(env, "Invalid instruction fetch: 0x\n" ADDRX "\n",
@@ -977,7 +977,7 @@ void cpu_loop(CPUPPCState *env)
break;
}
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_EXTERNAL: /* External input */
cpu_abort(env, "External interrupt while in user mode. "
@@ -990,7 +990,7 @@ void cpu_loop(CPUPPCState *env)
info.si_errno = 0;
info.si_code = TARGET_BUS_ADRALN;
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_PROGRAM: /* Program exception */
/* XXX: check this */
@@ -1083,7 +1083,7 @@ void cpu_loop(CPUPPCState *env)
break;
}
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_FPU: /* Floating-point unavailable exception */
EXCP_DUMP(env, "No floating point allowed\n");
@@ -1091,7 +1091,7 @@ void cpu_loop(CPUPPCState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_COPROC;
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_SYSCALL: /* System call exception */
cpu_abort(env, "Syscall exception while in user mode. "
@@ -1103,7 +1103,7 @@ void cpu_loop(CPUPPCState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_COPROC;
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_DECR: /* Decrementer exception */
cpu_abort(env, "Decrementer interrupt while in user mode. "
@@ -1135,7 +1135,7 @@ void cpu_loop(CPUPPCState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -1145,7 +1145,7 @@ void cpu_loop(CPUPPCState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_COPROC;
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_EFPDI: /* Embedded floating-point data IRQ */
cpu_abort(env, "Embedded floating-point data IRQ not handled\n");
@@ -1209,7 +1209,7 @@ void cpu_loop(CPUPPCState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_COPROC;
info._sifields._sigfault._addr = env->nip - 4;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case POWERPC_EXCP_PIT: /* Programmable interval timer IRQ */
cpu_abort(env, "Programable interval timer interrupt "
@@ -1685,7 +1685,7 @@ void cpu_loop(CPUMIPSState *env)
info.si_signo = TARGET_SIGILL;
info.si_errno = 0;
info.si_code = 0;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case EXCP_INTERRUPT:
/* just indicate that signals should be handled asap */
@@ -1700,7 +1700,7 @@ void cpu_loop(CPUMIPSState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -1751,7 +1751,7 @@ void cpu_loop (CPUState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -1761,7 +1761,7 @@ void cpu_loop (CPUState *env)
info.si_errno = 0;
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->tea;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
default:
@@ -1790,7 +1790,7 @@ void cpu_loop (CPUState *env)
/* XXX: check env->error_code */
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->pregs[PR_EDA];
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP_INTERRUPT:
@@ -1818,7 +1818,7 @@ void cpu_loop (CPUState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -1869,7 +1869,7 @@ void cpu_loop(CPUM68KState *env)
info.si_errno = 0;
info.si_code = TARGET_ILL_ILLOPN;
info._sifields._sigfault._addr = env->pc;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
break;
case EXCP_TRAP0:
{
@@ -1896,7 +1896,7 @@ void cpu_loop(CPUM68KState *env)
/* XXX: check env->error_code */
info.si_code = TARGET_SEGV_MAPERR;
info._sifields._sigfault._addr = env->mmu.ar;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
break;
case EXCP_DEBUG:
@@ -1909,7 +1909,7 @@ void cpu_loop(CPUM68KState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -2000,7 +2000,7 @@ void cpu_loop (CPUState *env)
info.si_signo = sig;
info.si_errno = 0;
info.si_code = TARGET_TRAP_BRKPT;
- queue_signal(info.si_signo, &info);
+ queue_signal(env, info.si_signo, &info);
}
}
break;
@@ -2047,9 +2047,19 @@ void usage(void)
/* XXX: currently only used for async signals (see signal.c) */
CPUState *global_env;
-/* used to free thread contexts */
-TaskState *first_task_state;
-
+void init_task_state(TaskState *ts)
+{
+ int i;
+
+ memset(ts, 0, sizeof(TaskState));
+ ts->used = 1;
+ ts->first_free = ts->sigqueue_table;
+ for (i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) {
+ ts->sigqueue_table[i].next = &ts->sigqueue_table[i + 1];
+ }
+ ts->sigqueue_table[i].next = NULL;
+}
+
int main(int argc, char **argv)
{
const char *filename;
@@ -2246,9 +2256,9 @@ int main(int argc, char **argv)
/* build Task State */
memset(ts, 0, sizeof(TaskState));
- env->opaque = ts;
- ts->used = 1;
+ init_task_state(ts);
ts->info = info;
+ env->opaque = ts;
env->user_mode_only = 1;
#if defined(TARGET_I386)
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index cc44c9a19a..8b114954f0 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -82,6 +82,20 @@ struct vm86_saved_state {
#include "nwfpe/fpa11.h"
#endif
+#define MAX_SIGQUEUE_SIZE 1024
+
+struct sigqueue {
+ struct sigqueue *next;
+ target_siginfo_t info;
+};
+
+struct emulated_sigtable {
+ int pending; /* true if signal is pending */
+ struct sigqueue *first;
+ struct sigqueue info; /* in order to always have memory for the
+ first signal, we put it here */
+};
+
/* NOTE: we force a big alignment so that the stack stored after is
aligned too */
typedef struct TaskState {
@@ -109,10 +123,16 @@ typedef struct TaskState {
#endif
int used; /* non zero if used */
struct image_info *info;
+
+ struct emulated_sigtable sigtab[TARGET_NSIG];
+ struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
+ struct sigqueue *first_free; /* first free siginfo queue entry */
+ int signal_pending; /* non zero if a signal may be pending */
+
uint8_t stack[0];
} __attribute__((aligned(16))) TaskState;
-extern TaskState *first_task_state;
+void init_task_state(TaskState *ts);
extern const char *qemu_uname_release;
/* ??? See if we can avoid exposing so much of the loader internals. */
@@ -182,9 +202,9 @@ void print_syscall_ret(int num, abi_long arg1);
extern int do_strace;
/* signal.c */
-void process_pending_signals(void *cpu_env);
+void process_pending_signals(CPUState *cpu_env);
void signal_init(void);
-int queue_signal(int sig, target_siginfo_t *info);
+int queue_signal(CPUState *env, int sig, target_siginfo_t *info);
void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
int target_to_host_signal(int sig);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 350ba67b92..e6e1a08267 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -31,31 +31,13 @@
//#define DEBUG_SIGNAL
-#define MAX_SIGQUEUE_SIZE 1024
-
-struct sigqueue {
- struct sigqueue *next;
- target_siginfo_t info;
-};
-
-struct emulated_sigaction {
- struct target_sigaction sa;
- int pending; /* true if signal is pending */
- struct sigqueue *first;
- struct sigqueue info; /* in order to always have memory for the
- first signal, we put it here */
-};
-
struct target_sigaltstack target_sigaltstack_used = {
.ss_sp = 0,
.ss_size = 0,
.ss_flags = TARGET_SS_DISABLE,
};
-static struct emulated_sigaction sigact_table[TARGET_NSIG];
-static struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
-static struct sigqueue *first_free; /* first free siginfo queue entry */
-static int signal_pending; /* non zero if a signal may be pending */
+static struct target_sigaction sigact_table[TARGET_NSIG];
static void host_signal_handler(int host_signum, siginfo_t *info,
void *puc);
@@ -96,6 +78,12 @@ static uint8_t host_to_target_signal_table[65] = {
[SIGPWR] = TARGET_SIGPWR,
[SIGSYS] = TARGET_SIGSYS,
/* next signals stay the same */
+ /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
+ host libpthread signals. This assumes noone actually uses SIGRTMAX :-/
+ To fix this properly we need to do manual signal delivery multiplexed
+ over a single host signal. */
+ [__SIGRTMIN] = __SIGRTMAX,
+ [__SIGRTMAX] = __SIGRTMIN,
};
static uint8_t target_to_host_signal_table[65];
@@ -278,7 +266,9 @@ void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo)
void signal_init(void)
{
struct sigaction act;
+ struct sigaction oact;
int i, j;
+ int host_sig;
/* generate signal conversion tables */
for(i = 1; i <= 64; i++) {
@@ -292,36 +282,45 @@ void signal_init(void)
/* set all host signal handlers. ALL signals are blocked during
the handlers to serialize them. */
+ memset(sigact_table, 0, sizeof(sigact_table));
+
sigfillset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = host_signal_handler;
- for(i = 1; i < NSIG; i++) {
- sigaction(i, &act, NULL);
+ for(i = 1; i <= TARGET_NSIG; i++) {
+ host_sig = target_to_host_signal(i);
+ sigaction(host_sig, NULL, &oact);
+ if (oact.sa_sigaction == (void *)SIG_IGN) {
+ sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN;
+ } else if (oact.sa_sigaction == (void *)SIG_DFL) {
+ sigact_table[i - 1]._sa_handler = TARGET_SIG_DFL;
+ }
+ /* If there's already a handler installed then something has
+ gone horribly wrong, so don't even try to handle that case. */
+ /* Install some handlers for our own use. */
+ if (host_sig == SIGSEGV || host_sig == SIGBUS) {
+ sigaction(host_sig, &act, NULL);
+ }
}
-
- memset(sigact_table, 0, sizeof(sigact_table));
-
- first_free = &sigqueue_table[0];
- for(i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++)
- sigqueue_table[i].next = &sigqueue_table[i + 1];
- sigqueue_table[MAX_SIGQUEUE_SIZE - 1].next = NULL;
}
/* signal queue handling */
-static inline struct sigqueue *alloc_sigqueue(void)
+static inline struct sigqueue *alloc_sigqueue(CPUState *env)
{
- struct sigqueue *q = first_free;
+ TaskState *ts = env->opaque;
+ struct sigqueue *q = ts->first_free;
if (!q)
return NULL;
- first_free = q->next;
+ ts->first_free = q->next;
return q;
}
-static inline void free_sigqueue(struct sigqueue *q)
+static inline void free_sigqueue(CPUState *env, struct sigqueue *q)
{
- q->next = first_free;
- first_free = q;
+ TaskState *ts = env->opaque;
+ q->next = ts->first_free;
+ ts->first_free = q;
}
/* abort execution with signal */
@@ -347,9 +346,10 @@ void __attribute((noreturn)) force_sig(int sig)
/* queue a signal so that it will be send to the virtual CPU as soon
as possible */
-int queue_signal(int sig, target_siginfo_t *info)
+int queue_signal(CPUState *env, int sig, target_siginfo_t *info)
{
- struct emulated_sigaction *k;
+ TaskState *ts = env->opaque;
+ struct emulated_sigtable *k;
struct sigqueue *q, **pq;
abi_ulong handler;
@@ -357,8 +357,8 @@ int queue_signal(int sig, target_siginfo_t *info)
fprintf(stderr, "queue_signal: sig=%d\n",
sig);
#endif
- k = &sigact_table[sig - 1];
- handler = k->sa._sa_handler;
+ k = &ts->sigtab[sig - 1];
+ handler = sigact_table[sig - 1]._sa_handler;
if (handler == TARGET_SIG_DFL) {
/* default handler : ignore some signal. The other are fatal */
if (sig != TARGET_SIGCHLD &&
@@ -386,7 +386,7 @@ int queue_signal(int sig, target_siginfo_t *info)
/* first signal */
q = &k->info;
} else {
- q = alloc_sigqueue();
+ q = alloc_sigqueue(env);
if (!q)
return -EAGAIN;
while (*pq != NULL)
@@ -398,7 +398,7 @@ int queue_signal(int sig, target_siginfo_t *info)
q->next = NULL;
k->pending = 1;
/* signal that a new signal is pending */
- signal_pending = 1;
+ ts->signal_pending = 1;
return 1; /* indicates that the signal was queued */
}
}
@@ -424,7 +424,7 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
fprintf(stderr, "qemu: got signal %d\n", sig);
#endif
host_to_target_siginfo_noswap(&tinfo, info);
- if (queue_signal(sig, &tinfo) == 1) {
+ if (queue_signal(global_env, sig, &tinfo) == 1) {
/* interrupt the virtual CPU as soon as possible */
cpu_interrupt(global_env, CPU_INTERRUPT_EXIT);
}
@@ -496,7 +496,7 @@ out:
int do_sigaction(int sig, const struct target_sigaction *act,
struct target_sigaction *oact)
{
- struct emulated_sigaction *k;
+ struct target_sigaction *k;
struct sigaction act1;
int host_sig;
int ret = 0;
@@ -509,34 +509,35 @@ int do_sigaction(int sig, const struct target_sigaction *act,
sig, (int)act, (int)oact);
#endif
if (oact) {
- oact->_sa_handler = tswapl(k->sa._sa_handler);
- oact->sa_flags = tswapl(k->sa.sa_flags);
+ oact->_sa_handler = tswapl(k->_sa_handler);
+ oact->sa_flags = tswapl(k->sa_flags);
#if !defined(TARGET_MIPS)
- oact->sa_restorer = tswapl(k->sa.sa_restorer);
+ oact->sa_restorer = tswapl(k->sa_restorer);
#endif
- oact->sa_mask = k->sa.sa_mask;
+ oact->sa_mask = k->sa_mask;
}
if (act) {
- k->sa._sa_handler = tswapl(act->_sa_handler);
- k->sa.sa_flags = tswapl(act->sa_flags);
+ /* FIXME: This is not threadsafe. */
+ k->_sa_handler = tswapl(act->_sa_handler);
+ k->sa_flags = tswapl(act->sa_flags);
#if !defined(TARGET_MIPS)
- k->sa.sa_restorer = tswapl(act->sa_restorer);
+ k->sa_restorer = tswapl(act->sa_restorer);
#endif
- k->sa.sa_mask = act->sa_mask;
+ k->sa_mask = act->sa_mask;
/* we update the host linux signal state */
host_sig = target_to_host_signal(sig);
if (host_sig != SIGSEGV && host_sig != SIGBUS) {
sigfillset(&act1.sa_mask);
act1.sa_flags = SA_SIGINFO;
- if (k->sa.sa_flags & TARGET_SA_RESTART)
+ if (k->sa_flags & TARGET_SA_RESTART)
act1.sa_flags |= SA_RESTART;
/* NOTE: it is important to update the host kernel signal
ignore state to avoid getting unexpected interrupted
syscalls */
- if (k->sa._sa_handler == TARGET_SIG_IGN) {
+ if (k->_sa_handler == TARGET_SIG_IGN) {
act1.sa_sigaction = (void *)SIG_IGN;
- } else if (k->sa._sa_handler == TARGET_SIG_DFL) {
+ } else if (k->_sa_handler == TARGET_SIG_DFL) {
act1.sa_sigaction = (void *)SIG_DFL;
} else {
act1.sa_sigaction = host_signal_handler;
@@ -712,14 +713,14 @@ setup_sigcontext(struct target_sigcontext *sc, struct target_fpstate *fpstate,
*/
static inline abi_ulong
-get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
+get_sigframe(struct target_sigaction *ka, CPUX86State *env, size_t frame_size)
{
unsigned long esp;
/* Default to using normal stack */
esp = env->regs[R_ESP];
/* This is the X/Open sanctioned signal stack switching. */
- if (ka->sa.sa_flags & TARGET_SA_ONSTACK) {
+ if (ka->sa_flags & TARGET_SA_ONSTACK) {
if (sas_ss_flags(esp) == 0)
esp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
}
@@ -727,15 +728,15 @@ get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
/* This is the legacy signal stack switching. */
else
if ((env->segs[R_SS].selector & 0xffff) != __USER_DS &&
- !(ka->sa.sa_flags & TARGET_SA_RESTORER) &&
- ka->sa.sa_restorer) {
- esp = (unsigned long) ka->sa.sa_restorer;
+ !(ka->sa_flags & TARGET_SA_RESTORER) &&
+ ka->sa_restorer) {
+ esp = (unsigned long) ka->sa_restorer;
}
return (esp - frame_size) & -8ul;
}
/* compare linux/arch/i386/kernel/signal.c:setup_frame() */
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUX86State *env)
{
abi_ulong frame_addr;
@@ -764,8 +765,8 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
- if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
- err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
+ if (ka->sa_flags & TARGET_SA_RESTORER) {
+ err |= __put_user(ka->sa_restorer, &frame->pretcode);
} else {
uint16_t val16;
abi_ulong retcode_addr;
@@ -784,7 +785,7 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
/* Set up registers for signal handler */
env->regs[R_ESP] = frame_addr;
- env->eip = ka->sa._sa_handler;
+ env->eip = ka->_sa_handler;
cpu_x86_load_seg(env, R_DS, __USER_DS);
cpu_x86_load_seg(env, R_ES, __USER_DS);
@@ -799,12 +800,12 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
give_sigsegv:
unlock_user_struct(frame, frame_addr, 1);
if (sig == TARGET_SIGSEGV)
- ka->sa._sa_handler = TARGET_SIG_DFL;
+ ka->_sa_handler = TARGET_SIG_DFL;
force_sig(TARGET_SIGSEGV /* , current */);
}
/* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUX86State *env)
{
@@ -846,8 +847,8 @@ static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
- if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
- err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
+ if (ka->sa_flags & TARGET_SA_RESTORER) {
+ err |= __put_user(ka->sa_restorer, &frame->pretcode);
} else {
uint16_t val16;
addr = frame_addr + offsetof(struct rt_sigframe, retcode);
@@ -864,7 +865,7 @@ static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
/* Set up registers for signal handler */
env->regs[R_ESP] = frame_addr;
- env->eip = ka->sa._sa_handler;
+ env->eip = ka->_sa_handler;
cpu_x86_load_seg(env, R_DS, __USER_DS);
cpu_x86_load_seg(env, R_ES, __USER_DS);
@@ -879,7 +880,7 @@ static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
give_sigsegv:
unlock_user_struct(frame, frame_addr, 1);
if (sig == TARGET_SIGSEGV)
- ka->sa._sa_handler = TARGET_SIG_DFL;
+ ka->_sa_handler = TARGET_SIG_DFL;
force_sig(TARGET_SIGSEGV /* , current */);
}
@@ -1122,14 +1123,14 @@ setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
}
static inline abi_ulong
-get_sigframe(struct emulated_sigaction *ka, CPUState *regs, int framesize)
+get_sigframe(struct target_sigaction *ka, CPUState *regs, int framesize)
{
unsigned long sp = regs->regs[13];
/*
* This is the X/Open sanctioned signal stack switching.
*/
- if ((ka->sa.sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp))
+ if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp))
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
/*
* ATPCS B01 mandates 8-byte alignment
@@ -1138,19 +1139,19 @@ get_sigframe(struct emulated_sigaction *ka, CPUState *regs, int framesize)
}
static int
-setup_return(CPUState *env, struct emulated_sigaction *ka,
+setup_return(CPUState *env, struct target_sigaction *ka,
abi_ulong *rc, abi_ulong frame_addr, int usig, abi_ulong rc_addr)
{
- abi_ulong handler = ka->sa._sa_handler;
+ abi_ulong handler = ka->_sa_handler;
abi_ulong retcode;
int thumb = handler & 1;
- if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
- retcode = ka->sa.sa_restorer;
+ if (ka->sa_flags & TARGET_SA_RESTORER) {
+ retcode = ka->sa_restorer;
} else {
unsigned int idx = thumb;
- if (ka->sa.sa_flags & TARGET_SA_SIGINFO)
+ if (ka->sa_flags & TARGET_SA_SIGINFO)
idx += 2;
if (__put_user(retcodes[idx], rc))
@@ -1200,7 +1201,7 @@ static void setup_sigframe_v2(struct target_ucontext_v2 *uc,
}
/* compare linux/arch/arm/kernel/signal.c:setup_frame() */
-static void setup_frame_v1(int usig, struct emulated_sigaction *ka,
+static void setup_frame_v1(int usig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *regs)
{
struct sigframe_v1 *frame;
@@ -1224,7 +1225,7 @@ end:
unlock_user_struct(frame, frame_addr, 1);
}
-static void setup_frame_v2(int usig, struct emulated_sigaction *ka,
+static void setup_frame_v2(int usig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *regs)
{
struct sigframe_v2 *frame;
@@ -1241,7 +1242,7 @@ static void setup_frame_v2(int usig, struct emulated_sigaction *ka,
unlock_user_struct(frame, frame_addr, 1);
}
-static void setup_frame(int usig, struct emulated_sigaction *ka,
+static void setup_frame(int usig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *regs)
{
if (get_osversion() >= 0x020612) {
@@ -1252,7 +1253,7 @@ static void setup_frame(int usig, struct emulated_sigaction *ka,
}
/* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */
-static void setup_rt_frame_v1(int usig, struct emulated_sigaction *ka,
+static void setup_rt_frame_v1(int usig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -1296,7 +1297,7 @@ end:
unlock_user_struct(frame, frame_addr, 1);
}
-static void setup_rt_frame_v2(int usig, struct emulated_sigaction *ka,
+static void setup_rt_frame_v2(int usig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -1322,7 +1323,7 @@ static void setup_rt_frame_v2(int usig, struct emulated_sigaction *ka,
unlock_user_struct(frame, frame_addr, 1);
}
-static void setup_rt_frame(int usig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int usig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -1650,7 +1651,7 @@ struct target_rt_signal_frame {
#define UREG_FP UREG_I6
#define UREG_SP UREG_O6
-static inline abi_ulong get_sigframe(struct emulated_sigaction *sa,
+static inline abi_ulong get_sigframe(struct target_sigaction *sa,
CPUState *env, unsigned long framesize)
{
abi_ulong sp;
@@ -1658,7 +1659,7 @@ static inline abi_ulong get_sigframe(struct emulated_sigaction *sa,
sp = env->regwptr[UREG_FP];
/* This is the X/Open sanctioned signal stack switching. */
- if (sa->sa.sa_flags & TARGET_SA_ONSTACK) {
+ if (sa->sa_flags & TARGET_SA_ONSTACK) {
if (!on_sig_stack(sp)
&& !((target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size) & 7))
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
@@ -1705,7 +1706,7 @@ setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
#endif
#define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7)))
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *env)
{
abi_ulong sf_addr;
@@ -1758,11 +1759,11 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
offsetof(struct target_signal_frame, info);
/* 4. signal handler */
- env->pc = ka->sa._sa_handler;
+ env->pc = ka->_sa_handler;
env->npc = (env->pc + 4);
/* 5. return to kernel instructions */
- if (ka->sa.sa_restorer)
- env->regwptr[UREG_I7] = ka->sa.sa_restorer;
+ if (ka->sa_restorer)
+ env->regwptr[UREG_I7] = ka->sa_restorer;
else {
uint32_t val32;
@@ -1834,7 +1835,7 @@ restore_fpu_state(CPUState *env, qemu_siginfo_fpu_t *fpu)
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -2182,13 +2183,13 @@ void sparc64_get_context(CPUSPARCState *env)
# warning signal handling not implemented
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *env)
{
fprintf(stderr, "setup_frame: not implemented\n");
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -2211,13 +2212,13 @@ long do_rt_sigreturn(CPUState *env)
# warning signal handling not implemented
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *env)
{
fprintf(stderr, "setup_frame: not implemented\n");
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -2431,7 +2432,7 @@ restore_sigcontext(CPUState *regs, struct target_sigcontext *sc)
* Determine which stack to use..
*/
static inline abi_ulong
-get_sigframe(struct emulated_sigaction *ka, CPUState *regs, size_t frame_size)
+get_sigframe(struct target_sigaction *ka, CPUState *regs, size_t frame_size)
{
unsigned long sp;
@@ -2446,7 +2447,7 @@ get_sigframe(struct emulated_sigaction *ka, CPUState *regs, size_t frame_size)
sp -= 32;
/* This is the X/Open sanctioned signal stack switching. */
- if ((ka->sa.sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags (sp) == 0)) {
+ if ((ka->sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags (sp) == 0)) {
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
}
@@ -2454,7 +2455,7 @@ get_sigframe(struct emulated_sigaction *ka, CPUState *regs, size_t frame_size)
}
/* compare linux/arch/mips/kernel/signal.c:setup_frame() */
-static void setup_frame(int sig, struct emulated_sigaction * ka,
+static void setup_frame(int sig, struct target_sigaction * ka,
target_sigset_t *set, CPUState *regs)
{
struct sigframe *frame;
@@ -2493,7 +2494,7 @@ static void setup_frame(int sig, struct emulated_sigaction * ka,
/* The original kernel code sets CP0_EPC to the handler
* since it returns to userland using eret
* we cannot do this here, and we must set PC directly */
- regs->PC[regs->current_tc] = regs->gpr[regs->current_tc][25] = ka->sa._sa_handler;
+ regs->PC[regs->current_tc] = regs->gpr[regs->current_tc][25] = ka->_sa_handler;
unlock_user_struct(frame, frame_addr, 1);
return;
@@ -2552,7 +2553,7 @@ badframe:
return 0;
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -2620,10 +2621,10 @@ struct target_rt_sigframe
#define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
#define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) SH3/4 */
-static abi_ulong get_sigframe(struct emulated_sigaction *ka,
+static abi_ulong get_sigframe(struct target_sigaction *ka,
unsigned long sp, size_t frame_size)
{
- if ((ka->sa.sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags(sp) == 0)) {
+ if ((ka->sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags(sp) == 0)) {
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
}
@@ -2682,7 +2683,7 @@ static int restore_sigcontext(struct CPUState *regs,
return err;
}
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *regs)
{
struct target_sigframe *frame;
@@ -2705,8 +2706,8 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
- if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
- regs->pr = (unsigned long) ka->sa.sa_restorer;
+ if (ka->sa_flags & TARGET_SA_RESTORER) {
+ regs->pr = (unsigned long) ka->sa_restorer;
} else {
/* Generate return code (system call to sigreturn) */
err |= __put_user(MOVW(2), &frame->retcode[0]);
@@ -2723,7 +2724,7 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
regs->gregs[4] = signal; /* Arg for signal handler */
regs->gregs[5] = 0;
regs->gregs[6] = (unsigned long) &frame->sc;
- regs->pc = (unsigned long) ka->sa._sa_handler;
+ regs->pc = (unsigned long) ka->_sa_handler;
unlock_user_struct(frame, frame_addr, 1);
return;
@@ -2733,7 +2734,7 @@ give_sigsegv:
force_sig(SIGSEGV);
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *regs)
{
@@ -2768,8 +2769,8 @@ static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
- if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
- regs->pr = (unsigned long) ka->sa.sa_restorer;
+ if (ka->sa_flags & TARGET_SA_RESTORER) {
+ regs->pr = (unsigned long) ka->sa_restorer;
} else {
/* Generate return code (system call to sigreturn) */
err |= __put_user(MOVW(2), &frame->retcode[0]);
@@ -2786,7 +2787,7 @@ static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
regs->gregs[4] = signal; /* Arg for signal handler */
regs->gregs[5] = (unsigned long) &frame->info;
regs->gregs[6] = (unsigned long) &frame->uc;
- regs->pc = (unsigned long) ka->sa._sa_handler;
+ regs->pc = (unsigned long) ka->_sa_handler;
unlock_user_struct(frame, frame_addr, 1);
return;
@@ -2944,7 +2945,7 @@ static abi_ulong get_sigframe(CPUState *env, int framesize)
return sp - framesize;
}
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *env)
{
struct target_signal_frame *frame;
@@ -2983,7 +2984,7 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
/* Move the stack and setup the arguments for the handler. */
env->regs[R_SP] = (uint32_t) frame;
env->regs[10] = sig;
- env->pc = (unsigned long) ka->sa._sa_handler;
+ env->pc = (unsigned long) ka->_sa_handler;
/* Link SRP so the guest returns through the trampoline. */
env->pregs[PR_SRP] = (uint32_t) &frame->retcode[0];
@@ -2994,7 +2995,7 @@ static void setup_frame(int sig, struct emulated_sigaction *ka,
force_sig(TARGET_SIGSEGV);
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -3043,13 +3044,13 @@ long do_rt_sigreturn(CPUState *env)
#else
-static void setup_frame(int sig, struct emulated_sigaction *ka,
+static void setup_frame(int sig, struct target_sigaction *ka,
target_sigset_t *set, CPUState *env)
{
fprintf(stderr, "setup_frame: not implemented\n");
}
-static void setup_rt_frame(int sig, struct emulated_sigaction *ka,
+static void setup_rt_frame(int sig, struct target_sigaction *ka,
target_siginfo_t *info,
target_sigset_t *set, CPUState *env)
{
@@ -3070,26 +3071,29 @@ long do_rt_sigreturn(CPUState *env)
#endif
-void process_pending_signals(void *cpu_env)
+void process_pending_signals(CPUState *cpu_env)
{
int sig;
abi_ulong handler;
sigset_t set, old_set;
target_sigset_t target_old_set;
- struct emulated_sigaction *k;
+ struct emulated_sigtable *k;
+ struct target_sigaction *sa;
struct sigqueue *q;
+ TaskState *ts = cpu_env->opaque;
- if (!signal_pending)
+ if (!ts->signal_pending)
return;
- k = sigact_table;
+ /* FIXME: This is not threadsafe. */
+ k = ts->sigtab;
for(sig = 1; sig <= TARGET_NSIG; sig++) {
if (k->pending)
goto handle_signal;
k++;
}
/* if no signal is pending, just return */
- signal_pending = 0;
+ ts->signal_pending = 0;
return;
handle_signal:
@@ -3108,7 +3112,8 @@ void process_pending_signals(void *cpu_env)
abort();
}
- handler = k->sa._sa_handler;
+ sa = &sigact_table[sig - 1];
+ handler = sa->_sa_handler;
if (handler == TARGET_SIG_DFL) {
/* default handler : ignore some signal. The other are fatal */
if (sig != TARGET_SIGCHLD &&
@@ -3122,10 +3127,10 @@ void process_pending_signals(void *cpu_env)
force_sig(sig);
} else {
/* compute the blocked signals during the handler execution */
- target_to_host_sigset(&set, &k->sa.sa_mask);
+ target_to_host_sigset(&set, &sa->sa_mask);
/* SA_NODEFER indicates that the current signal should not be
blocked during the handler */
- if (!(k->sa.sa_flags & TARGET_SA_NODEFER))
+ if (!(sa->sa_flags & TARGET_SA_NODEFER))
sigaddset(&set, target_to_host_signal(sig));
/* block signals in the handler using Linux */
@@ -3143,13 +3148,13 @@ void process_pending_signals(void *cpu_env)
}
#endif
/* prepare the stack frame of the virtual CPU */
- if (k->sa.sa_flags & TARGET_SA_SIGINFO)
- setup_rt_frame(sig, k, &q->info, &target_old_set, cpu_env);
+ if (sa->sa_flags & TARGET_SA_SIGINFO)
+ setup_rt_frame(sig, sa, &q->info, &target_old_set, cpu_env);
else
- setup_frame(sig, k, &target_old_set, cpu_env);
- if (k->sa.sa_flags & TARGET_SA_RESETHAND)
- k->sa._sa_handler = TARGET_SIG_DFL;
+ setup_frame(sig, sa, &target_old_set, cpu_env);
+ if (sa->sa_flags & TARGET_SA_RESETHAND)
+ sa->_sa_handler = TARGET_SIG_DFL;
}
if (q != &k->info)
- free_sigqueue(q);
+ free_sigqueue(cpu_env, q);
}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a8ea6c565a..5f2b48aa13 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2736,12 +2736,8 @@ int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
}
#endif
ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
- memset(ts, 0, sizeof(TaskState));
+ init_task_state(ts);
new_stack = ts->stack;
- ts->used = 1;
- /* add in task state list */
- ts->next = first_task_state;
- first_task_state = ts;
/* we create a new CPU instance. */
new_env = cpu_copy(env);
/* Init regs that differ from the parent. */