Skip to content

Commit

Permalink
Remove naked_functions feature usage for x86
Browse files Browse the repository at this point in the history
Given that this function has no generics, it could easily use `global_asm!`
instead.
  • Loading branch information
nbdd0121 committed Jul 5, 2023
1 parent 4065385 commit 385e0b0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
8 changes: 2 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ fn main() {
// x86 our asm support requires naked functions. On PowerPC and MIPS,
// Rust's inline asm is considered experimental, so only use it if
// `--cfg=rustix_use_experimental_asm` is given.
if (arch != "x86" || has_feature("naked_functions"))
&& ((arch != "powerpc64" && arch != "mips" && arch != "mips64")
|| rustix_use_experimental_asm)
if (arch != "powerpc64" && arch != "mips" && arch != "mips64")
|| rustix_use_experimental_asm
{
use_feature("asm");
if arch == "x86" {
use_feature("naked_functions");
}
if rustix_use_experimental_asm {
use_feature("asm_experimental_arch");
}
Expand Down
39 changes: 26 additions & 13 deletions src/backend/linux_raw/vdso_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#[cfg(target_arch = "x86")]
use super::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0};
use super::vdso;
#[cfg(all(asm, target_arch = "x86"))]
use core::arch::asm;
#[cfg(target_arch = "x86")]
use core::arch::global_asm;
use core::mem::transmute;
use core::ptr::null_mut;
use core::sync::atomic::AtomicPtr;
Expand Down Expand Up @@ -310,21 +310,34 @@ unsafe fn _rustix_clock_gettime_via_syscall(
ret(syscall!(__NR_clock_gettime, c_int(clockid), res))
}

/// A symbol pointing to an `int 0x80` instruction. This “function” is only
/// called from assembly, and only with the x86 syscall calling convention,
/// so its signature here is not its true signature.
#[cfg(all(asm, target_arch = "x86"))]
#[naked]
unsafe extern "C" fn rustix_int_0x80() {
asm!("int $$0x80", "ret", options(noreturn))
}

// The outline version of the `rustix_int_0x80` above.
#[cfg(all(not(asm), target_arch = "x86"))]
#[cfg(target_arch = "x86")]
extern "C" {
/// A symbol pointing to an `int 0x80` instruction. This “function” is only
/// called from assembly, and only with the x86 syscall calling convention.
/// so its signature here is not its true signature.
///
/// This extern block and the `global_asm!` below can be replaced with
/// `#[naked]` if it's stabilized.
fn rustix_int_0x80();
}

#[cfg(target_arch = "x86")]
global_asm!(
r#"
.section .text.rustix_int_0x80,"ax",@progbits
.p2align 4
.weak rustix_int_0x80
.hidden rustix_int_0x80
.type rustix_int_0x80, @function
rustix_int_0x80:
.cfi_startproc
int 0x80
ret
.cfi_endproc
.size rustix_int_0x80, .-rustix_int_0x80
"#
);

fn minimal_init() {
// SAFETY: Store default function addresses in static storage so that if we
// end up making any system calls while we read the vDSO, they'll work.
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@
#![cfg_attr(rustc_attrs, feature(rustc_attrs))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))]
#![cfg_attr(
all(linux_raw, naked_functions, target_arch = "x86"),
feature(naked_functions)
)]
#![cfg_attr(core_ffi_c, feature(core_ffi_c))]
#![cfg_attr(core_c_str, feature(core_c_str))]
#![cfg_attr(alloc_c_string, feature(alloc_ffi))]
Expand Down

0 comments on commit 385e0b0

Please sign in to comment.