diff --git a/.github/workflows/nopanic.yaml b/.github/workflows/nopanic.yaml index a4c24173..a5bd6e02 100644 --- a/.github/workflows/nopanic.yaml +++ b/.github/workflows/nopanic.yaml @@ -47,6 +47,13 @@ jobs: - name: Check (rdrand.rs) run: ret=$(grep panic target/release/libgetrandom_wrapper.so; echo $?); [ $ret -eq 1 ] + - name: Build (custom.rs) + env: + RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom" + run: cargo build --release + - name: Check (custom.rs) + run: ret=$(grep panic target/release/libgetrandom_wrapper.so; echo $?); [ $ret -eq 1 ] + - name: Build (wasi.rs, preview 1) run: cargo build --release --target wasm32-wasip1 - name: Check (wasi.rs, preview 1) diff --git a/nopanic_check/Cargo.toml b/nopanic_check/Cargo.toml index 11b51024..f8c21c68 100644 --- a/nopanic_check/Cargo.toml +++ b/nopanic_check/Cargo.toml @@ -14,3 +14,9 @@ getrandom = { path = ".." } [profile.release] panic = "abort" + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(getrandom_backend, values("custom"))', +] diff --git a/nopanic_check/src/lib.rs b/nopanic_check/src/lib.rs index 0c0a7a0d..af2c8ee3 100644 --- a/nopanic_check/src/lib.rs +++ b/nopanic_check/src/lib.rs @@ -16,3 +16,15 @@ pub extern "C" fn getrandom_wrapper(buf_ptr: *mut u8, buf_len: usize) -> u32 { let res = getrandom::getrandom_uninit(buf).map(|_| ()); unsafe { core::mem::transmute(res) } } + +#[cfg(getrandom_backend = "custom")] +#[no_mangle] +unsafe extern "Rust" fn __getrandom_custom( + dest: *mut u8, + len: usize, +) -> Result<(), getrandom::Error> { + for i in 0..len { + core::ptr::write(dest.add(i), i as u8); + } + Ok(()) +}