aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2012-08-01 18:49:17 -0400
committerRichard Weinberger <richard@nod.at>2012-08-01 18:49:17 -0400
commitd3c1cfcdb43e023ab1b1c7a555cd9e929026500a (patch)
treead79f90d97a0316ae4058e4501e7b6ad54540ff4
parentd4afcba95fca4dd0f831fe72c1fa4f0638f23765 (diff)
um: pass siginfo to guest process
UML guest processes now get correct siginfo_t for SIGTRAP, SIGFPE, SIGILL and SIGBUS. Specifically, si_addr and si_code are now correct where previously they were si_addr = NULL and si_code = 128. Signed-off-by: Martin Pärtel <martin.partel@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r--arch/um/include/shared/as-layout.h3
-rw-r--r--arch/um/include/shared/irq_user.h3
-rw-r--r--arch/um/include/shared/kern_util.h13
-rw-r--r--arch/um/kernel/irq.c2
-rw-r--r--arch/um/kernel/time.c2
-rw-r--r--arch/um/kernel/trap.c39
-rw-r--r--arch/um/os-Linux/internal.h2
-rw-r--r--arch/um/os-Linux/signal.c26
-rw-r--r--arch/um/os-Linux/skas/process.c13
-rw-r--r--arch/um/os-Linux/time.c2
10 files changed, 71 insertions, 34 deletions
diff --git a/arch/um/include/shared/as-layout.h b/arch/um/include/shared/as-layout.h
index 896e16602176..86daa5461815 100644
--- a/arch/um/include/shared/as-layout.h
+++ b/arch/um/include/shared/as-layout.h
@@ -60,7 +60,8 @@ extern unsigned long host_task_size;
60 60
61extern int linux_main(int argc, char **argv); 61extern int linux_main(int argc, char **argv);
62 62
63extern void (*sig_info[])(int, struct uml_pt_regs *); 63struct siginfo;
64extern void (*sig_info[])(int, struct siginfo *si, struct uml_pt_regs *);
64 65
65#endif 66#endif
66 67
diff --git a/arch/um/include/shared/irq_user.h b/arch/um/include/shared/irq_user.h
index c6c784df2673..2b6d703925b5 100644
--- a/arch/um/include/shared/irq_user.h
+++ b/arch/um/include/shared/irq_user.h
@@ -20,7 +20,8 @@ struct irq_fd {
20 20
21enum { IRQ_READ, IRQ_WRITE }; 21enum { IRQ_READ, IRQ_WRITE };
22 22
23extern void sigio_handler(int sig, struct uml_pt_regs *regs); 23struct siginfo;
24extern void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs);
24extern void free_irq_by_fd(int fd); 25extern void free_irq_by_fd(int fd);
25extern void reactivate_fd(int fd, int irqnum); 26extern void reactivate_fd(int fd, int irqnum);
26extern void deactivate_fd(int fd, int irqnum); 27extern void deactivate_fd(int fd, int irqnum);
diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/kern_util.h
index 00965d06d2ca..af6b6dc868ba 100644
--- a/arch/um/include/shared/kern_util.h
+++ b/arch/um/include/shared/kern_util.h
@@ -9,6 +9,8 @@
9#include "sysdep/ptrace.h" 9#include "sysdep/ptrace.h"
10#include "sysdep/faultinfo.h" 10#include "sysdep/faultinfo.h"
11 11
12struct siginfo;
13
12extern int uml_exitcode; 14extern int uml_exitcode;
13 15
14extern int ncpus; 16extern int ncpus;
@@ -22,7 +24,7 @@ extern void free_stack(unsigned long stack, int order);
22 24
23extern int do_signal(void); 25extern int do_signal(void);
24extern void interrupt_end(void); 26extern void interrupt_end(void);
25extern void relay_signal(int sig, struct uml_pt_regs *regs); 27extern void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs);
26 28
27extern unsigned long segv(struct faultinfo fi, unsigned long ip, 29extern unsigned long segv(struct faultinfo fi, unsigned long ip,
28 int is_user, struct uml_pt_regs *regs); 30 int is_user, struct uml_pt_regs *regs);
@@ -33,9 +35,8 @@ extern unsigned int do_IRQ(int irq, struct uml_pt_regs *regs);
33extern int smp_sigio_handler(void); 35extern int smp_sigio_handler(void);
34extern void initial_thread_cb(void (*proc)(void *), void *arg); 36extern void initial_thread_cb(void (*proc)(void *), void *arg);
35extern int is_syscall(unsigned long addr); 37extern int is_syscall(unsigned long addr);
36extern void timer_handler(int sig, struct uml_pt_regs *regs);
37 38
38extern void timer_handler(int sig, struct uml_pt_regs *regs); 39extern void timer_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs);
39 40
40extern int start_uml(void); 41extern int start_uml(void);
41extern void paging_init(void); 42extern void paging_init(void);
@@ -59,9 +60,9 @@ extern unsigned long from_irq_stack(int nested);
59extern void syscall_trace(struct uml_pt_regs *regs, int entryexit); 60extern void syscall_trace(struct uml_pt_regs *regs, int entryexit);
60extern int singlestepping(void *t); 61extern int singlestepping(void *t);
61 62
62extern void segv_handler(int sig, struct uml_pt_regs *regs); 63extern void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs);
63extern void bus_handler(int sig, struct uml_pt_regs *regs); 64extern void bus_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs);
64extern void winch(int sig, struct uml_pt_regs *regs); 65extern void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs);
65extern void fatal_sigsegv(void) __attribute__ ((noreturn)); 66extern void fatal_sigsegv(void) __attribute__ ((noreturn));
66 67
67 68
diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
index 00506c3d5d6e..9883026f0730 100644
--- a/arch/um/kernel/irq.c
+++ b/arch/um/kernel/irq.c
@@ -30,7 +30,7 @@ static struct irq_fd **last_irq_ptr = &active_fds;
30 30
31extern void free_irqs(void); 31extern void free_irqs(void);
32 32
33void sigio_handler(int sig, struct uml_pt_regs *regs) 33void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
34{ 34{
35 struct irq_fd *irq_fd; 35 struct irq_fd *irq_fd;
36 int n; 36 int n;
diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c
index d1a23fb3190d..5f76d4ba151c 100644
--- a/arch/um/kernel/time.c
+++ b/arch/um/kernel/time.c
@@ -13,7 +13,7 @@
13#include "kern_util.h" 13#include "kern_util.h"
14#include "os.h" 14#include "os.h"
15 15
16void timer_handler(int sig, struct uml_pt_regs *regs) 16void timer_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
17{ 17{
18 unsigned long flags; 18 unsigned long flags;
19 19
diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index 3be60765c0e2..0353b98ae35a 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -172,7 +172,7 @@ void fatal_sigsegv(void)
172 os_dump_core(); 172 os_dump_core();
173} 173}
174 174
175void segv_handler(int sig, struct uml_pt_regs *regs) 175void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
176{ 176{
177 struct faultinfo * fi = UPT_FAULTINFO(regs); 177 struct faultinfo * fi = UPT_FAULTINFO(regs);
178 178
@@ -258,8 +258,11 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
258 return 0; 258 return 0;
259} 259}
260 260
261void relay_signal(int sig, struct uml_pt_regs *regs) 261void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs)
262{ 262{
263 struct faultinfo *fi;
264 struct siginfo clean_si;
265
263 if (!UPT_IS_USER(regs)) { 266 if (!UPT_IS_USER(regs)) {
264 if (sig == SIGBUS) 267 if (sig == SIGBUS)
265 printk(KERN_ERR "Bus error - the host /dev/shm or /tmp " 268 printk(KERN_ERR "Bus error - the host /dev/shm or /tmp "
@@ -269,18 +272,40 @@ void relay_signal(int sig, struct uml_pt_regs *regs)
269 272
270 arch_examine_signal(sig, regs); 273 arch_examine_signal(sig, regs);
271 274
272 current->thread.arch.faultinfo = *UPT_FAULTINFO(regs); 275 memset(&clean_si, 0, sizeof(clean_si));
273 force_sig(sig, current); 276 clean_si.si_signo = si->si_signo;
277 clean_si.si_errno = si->si_errno;
278 clean_si.si_code = si->si_code;
279 switch (sig) {
280 case SIGILL:
281 case SIGFPE:
282 case SIGSEGV:
283 case SIGBUS:
284 case SIGTRAP:
285 fi = UPT_FAULTINFO(regs);
286 clean_si.si_addr = (void __user *) FAULT_ADDRESS(*fi);
287 current->thread.arch.faultinfo = *fi;
288#ifdef __ARCH_SI_TRAPNO
289 clean_si.si_trapno = si->si_trapno;
290#endif
291 break;
292 default:
293 printk(KERN_ERR "Attempted to relay unknown signal %d (si_code = %d)\n",
294 sig, si->si_code);
295 }
296
297 force_sig_info(sig, &clean_si, current);
274} 298}
275 299
276void bus_handler(int sig, struct uml_pt_regs *regs) 300void bus_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs)
277{ 301{
278 if (current->thread.fault_catcher != NULL) 302 if (current->thread.fault_catcher != NULL)
279 UML_LONGJMP(current->thread.fault_catcher, 1); 303 UML_LONGJMP(current->thread.fault_catcher, 1);
280 else relay_signal(sig, regs); 304 else
305 relay_signal(sig, si, regs);
281} 306}
282 307
283void winch(int sig, struct uml_pt_regs *regs) 308void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
284{ 309{
285 do_IRQ(WINCH_IRQ, regs); 310 do_IRQ(WINCH_IRQ, regs);
286} 311}
diff --git a/arch/um/os-Linux/internal.h b/arch/um/os-Linux/internal.h
index 2c3c3ecd8c01..0dc2c9f135f6 100644
--- a/arch/um/os-Linux/internal.h
+++ b/arch/um/os-Linux/internal.h
@@ -1 +1 @@
void alarm_handler(int, mcontext_t *); void alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc);
diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
index 2d22f1fcd8e2..6366ce904b9b 100644
--- a/arch/um/os-Linux/signal.c
+++ b/arch/um/os-Linux/signal.c
@@ -13,8 +13,9 @@
13#include "kern_util.h" 13#include "kern_util.h"
14#include "os.h" 14#include "os.h"
15#include "sysdep/mcontext.h" 15#include "sysdep/mcontext.h"
16#include "internal.h"
16 17
17void (*sig_info[NSIG])(int, struct uml_pt_regs *) = { 18void (*sig_info[NSIG])(int, siginfo_t *, struct uml_pt_regs *) = {
18 [SIGTRAP] = relay_signal, 19 [SIGTRAP] = relay_signal,
19 [SIGFPE] = relay_signal, 20 [SIGFPE] = relay_signal,
20 [SIGILL] = relay_signal, 21 [SIGILL] = relay_signal,
@@ -24,7 +25,7 @@ void (*sig_info[NSIG])(int, struct uml_pt_regs *) = {
24 [SIGIO] = sigio_handler, 25 [SIGIO] = sigio_handler,
25 [SIGVTALRM] = timer_handler }; 26 [SIGVTALRM] = timer_handler };
26 27
27static void sig_handler_common(int sig, mcontext_t *mc) 28static void sig_handler_common(int sig, siginfo_t *si, mcontext_t *mc)
28{ 29{
29 struct uml_pt_regs r; 30 struct uml_pt_regs r;
30 int save_errno = errno; 31 int save_errno = errno;
@@ -40,7 +41,7 @@ static void sig_handler_common(int sig, mcontext_t *mc)
40 if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM)) 41 if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM))
41 unblock_signals(); 42 unblock_signals();
42 43
43 (*sig_info[sig])(sig, &r); 44 (*sig_info[sig])(sig, si, &r);
44 45
45 errno = save_errno; 46 errno = save_errno;
46} 47}
@@ -60,7 +61,7 @@ static void sig_handler_common(int sig, mcontext_t *mc)
60static int signals_enabled; 61static int signals_enabled;
61static unsigned int signals_pending; 62static unsigned int signals_pending;
62 63
63void sig_handler(int sig, mcontext_t *mc) 64void sig_handler(int sig, siginfo_t *si, mcontext_t *mc)
64{ 65{
65 int enabled; 66 int enabled;
66 67
@@ -72,7 +73,7 @@ void sig_handler(int sig, mcontext_t *mc)
72 73
73 block_signals(); 74 block_signals();
74 75
75 sig_handler_common(sig, mc); 76 sig_handler_common(sig, si, mc);
76 77
77 set_signals(enabled); 78 set_signals(enabled);
78} 79}
@@ -85,10 +86,10 @@ static void real_alarm_handler(mcontext_t *mc)
85 get_regs_from_mc(&regs, mc); 86 get_regs_from_mc(&regs, mc);
86 regs.is_user = 0; 87 regs.is_user = 0;
87 unblock_signals(); 88 unblock_signals();
88 timer_handler(SIGVTALRM, &regs); 89 timer_handler(SIGVTALRM, NULL, &regs);
89} 90}
90 91
91void alarm_handler(int sig, mcontext_t *mc) 92void alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
92{ 93{
93 int enabled; 94 int enabled;
94 95
@@ -119,7 +120,7 @@ void set_sigstack(void *sig_stack, int size)
119 panic("enabling signal stack failed, errno = %d\n", errno); 120 panic("enabling signal stack failed, errno = %d\n", errno);
120} 121}
121 122
122static void (*handlers[_NSIG])(int sig, mcontext_t *mc) = { 123static void (*handlers[_NSIG])(int sig, siginfo_t *si, mcontext_t *mc) = {
123 [SIGSEGV] = sig_handler, 124 [SIGSEGV] = sig_handler,
124 [SIGBUS] = sig_handler, 125 [SIGBUS] = sig_handler,
125 [SIGILL] = sig_handler, 126 [SIGILL] = sig_handler,
@@ -132,7 +133,7 @@ static void (*handlers[_NSIG])(int sig, mcontext_t *mc) = {
132}; 133};
133 134
134 135
135static void hard_handler(int sig, siginfo_t *info, void *p) 136static void hard_handler(int sig, siginfo_t *si, void *p)
136{ 137{
137 struct ucontext *uc = p; 138 struct ucontext *uc = p;
138 mcontext_t *mc = &uc->uc_mcontext; 139 mcontext_t *mc = &uc->uc_mcontext;
@@ -161,7 +162,7 @@ static void hard_handler(int sig, siginfo_t *info, void *p)
161 while ((sig = ffs(pending)) != 0){ 162 while ((sig = ffs(pending)) != 0){
162 sig--; 163 sig--;
163 pending &= ~(1 << sig); 164 pending &= ~(1 << sig);
164 (*handlers[sig])(sig, mc); 165 (*handlers[sig])(sig, si, mc);
165 } 166 }
166 167
167 /* 168 /*
@@ -273,9 +274,12 @@ void unblock_signals(void)
273 * Deal with SIGIO first because the alarm handler might 274 * Deal with SIGIO first because the alarm handler might
274 * schedule, leaving the pending SIGIO stranded until we come 275 * schedule, leaving the pending SIGIO stranded until we come
275 * back here. 276 * back here.
277 *
278 * SIGIO's handler doesn't use siginfo or mcontext,
279 * so they can be NULL.
276 */ 280 */
277 if (save_pending & SIGIO_MASK) 281 if (save_pending & SIGIO_MASK)
278 sig_handler_common(SIGIO, NULL); 282 sig_handler_common(SIGIO, NULL, NULL);
279 283
280 if (save_pending & SIGVTALRM_MASK) 284 if (save_pending & SIGVTALRM_MASK)
281 real_alarm_handler(NULL); 285 real_alarm_handler(NULL);
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 2687f1f3a709..d93bb40499f7 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -346,6 +346,7 @@ void userspace(struct uml_pt_regs *regs)
346 int err, status, op, pid = userspace_pid[0]; 346 int err, status, op, pid = userspace_pid[0];
347 /* To prevent races if using_sysemu changes under us.*/ 347 /* To prevent races if using_sysemu changes under us.*/
348 int local_using_sysemu; 348 int local_using_sysemu;
349 siginfo_t si;
349 350
350 /* Handle any immediate reschedules or signals */ 351 /* Handle any immediate reschedules or signals */
351 interrupt_end(); 352 interrupt_end();
@@ -407,13 +408,17 @@ void userspace(struct uml_pt_regs *regs)
407 408
408 if (WIFSTOPPED(status)) { 409 if (WIFSTOPPED(status)) {
409 int sig = WSTOPSIG(status); 410 int sig = WSTOPSIG(status);
411
412 ptrace(PTRACE_GETSIGINFO, pid, 0, &si);
413
410 switch (sig) { 414 switch (sig) {
411 case SIGSEGV: 415 case SIGSEGV:
412 if (PTRACE_FULL_FAULTINFO || 416 if (PTRACE_FULL_FAULTINFO ||
413 !ptrace_faultinfo) { 417 !ptrace_faultinfo) {
414 get_skas_faultinfo(pid, 418 get_skas_faultinfo(pid,
415 &regs->faultinfo); 419 &regs->faultinfo);
416 (*sig_info[SIGSEGV])(SIGSEGV, regs); 420 (*sig_info[SIGSEGV])(SIGSEGV, &si,
421 regs);
417 } 422 }
418 else handle_segv(pid, regs); 423 else handle_segv(pid, regs);
419 break; 424 break;
@@ -421,14 +426,14 @@ void userspace(struct uml_pt_regs *regs)
421 handle_trap(pid, regs, local_using_sysemu); 426 handle_trap(pid, regs, local_using_sysemu);
422 break; 427 break;
423 case SIGTRAP: 428 case SIGTRAP:
424 relay_signal(SIGTRAP, regs); 429 relay_signal(SIGTRAP, &si, regs);
425 break; 430 break;
426 case SIGVTALRM: 431 case SIGVTALRM:
427 now = os_nsecs(); 432 now = os_nsecs();
428 if (now < nsecs) 433 if (now < nsecs)
429 break; 434 break;
430 block_signals(); 435 block_signals();
431 (*sig_info[sig])(sig, regs); 436 (*sig_info[sig])(sig, &si, regs);
432 unblock_signals(); 437 unblock_signals();
433 nsecs = timer.it_value.tv_sec * 438 nsecs = timer.it_value.tv_sec *
434 UM_NSEC_PER_SEC + 439 UM_NSEC_PER_SEC +
@@ -442,7 +447,7 @@ void userspace(struct uml_pt_regs *regs)
442 case SIGFPE: 447 case SIGFPE:
443 case SIGWINCH: 448 case SIGWINCH:
444 block_signals(); 449 block_signals();
445 (*sig_info[sig])(sig, regs); 450 (*sig_info[sig])(sig, &si, regs);
446 unblock_signals(); 451 unblock_signals();
447 break; 452 break;
448 default: 453 default:
diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c
index 910499d76a67..f60238559af3 100644
--- a/arch/um/os-Linux/time.c
+++ b/arch/um/os-Linux/time.c
@@ -87,7 +87,7 @@ static int after_sleep_interval(struct timespec *ts)
87 87
88static void deliver_alarm(void) 88static void deliver_alarm(void)
89{ 89{
90 alarm_handler(SIGVTALRM, NULL); 90 alarm_handler(SIGVTALRM, NULL, NULL);
91} 91}
92 92
93static unsigned long long sleep_time(unsigned long long nsecs) 93static unsigned long long sleep_time(unsigned long long nsecs)