-
Notifications
You must be signed in to change notification settings - Fork 12
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
riot-rs-embassy: improve SWI
selection
#285
Conversation
I didn't find a way to do this directly in Rust. There might be one using proc macros, but I dug quite far, IMO the build.rs solution is preferable. The difficulty lies in |
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.
Looks like a good simplification; see comment inline.
I'm not super happy with how (as I've learned as part of reviewing this) InterruptExecutor::start as a safe function trusts the user to pass in the right interrupt, but that's nothing to fix in this PR.
if let Ok(var) = env::var("CONFIG_SWI") { | ||
fs::write( | ||
&dest_path, | ||
format!("crate::executor_swi!({});\n", var).as_bytes(), |
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.
This allows arbitrary Rust injection from the environment; since it's only expecting an identifier, I think it should be validated by checking that the environment variable value is only composed of a-z
, A-Z
, 0-9
, and _
.
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.
Generally, an attacker in control of the execution environment already owns the build process and host machine.
If we want to introduce a check, syn::Ident can be parsed from a string without making arbitrary validity choices.
This PR tries to make the incoming wave of different SWI choices more managable.
add
executor_swi!(NAME)
-macro (reduces code duplication, see e.g.,arch/nrf/mod.rs
)adds logic to
build.rs
that, if set, generates aswi.rs
that basically just containsexecutor_swi!(NAME)
withNAME
taken from the env variableCONFIG_SWI
. This will be used in add stm32 support #237.