|
|
@ -71,15 +71,29 @@ unsafe extern "C" fn clock_gettime( |
|
|
|
#[no_mangle] |
|
|
|
#[no_mangle] |
|
|
|
unsafe extern "C" fn getrandom( |
|
|
|
unsafe extern "C" fn getrandom( |
|
|
|
buf: *mut libc::c_void, |
|
|
|
buf: *mut libc::c_void, |
|
|
|
buflen: libc::size_t, |
|
|
|
mut buflen: libc::size_t, |
|
|
|
_flags: libc::c_uint, |
|
|
|
flags: libc::c_uint, |
|
|
|
) -> libc::ssize_t { |
|
|
|
) -> libc::ssize_t { |
|
|
|
let ret = ctru_sys::psInit(); |
|
|
|
// TODO: is this needed? Maybe just `buflen = buflen.min(libc::ssize_t::MAX)` ?
|
|
|
|
if ret != 0 { |
|
|
|
buflen = buflen.min(0x1FFFFFF); |
|
|
|
return ret.try_into().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
if flags != 0 { |
|
|
|
|
|
|
|
// no flags are supported on 3DS
|
|
|
|
|
|
|
|
*__errno() = libc::EINVAL; |
|
|
|
|
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctru_sys::PS_GenerateRandomBytes(buf, buflen.try_into().unwrap()) |
|
|
|
let ret = ctru_sys::PS_GenerateRandomBytes(buf, buflen as libc::c_uint) as libc::ssize_t; |
|
|
|
.try_into() |
|
|
|
if ret < 0 { |
|
|
|
.unwrap() |
|
|
|
// this is kind of a hack, but at least gives some visibility to the
|
|
|
|
|
|
|
|
// error code returned by PS_GenerateRandomBytes I guess? Another option
|
|
|
|
|
|
|
|
// might be to panic, which could use a payload of a specific error type
|
|
|
|
|
|
|
|
// that the ctru panic handler could decode into 3DS-specific human-readable
|
|
|
|
|
|
|
|
// errors.
|
|
|
|
|
|
|
|
*__errno() = ret as libc::c_int; |
|
|
|
|
|
|
|
-1 |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// safe because above ensures buflen < isize::MAX
|
|
|
|
|
|
|
|
buflen as libc::ssize_t |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|