Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1449, POSIX implementation honors stack pointer #1450

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

jphickey
Copy link
Contributor

Checklist (Please check before submitting)

Describe the contribution
When the OS_TaskCreate() function is called with a non-NULL stack pointer, the POSIX implementation now should use this pointer as intended. Previously it was always allocating a new stack buffer, ignoring the passed-in pointer.

NOTE: When using this feature, the caller must use caution to make sure the buffer being passed in is large enough to use as a task stack. Particularly when running under a desktop Linux/Glibc environment, the infrastructure puts a considerably large object on the stack. For example, in the osal-core-tests, the stack size was too small.

Fixes #1449

Testing performed
Build and run all tests. Added tests that ensure the stack pointer is being honored as expected.

Expected behavior changes
User-supplied stack buffer will be used on POSIX.

System(s) tested on
Debian

Additional context
This could have negative consequences if the user was assuming RTOS-like behavior (e.g. no thread local storage) and was using very small stack sizes. If the supplied stack size is less than 16k, (or PTHREAD_STACK_MIN) then the call will now fail, whereas previously it would quietly be made bigger than requested.

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

@@ -447,8 +447,8 @@
* Purpose: Local helper routine, not part of OSAL API.
*
*-----------------------------------------------------------------*/
int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, size_t stacksz,
PthreadFuncPtr_t entry, void *entry_arg)
int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, osal_stackptr_t stackptr,

Check notice

Code scanning / CodeQL

Function too long Note

OS_Posix_InternalTaskCreate_Impl has too many lines (129, while 60 are allowed).
@@ -447,8 +447,8 @@
* Purpose: Local helper routine, not part of OSAL API.
*
*-----------------------------------------------------------------*/
int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, size_t stacksz,
PthreadFuncPtr_t entry, void *entry_arg)
int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, osal_stackptr_t stackptr,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
When the OS_TaskCreate() function is called with a non-NULL stack pointer,
the POSIX implementation now should use this pointer as intended.  Previously
it was always allocating a new stack buffer, ignoring the passed-in pointer.

NOTE: When using this feature, the caller must use caution to make sure the
buffer being passed in is large enough to use as a task stack.  Particularly
when running under a desktop Linux/Glibc environment, the infrastructure
puts a considerably large object on the stack.  For example, in the
osal-core-tests, the stack size was too small.
@jphickey jphickey added the CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) label Feb 14, 2024
@dzbaker dzbaker added CCB:Approved Indicates code review and approval by community CCB and removed CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) labels Feb 15, 2024
dzbaker added a commit that referenced this pull request Feb 22, 2024
Fix #1449, POSIX implementation honors stack pointer
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 22, 2024
*Combines:*

cFE equuleus-rc1+dev94
osal equuleus-rc1+dev47
to_lab equuleus-rc1+dev42

**Includes:**

*cFE*
- nasa/cFE#2515

*osal*
- nasa/osal#1448
- nasa/osal#1450

*to_lab*
- nasa/to_lab#191

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
Co-authored by: Avi Weiss <thnkslprpt@users.noreply.github.com>
@jphickey jphickey added the CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) label Feb 26, 2024
@jphickey
Copy link
Contributor Author

Ready for [re-]review. Checking further into detail of the RTEMS implementation -- the needed API was only added in the latest development branch (6.x) and is not available on either RTEMS 4.11 nor 5.x. Furthermore, the documentation warns that this is only intended for use with low-level device drivers that have special requirements, and general tasks should not force a stack pointer, as the stack buffers have special requirements for size and alignment.

Therefore, with the consideration that we will likely also deprecate/discourage users from specifying a stack buffer due to similar issues on other platforms, the best solution for now is to simply skip this functional test on RTEMS.

@dzbaker dzbaker removed the CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) label Feb 29, 2024
@chillfig chillfig added the bug label Feb 29, 2024
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 29, 2024
*Combines:*

cFE equuleus-rc1+dev100
osal equuleus-rc1+dev58

**Includes:**

*cFE*
- nasa/cFE#2520

*osal*
- nasa/osal#1450

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
@dzbaker dzbaker merged commit 4ff765e into nasa:main Feb 29, 2024
20 checks passed
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 29, 2024
*Combines:*

cFE equuleus-rc1+dev100
osal equuleus-rc1+dev58

**Includes:**

*cFE*
- nasa/cFE#2520

*osal*
- nasa/osal#1450

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
@jphickey jphickey deleted the fix-1449-stackptr branch May 29, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CCB:Approved Indicates code review and approval by community CCB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POSIX implementation does not adhere to user-specified stack pointer
3 participants