diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5c9fc4..d982ce6 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-01-02] + rust: [1.78, nightly-2025-03-05] include: - build: ubuntu os: ubuntu-latest @@ -51,7 +51,7 @@ jobs: qemu: qemu-riscv64 -L /usr/riscv64-linux-gnu qemu_target: riscv64-linux-user host_target: riscv64gc-unknown-linux-gnu - - rust: nightly-2025-01-02 + - rust: nightly-2025-03-05 features: nightly steps: - uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 45d11cb..a19ee90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,11 +15,11 @@ include = ["src", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.78" [dependencies] -linux-raw-sys = { version = "0.4.9", default-features = false, features = ["general", "no_std", "elf"] } -rustix = { version = "0.38.35", default-features = false } +linux-raw-sys = { version = "0.9.2", default-features = false, features = ["general", "no_std", "elf"] } +rustix = { version = "1.0.0", default-features = false } bitflags = { version = "2.4.0", default-features = false } log = { version = "0.4.14", default-features = false, optional = true } -rustix-futex-sync = { version = "0.2.1", optional = true } +rustix-futex-sync = { version = "0.3.0", optional = true } smallvec = { version = "1.11.1", optional = true, features = ["const_new"] } # Optional logging backends for use with "take-charge". You can use any @@ -31,7 +31,7 @@ smallvec = { version = "1.11.1", optional = true, features = ["const_new"] } env_logger = { version = "0.11.0", default-features = false, optional = true } # Enable `atomic-dbg`'s simple logger. This doesn't require `std`. -atomic-dbg = { version = "0.1", default-features = false, optional = true } +atomic-dbg = { version = "0.1.11", default-features = false, optional = true } # Enable this when disabling origin's implementations. libc = { version = "0.2.149", default-features = false, optional = true } @@ -52,7 +52,7 @@ optional = true # On aarch64, compiler_builtins depends on `getauxval`, so we need rustix with # the "param" feature. [target.'cfg(target_arch = "aarch64")'.dependencies.rustix] -version = "0.38.35" +version = "1.0.0" default-features = false features = ["param"] diff --git a/README.md b/README.md index e3151e4..0402667 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,6 @@ Origin can also be used on its own, in several different configurations: - The [basic example] shows a simple example of using Origin as a simple library. In this configuration, libc is doing most of the work. - - The [no-std example] uses `#![no_std]` and starts the program using Rust's - `#[start]` feature, and then hands control to Origin. libc is still - doing most of the work here. - - The [external-start example] uses `#![no_std]` and `#![no_main]`, and starts the program by taking over control from libc as soon as possible, and then hands control to Origin. Origin handles program and thread startup and diff --git a/example-crates/external-start/Cargo.toml b/example-crates/external-start/Cargo.toml index 91301bb..098165e 100644 --- a/example-crates/external-start/Cargo.toml +++ b/example-crates/external-start/Cargo.toml @@ -13,8 +13,8 @@ origin = { path = "../..", default-features = false, features = ["external-start libc = { version = "0.2", default-features = false } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } # This is just an example crate, and not part of the origin workspace. [workspace] diff --git a/example-crates/no-std/Cargo.toml b/example-crates/no-std/Cargo.toml deleted file mode 100644 index ba40e66..0000000 --- a/example-crates/no-std/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "no-std" -version = "0.0.0" -edition = "2021" -publish = false - -[dependencies] -# Origin can be depended on just like any other crate. For no_std, disable -# the default features. And enable "libc" to enable the libc implementations. -origin = { path = "../..", default-features = false, features = ["libc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-trap", "nightly"] } - -# Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } - -# This is just an example crate, and not part of the origin workspace. -[workspace] diff --git a/example-crates/no-std/README.md b/example-crates/no-std/README.md deleted file mode 100644 index e0fe57d..0000000 --- a/example-crates/no-std/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This crate demonstrates the use of origin as a plain library API using -`#![no_std]`. diff --git a/example-crates/no-std/src/main.rs b/example-crates/no-std/src/main.rs deleted file mode 100644 index 41b505a..0000000 --- a/example-crates/no-std/src/main.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! A simple example using `no_std`. - -#![no_std] -#![feature(start)] - -extern crate alloc; - -use alloc::boxed::Box; -use atomic_dbg::eprintln; -use origin::{program, thread}; - -#[global_allocator] -static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::GlobalDlmalloc; - -#[start] -fn start(_argc: isize, _argv: *const *const u8) -> isize { - eprintln!("Hello from main thread"); - - program::at_exit(Box::new(|| { - eprintln!("Hello from a `program::at_exit` handler") - })); - thread::at_exit(Box::new(|| { - eprintln!("Hello from a main-thread `thread::at_exit` handler") - })); - - let thread = unsafe { - thread::create( - |_args| { - eprintln!("Hello from child thread"); - thread::at_exit(Box::new(|| { - eprintln!("Hello from child thread's `thread::at_exit` handler") - })); - None - }, - &[], - thread::default_stack_size(), - thread::default_guard_size(), - ) - .unwrap() - }; - - unsafe { - thread::join(thread); - } - - eprintln!("Goodbye from main"); - program::exit(0); -} diff --git a/example-crates/origin-start-dynamic-linker/Cargo.toml b/example-crates/origin-start-dynamic-linker/Cargo.toml index 44e867a..be034aa 100644 --- a/example-crates/origin-start-dynamic-linker/Cargo.toml +++ b/example-crates/origin-start-dynamic-linker/Cargo.toml @@ -13,8 +13,8 @@ crate-type = ["cdylib"] origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "experimental-relocate", "eh-personality-continue", "panic-handler-trap", "nightly"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } # This is just an example crate, and not part of the origin workspace. [workspace] diff --git a/example-crates/origin-start-lto/Cargo.toml b/example-crates/origin-start-lto/Cargo.toml index 3770259..e384b7e 100644 --- a/example-crates/origin-start-lto/Cargo.toml +++ b/example-crates/origin-start-lto/Cargo.toml @@ -10,8 +10,8 @@ publish = false origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-trap", "nightly"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } # This is just an example crate, and not part of the origin workspace. [workspace] diff --git a/example-crates/origin-start-no-alloc/Cargo.toml b/example-crates/origin-start-no-alloc/Cargo.toml index b32ba06..ced2aa5 100644 --- a/example-crates/origin-start-no-alloc/Cargo.toml +++ b/example-crates/origin-start-no-alloc/Cargo.toml @@ -10,7 +10,7 @@ publish = false origin = { path = "../..", default-features = false, features = ["origin-start", "eh-personality-continue", "panic-handler-trap", "nightly"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } +atomic-dbg = { version = "0.1.11", default-features = false } # This is just an example crate, and not part of the origin workspace. [workspace] diff --git a/example-crates/origin-start-panic-abort/Cargo.toml b/example-crates/origin-start-panic-abort/Cargo.toml index b1d258e..e349344 100644 --- a/example-crates/origin-start-panic-abort/Cargo.toml +++ b/example-crates/origin-start-panic-abort/Cargo.toml @@ -10,8 +10,8 @@ publish = false origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-trap", "nightly"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } [profile.dev] panic = "abort" diff --git a/example-crates/origin-start-stable/Cargo.toml b/example-crates/origin-start-stable/Cargo.toml index 2aa63f2..959c53b 100644 --- a/example-crates/origin-start-stable/Cargo.toml +++ b/example-crates/origin-start-stable/Cargo.toml @@ -10,8 +10,8 @@ publish = false origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-trap"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } [profile.dev] panic = "abort" diff --git a/example-crates/origin-start/Cargo.toml b/example-crates/origin-start/Cargo.toml index ad29645..f2548ce 100644 --- a/example-crates/origin-start/Cargo.toml +++ b/example-crates/origin-start/Cargo.toml @@ -10,8 +10,8 @@ publish = false origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-trap", "nightly"] } # Crates to help writing no_std code. -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } # This is just an example crate, and not part of the origin workspace. [workspace] diff --git a/example-crates/tiny-hello/Cargo.toml b/example-crates/tiny-hello/Cargo.toml index 0d77311..4bfff34 100644 --- a/example-crates/tiny-hello/Cargo.toml +++ b/example-crates/tiny-hello/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] # Origin can be depended on just like any other crate. For no_std, disable # the default features, and add the desired features. -rustix = { version = "0.38.35", default-features = false, features = ["stdio"] } +rustix = { version = "1.0.0", default-features = false, features = ["stdio"] } origin = { path = "../..", default-features = false, features = ["origin-start", "eh-personality-continue", "panic-handler-trap", "nightly", "optimize_for_size"] } # This is just an example crate, and not part of the origin workspace. diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index b62bd59..c8f2b8b 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -7,7 +7,7 @@ use core::arch::asm; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] -use linux_raw_sys::elf::{Elf_Dyn, Elf_Ehdr}; +use linux_raw_sys::elf::Elf_Ehdr; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] #[cfg(test)] @@ -60,9 +60,12 @@ pub(super) fn trap() -> ! { } /// Compute the dynamic address of `_DYNAMIC`. -#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] -#[cfg(relocation_model = "pic")] -pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { +#[cfg(any( + all(feature = "thread", feature = "take-charge"), + all(feature = "experimental-relocate", feature = "origin-start") +))] +#[allow(dead_code)] +pub(super) fn dynamic_table_addr() -> *const linux_raw_sys::elf::Elf_Dyn { let addr; unsafe { asm!( diff --git a/src/arch/arm.rs b/src/arch/arm.rs index 5766717..381b4cb 100644 --- a/src/arch/arm.rs +++ b/src/arch/arm.rs @@ -7,7 +7,7 @@ use core::arch::asm; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] -use linux_raw_sys::elf::{Elf_Dyn, Elf_Ehdr}; +use linux_raw_sys::elf::Elf_Ehdr; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] use linux_raw_sys::general::{__NR_mprotect, PROT_READ}; @@ -60,9 +60,12 @@ pub(super) fn trap() -> ! { } /// Compute the dynamic address of `_DYNAMIC`. -#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] -#[cfg(relocation_model = "pic")] -pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { +#[cfg(any( + all(feature = "thread", feature = "take-charge"), + all(feature = "experimental-relocate", feature = "origin-start") +))] +#[allow(dead_code)] +pub(super) fn dynamic_table_addr() -> *const linux_raw_sys::elf::Elf_Dyn { let addr; unsafe { asm!( diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index 7110461..9861042 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -7,7 +7,7 @@ use core::arch::asm; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] -use linux_raw_sys::elf::{Elf_Dyn, Elf_Ehdr}; +use linux_raw_sys::elf::Elf_Ehdr; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] use linux_raw_sys::general::{__NR_mprotect, PROT_READ}; @@ -57,9 +57,12 @@ pub(super) fn trap() -> ! { } /// Compute the dynamic address of `_DYNAMIC`. -#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] -#[cfg(relocation_model = "pic")] -pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { +#[cfg(any( + all(feature = "thread", feature = "take-charge"), + all(feature = "experimental-relocate", feature = "origin-start") +))] +#[allow(dead_code)] +pub(super) fn dynamic_table_addr() -> *const linux_raw_sys::elf::Elf_Dyn { let addr; unsafe { asm!( diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 751a0cc..348fe1f 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -15,7 +15,7 @@ use core::arch::asm; use core::ptr::without_provenance_mut; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] -use linux_raw_sys::elf::{Elf_Dyn, Elf_Ehdr}; +use linux_raw_sys::elf::Elf_Ehdr; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] use linux_raw_sys::general::{__NR_mprotect, PROT_READ}; @@ -72,9 +72,12 @@ pub(super) fn trap() -> ! { } /// Compute the dynamic address of `_DYNAMIC`. -#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] -#[cfg(relocation_model = "pic")] -pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { +#[cfg(any( + all(feature = "thread", feature = "take-charge"), + all(feature = "experimental-relocate", feature = "origin-start") +))] +#[allow(dead_code)] +pub(super) fn dynamic_table_addr() -> *const linux_raw_sys::elf::Elf_Dyn { let addr; unsafe { asm!( @@ -83,17 +86,8 @@ pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { "call 2f", ".cfi_adjust_cfa_offset 4", "2:", - "pop {0}", + "pop {0}", // We depend on this being exactly one byte long. ".cfi_adjust_cfa_offset -4", - "3:", - // Use "2" and "3" instead of "0" and "1" because "0b" and "1b" are - // parsed as binary literals rather than as label references. And, - // hard-code the value `1` here because the assembler doesn't support - // the symbol difference expression in an instruction operand - // context. Then, check that the hard-coded value is what we expect. - ".ifne (3b-2b)-1", - ".error \"The pop opcode is expected to be 1 byte long.\"", - ".endif", "add {0}, offset _GLOBAL_OFFSET_TABLE_+1", "lea {0}, [{0} + _DYNAMIC@GOTOFF]", out(reg) addr diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 04e9861..9845450 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -7,7 +7,7 @@ use core::arch::asm; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] -use linux_raw_sys::elf::{Elf_Dyn, Elf_Ehdr}; +use linux_raw_sys::elf::Elf_Ehdr; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] #[cfg(test)] @@ -60,9 +60,12 @@ pub(super) fn trap() -> ! { } /// Compute the dynamic address of `_DYNAMIC`. -#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] -#[cfg(relocation_model = "pic")] -pub(super) fn dynamic_table_addr() -> *const Elf_Dyn { +#[cfg(any( + all(feature = "thread", feature = "take-charge"), + all(feature = "experimental-relocate", feature = "origin-start") +))] +#[allow(dead_code)] +pub(super) fn dynamic_table_addr() -> *const linux_raw_sys::elf::Elf_Dyn { let addr; unsafe { asm!( diff --git a/src/relocate.rs b/src/relocate.rs index 0a64ce5..13e9c9e 100644 --- a/src/relocate.rs +++ b/src/relocate.rs @@ -138,10 +138,12 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { return; } + let the_ehdr = &*ehdr_addr(); + let base = if auxv_base == null_mut() { // Obtain the static address of `_start`, which is recorded in the // entry field of the ELF header. - let static_start = (*ehdr_addr()).e_entry; + let static_start = the_ehdr.e_entry; // This is case 2) as without dynamic linker `AT_BASE` doesn't exist // and we have already excluded case 1) above. @@ -330,18 +332,14 @@ pub(super) unsafe fn relocate(envp: *mut *mut u8) { // Finally, look through the static segment headers (phdrs) to find the // the relro description if present. Also do a debug assertion that // the dynv argument matches the PT_DYNAMIC segment. - extern "C" { - #[link_name = "__ehdr_start"] - static EHDR: Elf_Ehdr; - } // The location and size of the `relro` region. let mut relro = 0; let mut relro_size = 0; - let phentsize = EHDR.e_phentsize as usize; - let mut current_phdr = base.byte_add(EHDR.e_phoff).cast::(); - let phdrs_end = current_phdr.byte_add(EHDR.e_phnum as usize * phentsize); + let phentsize = the_ehdr.e_phentsize as usize; + let mut current_phdr = base.byte_add(the_ehdr.e_phoff).cast::(); + let phdrs_end = current_phdr.byte_add(the_ehdr.e_phnum as usize * phentsize); while current_phdr != phdrs_end { let phdr = &*current_phdr; current_phdr = current_phdr.byte_add(phentsize); diff --git a/src/signal/libc.rs b/src/signal/libc.rs index 843d014..27d8405 100644 --- a/src/signal/libc.rs +++ b/src/signal/libc.rs @@ -14,11 +14,38 @@ pub use rustix::runtime::Signal; pub use libc::sighandler_t as Sighandler; /// A signal information record for use with [`Sigaction`]. -// TODO: Convert the fields of this to friendlier APIs. -pub use linux_raw_sys::general::siginfo_t as Siginfo; +pub use libc::siginfo_t as Siginfo; -/// A flags type for use with [`Sigaction`]. -pub use linux_raw_sys::ctypes::c_int as Sigflags; +bitflags::bitflags! { + /// A flags type for use with [`Sigaction`]. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)] + pub struct SigactionFlags: libc::c_int { + /// `SA_NOCLDSTOP` + const NOCLDSTOP = libc::SA_NOCLDSTOP as _; + + /// `SA_NOCLDWAIT` (since Linux 2.6) + const NOCLDWAIT = libc::SA_NOCLDWAIT as _; + + /// `SA_NODEFER` + const NODEFER = libc::SA_NODEFER as _; + + /// `SA_ONSTACK` + const ONSTACK = libc::SA_ONSTACK as _; + + /// `SA_RESETHAND` + const RESETHAND = libc::SA_RESETHAND as _; + + /// `SA_RESTART` + const RESTART = libc::SA_RESTART as _; + + /// `SA_SIGINFO` (since Linux 2.2) + const SIGINFO = libc::SA_SIGINFO as _; + + /// + const _ = !0; + } +} /// Register a signal handler. /// @@ -32,7 +59,7 @@ pub unsafe fn sigaction(sig: Signal, action: Option) -> io::Result::uninit(); - if libc::sigaction(sig as libc::c_int, action, old.as_mut_ptr()) == 0 { + if libc::sigaction(sig.as_raw(), action, old.as_mut_ptr()) == 0 { Ok(old.assume_init()) } else { Err(rustix::io::Errno::from_raw_os_error(errno::errno().0)) @@ -52,17 +79,7 @@ pub const fn sig_ign() -> Sighandler { /// for handling a signal. /// /// If you're looking for `SigIgn`; use [`sig_ign`]. -#[doc(alias = "SIG_DFL")] -pub use libc::SIG_DFL as SigDfl; - -// TODO: Convert these to a `bitflags`. - -/// `SA_RESTART` -pub const SA_RESTART: Sigflags = libc::SA_RESTART; -/// `SA_ONSTACK` -pub const SA_ONSTACK: Sigflags = libc::SA_ONSTACK; -/// `SA_SIGINFO` -pub const SA_SIGINFO: Sigflags = libc::SA_SIGINFO; +pub use libc::SIG_DFL; /// `SIGSTKSZ` pub const SIGSTKSZ: usize = libc::SIGSTKSZ; diff --git a/src/signal/linux_raw.rs b/src/signal/linux_raw.rs index 4436dcd..23b5258 100644 --- a/src/signal/linux_raw.rs +++ b/src/signal/linux_raw.rs @@ -1,27 +1,15 @@ //! Signal handlers. -use rustix::io; #[cfg(not(target_arch = "riscv64"))] -use {crate::arch, linux_raw_sys::ctypes::c_ulong, linux_raw_sys::general::SA_RESTORER}; - -/// A signal action record for use with [`sigaction`]. -pub use rustix::runtime::Sigaction; - -/// A signal identifier for use with [`sigaction`]. -pub use rustix::runtime::Signal; - -/// A signal set for use with [`Sigaction`]. -pub use rustix::runtime::Sigset; - -/// A signal handler function for use with [`Sigaction`]. -pub use linux_raw_sys::general::__kernel_sighandler_t as Sighandler; +use crate::arch; +use rustix::io; -/// A signal information record for use with [`Sigaction`]. -// TODO: Convert the fields of this to friendlier APIs. -pub use linux_raw_sys::general::siginfo_t as Siginfo; +pub use rustix::runtime::{ + KernelSigaction as Sigaction, KernelSigactionFlags as SigactionFlags, Siginfo, Signal, +}; -/// A flags type for use with [`Sigaction`]. -pub use linux_raw_sys::ctypes::c_ulong as Sigflags; +/// A handler function type for use with [`Sigaction`]. +pub type Sighandler = rustix::runtime::KernelSighandler; /// Register a signal handler. /// @@ -34,16 +22,16 @@ pub unsafe fn sigaction(sig: Signal, action: Option) -> io::Result) -> io::Result Sighandler { - linux_raw_sys::signal_macros::sig_ign() + rustix::runtime::kernel_sig_ign() } /// A special “default” signal handler representing the default behavior /// for handling a signal. /// /// If you're looking for `SigIgn`; use [`sig_ign`]. -#[doc(alias = "SIG_DFL")] -pub use linux_raw_sys::signal_macros::SIG_DFL as SigDfl; - -// TODO: Convert these to a `bitflags`. - -/// `SA_RESTART` -pub const SA_RESTART: Sigflags = linux_raw_sys::general::SA_RESTART as _; -/// `SA_ONSTACK` -pub const SA_ONSTACK: Sigflags = linux_raw_sys::general::SA_ONSTACK as _; -/// `SA_SIGINFO` -pub const SA_SIGINFO: Sigflags = linux_raw_sys::general::SA_SIGINFO as _; +pub use rustix::runtime::KERNEL_SIG_DFL as SIG_DFL; /// `SIGSTKSZ` pub const SIGSTKSZ: usize = linux_raw_sys::general::SIGSTKSZ as usize; diff --git a/src/thread/linux_raw.rs b/src/thread/linux_raw.rs index 40bf8be..b556c93 100644 --- a/src/thread/linux_raw.rs +++ b/src/thread/linux_raw.rs @@ -30,7 +30,7 @@ use rustix::param::{linux_execfn, page_size}; use rustix::process::{getrlimit, Resource}; use rustix::runtime::{exe_phdrs, set_tid_address}; #[cfg(feature = "signal")] -use rustix::runtime::{sigprocmask, How, Sigset}; +use rustix::runtime::{kernel_sigprocmask, How, KernelSigSet}; use rustix::thread::gettid; pub use rustix::thread::Pid as ThreadId; @@ -253,7 +253,7 @@ pub(super) fn initialize_startup_info() { // // SAFETY: We're just taking the address of `_DYNAMIC` for arithmetic // purposes, not dereferencing it. - let dynamic_addr: *const c_void = unsafe { &_DYNAMIC }; + let dynamic_addr: *const u8 = crate::arch::dynamic_table_addr().cast(); // SAFETY: We assume that the phdr array pointer and length the kernel // provided to the process describe a valid phdr array, and that there are @@ -734,15 +734,8 @@ unsafe fn exit(return_value: Option>) -> ! { // no signals for the process are delivered to this thread. #[cfg(feature = "signal")] { - #[cfg(any(target_arch = "arm", target_arch = "x86"))] - let all = Sigset { sig: [!0, !0] }; - #[cfg(any( - target_arch = "aarch64", - target_arch = "riscv64", - target_arch = "x86_64" - ))] - let all = Sigset { sig: [!0] }; - sigprocmask(How::BLOCK, Some(&all)).ok(); + let all = KernelSigSet::all(); + kernel_sigprocmask(How::BLOCK, Some(&all)).ok(); } // `munmap` the memory, which also frees the stack we're currently @@ -1097,7 +1090,7 @@ pub fn default_guard_size() -> usize { /// Yield the current thread, encouraging other threads to run. #[inline] pub fn yield_current() { - rustix::process::sched_yield() + rustix::thread::sched_yield() } /// The ARM ABI expects this to be defined. diff --git a/test-crates/origin-start/Cargo.toml b/test-crates/origin-start/Cargo.toml index 301755b..9bf7770 100644 --- a/test-crates/origin-start/Cargo.toml +++ b/test-crates/origin-start/Cargo.toml @@ -6,10 +6,10 @@ publish = false [dependencies] origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "signal", "unwinding", "eh-personality-continue", "panic-handler-trap", "nightly"] } -atomic-dbg = { version = "0.1.8", default-features = false } -rustix-dlmalloc = { version = "0.1.0", features = ["global"] } -rustix = { version = "0.38", default-features = false, features = ["thread"] } -rustix-futex-sync = "0.2.1" +atomic-dbg = { version = "0.1.11", default-features = false } +rustix-dlmalloc = { version = "0.2.1", features = ["global"] } +rustix = { version = "1.0.0", default-features = false, features = ["process", "thread"] } +rustix-futex-sync = "0.3.0" # This is just a test crate, and not part of the origin workspace. [workspace] diff --git a/test-crates/origin-start/src/bin/abort-via-raise.rs b/test-crates/origin-start/src/bin/abort-via-raise.rs index cf998a2..4253840 100644 --- a/test-crates/origin-start/src/bin/abort-via-raise.rs +++ b/test-crates/origin-start/src/bin/abort-via-raise.rs @@ -13,8 +13,8 @@ static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::Glob #[no_mangle] unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) -> i32 { - // Terminate the current process using `Signal::Abort`. - rustix::runtime::tkill(rustix::thread::gettid(), signal::Signal::Abort).ok(); + // Terminate the current process using `Signal::ABORT`. + rustix::process::kill_process(rustix::process::getpid(), signal::Signal::ABORT).ok(); // We shouldn't get here. 12 } diff --git a/tests/example_crates.rs b/tests/example_crates.rs index 80815ce..b5323e8 100644 --- a/tests/example_crates.rs +++ b/tests/example_crates.rs @@ -37,24 +37,6 @@ fn example_crate_basic_relocate() { ); } -#[test] -fn example_crate_no_std() { - test_crate("no-std", &[], &[], "", COMMON_STDERR, None); -} - -/// Like `example_crate_no_std` but redundantly call `relocate`. -#[test] -fn example_crate_no_std_relocate() { - test_crate( - "no-std", - &["--features=origin/experimental-relocate"], - &[], - "", - COMMON_STDERR, - None, - ); -} - #[test] fn example_crate_external_start() { test_crate("external-start", &[], &[], "", COMMON_STDERR, None); diff --git a/tests/test_crates.rs b/tests/test_crates.rs index 16125ea..02fa830 100644 --- a/tests/test_crates.rs +++ b/tests/test_crates.rs @@ -132,7 +132,7 @@ fn test_trap() { let mut command = utils::run_test("test", "run", "origin-start", &["--bin=trap"], &[]); assert_eq!( command.output().unwrap().status.signal(), - Some(origin::signal::Signal::Ill as i32) + Some(origin::signal::Signal::ILL.as_raw() as i32) ); } @@ -147,6 +147,6 @@ fn test_abort_via_raise() { ); assert_eq!( command.output().unwrap().status.signal(), - Some(origin::signal::Signal::Abort as i32) + Some(origin::signal::Signal::ABORT.as_raw() as i32) ); }