summary refs log tree commit diff stats
path: root/linux-user/signal.c
diff options
context:
space:
mode:
authorpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>2008-05-31 16:11:38 +0000
committerpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>2008-05-31 16:11:38 +0000
commit624f7979058b84cbf81c76d45f302ce757b213ca (patch)
treef226ad71b17a623c4bd4eefdfeceb15fbb71b765 /linux-user/signal.c
parentafd7cd92e848f094cce4a03286e03634f49be573 (diff)
downloadfocaccia-qemu-624f7979058b84cbf81c76d45f302ce757b213ca.tar.gz
focaccia-qemu-624f7979058b84cbf81c76d45f302ce757b213ca.zip
Make signal queues per thread.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4635 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'linux-user/signal.c')
-rw-r--r--linux-user/signal.c257
1 files changed, 131 insertions, 126 deletions
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);
 }