diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-24 15:56:27 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-24 15:56:27 +0000 |
commit | 82623e0919811f68b804ea7793ade3250a0aeda1 (patch) | |
tree | 498c3f329b23d4c1790a7faa9ce78259534f7f5b /nuttx/sched | |
parent | 8f42a44253a96f8552f4e03f8f0a0c672d3b4a67 (diff) | |
download | px4-nuttx-82623e0919811f68b804ea7793ade3250a0aeda1.tar.gz px4-nuttx-82623e0919811f68b804ea7793ade3250a0aeda1.tar.bz2 px4-nuttx-82623e0919811f68b804ea7793ade3250a0aeda1.zip |
Add logic to protect the user task errno when errno access are performed from interrupt handlers.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@141 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/get_errno_ptr.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/nuttx/sched/get_errno_ptr.c b/nuttx/sched/get_errno_ptr.c index 23503243b..82eacb762 100644 --- a/nuttx/sched/get_errno_ptr.c +++ b/nuttx/sched/get_errno_ptr.c @@ -37,14 +37,22 @@ * Included Files ************************************************************/ +#include <nuttx/config.h> #include <sched.h> #include <errno.h> +#include <nuttx/arch.h> #include "os_internal.h" #undef get_errno_ptr /************************************************************ - * Global Functions + * Private Data + ************************************************************/ + +static int g_irqerrno; + +/************************************************************ + * Public Functions ************************************************************/ /************************************************************ @@ -65,8 +73,32 @@ FAR int *get_errno_ptr(void) { - FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head; - return &ptcb->errno; + /* Check if this function was called from an interrupt + * handler. In that case, we have to do things a little + * differently. + */ + + if (up_interrupt_context()) + { + /* Yes, we were called from an interrupt handler. Do + * not permit access to the errno in the TCB of the + * interrupt task. Instead, use a separate errno just + * for interrupt handlers. Of course, this would have + * to change if we ever wanted to support nested + * interrupts. + */ + + return &g_irqerrno; + } + else + { + /* We were called from the normal tasking context. Return + * a reference to the thread-private errno in the TCB. + */ + + FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head; + return &ptcb->errno; + } } |