oscall 0.1.1

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
//! `rand` on Windows: `ProcessPrng`, the generator behind `BCryptGenRandom`
//! and `RtlGenRandom`, which needs no provider handle and cannot fail.

use core::mem::MaybeUninit;

use crate::sys::dll;
use crate::{ErrorKind, Result};

dll!("bcryptprimitives.dll" {
    fn ProcessPrng(data: *mut u8, len: usize) -> i32;
});

pub(crate) fn fill(buf: &mut [MaybeUninit<u8>]) -> Result<()> {
    // SAFETY: the function writes exactly `buf.len()` bytes.
    let ok = unsafe { ProcessPrng(buf.as_mut_ptr().cast(), buf.len()) };
    // It is documented to always return TRUE, and sets no error code.
    if ok == 0 {
        return Err(ErrorKind::Other.into());
    }
    Ok(())
}