From 4dd98fc184208b1a2309f9b82d723268121b81ec Mon Sep 17 00:00:00 2001 From: Martin Hughes Date: Fri, 2 Oct 2026 20:10:41 +0100 Subject: [PATCH 1/2] Constrain NativeMethod to Send + Sync This makes Object Send + Sync, and by extension WrappedObject (although gain_mut is still a potential footgun). If #361 is merged as well, then Interpreter becomes Send + Sync without needing an `unsafe impl` block. --- Cargo.toml | 2 ++ src/aml/mod.rs | 2 +- src/aml/object.rs | 11 +++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c7bb871..7147e12d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,8 @@ spinning_top = { version = "0.3.0", optional = true, public = true } pci_types = { version = "0.10.0", public = true } byteorder = { version = "1.5.0", optional = true, default-features = false } smallvec = { version = "1.15.2", optional = true, default-features = false, public = true } +# TODO: If necessary, remove from "dev-dependencies" if #361 is merged +static_assertions = "1.1.0" [dev-dependencies] aml-test-tools = { path = "tools/aml-test-tools" } diff --git a/src/aml/mod.rs b/src/aml/mod.rs index a28ba497..99c45187 100644 --- a/src/aml/mod.rs +++ b/src/aml/mod.rs @@ -133,7 +133,7 @@ pub type NoSendInterpreter = BaseInterpreter; /// An Interpreter that is known to be Send + Sync. The version you should prefer by default. pub type Interpreter = BaseInterpreter; -// TODO: Make sure to remove these two lines after Interpreter really is Send + Sync. +// TODO: After #361 is merged, it should be possible to remove these lines. unsafe impl Send for Interpreter where H: Handler + Send {} unsafe impl Sync for Interpreter where H: Handler + Send {} diff --git a/src/aml/object.rs b/src/aml/object.rs index ebaca18b..7c788467 100644 --- a/src/aml/object.rs +++ b/src/aml/object.rs @@ -7,8 +7,9 @@ use alloc::{ }; use bit_field::BitField; use core::{cell::UnsafeCell, cmp::Ordering, fmt, ops, sync::atomic::AtomicU64}; +use static_assertions::assert_impl_all; -type NativeMethod = dyn Fn(&[WrappedObject]) -> Result; +type NativeMethod = dyn Fn(&[WrappedObject]) -> Result + Send + Sync; #[derive(Clone)] pub enum Object { @@ -37,7 +38,7 @@ pub enum Object { impl Object { pub fn native_method(num_args: u8, f: F) -> Object where - F: Fn(&[WrappedObject]) -> Result + 'static, + F: Fn(&[WrappedObject]) -> Result + 'static + Send + Sync, { let mut flags = 0; flags.set_bits(0..3, num_args); @@ -104,9 +105,15 @@ impl ObjectToken { } } +// In order for us to assert WrappedObject is Send + Sync, Object must be. +assert_impl_all!(Object: Send, Sync); + #[derive(Clone, Debug)] pub struct WrappedObject(Arc>); +unsafe impl Send for WrappedObject {} +unsafe impl Sync for WrappedObject {} + impl WrappedObject { pub fn new(object: Object) -> WrappedObject { #[allow(clippy::arc_with_non_send_sync)] From c5237879db731c003fe18d268280d0ed7027003a Mon Sep 17 00:00:00 2001 From: Martin Hughes Date: Sun, 4 Oct 2026 11:28:50 +0100 Subject: [PATCH 2/2] Interpreter is Send + Sync! Updates since #361 got merged --- Cargo.toml | 2 -- src/aml/mod.rs | 4 ---- 2 files changed, 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7147e12d..583bd40b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ spinning_top = { version = "0.3.0", optional = true, public = true } pci_types = { version = "0.10.0", public = true } byteorder = { version = "1.5.0", optional = true, default-features = false } smallvec = { version = "1.15.2", optional = true, default-features = false, public = true } -# TODO: If necessary, remove from "dev-dependencies" if #361 is merged static_assertions = "1.1.0" [dev-dependencies] @@ -32,7 +31,6 @@ lock_api = "0.4.14" parking_lot = "0.12.5" pretty_env_logger = "0.5.0" serial_test = "4.0.1" -static_assertions = "1.1.0" [features] default = ["alloc", "aml"] diff --git a/src/aml/mod.rs b/src/aml/mod.rs index 99c45187..e317f65d 100644 --- a/src/aml/mod.rs +++ b/src/aml/mod.rs @@ -133,10 +133,6 @@ pub type NoSendInterpreter = BaseInterpreter; /// An Interpreter that is known to be Send + Sync. The version you should prefer by default. pub type Interpreter = BaseInterpreter; -// TODO: After #361 is merged, it should be possible to remove these lines. -unsafe impl Send for Interpreter where H: Handler + Send {} -unsafe impl Sync for Interpreter where H: Handler + Send {} - /// The value returned by the `Revision` opcode. const INTERPRETER_REVISION: u64 = 1;