diff options
Diffstat (limited to 'nuttx/arch/x86/src/i486/up_createstack.c')
-rw-r--r-- | nuttx/arch/x86/src/i486/up_createstack.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/nuttx/arch/x86/src/i486/up_createstack.c b/nuttx/arch/x86/src/i486/up_createstack.c index bcce5fdcc..ae394dea6 100644 --- a/nuttx/arch/x86/src/i486/up_createstack.c +++ b/nuttx/arch/x86/src/i486/up_createstack.c @@ -103,30 +103,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); |