From 0f7c992cea40e63cd8475d73b3d85a228bcfbc82 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 6 Jun 2025 18:32:01 +0800 Subject: [PATCH] sched/task: fix gettid by moving tls_dup_info after child pid initialization Move tls_dup_info() call to after child process priority is set, ensuring the child's pid is properly initialized before duplicating TLS information. This fixes incorrect thread ID assignment during task fork operations. Signed-off-by: hujun5 --- sched/task/task_fork.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c index 964c55b0395..359db312f48 100644 --- a/sched/task/task_fork.c +++ b/sched/task/task_fork.c @@ -221,14 +221,6 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr) } #endif - /* Setup thread local storage */ - - ret = tls_dup_info(child, parent); - if (ret < OK) - { - goto errout_with_tcb; - } - /* Get the priority of the parent task */ #ifdef CONFIG_PRIORITY_INHERITANCE @@ -247,6 +239,14 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr) goto errout_with_tcb; } + /* Setup thread local storage */ + + ret = tls_dup_info(child, parent); + if (ret < OK) + { + goto errout_with_tcb; + } + /* Setup to pass parameters to the new task */ ret = nxtask_setup_stackargs(child, argv[0], &argv[1]);