diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d982ce6..10113f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: build: [ubuntu, i686-linux, aarch64-linux, riscv64-linux] - rust: [1.78, nightly-2025-03-05] + rust: [1.84, nightly-2025-03-05] include: - build: ubuntu os: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index a19ee90..f859b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" keywords = ["linux"] categories = ["no-std"] include = ["src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] -rust-version = "1.78" +rust-version = "1.84" [dependencies] linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "no_std", "elf"] } diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 348fe1f..c1367d4 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -1,9 +1,5 @@ //! Architecture-specific assembly code. -#[cfg(feature = "take-charge")] -#[cfg(feature = "thread")] -#[cfg(not(feature = "nightly"))] -use crate::ptr::{without_provenance_mut, Polyfill as _}; #[cfg(any( feature = "take-charge", all(not(feature = "unwinding"), feature = "panic-handler-trap") @@ -11,7 +7,6 @@ use crate::ptr::{without_provenance_mut, Polyfill as _}; use core::arch::asm; #[cfg(feature = "take-charge")] #[cfg(feature = "thread")] -#[cfg(feature = "nightly")] use core::ptr::without_provenance_mut; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] diff --git a/src/getauxval.rs b/src/getauxval.rs index a4bcb1c..f5784dd 100644 --- a/src/getauxval.rs +++ b/src/getauxval.rs @@ -2,10 +2,7 @@ //! //! This may be needed to satisfy `compiler_builtins` or other low-level code. -#[cfg(not(feature = "nightly"))] -use crate::ptr::without_provenance_mut; use core::ffi::{c_ulong, c_void}; -#[cfg(feature = "nightly")] use core::ptr::without_provenance_mut; // `getauxval` usually returns `unsigned long`, but we make it a pointer type diff --git a/src/lib.rs b/src/lib.rs index 9e112ac..463e220 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,18 +11,10 @@ all(debug_assertions, feature = "nightly"), feature(link_llvm_intrinsics) )] -// Allow our polyfills to polyfill nightly features. -#![cfg_attr(not(feature = "nightly"), allow(unstable_name_collisions))] -// Allow `Polyfill` imports to be unused for now. -#![cfg_attr(not(feature = "nightly"), allow(unused_imports))] #[cfg(all(feature = "alloc", not(feature = "rustc-dep-of-std")))] extern crate alloc; -// Strict-provenance API polyfill. -#[cfg(not(feature = "nightly"))] -pub(crate) mod ptr; - // Wrapper/polyfill for `#[naked]`. #[macro_use] pub(crate) mod naked; diff --git a/src/mem/fast.rs b/src/mem/fast.rs index dd7b81e..74e2590 100644 --- a/src/mem/fast.rs +++ b/src/mem/fast.rs @@ -6,9 +6,6 @@ //! //! [compiler_builtins library]: https://github.com/rust-lang/compiler-builtins -#[cfg(not(feature = "nightly"))] -use crate::ptr::Polyfill as _; - // memcpy/memmove/memset have optimized implementations on some architectures #[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")] #[cfg_attr(not(target_arch = "x86_64"), path = "impls.rs")] diff --git a/src/mem/impls.rs b/src/mem/impls.rs index da192e0..505ca96 100644 --- a/src/mem/impls.rs +++ b/src/mem/impls.rs @@ -4,9 +4,6 @@ //! //! [compiler_builtins library]: https://github.com/rust-lang/compiler-builtins -#[cfg(not(feature = "nightly"))] -use crate::ptr::Polyfill as _; - const WORD_SIZE: usize = core::mem::size_of::(); const WORD_MASK: usize = WORD_SIZE - 1; diff --git a/src/mem/small.rs b/src/mem/small.rs index c098742..77dc433 100644 --- a/src/mem/small.rs +++ b/src/mem/small.rs @@ -3,8 +3,6 @@ //! This code uses `core::arch::asm!("")` to try to discourage optimizers from //! vectorizing or pattern-matching these loops. -#[cfg(not(feature = "nightly"))] -use crate::ptr::Polyfill as _; use core::ffi::{c_char, c_int, c_void}; #[no_mangle] diff --git a/src/mem/x86_64.rs b/src/mem/x86_64.rs index 4eaa34e..7a28430 100644 --- a/src/mem/x86_64.rs +++ b/src/mem/x86_64.rs @@ -22,8 +22,6 @@ // feature is present at compile-time. We don't bother detecting other features. // Note that ERMSB does not enhance the backwards (DF=1) "rep movsb". -#[cfg(not(feature = "nightly"))] -use crate::ptr::Polyfill as _; use core::arch::asm; use core::mem; diff --git a/src/program/linux_raw.rs b/src/program/linux_raw.rs index c788967..43e3b33 100644 --- a/src/program/linux_raw.rs +++ b/src/program/linux_raw.rs @@ -53,9 +53,6 @@ pub(super) unsafe extern "C" fn entry(mem: *mut usize) -> ! { #[cfg(debug_assertions)] #[cfg(feature = "origin-start")] { - #[cfg(not(feature = "nightly"))] - use crate::ptr::Polyfill; - // Check that `mem` is where we expect it to be. debug_assert_ne!(mem, core::ptr::null_mut()); debug_assert_eq!(mem.addr() & 0xf, 0); diff --git a/src/ptr.rs b/src/ptr.rs deleted file mode 100644 index a24a88e..0000000 --- a/src/ptr.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Polyfill for nightly Rust APIs. - -#![allow(dead_code)] - -#[inline] -pub(crate) const fn without_provenance_mut(addr: usize) -> *mut T { - // SAFETY: Every valid `usize` is also a valid pointer. - unsafe { core::mem::transmute(addr) } -} - -#[inline] -pub(crate) fn with_exposed_provenance_mut(addr: usize) -> *mut T { - addr as *mut T -} - -/// Replacement for `.addr()` for the relocation code which can't call trait -/// methods because they might not be relocated yet. -#[cfg(feature = "experimental-relocate")] -#[inline] -pub(crate) fn addr(addr: *const T) -> usize { - // SAFETY: Every pointer is also a valid `usize`. - unsafe { core::mem::transmute(addr) } -} - -pub(crate) trait Polyfill { - fn addr(self) -> usize; - fn expose_provenance(self) -> usize; - fn with_addr(self, addr: usize) -> *mut T; - fn map_addr(self, f: impl FnOnce(usize) -> usize) -> *mut T; - fn cast_mut(self) -> *mut T; -} - -impl Polyfill for *mut T { - #[inline] - fn addr(self) -> usize { - // SAFETY: Every pointer is also a valid `usize`. - unsafe { core::mem::transmute(self) } - } - - #[inline] - fn expose_provenance(self) -> usize { - self as usize - } - - #[inline] - fn with_addr(self, addr: usize) -> *mut T { - self.wrapping_byte_offset((addr as isize).wrapping_sub(self.addr() as isize)) - } - - #[inline] - fn map_addr(self, f: impl FnOnce(usize) -> usize) -> *mut T { - self.with_addr(f(self.addr())) - } - - #[inline] - fn cast_mut(self) -> *mut T { - self - } -} - -impl Polyfill for *const T { - #[inline] - fn addr(self) -> usize { - // SAFETY: Every pointer is also a valid `usize`. - unsafe { core::mem::transmute(self) } - } - - #[inline] - fn expose_provenance(self) -> usize { - self as usize - } - - #[inline] - fn with_addr(self, addr: usize) -> *mut T { - self.wrapping_byte_offset((addr as isize).wrapping_sub(self.addr() as isize)) as *mut T - } - - #[inline] - fn map_addr(self, f: impl FnOnce(usize) -> usize) -> *mut T { - self.with_addr(f(self.addr())).cast_mut() - } - - #[inline] - fn cast_mut(self) -> *mut T { - self as *mut T - } -} diff --git a/src/relocate.rs b/src/relocate.rs index 13e9c9e..288370c 100644 --- a/src/relocate.rs +++ b/src/relocate.rs @@ -18,22 +18,12 @@ use crate::arch::{ dynamic_table_addr, ehdr_addr, relocation_load, relocation_mprotect_readonly, relocation_store, trap, }; -#[cfg(not(feature = "nightly"))] -use crate::ptr::addr; use core::ffi::c_void; use core::mem; use core::ptr::{null, null_mut}; use linux_raw_sys::elf::*; use linux_raw_sys::general::{AT_BASE, AT_ENTRY, AT_NULL, AT_PAGESZ}; -/// Wrapper around `.addr()` for pointers, because we can't use the polyfill -/// in the relocation code because that might emit calls to things that aren't -/// relocated yet. -#[cfg(feature = "nightly")] -fn addr(addr: *const T) -> usize { - addr.addr() -} - // The Linux UAPI headers don't define the .relr types and consts yet. #[allow(non_camel_case_types)] type Elf_Relr = usize; @@ -105,7 +95,7 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { match a_type as _ { AT_BASE => auxv_base = a_val, - AT_PAGESZ => auxv_page_size = addr(a_val), + AT_PAGESZ => auxv_page_size = a_val.addr(), AT_ENTRY => auxv_entry = a_val, AT_NULL => break, _ => (), @@ -129,7 +119,7 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { // program headers and `AT_ENTRY` doesn't point to our own entry point. // `AT_BASE` contains our own relocation offset. - if load_static_start() == addr(auxv_entry) { + if load_static_start() == auxv_entry.addr() { // This is case 1) or case 3). If `AT_BASE` doesn't exist, then we are // already loaded at our static address despite the lack of any dynamic // linker. As such it would be case 1). If `AT_BASE` does exist, we have @@ -154,7 +144,7 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { // `AT_BASE` contains the relocation offset of the dynamic linker. auxv_base }; - let offset = addr(base); + let offset = base.addr(); // This is case 2) or 4). We need to do all `R_RELATIVE` relocations. // There should be no other kind of relocation because we are either a @@ -326,7 +316,7 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { // entry point when AT_BASE is not zero and thus a dynamic linker is in // use. In this case the assertion would fail. if auxv_base == null_mut() { - debug_assert_eq!(load_static_start(), addr(auxv_entry)); + debug_assert_eq!(load_static_start(), auxv_entry.addr()); } // Finally, look through the static segment headers (phdrs) to find the @@ -397,5 +387,5 @@ fn load_static_start() -> usize { // Use `relocation_load` to do the load because the optimizer won't have // any idea what we're up to. let static_start_addr: *const *const c_void = &STATIC_START.0; - unsafe { relocation_load(addr(static_start_addr)) } + unsafe { relocation_load(static_start_addr.addr()) } } diff --git a/src/thread/libc.rs b/src/thread/libc.rs index 03de7df..d73c9a7 100644 --- a/src/thread/libc.rs +++ b/src/thread/libc.rs @@ -7,15 +7,11 @@ //! more control when creating efficient higher-level abstractions like //! pthreads or `std::thread::Thread`. -#[cfg(not(feature = "nightly"))] -use crate::ptr::{with_exposed_provenance_mut, without_provenance_mut, Polyfill as _}; #[cfg(feature = "thread-at-exit")] use alloc::boxed::Box; use core::ffi::{c_int, c_void}; use core::mem::{size_of, transmute, zeroed}; -use core::ptr::{null_mut, NonNull}; -#[cfg(feature = "nightly")] -use core::ptr::{with_exposed_provenance_mut, without_provenance_mut}; +use core::ptr::{null_mut, with_exposed_provenance_mut, without_provenance_mut, NonNull}; use core::slice; use rustix::io; diff --git a/src/thread/linux_raw.rs b/src/thread/linux_raw.rs index b556c93..24579ae 100644 --- a/src/thread/linux_raw.rs +++ b/src/thread/linux_raw.rs @@ -10,8 +10,6 @@ use crate::arch::{ clone, munmap_and_exit_thread, set_thread_pointer, thread_pointer, STACK_ALIGNMENT, TLS_OFFSET, }; -#[cfg(not(feature = "nightly"))] -use crate::ptr::Polyfill as _; #[cfg(feature = "thread-at-exit")] use alloc::boxed::Box; #[cfg(feature = "unstable-errno")]