From d08b81db9dcb9e775c901f41f2f7b9e935ec6a1f Mon Sep 17 00:00:00 2001 From: fangxinyong Date: Fri, 23 Jun 2023 22:19:56 +0800 Subject: [PATCH] sched: fix pthread_exit crash A normal user task calls pthread_exit(), will crash at DEBUGASSERT. Cause pthread_exit limit in user pthread task. test case: int main(int argc, FAR char *argv[]) { pthread_exit(NULL); return 0; } >> test >> echo $? >> 0 Signed-off-by: fangxinyong --- sched/pthread/pthread_completejoin.c | 5 ++++- sched/pthread/pthread_exit.c | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sched/pthread/pthread_completejoin.c b/sched/pthread/pthread_completejoin.c index dedabf19a3..42656c1705 100644 --- a/sched/pthread/pthread_completejoin.c +++ b/sched/pthread/pthread_completejoin.c @@ -203,7 +203,10 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) if (ret != OK) { nxmutex_unlock(&group->tg_joinlock); - return tcb->flags & TCB_FLAG_DETACHED ? OK : ERROR; + + return ((tcb->flags & TCB_FLAG_DETACHED) || + (tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) ? + OK : ERROR; } else { diff --git a/sched/pthread/pthread_exit.c b/sched/pthread/pthread_exit.c index 5280bf5f92..946e0eac8a 100644 --- a/sched/pthread/pthread_exit.c +++ b/sched/pthread/pthread_exit.c @@ -69,7 +69,6 @@ void nx_pthread_exit(FAR void *exit_value) sinfo("exit_value=%p\n", exit_value); DEBUGASSERT(tcb != NULL); - DEBUGASSERT((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD); /* Block any signal actions that would awaken us while were * are performing the JOIN handshake.