From 8193d5aea66f75c1b40248021760785428a1bf96 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 8 Jun 2025 10:23:41 +0200 Subject: Fix references allowed in `spawn` The futures passed to the executor were not bound to be 'static, which allowed task futures to reference data that's on the spawnee's stack. The executor now requires futures to be 'static. --- rtic/CHANGELOG.md | 4 ++++ rtic/src/export/executor.rs | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/rtic/CHANGELOG.md b/rtic/CHANGELOG.md index 27eb257..6b7ff15 100644 --- a/rtic/CHANGELOG.md +++ b/rtic/CHANGELOG.md @@ -20,6 +20,10 @@ Example: ## [Unreleased] +### Fixed + +- Task executors were not required to be 'static, allowing spawn to reference the stack of the spawnee. + ### Changed - Updated esp32c3 dependency to v0.28.0 diff --git a/rtic/src/export/executor.rs b/rtic/src/export/executor.rs index 8d42c41..bc31bf8 100644 --- a/rtic/src/export/executor.rs +++ b/rtic/src/export/executor.rs @@ -42,7 +42,7 @@ impl AsyncTaskExecutorPtr { } #[inline(always)] - pub fn set_in_main(&self, executor: &ManuallyDrop>) { + pub fn set_in_main(&self, executor: &ManuallyDrop>) { self.ptr.store(executor as *const _ as _, Ordering::Relaxed); } @@ -59,14 +59,14 @@ impl Default for AsyncTaskExecutorPtr { } /// Executor for an async task. -pub struct AsyncTaskExecutor { +pub struct AsyncTaskExecutor { // `task` is protected by the `running` flag. task: UnsafeCell>, running: AtomicBool, pending: AtomicBool, } -unsafe impl Sync for AsyncTaskExecutor {} +unsafe impl Sync for AsyncTaskExecutor {} macro_rules! new_n_args { ($name:ident, $($t:ident),*) => { @@ -86,13 +86,13 @@ macro_rules! from_ptr_n_args { }; } -impl Default for AsyncTaskExecutor { +impl Default for AsyncTaskExecutor { fn default() -> Self { Self::new() } } -impl AsyncTaskExecutor { +impl AsyncTaskExecutor { /// Create a new executor. #[inline(always)] pub const fn new() -> Self { -- cgit v1.2.3