use super::*;
use crate::syscalls::*;
#[instrument(level = "trace", skip_all, fields(%buf_len), ret)]
pub fn random_get<M: MemorySize>(
ctx: FunctionEnvMut<'_, WasiEnv>,
buf: WasmPtr<u8, M>,
buf_len: M::Offset,
) -> Errno {
let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
let buf_len64: u64 = buf_len.into();
let mut u8_buffer = vec![0; buf_len64 as usize];
let res = getrandom::getrandom(&mut u8_buffer);
match res {
Ok(()) => {
let buf = wasi_try_mem!(buf.slice(&memory, buf_len));
wasi_try_mem!(buf.write_slice(&u8_buffer));
Errno::Success
}
Err(_) => Errno::Io,
}
}