diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index df5f0ec0..abb18135 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-24.04, windows-2022] - toolchain: [nightly, beta, stable, "1.63"] + toolchain: [nightly, beta, stable, "1.85"] # Only Test macOS on stable to reduce macOS CI jobs include: # aarch64-apple-darwin. @@ -340,7 +340,7 @@ jobs: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.82 + toolchain: 1.85 targets: wasm32-wasip1,wasm32-wasip2 - name: Install Wasmtime run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index d360e8e8..cce685f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `RawOsError` type alias [#739] +### Changed +- Use Edition 2024 and MSRV 1.85 [#749] + [#739]: https://github.com/rust-random/getrandom/pull/739 +[#749]: https://github.com/rust-random/getrandom/pull/749 ## [0.3.4] - 2025-10-14 diff --git a/Cargo.toml b/Cargo.toml index 933b9d9c..dc4bb20a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "getrandom" version = "0.3.4" -edition = "2021" -rust-version = "1.63" # Sync tests.yml and README.md. +edition = "2024" +rust-version = "1.85" # Sync tests.yml and README.md. authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" description = "A small cross-platform library for retrieving random data from system source" diff --git a/README.md b/README.md index 13d4388a..297b5542 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Next, you need to define an `extern` function with the following signature: ```rust use getrandom::Error; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "Rust" fn __getrandom_v03_custom( dest: *mut u8, len: usize, @@ -189,7 +189,7 @@ fn my_entropy_source(buf: &mut [u8]) -> Result<(), getrandom::Error> { Ok(()) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "Rust" fn __getrandom_v03_custom( dest: *mut u8, len: usize, @@ -302,7 +302,7 @@ RUSTFLAGS="-Zsanitizer=memory" cargo test -Zbuild-std --target=x86_64-unknown-li ## Minimum Supported Rust Version -This crate requires Rust 1.63 or later. +This crate requires Rust 1.85 or later. ## License diff --git a/benches/buffer.rs b/benches/buffer.rs index 0063a453..34ed3c84 100644 --- a/benches/buffer.rs +++ b/benches/buffer.rs @@ -2,7 +2,7 @@ extern crate test; use std::{ - mem::{size_of, MaybeUninit}, + mem::{MaybeUninit, size_of}, slice, }; diff --git a/nopanic_check/Cargo.toml b/nopanic_check/Cargo.toml index 0b838eaa..029ea589 100644 --- a/nopanic_check/Cargo.toml +++ b/nopanic_check/Cargo.toml @@ -2,7 +2,7 @@ name = "nopanic_check" description = "Helper crate for checking that getrandom implementation does not contain potential panics" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [workspace] diff --git a/nopanic_check/src/lib.rs b/nopanic_check/src/lib.rs index 9a6a02b9..0147fe58 100644 --- a/nopanic_check/src/lib.rs +++ b/nopanic_check/src/lib.rs @@ -4,27 +4,27 @@ #[cfg(not(any(test, all(target_arch = "wasm32", target_env = "p2"))))] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { - extern "C" { + unsafe extern "C" { fn panic_nonexistent() -> !; } unsafe { panic_nonexistent() } } -#[no_mangle] -pub extern "C" fn getrandom_wrapper(buf_ptr: *mut u8, buf_len: usize) -> u32 { +#[unsafe(no_mangle)] +pub unsafe extern "C" fn getrandom_wrapper(buf_ptr: *mut u8, buf_len: usize) -> u32 { let buf = unsafe { core::slice::from_raw_parts_mut(buf_ptr.cast(), buf_len) }; let res = getrandom::fill_uninit(buf).map(|_| ()); unsafe { core::mem::transmute(res) } } #[cfg(getrandom_backend = "custom")] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "Rust" fn __getrandom_v03_custom( dest: *mut u8, len: usize, ) -> Result<(), getrandom::Error> { for i in 0..len { - core::ptr::write(dest.add(i), i as u8); + unsafe { core::ptr::write(dest.add(i), i as u8) }; } Ok(()) } diff --git a/src/backends/custom.rs b/src/backends/custom.rs index c505481a..ea22de7a 100644 --- a/src/backends/custom.rs +++ b/src/backends/custom.rs @@ -6,7 +6,7 @@ pub use crate::util::{inner_u32, inner_u64}; #[inline] pub fn fill_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { - extern "Rust" { + unsafe extern "Rust" { fn __getrandom_v03_custom(dest: *mut u8, len: usize) -> Result<(), Error>; } unsafe { __getrandom_v03_custom(dest.as_mut_ptr().cast(), dest.len()) } diff --git a/src/backends/efi_rng.rs b/src/backends/efi_rng.rs index 768c8cc8..9d588840 100644 --- a/src/backends/efi_rng.rs +++ b/src/backends/efi_rng.rs @@ -2,7 +2,7 @@ use crate::Error; use core::{ mem::MaybeUninit, - ptr::{self, null_mut, NonNull}, + ptr::{self, NonNull, null_mut}, sync::atomic::{AtomicPtr, Ordering::Relaxed}, }; use r_efi::{ diff --git a/src/backends/esp_idf.rs b/src/backends/esp_idf.rs index 4d1689dc..6e3039df 100644 --- a/src/backends/esp_idf.rs +++ b/src/backends/esp_idf.rs @@ -4,7 +4,7 @@ use core::{ffi::c_void, mem::MaybeUninit}; pub use crate::util::{inner_u32, inner_u64}; -extern "C" { +unsafe extern "C" { fn esp_fill_random(buf: *mut c_void, len: usize) -> u32; } diff --git a/src/backends/fuchsia.rs b/src/backends/fuchsia.rs index b5f1ade5..f8abfbef 100644 --- a/src/backends/fuchsia.rs +++ b/src/backends/fuchsia.rs @@ -5,7 +5,7 @@ use core::mem::MaybeUninit; pub use crate::util::{inner_u32, inner_u64}; #[link(name = "zircon")] -extern "C" { +unsafe extern "C" { fn zx_cprng_draw(buffer: *mut u8, length: usize); } diff --git a/src/backends/hermit.rs b/src/backends/hermit.rs index 34d7cdbb..aab30121 100644 --- a/src/backends/hermit.rs +++ b/src/backends/hermit.rs @@ -2,7 +2,7 @@ use crate::Error; use core::mem::MaybeUninit; -extern "C" { +unsafe extern "C" { fn sys_read_entropy(buffer: *mut u8, length: usize, flags: u32) -> isize; // Note that `sys_secure_rand32/64` are implemented using `sys_read_entropy`: // https://github.com/hermit-os/kernel/blob/430da84/src/syscalls/entropy.rs#L62-L104 diff --git a/src/backends/linux_android_with_fallback.rs b/src/backends/linux_android_with_fallback.rs index 6c9dd065..d4ae6f24 100644 --- a/src/backends/linux_android_with_fallback.rs +++ b/src/backends/linux_android_with_fallback.rs @@ -3,7 +3,7 @@ use super::{sanitizer, use_file}; use crate::Error; use core::{ ffi::c_void, - mem::{transmute, MaybeUninit}, + mem::{MaybeUninit, transmute}, ptr::NonNull, sync::atomic::{AtomicPtr, Ordering}, }; diff --git a/src/backends/linux_raw.rs b/src/backends/linux_raw.rs index 2a74e585..6185d7e1 100644 --- a/src/backends/linux_raw.rs +++ b/src/backends/linux_raw.rs @@ -20,18 +20,20 @@ unsafe fn getrandom_syscall(buf: *mut u8, buflen: usize, flags: u32) -> isize { // Theoretically, we could detect thumb mode in the build script, but several // register moves are cheap enough compared to the syscall cost, so we do not // bother with it. - core::arch::asm!( - "mov {tmp}, r7", - // TODO(MSRV-1.82): replace with `nr = const __NR_getrandom,` - "mov r7, #384", - "svc 0", - "mov r7, {tmp}", - tmp = out(reg) _, - inlateout("r0") buf => r0, - in("r1") buflen, - in("r2") flags, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "mov {tmp}, r7", + // TODO(MSRV-1.82): replace with `nr = const __NR_getrandom,` + "mov r7, #384", + "svc 0", + "mov r7, {tmp}", + tmp = out(reg) _, + inlateout("r0") buf => r0, + in("r1") buflen, + in("r2") flags, + options(nostack, preserves_flags) + ); + } } else if #[cfg(target_arch = "aarch64")] { // TODO(MSRV-1.78): Also check `any(target_abi = "", target_abi = "ilp32")` above. // According to the ILP32 patch for the kernel that hasn't yet @@ -39,76 +41,88 @@ unsafe fn getrandom_syscall(buf: *mut u8, buflen: usize, flags: u32) -> isize { // syscall table [...] with the exceptions listed below," where // getrandom is not mentioned as an exception. const __NR_getrandom: u32 = 278; - core::arch::asm!( - "svc 0", - in("x8") __NR_getrandom, - inlateout("x0") buf => r0, - in("x1") buflen, - in("x2") flags, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "svc 0", + in("x8") __NR_getrandom, + inlateout("x0") buf => r0, + in("x1") buflen, + in("x2") flags, + options(nostack, preserves_flags) + ); + } } else if #[cfg(target_arch = "loongarch64")] { // TODO(MSRV-1.78): Also check `any(target_abi = "", target_abi = "ilp32")` above. const __NR_getrandom: u32 = 278; - core::arch::asm!( - "syscall 0", - in("$a7") __NR_getrandom, - inlateout("$a0") buf => r0, - in("$a1") buflen, - in("$a2") flags, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "syscall 0", + in("$a7") __NR_getrandom, + inlateout("$a0") buf => r0, + in("$a1") buflen, + in("$a2") flags, + options(nostack, preserves_flags) + ); + } } else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { const __NR_getrandom: u32 = 278; - core::arch::asm!( - "ecall", - in("a7") __NR_getrandom, - inlateout("a0") buf => r0, - in("a1") buflen, - in("a2") flags, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "ecall", + in("a7") __NR_getrandom, + inlateout("a0") buf => r0, + in("a1") buflen, + in("a2") flags, + options(nostack, preserves_flags) + ); + } } else if #[cfg(target_arch = "s390x")] { const __NR_getrandom: u32 = 349; - core::arch::asm!( - "svc 0", - in("r1") __NR_getrandom, - inlateout("r2") buf => r0, - in("r3") buflen, - in("r4") flags, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "svc 0", + in("r1") __NR_getrandom, + inlateout("r2") buf => r0, + in("r3") buflen, + in("r4") flags, + options(nostack, preserves_flags) + ); + } } else if #[cfg(target_arch = "x86")] { const __NR_getrandom: u32 = 355; // `int 0x80` is famously slow, but implementing vDSO is too complex // and `sysenter`/`syscall` have their own portability issues, // so we use the simple "legacy" way of doing syscalls. - core::arch::asm!( - "int $$0x80", - in("eax") __NR_getrandom, - in("ebx") buf, - in("ecx") buflen, - in("edx") flags, - lateout("eax") r0, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "int $$0x80", + in("eax") __NR_getrandom, + in("ebx") buf, + in("ecx") buflen, + in("edx") flags, + lateout("eax") r0, + options(nostack, preserves_flags) + ); + } } else if #[cfg(target_arch = "x86_64")] { // TODO(MSRV-1.78): Add `any(target_abi = "", target_abi = "x32")` above. const __X32_SYSCALL_BIT: u32 = 0x40000000; const OFFSET: u32 = if cfg!(target_pointer_width = "32") { __X32_SYSCALL_BIT } else { 0 }; const __NR_getrandom: u32 = OFFSET + 318; - core::arch::asm!( - "syscall", - in("rax") __NR_getrandom, - in("rdi") buf, - in("rsi") buflen, - in("rdx") flags, - lateout("rax") r0, - lateout("rcx") _, - lateout("r11") _, - options(nostack, preserves_flags) - ); + unsafe { + core::arch::asm!( + "syscall", + in("rax") __NR_getrandom, + in("rdi") buf, + in("rsi") buflen, + in("rdx") flags, + lateout("rax") r0, + lateout("rcx") _, + lateout("r11") _, + options(nostack, preserves_flags) + ); + } } else { compile_error!("`linux_raw` backend does not support this target arch"); } diff --git a/src/backends/rdrand.rs b/src/backends/rdrand.rs index 609fcc38..650c69d5 100644 --- a/src/backends/rdrand.rs +++ b/src/backends/rdrand.rs @@ -1,6 +1,6 @@ //! RDRAND backend for x86(-64) targets -use crate::{util::slice_as_uninit, Error}; -use core::mem::{size_of, MaybeUninit}; +use crate::{Error, util::slice_as_uninit}; +use core::mem::{MaybeUninit, size_of}; #[path = "../lazy.rs"] mod lazy; @@ -28,10 +28,11 @@ static RDRAND_GOOD: lazy::LazyBool = lazy::LazyBool::new(); const RETRY_LIMIT: usize = 10; #[target_feature(enable = "rdrand")] +#[cfg_attr(target_os = "uefi", allow(unused_unsafe))] // HACK: Rust lint gives false positive on uefi unsafe fn rdrand() -> Option { for _ in 0..RETRY_LIMIT { let mut val = 0; - if rdrand_step(&mut val) == 1 { + if unsafe { rdrand_step(&mut val) } == 1 { return Some(val); } } @@ -53,7 +54,7 @@ unsafe fn self_test() -> bool { let mut prev = !0; // TODO(MSRV 1.43): Move to usize::MAX let mut fails = 0; for _ in 0..8 { - match rdrand() { + match unsafe { rdrand() } { Some(val) if val == prev => fails += 1, Some(val) => prev = val, None => return false, @@ -108,14 +109,14 @@ unsafe fn rdrand_exact(dest: &mut [MaybeUninit]) -> Option<()> { // calls to memcpy to be elided by the compiler. let mut chunks = dest.chunks_exact_mut(size_of::()); for chunk in chunks.by_ref() { - let src = rdrand()?.to_ne_bytes(); + let src = unsafe { rdrand() }?.to_ne_bytes(); chunk.copy_from_slice(slice_as_uninit(&src)); } let tail = chunks.into_remainder(); let n = tail.len(); if n > 0 { - let src = rdrand()?.to_ne_bytes(); + let src = unsafe { rdrand() }?.to_ne_bytes(); tail.copy_from_slice(slice_as_uninit(&src[..n])); } Some(()) @@ -124,26 +125,26 @@ unsafe fn rdrand_exact(dest: &mut [MaybeUninit]) -> Option<()> { #[cfg(target_arch = "x86_64")] #[target_feature(enable = "rdrand")] unsafe fn rdrand_u32() -> Option { - rdrand().map(crate::util::truncate) + unsafe { rdrand() }.map(crate::util::truncate) } #[cfg(target_arch = "x86_64")] #[target_feature(enable = "rdrand")] unsafe fn rdrand_u64() -> Option { - rdrand() + unsafe { rdrand() } } #[cfg(target_arch = "x86")] #[target_feature(enable = "rdrand")] unsafe fn rdrand_u32() -> Option { - rdrand() + unsafe { rdrand() } } #[cfg(target_arch = "x86")] #[target_feature(enable = "rdrand")] unsafe fn rdrand_u64() -> Option { - let a = rdrand()?; - let b = rdrand()?; + let a = unsafe { rdrand() }?; + let b = unsafe { rdrand() }?; Some((u64::from(a) << 32) | u64::from(b)) } diff --git a/src/backends/rndr.rs b/src/backends/rndr.rs index eea741a2..0b0636ae 100644 --- a/src/backends/rndr.rs +++ b/src/backends/rndr.rs @@ -3,11 +3,11 @@ //! Arm Architecture Reference Manual for A-profile architecture: //! ARM DDI 0487K.a, ID032224, D23.2.147 RNDR, Random Number use crate::{ - util::{slice_as_uninit, truncate}, Error, + util::{slice_as_uninit, truncate}, }; use core::arch::asm; -use core::mem::{size_of, MaybeUninit}; +use core::mem::{MaybeUninit, size_of}; #[cfg(not(target_arch = "aarch64"))] compile_error!("the `rndr` backend can be enabled only for AArch64 targets!"); @@ -27,12 +27,14 @@ unsafe fn rndr() -> Option { let mut nzcv: u64; // AArch64 RNDR register is accessible by s3_3_c2_c4_0 - asm!( - "mrs {x}, RNDR", - "mrs {nzcv}, NZCV", - x = out(reg) x, - nzcv = out(reg) nzcv, - ); + unsafe { + asm!( + "mrs {x}, RNDR", + "mrs {nzcv}, NZCV", + x = out(reg) x, + nzcv = out(reg) nzcv, + ); + } // If the hardware returns a genuine random number, PSTATE.NZCV is set to 0b0000 if nzcv == 0 { @@ -47,14 +49,14 @@ unsafe fn rndr() -> Option { unsafe fn rndr_fill(dest: &mut [MaybeUninit]) -> Option<()> { let mut chunks = dest.chunks_exact_mut(size_of::()); for chunk in chunks.by_ref() { - let src = rndr()?.to_ne_bytes(); + let src = unsafe { rndr() }?.to_ne_bytes(); chunk.copy_from_slice(slice_as_uninit(&src)); } let tail = chunks.into_remainder(); let n = tail.len(); if n > 0 { - let src = rndr()?.to_ne_bytes(); + let src = unsafe { rndr() }?.to_ne_bytes(); tail.copy_from_slice(slice_as_uninit(&src[..n])); } Some(()) diff --git a/src/backends/sanitizer.rs b/src/backends/sanitizer.rs index 0e074d43..bb295b85 100644 --- a/src/backends/sanitizer.rs +++ b/src/backends/sanitizer.rs @@ -15,7 +15,7 @@ use core::mem::MaybeUninit; pub unsafe fn unpoison(buf: &mut [MaybeUninit]) { cfg_if! { if #[cfg(getrandom_msan)] { - extern "C" { + unsafe extern "C" { fn __msan_unpoison(a: *mut core::ffi::c_void, size: usize); } let a = buf.as_mut_ptr().cast(); diff --git a/src/backends/solid.rs b/src/backends/solid.rs index caa773f8..cd3335b4 100644 --- a/src/backends/solid.rs +++ b/src/backends/solid.rs @@ -4,7 +4,7 @@ use core::mem::MaybeUninit; pub use crate::util::{inner_u32, inner_u64}; -extern "C" { +unsafe extern "C" { pub fn SOLID_RNG_SampleRandomBytes(buffer: *mut u8, length: usize) -> i32; } diff --git a/src/backends/use_file.rs b/src/backends/use_file.rs index 071ce930..deefeb8b 100644 --- a/src/backends/use_file.rs +++ b/src/backends/use_file.rs @@ -147,7 +147,7 @@ mod sync { #[cfg(any(target_os = "android", target_os = "linux"))] mod sync { - use super::{open_readonly, util_libc::last_os_error, Error, FD, FD_ONGOING_INIT}; + use super::{Error, FD, FD_ONGOING_INIT, open_readonly, util_libc::last_os_error}; /// Wait for atomic `FD` to change value from `FD_ONGOING_INIT` to something else. /// diff --git a/src/backends/wasi_p1.rs b/src/backends/wasi_p1.rs index 25b5ca3b..9e8a2a6b 100644 --- a/src/backends/wasi_p1.rs +++ b/src/backends/wasi_p1.rs @@ -7,7 +7,7 @@ pub use crate::util::{inner_u32, inner_u64}; // This linking is vendored from the wasi crate: // https://docs.rs/wasi/0.11.0+wasi-snapshot-preview1/src/wasi/lib_generated.rs.html#2344-2350 #[link(wasm_import_module = "wasi_snapshot_preview1")] -extern "C" { +unsafe extern "C" { fn random_get(arg0: i32, arg1: i32) -> i32; } diff --git a/src/backends/wasm_js.rs b/src/backends/wasm_js.rs index 1320d9fc..ce49bec3 100644 --- a/src/backends/wasm_js.rs +++ b/src/backends/wasm_js.rs @@ -56,7 +56,7 @@ pub fn fill_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { } #[wasm_bindgen] -extern "C" { +unsafe extern "C" { // Crypto.getRandomValues() #[cfg(not(target_feature = "atomics"))] #[wasm_bindgen(js_namespace = ["globalThis", "crypto"], js_name = getRandomValues, catch)] diff --git a/src/backends/windows.rs b/src/backends/windows.rs index 18a38bdd..8efee584 100644 --- a/src/backends/windows.rs +++ b/src/backends/windows.rs @@ -41,7 +41,7 @@ pub use crate::util::{inner_u32, inner_u64}; not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib") )] -extern "system" { +unsafe extern "system" { fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL; } #[allow(clippy::upper_case_acronyms, clippy::incompatible_msrv)] diff --git a/src/backends/windows_legacy.rs b/src/backends/windows_legacy.rs index 4b3f0927..0e917015 100644 --- a/src/backends/windows_legacy.rs +++ b/src/backends/windows_legacy.rs @@ -20,7 +20,7 @@ compile_error!("`windows_legacy` backend can be enabled only for Windows targets // Binding to the Windows.Win32.Security.Authentication.Identity.RtlGenRandom // API. Don't use windows-targets as it doesn't support Windows 7 targets. #[link(name = "advapi32")] -extern "system" { +unsafe extern "system" { #[link_name = "SystemFunction036"] fn RtlGenRandom(randombuffer: *mut c_void, randombufferlength: u32) -> BOOLEAN; } diff --git a/src/error_std_impls.rs b/src/error_std_impls.rs index 2c326012..cdfd4077 100644 --- a/src/error_std_impls.rs +++ b/src/error_std_impls.rs @@ -7,7 +7,7 @@ impl From for io::Error { fn from(err: Error) -> Self { match err.raw_os_error() { Some(errno) => io::Error::from_raw_os_error(errno), - None => io::Error::new(io::ErrorKind::Other, err), + None => io::Error::other(err), } } } diff --git a/src/lib.rs b/src/lib.rs index c98ea19d..befea654 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,7 +100,7 @@ pub fn fill_uninit(dest: &mut [MaybeUninit]) -> Result<&mut [u8], Error> { } #[cfg(getrandom_msan)] - extern "C" { + unsafe extern "C" { fn __msan_unpoison(a: *mut core::ffi::c_void, size: usize); } diff --git a/src/util_libc.rs b/src/util_libc.rs index 24c53c0c..69432891 100644 --- a/src/util_libc.rs +++ b/src/util_libc.rs @@ -15,7 +15,7 @@ cfg_if! { } else if #[cfg(target_os = "nto")] { use libc::__get_errno_ptr as errno_location; } else if #[cfg(any(all(target_os = "horizon", target_arch = "arm"), target_os = "vita"))] { - extern "C" { + unsafe extern "C" { // Not provided by libc: https://github.com/rust-lang/libc/issues/1995 fn __errno() -> *mut libc::c_int; } @@ -29,7 +29,7 @@ cfg_if! { if #[cfg(target_os = "vxworks")] { use libc::errnoGet as get_errno; } else { - unsafe fn get_errno() -> libc::c_int { *errno_location() } + unsafe fn get_errno() -> libc::c_int { unsafe { *errno_location() }} } } diff --git a/tests/mod.rs b/tests/mod.rs index 9f1e6338..baa813a0 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -260,7 +260,8 @@ mod custom { // This implementation uses current timestamp as a PRNG seed. // // WARNING: this custom implementation is for testing purposes ONLY! - #[no_mangle] + + #[unsafe(no_mangle)] unsafe extern "Rust" fn __getrandom_v03_custom(dest: *mut u8, len: usize) -> Result<(), Error> { use std::time::{SystemTime, UNIX_EPOCH}; @@ -275,13 +276,13 @@ mod custom { let mut rng = Xoshiro128PlusPlus::new(ts.as_nanos() as u64); for i in 0..len / 4 { let val = rng.next_u32(); - core::ptr::write_unaligned(dest_u32.add(i), val); + unsafe { core::ptr::write_unaligned(dest_u32.add(i), val) }; } if len % 4 != 0 { let start = 4 * (len / 4); for i in start..len { let val = rng.next_u32(); - core::ptr::write_unaligned(dest.add(i), val as u8); + unsafe { core::ptr::write_unaligned(dest.add(i), val as u8) }; } } Ok(())