diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index a902c414d4846fd090a9acca54cb92b1e5be4f87..c27fa32ed26e0f411373243e77ff971083c079e1 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -1,5 +1,5 @@ //! strings implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/strings.h.html - +#![feature(llvm_asm)] use core::ptr; use crate::{ @@ -22,6 +22,14 @@ pub unsafe extern "C" fn bzero(dst: *mut c_void, n: size_t) { ptr::write_bytes(dst as *mut u8, 0, n); } +#[no_mangle] +pub unsafe extern "C" fn explicit_bzero(s: *mut c_void, n: size_t) { + for i in 0..n { + *(s as *mut u8).add(i) = 0 as u8; + } + llvm_asm!("" :: "r"(s) : "memory") +} + #[no_mangle] pub extern "C" fn ffs(i: c_int) -> c_int { if i == 0 { diff --git a/tests/strings.c b/tests/strings.c index 6d3c4742cbb20c38dc3640cfe907dcf23477f23b..ede5d6289cd6a6f6b29a844ecadf2d386b7f3aba 100644 --- a/tests/strings.c +++ b/tests/strings.c @@ -40,4 +40,8 @@ int main(void) { char* str = "hihih"; assert(index(str, 'i') == str + 1); assert(rindex(str, 'i') == str + 3); + + char buf[] = "password"; + explicit_bzero(buf, sizeof(buf)); + assert(buf[0] == 0); }