From e5c4aff96d4fc1ff98fb308ce4956ca3b70ea954 Mon Sep 17 00:00:00 2001 From: jake <77554505+brxken128@users.noreply.github.com> Date: Sun, 22 Oct 2023 02:14:19 +0100 Subject: [PATCH] add support for `wasm`'s `v128` SIMD register --- zeroize/src/lib.rs | 2 ++ zeroize/src/wasm32.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 zeroize/src/wasm32.rs diff --git a/zeroize/src/lib.rs b/zeroize/src/lib.rs index b67b5c95..dc27eb3f 100644 --- a/zeroize/src/lib.rs +++ b/zeroize/src/lib.rs @@ -247,6 +247,8 @@ pub use zeroize_derive::{Zeroize, ZeroizeOnDrop}; #[cfg(all(feature = "aarch64", target_arch = "aarch64"))] mod aarch64; +#[cfg(all(target_arch = "wasm32", target_family = "wasm"))] +mod wasm32; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] mod x86; diff --git a/zeroize/src/wasm32.rs b/zeroize/src/wasm32.rs new file mode 100644 index 00000000..88442aa8 --- /dev/null +++ b/zeroize/src/wasm32.rs @@ -0,0 +1,22 @@ +//! [`Zeroize`] impls for WASM SIMD registers. + +use crate::{atomic_fence, volatile_write, Zeroize}; + +use core::arch::wasm32::v128; + +macro_rules! impl_zeroize_for_simd_register { + ($($type:ty),* $(,)?) => { + $( + #[cfg_attr(docsrs, doc(cfg(target_arch = "wasm32", target_family = "wasm")))] + impl Zeroize for $type { + #[inline] + fn zeroize(&mut self) { + volatile_write(self, unsafe { core::mem::zeroed() }); + atomic_fence(); + } + } + )+ + }; +} + +impl_zeroize_for_simd_register!(v128);