Skip to content

Commit

Permalink
Update to the latest nightly Rust. (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode authored Oct 13, 2024
1 parent 5de7903 commit 748fa56
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 41 deletions.
4 changes: 2 additions & 2 deletions 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.0", default-features = false, features = ["init-fini-arrays", "program-at-exit", "thread-at-exit", "nightly", "getauxval"] }
origin = { version = "0.23.1", 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 All @@ -47,7 +47,7 @@ alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-all
# upstream `unwinding` so that it doesn't need to go through `dl_iterate_phdr`,
# but `fde-phdr-dl` works for now.
[target.'cfg(not(target_arch = "arm"))'.dependencies.unwinding]
version = "0.2.0"
version = "0.2.3"
default-features = false
features = [
"unwinder",
Expand Down
62 changes: 25 additions & 37 deletions c-scape/src/jmp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::naked_asm;
use core::mem::size_of;
use libc::{c_int, c_void};
use rustix::runtime::{How, Sigset};
Expand All @@ -23,7 +23,7 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int {

#[cfg(target_arch = "aarch64")]
{
asm!(
naked_asm!(
// Save all the callee-saved registers, the incoming stack pointer
// value, and the incoming return address into the `jmp_buf`.
"stp x19, x20, [x0,#0]",
Expand All @@ -41,14 +41,13 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int {
// Return 0.
"mov x0, #0",
// Return to the caller normally.
"ret",
options(noreturn)
"ret"
)
}

#[cfg(target_arch = "riscv64")]
{
asm!(
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)",
Expand Down Expand Up @@ -80,14 +79,13 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int {
// Return 0.
"li a0, 0",
// Return to the caller normally.
"ret",
options(noreturn)
"ret"
)
}

#[cfg(target_arch = "x86_64")]
{
asm!(
naked_asm!(
// Load the incoming return address.
"mov rsi, [rsp]",
// Save all the callee-saved registers, the incoming stack pointer
Expand All @@ -103,14 +101,13 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int {
// Return 0.
"xor eax, eax",
// Return to the caller normally.
"ret",
options(noreturn)
"ret"
)
}

#[cfg(target_arch = "x86")]
{
asm!(
naked_asm!(
// Load the `jmp_buf` address.
"mov eax, [esp+4]",
// Load the incoming return address.
Expand All @@ -126,8 +123,7 @@ unsafe extern "C" fn setjmp(env: jmp_buf) -> c_int {
// Return 0.
"xor eax, eax",
// Return to the caller normally.
"ret",
options(noreturn)
"ret"
)
}

Expand Down Expand Up @@ -160,7 +156,7 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! {

#[cfg(target_arch = "aarch64")]
{
asm!(
naked_asm!(
// Restore the callee-saved registers and the stack pointer.
"ldp x19, x20, [x0,#0]",
"ldp x21, x22, [x0,#16]",
Expand All @@ -178,14 +174,13 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! {
"cmp w1, 0",
"csinc w0, w1, wzr, ne",
// Jump to the `setjmp`'s return address.
"br x30",
options(noreturn)
"br x30"
)
}

#[cfg(target_arch = "riscv64")]
{
asm!(
naked_asm!(
// Restore the callee-saved registers and the stack pointer.
"ld s0, 0(a0)",
"ld s1, 8(a0)",
Expand Down Expand Up @@ -217,14 +212,13 @@ 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",
options(noreturn)
"ret"
);
}

#[cfg(target_arch = "x86_64")]
{
asm!(
naked_asm!(
// Restore the callee-saved registers and the stack pointer.
"mov rbx, [rdi]",
"mov rbp, [rdi+8]",
Expand All @@ -240,14 +234,13 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! {
"cmp esi, 1",
"adc eax, esi",
// Jump to the `setjmp`'s return address.
"jmp [rdi+56]",
options(noreturn)
"jmp [rdi+56]"
)
}

#[cfg(target_arch = "x86")]
{
asm!(
naked_asm!(
// Load the `jmp_buf` address.
"mov ecx, [esp+4]",
// Load `val`.
Expand All @@ -264,8 +257,7 @@ unsafe extern "C" fn longjmp(env: jmp_buf, val: c_int) -> ! {
"cmp eax, 1",
"adc eax, 0",
// Jump to the `setjmp`'s return address.
"jmp [ecx+20]",
options(noreturn)
"jmp [ecx+20]"
);
}

Expand Down Expand Up @@ -300,51 +292,48 @@ unsafe extern "C" fn sigsetjmp(_env: sigjmp_buf, _savesigs: c_int) -> c_int {

#[cfg(target_arch = "aarch64")]
{
asm!(
naked_asm!(
"stp x29, x30, [sp, -16]!",
"mov x29, sp",
"bl {__sigsetjmp_save}",
"ldp x29, x30, [sp], 16",
"b {setjmp}",
__sigsetjmp_save = sym __sigsetjmp_save,
setjmp = sym setjmp,
options(noreturn)
setjmp = sym setjmp
)
}

#[cfg(target_arch = "riscv64")]
{
asm!(
naked_asm!(
"addi sp, sp, -16",
"sd ra, 8(sp)",
"call {__sigsetjmp_save}",
"ld ra, 8(sp)",
"addi sp, sp, 16",
"tail {setjmp}",
__sigsetjmp_save = sym __sigsetjmp_save,
setjmp = sym setjmp,
options(noreturn)
setjmp = sym setjmp
)
}

#[cfg(target_arch = "x86_64")]
{
asm!(
naked_asm!(
"push rbp",
"mov rbp, rsp",
"call {__sigsetjmp_save}",
"mov rdi, rax",
"pop rbp",
"jmp {setjmp}",
__sigsetjmp_save = sym __sigsetjmp_save,
setjmp = sym setjmp,
options(noreturn)
setjmp = sym setjmp
)
}

#[cfg(target_arch = "x86")]
{
asm!(
naked_asm!(
"sub esp, 20",
"push [esp+28]",
"push [esp+28]",
Expand All @@ -353,8 +342,7 @@ unsafe extern "C" fn sigsetjmp(_env: sigjmp_buf, _savesigs: c_int) -> c_int {
"add esp, 28",
"jmp {setjmp}",
__sigsetjmp_save = sym __sigsetjmp_save,
setjmp = sym setjmp,
options(noreturn)
setjmp = sym setjmp
)
}

Expand Down
2 changes: 1 addition & 1 deletion example-crates/c-scape-unwinding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package = "c-scape"
errno = { version = "0.3.3", default-features = false }
rustix-dlmalloc = { version = "0.1.0", features = ["global"] }
# Depend on `unwinding` so that we can do `catch_unwind`.
unwinding = { version = "0.2.2", default-features = false, features = ["panic"] }
unwinding = { version = "0.2.3", default-features = false, features = ["panic"] }

# This is just an example crate, and not part of the c-ward workspace.
[workspace]
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-06"
channel = "nightly-2024-10-12"
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]

0 comments on commit 748fa56

Please sign in to comment.