aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/software_tasks.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2022-08-05 11:28:02 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2022-08-05 11:37:16 +0200
commit46a3f2befd6fd821e5747ce9db112c550bc989f3 (patch)
tree384667a40772d821e9d3e95a73293254170adbb5 /macros/src/codegen/software_tasks.rs
parentb48a95e87930fa51ef6fb47ad08a95d3159d9bac (diff)
downloadrtic-46a3f2befd6fd821e5747ce9db112c550bc989f3.tar.gz
rtic-46a3f2befd6fd821e5747ce9db112c550bc989f3.tar.zst
rtic-46a3f2befd6fd821e5747ce9db112c550bc989f3.zip
Fix UB in the access of `Priority` for asyc executors
The `Priority` was generated on the stack in the dispatcher which caused it to be dropped after usage. This is now fixed by having the `Priority` being a static variable for executors
Diffstat (limited to 'macros/src/codegen/software_tasks.rs')
-rw-r--r--macros/src/codegen/software_tasks.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index 6d08a221..71869b6e 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -139,17 +139,24 @@ pub fn codegen(
let attrs = &task.attrs;
let cfgs = &task.cfgs;
let stmts = &task.stmts;
- let async_marker = if task.is_async {
- quote!(async)
+ let (async_marker, context_lifetime) = if task.is_async {
+ (
+ quote!(async),
+ if shared_needs_lt || local_needs_lt {
+ quote!(<'static>)
+ } else {
+ quote!()
+ },
+ )
} else {
- quote!()
+ (quote!(), quote!())
};
user_tasks.push(quote!(
#(#attrs)*
#(#cfgs)*
#[allow(non_snake_case)]
- #async_marker fn #name(#context: #name::Context #(,#inputs)*) {
+ #async_marker fn #name(#context: #name::Context #context_lifetime #(,#inputs)*) {
use rtic::Mutex as _;
use rtic::mutex::prelude::*;