Closed cinlyooi-intel closed 5 years ago
Thanks, @cinlyooi-intel , I can reproduce this one. Looking at it.
@andrewboie, the test is failing because it tries to access the userspace_local_data
, which, if I am not mistaken, is set to:
new_thread->userspace_local_data =
(struct _thread_userspace_local_data *)
(K_THREAD_STACK_BUFFER(stack) + stack_size);
but only after stack_size
is decremented (to exclude the userspace_local_data
).
The tests tries to access the data from user mode.
We need to discuss whether the error is:
The error appeared now, due to fixing #12688, where we aligned the stack protection for NXP_MPU with that of ARM_MPU. For ARM7_MPU we probably do not see the error due to rounding-up the protected area to the power of 2.
I also see the error on ARMv8-M which, like NXP MPU, does not require power-of-two alignment.
We have a problem in how the thread-specific storage area is being reserved. The intent of this region is for thread-specific data that the thread can manipulate directly, without having to make a syscall. Currently, we are using this to store errno.
What's happening is that the room for this area is being subtracted from the stack size being passed to _new_thread. With the NXP MPU, this results in this memory not being covered by the MPU region for the stack as it should be.
I'm still studying the code to determine the best solution. The way that stack memory bounds are accounted for differ in subtle ways across ARM, ARC, x86 and this is making this more confusing. My current thinking is that _new_thread needs a 'offset' parameter instead of subtracting the desired offset from the stack size passed in.
@ioannisg if you want to focus on other stuff I can handle addressing this bug.
To Reproduce Steps to reproduce the behavior:
Screenshots or console output
Environment (please complete the following information):