diff --git a/arch/arm/src/common/arm_createstack.c b/arch/arm/src/common/arm_createstack.c index b14ba8892fd..14da833f932 100644 --- a/arch/arm/src/common/arm_createstack.c +++ b/arch/arm/src/common/arm_createstack.c @@ -197,7 +197,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ tcb->adj_stack_size = stack_size; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; #ifdef CONFIG_STACK_COLORATION /* If stack debug is enabled, then fill the stack with a @@ -207,6 +207,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) arm_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size); #endif /* CONFIG_STACK_COLORATION */ + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/arm/src/common/arm_releasestack.c b/arch/arm/src/common/arm_releasestack.c index 351d2d066da..34e095967cf 100644 --- a/arch/arm/src/common/arm_releasestack.c +++ b/arch/arm/src/common/arm_releasestack.c @@ -71,35 +71,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/arm/src/common/arm_usestack.c b/arch/arm/src/common/arm_usestack.c index dcef7341c08..879b36c0eb6 100644 --- a/arch/arm/src/common/arm_usestack.c +++ b/arch/arm/src/common/arm_usestack.c @@ -117,7 +117,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the new stack allocation */ tcb->stack_alloc_ptr = stack; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = STACK_ALIGN_DOWN((uintptr_t)stack + stack_size) - (uintptr_t)stack; diff --git a/arch/avr/src/avr/up_createstack.c b/arch/avr/src/avr/up_createstack.c index 8ac95e7b557..2e99d3d361d 100644 --- a/arch/avr/src/avr/up_createstack.c +++ b/arch/avr/src/avr/up_createstack.c @@ -177,8 +177,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = stack_size; + tcb->flags |= TCB_FLAG_FREE_STACK; #if defined(ARCH_HAVE_LEDS) board_autoled_on(LED_STACKCREATED); diff --git a/arch/avr/src/avr/up_usestack.c b/arch/avr/src/avr/up_usestack.c index 8e796e97105..c16b29ef5a1 100644 --- a/arch/avr/src/avr/up_usestack.c +++ b/arch/avr/src/avr/up_usestack.c @@ -105,7 +105,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = stack_size; return OK; diff --git a/arch/avr/src/avr32/up_createstack.c b/arch/avr/src/avr32/up_createstack.c index daa48d6cc8e..1e75a56e95f 100644 --- a/arch/avr/src/avr32/up_createstack.c +++ b/arch/avr/src/avr32/up_createstack.c @@ -200,8 +200,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/avr/src/avr32/up_usestack.c b/arch/avr/src/avr32/up_usestack.c index c2532262a2a..7aac1b57fb0 100644 --- a/arch/avr/src/avr32/up_usestack.c +++ b/arch/avr/src/avr32/up_usestack.c @@ -118,7 +118,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/avr/src/common/up_releasestack.c b/arch/avr/src/common/up_releasestack.c index a44a41a1b96..bd53ac1615a 100644 --- a/arch/avr/src/common/up_releasestack.c +++ b/arch/avr/src/common/up_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/hc/src/common/up_createstack.c b/arch/hc/src/common/up_createstack.c index 3fe163fe287..0b5b7f83def 100644 --- a/arch/hc/src/common/up_createstack.c +++ b/arch/hc/src/common/up_createstack.c @@ -199,8 +199,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->alloc_stack_ptr; + tcb->stack_base_ptr = tcb->alloc_stack_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/hc/src/common/up_releasestack.c b/arch/hc/src/common/up_releasestack.c index e7fcb21c929..c695b0f9964 100644 --- a/arch/hc/src/common/up_releasestack.c +++ b/arch/hc/src/common/up_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/mips/src/common/mips_createstack.c b/arch/mips/src/common/mips_createstack.c index b906a0dfeaf..4fa89ee7b6d 100644 --- a/arch/mips/src/common/mips_createstack.c +++ b/arch/mips/src/common/mips_createstack.c @@ -226,8 +226,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/mips/src/common/mips_releasestack.c b/arch/mips/src/common/mips_releasestack.c index 3ca1292ca20..79bfdb3fe0e 100644 --- a/arch/mips/src/common/mips_releasestack.c +++ b/arch/mips/src/common/mips_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/mips/src/common/mips_usestack.c b/arch/mips/src/common/mips_usestack.c index e6e4e60899f..faedc452512 100644 --- a/arch/mips/src/common/mips_usestack.c +++ b/arch/mips/src/common/mips_usestack.c @@ -144,7 +144,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/misoc/src/lm32/lm32_createstack.c b/arch/misoc/src/lm32/lm32_createstack.c index e00f5ab9a0f..ff40cf6e72e 100644 --- a/arch/misoc/src/lm32/lm32_createstack.c +++ b/arch/misoc/src/lm32/lm32_createstack.c @@ -234,8 +234,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/misoc/src/lm32/lm32_releasestack.c b/arch/misoc/src/lm32/lm32_releasestack.c index 5bdae5bf510..d940d8507cf 100644 --- a/arch/misoc/src/lm32/lm32_releasestack.c +++ b/arch/misoc/src/lm32/lm32_releasestack.c @@ -87,35 +87,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/misoc/src/lm32/lm32_usestack.c b/arch/misoc/src/lm32/lm32_usestack.c index c55a100cf59..457b0aea84c 100644 --- a/arch/misoc/src/lm32/lm32_usestack.c +++ b/arch/misoc/src/lm32/lm32_usestack.c @@ -114,7 +114,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/misoc/src/minerva/minerva_createstack.c b/arch/misoc/src/minerva/minerva_createstack.c index 186e564120c..8f3880ffa7b 100644 --- a/arch/misoc/src/minerva/minerva_createstack.c +++ b/arch/misoc/src/minerva/minerva_createstack.c @@ -227,8 +227,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/misoc/src/minerva/minerva_releasestack.c b/arch/misoc/src/minerva/minerva_releasestack.c index 8c70d29d64a..113568c24e1 100644 --- a/arch/misoc/src/minerva/minerva_releasestack.c +++ b/arch/misoc/src/minerva/minerva_releasestack.c @@ -87,35 +87,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/misoc/src/minerva/minerva_usestack.c b/arch/misoc/src/minerva/minerva_usestack.c index 3d1c6d76621..193a8f2d9c6 100644 --- a/arch/misoc/src/minerva/minerva_usestack.c +++ b/arch/misoc/src/minerva/minerva_usestack.c @@ -114,7 +114,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/or1k/src/common/up_createstack.c b/arch/or1k/src/common/up_createstack.c index 8a921347a4e..404a29aec06 100644 --- a/arch/or1k/src/common/up_createstack.c +++ b/arch/or1k/src/common/up_createstack.c @@ -191,7 +191,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; #ifdef CONFIG_STACK_COLORATION @@ -201,8 +201,8 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ up_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size); - #endif /* CONFIG_STACK_COLORATION */ + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/or1k/src/common/up_releasestack.c b/arch/or1k/src/common/up_releasestack.c index 1aba6ddac2b..ba85410f8c3 100644 --- a/arch/or1k/src/common/up_releasestack.c +++ b/arch/or1k/src/common/up_releasestack.c @@ -75,35 +75,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/or1k/src/common/up_usestack.c b/arch/or1k/src/common/up_usestack.c index 9866c4c2422..bf38cb7ae23 100644 --- a/arch/or1k/src/common/up_usestack.c +++ b/arch/or1k/src/common/up_usestack.c @@ -114,7 +114,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/renesas/src/common/up_createstack.c b/arch/renesas/src/common/up_createstack.c index c5043715cd3..bf0ad9e3120 100644 --- a/arch/renesas/src/common/up_createstack.c +++ b/arch/renesas/src/common/up_createstack.c @@ -199,8 +199,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/renesas/src/common/up_releasestack.c b/arch/renesas/src/common/up_releasestack.c index 77ac43e55f0..0d440d4c70d 100644 --- a/arch/renesas/src/common/up_releasestack.c +++ b/arch/renesas/src/common/up_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/renesas/src/common/up_usestack.c b/arch/renesas/src/common/up_usestack.c index b447b3ebedd..f35166db903 100644 --- a/arch/renesas/src/common/up_usestack.c +++ b/arch/renesas/src/common/up_usestack.c @@ -116,7 +116,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/risc-v/src/common/riscv_createstack.c b/arch/risc-v/src/common/riscv_createstack.c index d4b4a5db952..4e77a469f80 100644 --- a/arch/risc-v/src/common/riscv_createstack.c +++ b/arch/risc-v/src/common/riscv_createstack.c @@ -203,7 +203,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; #ifdef CONFIG_STACK_COLORATION @@ -215,6 +215,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) riscv_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size); #endif /* CONFIG_STACK_COLORATION */ + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/risc-v/src/common/riscv_releasestack.c b/arch/risc-v/src/common/riscv_releasestack.c index d681c4257be..a50f5db90c9 100644 --- a/arch/risc-v/src/common/riscv_releasestack.c +++ b/arch/risc-v/src/common/riscv_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/sim/src/sim/up_createstack.c b/arch/sim/src/sim/up_createstack.c index 308774944e4..164d10c8506 100644 --- a/arch/sim/src/sim/up_createstack.c +++ b/arch/sim/src/sim/up_createstack.c @@ -123,7 +123,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) tcb->adj_stack_size = adj_stack_size; tcb->stack_alloc_ptr = stack_alloc_ptr; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; #ifdef CONFIG_STACK_COLORATION /* If stack debug is enabled, then fill the stack with a @@ -132,8 +132,8 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ up_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size); - #endif /* CONFIG_STACK_COLORATION */ + tcb->flags |= TCB_FLAG_FREE_STACK; ret = OK; } diff --git a/arch/sim/src/sim/up_releasestack.c b/arch/sim/src/sim/up_releasestack.c index 179b699701d..1210e390c5d 100644 --- a/arch/sim/src/sim/up_releasestack.c +++ b/arch/sim/src/sim/up_releasestack.c @@ -62,17 +62,15 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; dtcb->stack_alloc_ptr = NULL; - dtcb->adj_stack_size = 0; - dtcb->stack_base_ptr = NULL; + dtcb->stack_base_ptr = NULL; + dtcb->adj_stack_size = 0; } diff --git a/arch/x86/src/i486/up_createstack.c b/arch/x86/src/i486/up_createstack.c index ed4a22b842c..05600bf0add 100644 --- a/arch/x86/src/i486/up_createstack.c +++ b/arch/x86/src/i486/up_createstack.c @@ -199,8 +199,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/x86/src/i486/up_releasestack.c b/arch/x86/src/i486/up_releasestack.c index 2e54e9f7a76..9122ae6d6ab 100644 --- a/arch/x86/src/i486/up_releasestack.c +++ b/arch/x86/src/i486/up_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/x86/src/i486/up_usestack.c b/arch/x86/src/i486/up_usestack.c index ac40aeb5f44..815a8bfe2fd 100644 --- a/arch/x86/src/i486/up_usestack.c +++ b/arch/x86/src/i486/up_usestack.c @@ -116,7 +116,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/x86_64/src/intel64/up_createstack.c b/arch/x86_64/src/intel64/up_createstack.c index 958e07240a9..fea234c3941 100644 --- a/arch/x86_64/src/intel64/up_createstack.c +++ b/arch/x86_64/src/intel64/up_createstack.c @@ -201,8 +201,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/x86_64/src/intel64/up_releasestack.c b/arch/x86_64/src/intel64/up_releasestack.c index eefe130dc3f..e14f9484378 100644 --- a/arch/x86_64/src/intel64/up_releasestack.c +++ b/arch/x86_64/src/intel64/up_releasestack.c @@ -81,7 +81,7 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ @@ -97,13 +97,12 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/x86_64/src/intel64/up_usestack.c b/arch/x86_64/src/intel64/up_usestack.c index 6a1bbed2315..d1c8f1385a1 100644 --- a/arch/x86_64/src/intel64/up_usestack.c +++ b/arch/x86_64/src/intel64/up_usestack.c @@ -118,7 +118,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c index cc9aa2084e2..ddc6619970b 100644 --- a/arch/xtensa/src/common/xtensa_createstack.c +++ b/arch/xtensa/src/common/xtensa_createstack.c @@ -241,7 +241,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; #ifdef CONFIG_STACK_COLORATION @@ -252,6 +252,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) up_stack_color(tcb->stack_base_ptr, tcb->adj_stack_size); #endif + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/xtensa/src/common/xtensa_releasestack.c b/arch/xtensa/src/common/xtensa_releasestack.c index 3130d15e982..0ef7f1913cc 100644 --- a/arch/xtensa/src/common/xtensa_releasestack.c +++ b/arch/xtensa/src/common/xtensa_releasestack.c @@ -72,35 +72,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (UMM_HEAPMEMEBER(dtcb->stack_alloc_ptr)) - { - UMM_FREE(dtcb->stack_alloc_ptr); - } + UMM_FREE(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c index 647b2bb4592..6371bf5d43c 100644 --- a/arch/xtensa/src/common/xtensa_usestack.c +++ b/arch/xtensa/src/common/xtensa_usestack.c @@ -122,7 +122,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; #if defined(CONFIG_STACK_COLORATION) diff --git a/arch/z16/src/common/z16_createstack.c b/arch/z16/src/common/z16_createstack.c index 5c3004db4c6..356bde3e5b4 100644 --- a/arch/z16/src/common/z16_createstack.c +++ b/arch/z16/src/common/z16_createstack.c @@ -193,8 +193,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/z16/src/common/z16_releasestack.c b/arch/z16/src/common/z16_releasestack.c index 95f5e9567d5..30810aaf8ce 100644 --- a/arch/z16/src/common/z16_releasestack.c +++ b/arch/z16/src/common/z16_releasestack.c @@ -73,19 +73,15 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; + kumm_free(dtcb->stack_alloc_ptr); } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/z80/src/common/z80_createstack.c b/arch/z80/src/common/z80_createstack.c index 4826af9e634..16f837cfac6 100644 --- a/arch/z80/src/common/z80_createstack.c +++ b/arch/z80/src/common/z80_createstack.c @@ -198,8 +198,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; + tcb->flags |= TCB_FLAG_FREE_STACK; board_autoled_on(LED_STACKCREATED); return OK; diff --git a/arch/z80/src/common/z80_releasestack.c b/arch/z80/src/common/z80_releasestack.c index a94b0b10d0e..b5725c262b2 100644 --- a/arch/z80/src/common/z80_releasestack.c +++ b/arch/z80/src/common/z80_releasestack.c @@ -79,35 +79,28 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype) { /* Is there a stack allocated? */ - if (dtcb->stack_alloc_ptr) + if (dtcb->stack_alloc_ptr && (dtcb->flags & TCB_FLAG_FREE_STACK)) { #ifdef CONFIG_MM_KERNEL_HEAP /* Use the kernel allocator if this is a kernel thread */ if (ttype == TCB_FLAG_TTYPE_KERNEL) { - if (kmm_heapmember(dtcb->stack_alloc_ptr)) - { - kmm_free(dtcb->stack_alloc_ptr); - } + kmm_free(dtcb->stack_alloc_ptr); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - if (umm_heapmember(dtcb->stack_alloc_ptr)) - { - kumm_free(dtcb->stack_alloc_ptr); - } + kumm_free(dtcb->stack_alloc_ptr); } - - /* Mark the stack freed */ - - dtcb->stack_alloc_ptr = NULL; } - /* The size of the allocated stack is now zero */ + /* Mark the stack freed */ + dtcb->flags &= ~TCB_FLAG_FREE_STACK; + dtcb->stack_alloc_ptr = NULL; + dtcb->stack_base_ptr = NULL; dtcb->adj_stack_size = 0; } diff --git a/arch/z80/src/common/z80_usestack.c b/arch/z80/src/common/z80_usestack.c index 40b212b594f..65bdef6a0b4 100644 --- a/arch/z80/src/common/z80_usestack.c +++ b/arch/z80/src/common/z80_usestack.c @@ -115,7 +115,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index a176e1c1a67..fb73ef8bcb8 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -106,7 +106,8 @@ #define TCB_FLAG_SIGNAL_ACTION (1 << 8) /* Bit 8: In a signal handler */ #define TCB_FLAG_SYSCALL (1 << 9) /* Bit 9: In a system call */ #define TCB_FLAG_EXIT_PROCESSING (1 << 10) /* Bit 10: Exitting */ - /* Bits 11-15: Available */ +#define TCB_FLAG_FREE_STACK (1 << 11) /* Bit 11: Free stack after exit */ + /* Bits 12-15: Available */ /* Values for struct task_group tg_flags */