[HUST CSE][core] validate thread priority at runtime#11297
[HUST CSE][core] validate thread priority at runtime#11297Telecaster2147 wants to merge 3 commits intoRT-Thread:masterfrom
Conversation
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_lwpReviewers: xu18838022837 Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-03-26 12:25 CST)
📝 Review Instructions
|
src/scheduler_comm.c
Outdated
| */ | ||
| rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority) | ||
| { | ||
| if (priority >= RT_THREAD_PRIORITY_MAX) |
There was a problem hiding this comment.
如果上层没有正确的针对返回值进行判断,系统是会继续运行的,而不会执行_rt_sched_update_priority进行assert异常停止。
系统也有很多调用此函数的地方没有对返回值进行处理:
Line 935 in e41c7cc
There was a problem hiding this comment.
如果上层没有正确的针对返回值进行判断,系统是会继续运行的,而不会执行
_rt_sched_update_priority进行assert异常停止。 系统也有很多调用此函数的地方没有对返回值进行处理:Line 935 in e41c7cc
感谢提醒,这个点我重新调整了。之前的确是把检查放得太靠下了,现在的推送已经把优先级校验前移到 sys_sched_setparam() / sys_sched_setscheduler() 的 syscall 入口,内核内部原有的 assert 路径保持不变,本地已经通过编译
7797e7f to
034f06d
Compare
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
当前调度优先级更新路径对非法优先级的保护主要依赖 RT_ASSERT。在非断言构建下,越界优先级可能继续进入核心调度逻辑,带来不可预期行为。
你的解决方案是什么 (what is your solution)
本 PR 在 rt_sched_thread_change_priority() 和 rt_sched_thread_reset_priority() 中增加运行时检查:当 priority 大于等于 RT_THREAD_PRIORITY_MAX 时,直接返回 -RT_EINVAL,避免非法值继续传入内部调度更新逻辑。
请提供验证的bsp和config (provide the config and bsp)
BSP:
bsp/qemu-vexpress-a9
.config:使用 bsp/qemu-vexpress-a9/.config 做基础编译验证。
action:currently unavailable
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up