sched: fix regression from PR #18040 by adding NULL pointer safety

Replace DEBUGASSERT checks with proper NULL pointer validation in getpid() and
task_get_info() functions. Return IDLE_PROCESS_ID or -ESRCH on NULL conditions
instead of asserting, improving robustness during early system startup and error conditions.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2026-01-23 09:39:03 +08:00
committed by Xiang Xiao
parent cd1000575e
commit 5f92db54a6
3 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <nuttx/sched.h>
#include <nuttx/tls.h>
/****************************************************************************
@@ -53,6 +54,5 @@ pid_t getpid(void)
{
FAR struct task_info_s *info = task_get_info();
DEBUGASSERT(info != NULL);
return info->ta_pid;
return info ? info->ta_pid : IDLE_PROCESS_ID;
}
+1 -1
View File
@@ -51,5 +51,5 @@ FAR struct task_info_s *task_get_info(void)
{
FAR struct tls_info_s *info = tls_get_info();
return info->tl_task;
return info ? info->tl_task : NULL;
}
+6 -1
View File
@@ -61,7 +61,12 @@ int nxsched_get_stackinfo(pid_t pid, FAR struct stackinfo_s *stackinfo)
FAR struct tcb_s *rtcb = this_task(); /* TCB of running task */
FAR struct tcb_s *qtcb; /* TCB of queried task */
DEBUGASSERT(rtcb != NULL && stackinfo != NULL);
DEBUGASSERT(stackinfo != NULL);
if (rtcb == NULL)
{
return -ENOENT;
}
/* Pid of 0 means that we are querying ourself */