diff --git a/c-gull/src/lib.rs b/c-gull/src/lib.rs index dd042ee..025d1ea 100644 --- a/c-gull/src/lib.rs +++ b/c-gull/src/lib.rs @@ -1,7 +1,5 @@ #![doc = include_str!("../README.md")] #![feature(sync_unsafe_cell)] -#![feature(strict_provenance)] -#![deny(fuzzy_provenance_casts, lossy_provenance_casts)] #![cfg_attr(not(feature = "std"), no_std)] // Don't warn if `try_into()` is fallible on some targets. #![allow(unreachable_patterns)] diff --git a/c-scape/Cargo.toml b/c-scape/Cargo.toml index 8417e66..0d064f8 100644 --- a/c-scape/Cargo.toml +++ b/c-scape/Cargo.toml @@ -23,7 +23,7 @@ rustix = { version = "0.38.35", default-features = false, features = ["event", " rustix-futex-sync = { version = "0.2.1", features = ["atomic_usize"] } memoffset = "0.9.0" realpath-ext = { version = "0.1.0", default-features = false } -origin = { version = "0.23.3", default-features = false, features = ["init-fini-arrays", "program-at-exit", "thread-at-exit", "nightly", "getauxval"] } +origin = { version = "0.24.0", default-features = false, features = ["init-fini-arrays", "program-at-exit", "thread-at-exit", "nightly", "getauxval"] } # We use the libc crate for C ABI types and constants, but we don't depend on # the actual platform libc. libc = { version = "0.2.155", default-features = false } diff --git a/c-scape/src/jmp.rs b/c-scape/src/jmp.rs index c1745b5..eb226c3 100644 --- a/c-scape/src/jmp.rs +++ b/c-scape/src/jmp.rs @@ -45,9 +45,40 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int { ) } - #[cfg(target_arch = "riscv64")] + #[cfg(all(target_arch = "riscv64", target_feature = "soft-float"))] + { + naked_asm!( + // Save all the callee-saved registers, the incoming stack pointer + // value, and the incoming return address into the `jmp_buf`. + "sd s0, 0(a0)", + "sd s1, 8(a0)", + "sd s2, 16(a0)", + "sd s3, 24(a0)", + "sd s4, 32(a0)", + "sd s5, 40(a0)", + "sd s6, 48(a0)", + "sd s7, 56(a0)", + "sd s8, 64(a0)", + "sd s9, 72(a0)", + "sd s10, 80(a0)", + "sd s11, 88(a0)", + "sd sp, 96(a0)", + "sd ra, 104(a0)", + // Soft-float mode; don't save the floating-point registers. + + // Return 0. + "li a0, 0", + // Return to the caller normally. + "ret" + ) + } + + #[cfg(all(target_arch = "riscv64", not(target_feature = "soft-float")))] { naked_asm!( + // arch option manipulation needed due to LLVM/Rust bug, see rust-lang/rust#80608 + ".option push", + ".option arch, +d", // Save all the callee-saved registers, the incoming stack pointer // value, and the incoming return address into the `jmp_buf`. "sd s0, 0(a0)", @@ -64,6 +95,7 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int { "sd s11, 88(a0)", "sd sp, 96(a0)", "sd ra, 104(a0)", + // Hard-float mode; save the floating-point registers. "fsd fs0, 112(a0)", "fsd fs1, 120(a0)", "fsd fs2, 128(a0)", @@ -79,7 +111,9 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int { // Return 0. "li a0, 0", // Return to the caller normally. - "ret" + "ret", + // arch option manipulation needed due to LLVM/Rust bug, see rust-lang/rust#80608 + ".option pop" ) } @@ -178,9 +212,40 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! { ) } - #[cfg(target_arch = "riscv64")] + #[cfg(all(target_arch = "riscv64", target_feature = "soft-float"))] + { + naked_asm!( + // Restore the callee-saved registers and the stack pointer. + "ld s0, 0(a0)", + "ld s1, 8(a0)", + "ld s2, 16(a0)", + "ld s3, 24(a0)", + "ld s4, 32(a0)", + "ld s5, 40(a0)", + "ld s6, 48(a0)", + "ld s7, 56(a0)", + "ld s8, 64(a0)", + "ld s9, 72(a0)", + "ld s10, 80(a0)", + "ld s11, 88(a0)", + "ld sp, 96(a0)", + "ld ra, 104(a0)", + // Soft-float mode; don't restore the floating-point registers. + + // Return `val == 0 ? 1 : val`. + "seqz a0, a1", + "add a0, a0, a1", + // Jump to the `setjmp`'s return address. + "ret" + ); + } + + #[cfg(all(target_arch = "riscv64", not(target_feature = "soft-float")))] { naked_asm!( + // arch option manipulation needed due to LLVM/Rust bug, see rust-lang/rust#80608 + ".option push", + ".option arch, +d", // Restore the callee-saved registers and the stack pointer. "ld s0, 0(a0)", "ld s1, 8(a0)", @@ -196,6 +261,7 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! { "ld s11, 88(a0)", "ld sp, 96(a0)", "ld ra, 104(a0)", + // Hard-float mode; restore the floating-point registers. "fld fs0, 112(a0)", "fld fs1, 120(a0)", "fld fs2, 128(a0)", @@ -212,7 +278,9 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! { "seqz a0, a1", "add a0, a0, a1", // Jump to the `setjmp`'s return address. - "ret" + "ret", + // arch option manipulation needed due to LLVM/Rust bug, see rust-lang/rust#80608 + ".option pop" ); } diff --git a/c-scape/src/lib.rs b/c-scape/src/lib.rs index 0c72614..8572149 100644 --- a/c-scape/src/lib.rs +++ b/c-scape/src/lib.rs @@ -7,10 +7,6 @@ #![feature(sync_unsafe_cell)] // for lots of libc static variables #![feature(linkage)] // for `malloc` etc. #![feature(naked_functions)] // for `setjmp` etc. -// Enable strict provenance. -#![feature(strict_provenance)] -#![feature(exposed_provenance)] -#![deny(fuzzy_provenance_casts, lossy_provenance_casts)] // Disable some common warnings. #![allow(unexpected_cfgs)] // Don't warn if `try_into()` is fallible on some targets. diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d126dcb..1a27b4e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-10-12" +channel = "nightly-2025-01-02" components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]