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

Use const operand for ARM syscall implementation #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ioan-Cristian
Copy link

asm_const feature has been stabilized in Rust 1.82. Using const operands for inline assembly eliminates a lot of the duplicated code in the ARM syscall implementation.

This commit has been tested by running a simple application that periodically blinks and writes a message on Raspberry Pi Pico.

alevy
alevy previously approved these changes Dec 3, 2024
@alevy
Copy link
Member

alevy commented Dec 3, 2024

Note that this requires an update of the Rust version. @jrvanwhy (and others) are any significant implications for downstream users)?

@jrvanwhy
Copy link
Collaborator

jrvanwhy commented Dec 9, 2024

Note that this requires an update of the Rust version. @jrvanwhy (and others) are any significant implications for downstream users)?

I discussed this with Lawrence, it sounds like there would be minimal impact (i.e. they would add #![feature(asm_const)] to libtock-rs when built on their toolchain).

Longer term, we may want to have a stricter MSRV policy, but this PR isn't an issue.

@lschuermann
Copy link
Member

Are the CI failures related to this change?

@Ioan-Cristian
Copy link
Author

Yes, they seem to fail on this branch, but not on master. I am not familiar with the test environment, so I don't know why they fail.

@jrvanwhy
Copy link
Collaborator

The error message makes it looks like the toolchain is catching something that would be UB -- a panic unwinding across the syscall boundary. However, subscribe catches unwinding and calls the Exit syscall. As far as I can tell, that Exit call should not unwind, so I don't know why we're getting the error message.

Regardless, the CI failure is almost certainly due to the toolchain update.

I don't have time to debug further for at least a few more days, sadly.

@jrvanwhy
Copy link
Collaborator

It seems the mechanism we use to catch unwinding upcalls is unreliable: rust-lang/rust#123231. I'm still reading through the thread; I don't have time to finish reading it (much less understand it) tonight. I suspect that this is defined behavior, but an abort is definitely not how we want this to be handled.

If so, then the unit test failure is correct: our code is not handling an unwinding upcall in the manner it is supposed to.

On another note, libtock-rs's current intended behavior in the event of an unwinding upcall is to exit with a successful completion code, which doesn't seem right to me. We should have a mechanism for libtock-rs to communicate that an upcall unwound, such as a dedicated completion code for it.

@jrvanwhy
Copy link
Collaborator

I've done some more reading. The good news: this is not and never was UB. Further, catching the unwind wasn't necessary for safety anyway -- code that tries to unwind across an extern "C" ABI will reliably abort. Also, due to rust-lang/rust#129582, this will start working again as of Rust 1.84.

The bad news: That behavior is not spec'd yet, so we can't rely on it. In that respect, the unit test failure is correct: our code does not reliably work. The only proper fix I see is to require the caller to inject a catch_unwind implementation, which might require some pretty major API changes to libtock-rs. If we do add new Subscribe APIs to libtock-rs (e.g. in #494), we should keep this in mind; perhaps we can provide better behaviors then.

For this PR, lets just delete the unwinding_upcall test.

`asm_const` feature has been stabilized in Rust 1.82. Using const
operands for inline assembly eliminates a lot of the duplicated code in
the ARM syscall implementation.

This commit has been tested by running a simple application that
periodically blinks and writes a message on Raspberry Pi Pico.
@Ioan-Cristian
Copy link
Author

I commented out the test explaining why it was removed and that it should be readded when Rust is updated to 1.84.

@jrvanwhy jrvanwhy added the upkeep Indicates a PR is upkeep as defined by the code review policy. label Dec 17, 2024
Copy link
Collaborator

@jrvanwhy jrvanwhy left a comment

Choose a reason for hiding this comment

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

Oh, CI is still failing. This time it appears to just be due to new lints.

@Ioan-Cristian
Copy link
Author

Do you think I should create a separate PR to fix the lint checks?

@hudson-ayers
Copy link
Contributor

IMO same PR in a standalone commit would be fine. Alternatively you could do a standalone PR for the Rust update which would include removing the test and the lint fixes, and this PR could just be the asm_const change and nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upkeep Indicates a PR is upkeep as defined by the code review policy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants