From ee885b45d830068411c0df2aab69e9aa742ada35 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 21 Mar 2013 20:02:14 +0000 Subject: [PATCH] Copy siginfo_t to step before calling a user-space signal handler git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5769 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 7 ++++++- Documentation/NuttxPortingGuide.html | 2 +- arch/arm/src/common/up_stackframe.c | 2 +- arch/avr/src/avr/up_stackframe.c | 2 +- arch/avr/src/avr32/up_stackframe.c | 2 +- arch/hc/src/common/up_stackframe.c | 2 +- arch/mips/src/common/up_stackframe.c | 2 +- arch/sh/src/common/up_stackframe.c | 2 +- arch/sim/src/up_stackframe.c | 2 +- arch/x86/src/i486/up_stackframe.c | 2 +- arch/z16/src/common/up_stackframe.c | 2 +- arch/z80/src/common/up_stackframe.c | 2 +- include/nuttx/arch.h | 2 +- sched/sig_deliver.c | 15 ++++++++++++++- 14 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c427ff292..5d454cda3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4410,4 +4410,9 @@ all system call inline functions with > 3 parameters (2013-03-20) * arch/*/src/common/up_stackframe.c and include/nuttx/arch.h: Add and new interface to set aside memory on the stack. This will be - used at least in the kernel build to hold task arguments 2013-03-21). + used at least in the kernel build to hold task arguments (2013-03-21). + * sched/sig_deliver.c: When dispatching signals to user threads, + copy the siginfo_t from the sigq to the stack. The signal queue + is allocated from kernel memory; however, the current stack is + the user's stack and the user code will be able to access the + signinfo_t data from the stack copy (2013-03-21). diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index 2fa0b2a71f..a7082a0ec5 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -1713,7 +1713,7 @@ The system can be re-made subsequently by just typing make. This function may be called anytime after up_create_stack() or up_use_stack() have been called but before the task has been started.

- Thread data may be kept in the stack (instead of in the TCB) if it is accessed by the user code directory. + Thread data may be kept in the stack (instead of in the TCB) if it is accessed by the user code directly. This includes such things as argv[]. The stack memory is guaranteed to be in the same protection domain as the thread.

diff --git a/arch/arm/src/common/up_stackframe.c b/arch/arm/src/common/up_stackframe.c index 3720d334ac..f509556aff 100644 --- a/arch/arm/src/common/up_stackframe.c +++ b/arch/arm/src/common/up_stackframe.c @@ -96,7 +96,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/avr/src/avr/up_stackframe.c b/arch/avr/src/avr/up_stackframe.c index 39253e2b56..f9748f2e7f 100644 --- a/arch/avr/src/avr/up_stackframe.c +++ b/arch/avr/src/avr/up_stackframe.c @@ -73,7 +73,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/avr/src/avr32/up_stackframe.c b/arch/avr/src/avr32/up_stackframe.c index 08c4cf51e6..d7c0a0fc34 100644 --- a/arch/avr/src/avr32/up_stackframe.c +++ b/arch/avr/src/avr32/up_stackframe.c @@ -85,7 +85,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/hc/src/common/up_stackframe.c b/arch/hc/src/common/up_stackframe.c index 0daa4f7daa..266881ec56 100644 --- a/arch/hc/src/common/up_stackframe.c +++ b/arch/hc/src/common/up_stackframe.c @@ -85,7 +85,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/mips/src/common/up_stackframe.c b/arch/mips/src/common/up_stackframe.c index 9b473ecc60..fd055d5e6f 100644 --- a/arch/mips/src/common/up_stackframe.c +++ b/arch/mips/src/common/up_stackframe.c @@ -88,7 +88,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/sh/src/common/up_stackframe.c b/arch/sh/src/common/up_stackframe.c index b1ef4c6b4f..f3e7f294ab 100644 --- a/arch/sh/src/common/up_stackframe.c +++ b/arch/sh/src/common/up_stackframe.c @@ -84,7 +84,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/sim/src/up_stackframe.c b/arch/sim/src/up_stackframe.c index 4d62e6ec05..f634005cb8 100644 --- a/arch/sim/src/up_stackframe.c +++ b/arch/sim/src/up_stackframe.c @@ -85,7 +85,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/x86/src/i486/up_stackframe.c b/arch/x86/src/i486/up_stackframe.c index ea4edc07a3..f2ab91f951 100644 --- a/arch/x86/src/i486/up_stackframe.c +++ b/arch/x86/src/i486/up_stackframe.c @@ -86,7 +86,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/z16/src/common/up_stackframe.c b/arch/z16/src/common/up_stackframe.c index c11106542d..11eec6c2e3 100644 --- a/arch/z16/src/common/up_stackframe.c +++ b/arch/z16/src/common/up_stackframe.c @@ -84,7 +84,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/arch/z80/src/common/up_stackframe.c b/arch/z80/src/common/up_stackframe.c index 01a7b0881a..2283116330 100644 --- a/arch/z80/src/common/up_stackframe.c +++ b/arch/z80/src/common/up_stackframe.c @@ -84,7 +84,7 @@ * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 6595b39110..b8e62e6c2d 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -228,7 +228,7 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size); * up_use_stack() have been called but before the task has been started. * * Thread data may be kept in the stack (instead of in the TCB) if it is - * accessed by the user code directory. This includes such things as + * accessed by the user code directly. This includes such things as * argv[]. The stack memory is guaranteed to be in the same protection * domain as the thread. * diff --git a/sched/sig_deliver.c b/sched/sig_deliver.c index bb6ca71a45..9b1e8cebe3 100644 --- a/sched/sig_deliver.c +++ b/sched/sig_deliver.c @@ -136,12 +136,25 @@ void sig_deliver(FAR struct tcb_s *stcb) #ifdef CONFIG_NUTTX_KERNEL if ((stcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL) { + /* The sigq_t pointed to by sigq resides in kernel space. So we + * cannot pass a reference to sigq->info to the user space. + * Instead, we will copy the siginfo_t structure onto that stack. + * We are currently executing on the stack of the user thread + * (albeit temporarily in kernel mode), so the copy of the + * siginfo_t structure will be accessible by the user thread. + */ + + siginfo_t info; + memcpy(&info, sigq->info, sizeof(siginfo_t)); + up_signal_handler(sigq->action.sighandler, sigq->info.si_signo, - &sigq->info, NULL); + &info, NULL); } else #endif { + /* The kernel thread signal handler is much simpler. */ + (*sigq->action.sighandler)(sigq->info.si_signo, &sigq->info, NULL); }