mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 10:46:28 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user