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

Optional unprivileged even-more-unsafe mode for certain use cases? #60

Open
cbiffle opened this issue Jan 11, 2023 · 3 comments
Open

Optional unprivileged even-more-unsafe mode for certain use cases? #60

cbiffle opened this issue Jan 11, 2023 · 3 comments
Assignees
Labels
C-enhancement Category: A new feature or an improvement for an existing one

Comments

@cbiffle
Copy link

cbiffle commented Jan 11, 2023

Hi! I stumbled upon this crate while researching some unrelated things, and it looks like it could make an excellent replacement for our ad-hoc atomics polyfill on Hubris for ARMv6-M.

However, our situation is slightly weird: as far as I can tell, we're some of the only folks in the embedded Rust world who are using the privileged/unprivileged modes of the processor. We're also using memory protection to isolate unprivileged tasks, and do not permit threading within a task.

This means our atomic polyfill within tasks winds up not generating the cpsid/cpsie instructions that you'd use in a threaded privileged context.

Would y'all be open to a PR adding an additional feature (with a name including the word unsafe and possibly some screaming) to suppress generation of the cpsid/cpsie instructions?

@taiki-e
Copy link
Owner

taiki-e commented Jan 12, 2023

In systems with no interrupts or preemption, it is also sound even if replace the code that disables interrupts and restores interrupt state with a compiler fence, so I think it is ok to have a new unsafe cfg to do that.

@taiki-e taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Jan 12, 2023
@cbiffle
Copy link
Author

cbiffle commented Jan 21, 2023

Agreed, a compiler fence seems like the right tool. I'll send a PR when I have some time. Thanks!

@taiki-e
Copy link
Owner

taiki-e commented Feb 25, 2023

By the way, you can also do this by enabling the critical-section feature of the portable-atomic and providing a critical-section implementation that just emits a compiler fence.

That said, since we cannot inline the critical-section implementation calls, a dedicated cfg would allow for more efficient code generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

No branches or pull requests

2 participants