diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-20 20:27:08 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-20 20:27:08 +0000 |
commit | ae6758d5518a0e92f10476592dc156af38f36244 (patch) | |
tree | f7e4cbe989ad3df45b6e062b8457e45c81556350 /nuttx/arch/z80/src/common/up_createstack.c | |
parent | fce497aecaf6826d6fec3cfcb761abeac7fe72bf (diff) | |
download | px4-nuttx-ae6758d5518a0e92f10476592dc156af38f36244.tar.gz px4-nuttx-ae6758d5518a0e92f10476592dc156af38f36244.tar.bz2 px4-nuttx-ae6758d5518a0e92f10476592dc156af38f36244.zip |
In the kernel build, allocate the stacks for kernel threads from the kernel heap so that they are protected from medddling by the applications
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5766 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/z80/src/common/up_createstack.c')
-rw-r--r-- | nuttx/arch/z80/src/common/up_createstack.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/nuttx/arch/z80/src/common/up_createstack.c b/nuttx/arch/z80/src/common/up_createstack.c index 1e47b09bd..a36a8aa7b 100644 --- a/nuttx/arch/z80/src/common/up_createstack.c +++ b/nuttx/arch/z80/src/common/up_createstack.c @@ -101,30 +101,52 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) { - /* Is there already a stack allocated of a different size? */ + /* Is there already a stack allocated of a different size? Because of + * alignment issues, stack_size might erroneously appear to be of a + * different size. Fortunately, this is not a critical operation. + */ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size) { - /* Yes.. free it */ + /* Yes.. Release the old stack */ - sched_ufree(tcb->stack_alloc_ptr); - tcb->stack_alloc_ptr = NULL; + up_release_stack(tcb, ttype); } - /* Do we need to allocate a stack? */ - + /* Do we need to allocate a new stack? */ + if (!tcb->stack_alloc_ptr) { /* Allocate the stack. If DEBUG is enabled (but not stack debug), * then create a zeroed stack to make stack dumps easier to trace. */ +#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) + /* Use the kernel allocator if this is a kernel thread */ + + if (ttype == TCB_FLAG_TTYPE_KERNEL) + { #if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK) - tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size); + tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size); #else - tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size); + tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size); #endif + } + else +#endif + { + /* Use the user-space allocator if this is a task or pthread */ + +#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK) + tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size); +#else + tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size); +#endif + } + #ifdef CONFIG_DEBUG + /* Was the allocation successful? */ + if (!tcb->stack_alloc_ptr) { sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size); |