From ffef751568c3565324bf3d0cdce9b1878ae2b5df Mon Sep 17 00:00:00 2001 From: Kaiyi Li <06393993lky@gmail.com> Date: Sun, 25 May 2025 07:25:38 -0700 Subject: [PATCH] Add a DispatchableHandle trait to Remove integer to pointer cast in from_raw ... so that from_raw is more friendly to miri tests with strict provenance. Closes #996 --- ash/src/vk.rs | 6 ++++++ ash/src/vk/macros.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 13cb8bcd6..cd6775e5e 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -30,6 +30,12 @@ pub mod native; mod platform_types; pub use platform_types::*; +pub trait DispatchableHandle: Handle { + // We choose to use a pointer type for the parameter to avoid possible integer-to-pointer cast, + // to keep the pointer provenance. See details at https://github.com/ash-rs/ash/issues/996. + fn from_raw_ptr(_: *mut u8) -> Self; +} + pub trait Handle: Sized { const TYPE: ObjectType; fn as_raw(self) -> u64; diff --git a/ash/src/vk/macros.rs b/ash/src/vk/macros.rs index a9b76f8d3..a928a77a2 100644 --- a/ash/src/vk/macros.rs +++ b/ash/src/vk/macros.rs @@ -141,6 +141,11 @@ macro_rules! define_handle { Self(x as _) } } + impl $crate::vk::DispatchableHandle for $name { + fn from_raw_ptr(x: *mut u8) -> Self { + Self(x) + } + } unsafe impl Send for $name {} unsafe impl Sync for $name {} impl $name {