From 814cab1cd13fc56d9b2fe9cadae929e0e686cb09 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 17 Feb 2022 03:02:39 +0800 Subject: [PATCH] arch/ceva: Mark the allocated stack with TCB_FLAG_FREE_STACK Signed-off-by: Xiang Xiao --- arch/ceva/src/common/up_createstack.c | 1 + arch/ceva/src/common/up_releasestack.c | 21 +++++++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/arch/ceva/src/common/up_createstack.c b/arch/ceva/src/common/up_createstack.c index fd4288d2a1..aa0dd241da 100644 --- a/arch/ceva/src/common/up_createstack.c +++ b/arch/ceva/src/common/up_createstack.c @@ -216,6 +216,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) #endif /* CONFIG_STACK_COLORATION */ + tcb->flags |= TCB_FLAG_FREE_STACK; return OK; } diff --git a/arch/ceva/src/common/up_releasestack.c b/arch/ceva/src/common/up_releasestack.c index 67c29664d4..a58939c8a6 100644 --- a/arch/ceva/src/common/up_releasestack.c +++ b/arch/ceva/src/common/up_releasestack.c @@ -83,35 +83,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 HAVE_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; }