!libphoenix: make pthread attrs (more) POSIX-compliant#484
!libphoenix: make pthread attrs (more) POSIX-compliant#484adamgreloch wants to merge 16 commits into
Conversation
TASK: RTOS-1353
There was a problem hiding this comment.
Code Review
This pull request adds NULL pointer checks to pthread_attr_init and pthread_attr_destroy to prevent potential dereferences, and fixes a logical bug in pthread_attr_setdetachstate by changing the logical OR (||) to a logical AND (&&) when validating the detachstate parameter. No review comments were provided, so there is no additional feedback.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread_attr_t structure, introduces new fields such as guardsize and inheritsched, and implements several missing pthread_attr_* getter and setter functions. However, two critical issues were identified in pthread_create: first, the thread's detached state is incorrectly initialized using the default attributes instead of the user-provided attributes; second, adding the stack size and guard size can result in an integer overflow, potentially leading to an undersized stack allocation and memory corruption.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
35b09b7 to
4dea89e
Compare
b20dbf9 to
68a70c5
Compare
The ceiling should be done only when the stack is mmaped. Ceiling in setstacksize violates POSIX and doesn't make sense if the stack is provided by the caller. Fixes: phoenix-rtos/phoenix-rtos-project#1641 TASK: RTOS-1353
TASK: RTOS-1353
68a70c5 to
e2a03e2
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread attributes implementation, updating the pthread_attr_t structure to support guardsize and inheritsched, renaming fields for clarity, and introducing macro-generated getters. Feedback points out POSIX compliance issues: sched_get_priority_max and sched_get_priority_min should set errno and return -1 on failure rather than returning the error code directly, and pthread_create should ignore guardsize when a custom stackaddr is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread attribute implementation, introducing support for guard size and inherit scheduling attributes, updating the pthread_attr_t structure, and cleaning up function declarations. The feedback highlights POSIX compliance issues: sched_get_priority_max and sched_get_priority_min should return -1 and set errno on failure instead of returning the error code directly, and pthread_attr_setschedparam should return EINVAL rather than ENOTSUP for invalid scheduling priorities.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread implementation by updating the pthread_attr_t structure, introducing support for guard size and scheduling inheritance, and adding corresponding getter and setter functions. The feedback highlights a critical issue where the guard area is not properly protected with PROT_NONE via mprotect, rendering it ineffective against stack overflows. Additionally, the reviewer points out that sched_get_priority_max and sched_get_priority_min should return -1 and set errno to EINVAL on failure to comply with POSIX standards.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
e2a03e2 to
9011c66
Compare
|
/gemini review (but this time please don't repeat yourself 3 times) |
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread attribute handling and scheduling priority queries. Key changes include updating the pthread_attr_t structure to support guard size and inherit-scheduling attributes, implementing guard page protection using mprotect in pthread_create, and replacing hardcoded scheduling priority limits with dynamic queries via sched_info. Additionally, extern specifiers were cleaned up across header files, and helper macros were introduced to generate attribute getter functions. There are no review comments, so no further feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
With the new syscall, this is now a breaking change. |
| ctx->is_detached = (attrs->detachstate == PTHREAD_CREATE_DETACHED) ? 1 : 0; | ||
| ctx->start_routine = start_routine; | ||
| ctx->arg = arg; | ||
| ctx->stack = stack; |
There was a problem hiding this comment.
it's already included in the stack. As the guard comes from the same allocation as the stack, this simplifies its management. Added a comment about this in pthread_ctx.
| } | ||
|
|
||
| if (guardsize > 0) { | ||
| if (mprotect(stack, guardsize, PROT_NONE) != 0) { |
There was a problem hiding this comment.
Did you test how this works in practice?
There was a problem hiding this comment.
Yes, after some issues it's finally working. I've been mistakenly creating a thread with stack pointed to stack, while it should be stack + guardsize. This mistake unveiled a bug in the kernel, as it turns out we don't validate the stack passed from userspace at all.
9011c66 to
0cbc7b2
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread and sched headers and implementations, removing the extern keyword from function declarations, introducing guardsize and inheritsched attributes to pthread_attr_t, and updating scheduling policy checks. Feedback on the changes highlights a potential memory leak in pthread_create when ctx allocation fails due to using the incorrect stack size in munmap, and suggests a more robust check for scheduling policies in pthread_attr_setschedpolicy instead of assuming contiguous policy values.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
0cbc7b2 to
2158e17
Compare
TASK: RTOS-1353
2158e17 to
78c62f8
Compare
TASK: RTOS-1353
TASK: RTOS-1353
78c62f8 to
3688750
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the pthread implementation to support additional thread attributes, including guard size, detach state, and scheduling inheritance. It also updates priority-related functions to retrieve limits dynamically via a new schedInfo system call instead of using hardcoded values. The feedback suggests optimizing pthread_attr_setschedparam by calling schedInfo directly once to avoid redundant system calls and prevent unintended side-effects on errno.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…llcheck TASK: RTOS-1353
TASK: RTOS-1353
TASK: RTOS-1353
PS-C-REC-016 TASK: RTOS-1353
POSIX requires either 0 or positive error number. TASK: RTOS-1353
TASK: RTOS-1353
3688750 to
126d2be
Compare
TASK: RTOS-1353
Description
Motivation and Context
Types of changes
Breaking change: adds dependency on new
schedInfosyscall.How Has This Been Tested?
Checklist:
Special treatment
proc: add sched_info syscall phoenix-rtos-kernel#791