diff options
Diffstat (limited to 'nuttx/arch/arm/src')
-rw-r--r-- | nuttx/arch/arm/src/common/up_createstack.c | 38 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_releasestack.c | 24 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_usestack.c | 8 |
3 files changed, 58 insertions, 12 deletions
diff --git a/nuttx/arch/arm/src/common/up_createstack.c b/nuttx/arch/arm/src/common/up_createstack.c index 65eb91159..634fb9d61 100644 --- a/nuttx/arch/arm/src/common/up_createstack.c +++ b/nuttx/arch/arm/src/common/up_createstack.c @@ -146,17 +146,19 @@ static void *memset32(void *s, uint32_t c, size_t n) 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) { @@ -164,12 +166,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) * 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 *)kzalloc(stack_size); +#else + 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); + tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size); #else - tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size); + 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); @@ -218,7 +240,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) - memset32(tcb->stack_alloc_ptr, 0xDEADBEEF, tcb->adj_stack_size/4); + memset32(tcb->stack_alloc_ptr, 0xdeadbeef, tcb->adj_stack_size/4); #endif up_ledon(LED_STACKCREATED); diff --git a/nuttx/arch/arm/src/common/up_releasestack.c b/nuttx/arch/arm/src/common/up_releasestack.c index 711022f93..9ab872d33 100644 --- a/nuttx/arch/arm/src/common/up_releasestack.c +++ b/nuttx/arch/arm/src/common/up_releasestack.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/common/up_releasestack.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -91,11 +91,31 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { + /* Is there a stack allocated? */ + if (dtcb->stack_alloc_ptr) { - sched_ufree(dtcb->stack_alloc_ptr); +#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) + { + sched_kfree(dtcb->stack_alloc_ptr); + } + else +#endif + { + /* Use the user-space allocator if this is a task or pthread */ + + sched_ufree(dtcb->stack_alloc_ptr); + } + + /* Mark the stack freed */ + dtcb->stack_alloc_ptr = NULL; } + /* The size of the allocated stack is now zero */ + dtcb->adj_stack_size = 0; } diff --git a/nuttx/arch/arm/src/common/up_usestack.c b/nuttx/arch/arm/src/common/up_usestack.c index a141006bb..a45ec99b5 100644 --- a/nuttx/arch/arm/src/common/up_usestack.c +++ b/nuttx/arch/arm/src/common/up_usestack.c @@ -121,12 +121,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) size_t top_of_stack; size_t size_of_stack; + /* Is there already a stack allocated? */ + if (tcb->stack_alloc_ptr) { - sched_ufree(tcb->stack_alloc_ptr); + /* Yes... Release the old stack allocation */ + + up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK); } - /* Save the stack allocation */ + /* Save the new stack allocation */ tcb->stack_alloc_ptr = stack; |