-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
pthread: facilitate dynamically allocated thread stacks #29029
pthread: facilitate dynamically allocated thread stacks #29029
Conversation
Looks like this assertion fails in some tests: atomic_val_t old_val = atomic_set(&new_thread->base.cookie,
THREAD_COOKIE);
/* Must be garbage or 0, never already set. Cleared at the end of
* z_thread_single_abort()
*/
__ASSERT(old_val != THREAD_COOKIE,
"re-use of active thread object %p detected", new_thread); and there are some (predictable) MPU / MMU faults due to permissions. Will address those issues shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also make sense to or with K_INHERIT_PERMS in this case? cc: @andrewboie
K_INHERIT_PERMS is a userspace thing, so I do not believe so. the posix layer doesn't support user mode. I might just not be seeing what you mean here though, can you elaborate?
Looks like this assertion fails in some tests:
How are you managing when it's safe to free stacks back to the heap? are you using k_thread_join() or is it the fn_abort hook? it should be safe to free them at that time. that assertion fails when you call k_thread_create() on a thread object that is already active and not exited yet.
Is this documented somewhere? Since I could not find this mentioned here: https://docs.zephyrproject.org/latest/guides/portability/posix.html and no
Which facility for aligned allocations does it has? I could only find |
I think I was somewhat confused and half awake when I made that comment and was conflating userspace with MMU / MPU protection.
Am using the Seems strange that this assertion would be triggered - will keep looking into it. |
I'll likely focus on eliminating MPU-related bugs in |
Ah, I think I see what's happening. Compensation for alignment and guard areas is happening in two places: I think
The issue here is that Would it be realistic to ask for something like |
Created issue #29519 |
@maxbachmann - I think you've really hit on an important topic. From the perspective of an application, it's using the same heap that "malloc" is using, which was a If you're interested in this topic though, I would suggest checking out #29529. I've added you as a reviewer. |
Why would you do this? I already told you sys_mem_pool and k_mem_pool are being removed from the kernel. #28611 |
This comment has been minimized.
This comment has been minimized.
This change allows users to call pthread_create(3) with the pthread_attr_t argument equal to NULL, or with the pthread_attr_t argument specifying a NULL stack but a custom stack size. If either of the above to requirements are met, then a stack will be heap-allocated internally and freed again after the thread has terminated. This makes the Zephyr implementation of pthread_create(3) more compliant with the normative spec. Fixes #25973 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
Tests for dynamically allocated POSIX thread stacks. Fixes #25973 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change allows users to call
pthread_create(3)
with thepthread_attr_t
argument equal toNULL
, or with thepthread_attr_t
argument specifying aNULL
stack.If either of the above to requirements are met, then a stack will be heap-allocated internally and freed again after the thread has terminated.
This helps the Zephyr implementation of
pthread_create(3)
become more compliant with the normative spec.Fixes #25973