Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zeroize: use asm! to improve performance #841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,17 @@ where
// object for at least `self.len()` elements of type `Z`.
// `self.len()` is also not larger than an `isize`, because of the assertion above.
// The memory of the slice should not wrap around the address space.
unsafe { volatile_set(self.as_mut_ptr(), Z::default(), self.len()) };
for z in self.iter_mut() {
*z = Z::default();
}
unsafe {
core::arch::asm!(
"/* {ptr} */",
ptr = in(reg) self.as_mut_ptr(),
options(nostack, readonly, preserves_flags),
);
Comment on lines +478 to +482
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asm! is only stable for x86/x86-64, ARM/AArch64, and RISC-V, so its usage needs to be gated for those platforms

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- No FFI or inline assembly! **WASM friendly** (and tested)!

This guarantee needs to be updated if this change is merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere we feature-gate asm, so we could perhaps maintain that guarantee so long as the asm feature is off

}

atomic_fence();
}
}
Expand Down