Enable optional logging of failures

This commit is contained in:
Diggory Hardy 2019-03-12 17:45:28 +00:00
parent d33356f55f
commit 214a71386f
10 changed files with 14 additions and 4 deletions

View File

@ -19,6 +19,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
Ok(())
} else {
let code = NonZeroU32::new(errno as u32).unwrap();
error!("cloudabi::random_get syscall failed with code {}", code);
Err(Error::from(code))
}
}

View File

@ -12,6 +12,7 @@ use std::num::NonZeroU32;
use {Error, ERROR_UNAVAILABLE};
pub fn getrandom_inner(_: &mut [u8]) -> Result<(), Error> {
error!("no support for this platform");
Err(ERROR_UNAVAILABLE)
}

View File

@ -26,6 +26,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
)
};
if ret == -1 || len != chunk.len() {
error!("freebsd: kern.arandom syscall failed");
return Err(io::Error::last_os_error().into());
}
}

View File

@ -113,7 +113,7 @@ extern crate wasm_bindgen;
#[cfg(feature = "log")] #[macro_use] extern crate log;
#[allow(unused)]
#[cfg(not(feature = "log"))] macro_rules! warn { ($($x:tt)*) => () }
#[cfg(not(feature = "log"))] macro_rules! error { ($($x:tt)*) => () }
#[cfg(any(
target_os = "android",

View File

@ -34,6 +34,7 @@ fn syscall_getrandom(dest: &mut [u8]) -> Result<(), io::Error> {
libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), dest.len(), 0)
};
if ret < 0 || (ret as usize) != dest.len() {
error!("Linux getrandom syscall failed with return value {}", ret);
return Err(io::Error::last_os_error());
}
Ok(())

View File

@ -36,6 +36,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
)
};
if ret == -1 {
error!("SecRandomCopyBytes call failed");
Err(io::Error::last_os_error().into())
} else {
Ok(())

View File

@ -22,6 +22,7 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
)
};
if ret == -1 {
error!("libc::getentropy call failed");
return Err(io::Error::last_os_error().into());
}
}

View File

@ -45,6 +45,7 @@ fn libc_getrandom(rand: GetRandomFn, dest: &mut [u8]) -> Result<(), Error> {
let ret = unsafe { rand(dest.as_mut_ptr(), dest.len(), 0) as libc::ssize_t };
if ret == -1 || ret != dest.len() as libc::ssize_t {
error!("getrandom syscall failed with ret={}", ret);
Err(io::Error::last_os_error().into())
} else {
Ok(())

View File

@ -66,7 +66,7 @@ fn getrandom_init() -> Result<RngSource, Error> {
else { unreachable!() }
} else {
let err: WebError = js!{ return @{ result }.error }.try_into().unwrap();
warn!("getrandom unavailable: {}", err);
error!("getrandom unavailable: {}", err);
Err(ERROR_UNAVAILABLE)
}
}
@ -102,7 +102,7 @@ fn getrandom_fill(source: &mut RngSource, dest: &mut [u8]) -> Result<(), Error>
if js!{ return @{ result.as_ref() }.success } != true {
let err: WebError = js!{ return @{ result }.error }.try_into().unwrap();
warn!("getrandom failed: {}", err);
error!("getrandom failed: {}", err);
return Err(ERROR_UNKNOWN)
}
}

View File

@ -20,7 +20,10 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
let ret = unsafe {
RtlGenRandom(dest.as_mut_ptr() as PVOID, dest.len() as ULONG)
};
if ret == 0 { return Err(io::Error::last_os_error().into()); }
if ret == 0 {
error!("RtlGenRandom call failed");
return Err(io::Error::last_os_error().into());
}
Ok(())
}