Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions c-gull/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion c-scape/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
76 changes: 72 additions & 4 deletions c-scape/src/jmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand All @@ -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"
)
}

Expand Down Expand Up @@ -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)",
Expand All @@ -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)",
Expand All @@ -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"
);
}

Expand Down
4 changes: 0 additions & 4 deletions c-scape/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-10-12"
channel = "nightly-2025-01-02"
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]
Loading