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

kernel: userspace: manipulate _thread_idx_map on per-byte basis #72781

Conversation

dcpleung
Copy link
Member

The sys_bitfield_(clear/set)_bit() work on pointer size element. However, _thread_idx_map[] is a byte array. On little endian systems, the bitops should work fine. However, on big endian systems, changing the lower bits may actually be manipulating memory outside the array when CONFIG_MAX_THREAD_BYTES is not multiple of 4. So modify the code to perform bit ops on a per-byte basis.

Fixes #72430

@dcpleung dcpleung force-pushed the kernel/userspace_thread_idx_map_out_of_bound branch from 25a4aef to 62fcb13 Compare May 15, 2024 14:18
The sys_bitfield_(clear/set)_bit() work on pointer size element.
However, _thread_idx_map[] is a byte array. On little endian
systems, the bitops should work fine. However, on big endian
systems, changing the lower bits may actually be manipulating
memory outside the array when CONFIG_MAX_THREAD_BYTES is not
multiple of 4. So modify the code to perform bit ops on
a per-byte basis.

Fixes zephyrproject-rtos#72430

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works.

It would be kind of nice to round up to longs for this bitmap, but I guess that there might have been significant other side effects that would have needed touching up.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. Nice catch.

@jhedberg jhedberg merged commit 2ad265c into zephyrproject-rtos:main May 18, 2024
32 checks passed
@dcpleung dcpleung deleted the kernel/userspace_thread_idx_map_out_of_bound branch May 20, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GCC 13 compiler warning in kernel/userspace.c
5 participants