mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Use more LFS functions.
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts. This is relevant to #94173. With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe #94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
This commit is contained in:
parent
01fbc5ae78
commit
27011b4185
@ -1743,8 +1743,13 @@ mod remove_dir_impl {
|
||||
use crate::sys::common::small_c_string::run_path_with_cstr;
|
||||
use crate::sys::{cvt, cvt_r};
|
||||
|
||||
#[cfg(not(all(target_os = "macos", not(target_arch = "aarch64")),))]
|
||||
#[cfg(not(any(
|
||||
target_os = "linux",
|
||||
all(target_os = "macos", not(target_arch = "aarch64"))
|
||||
)))]
|
||||
use libc::{fdopendir, openat, unlinkat};
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::{fdopendir, openat64 as openat, unlinkat};
|
||||
#[cfg(all(target_os = "macos", not(target_arch = "aarch64")))]
|
||||
use macos_weak::{fdopendir, openat, unlinkat};
|
||||
|
||||
|
@ -61,6 +61,10 @@ use crate::ptr;
|
||||
use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use crate::sys::cvt;
|
||||
use crate::sys::weak::syscall;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::sendfile as sendfile64;
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::sendfile64;
|
||||
use libc::{EBADF, EINVAL, ENOSYS, EOPNOTSUPP, EOVERFLOW, EPERM, EXDEV};
|
||||
|
||||
#[cfg(test)]
|
||||
@ -647,7 +651,7 @@ fn sendfile_splice(mode: SpliceMode, reader: RawFd, writer: RawFd, len: u64) ->
|
||||
|
||||
let result = match mode {
|
||||
SpliceMode::Sendfile => {
|
||||
cvt(unsafe { libc::sendfile(writer, reader, ptr::null_mut(), chunk_size) })
|
||||
cvt(unsafe { sendfile64(writer, reader, ptr::null_mut(), chunk_size) })
|
||||
}
|
||||
SpliceMode::Splice => cvt(unsafe {
|
||||
splice(reader, ptr::null_mut(), writer, ptr::null_mut(), chunk_size, 0)
|
||||
|
@ -95,6 +95,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
)))]
|
||||
'poll: {
|
||||
use crate::sys::os::errno;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::open as open64;
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::open64;
|
||||
let pfds: &mut [_] = &mut [
|
||||
libc::pollfd { fd: 0, events: 0, revents: 0 },
|
||||
libc::pollfd { fd: 1, events: 0, revents: 0 },
|
||||
@ -116,7 +120,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
if pfd.revents & libc::POLLNVAL == 0 {
|
||||
continue;
|
||||
}
|
||||
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
// If the stream is closed but we failed to reopen it, abort the
|
||||
// process. Otherwise we wouldn't preserve the safety of
|
||||
// operations on the corresponding Rust object Stdin, Stdout, or
|
||||
@ -139,9 +143,13 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
)))]
|
||||
{
|
||||
use crate::sys::os::errno;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::open as open64;
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::open64;
|
||||
for fd in 0..3 {
|
||||
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
|
||||
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
// If the stream is closed but we failed to reopen it, abort the
|
||||
// process. Otherwise we wouldn't preserve the safety of
|
||||
// operations on the corresponding Rust object Stdin, Stdout, or
|
||||
|
@ -45,7 +45,10 @@ mod imp {
|
||||
use crate::thread;
|
||||
|
||||
use libc::MAP_FAILED;
|
||||
use libc::{mmap, munmap};
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::{mmap as mmap64, munmap};
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::{mmap64, munmap};
|
||||
use libc::{sigaction, sighandler_t, SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_DFL};
|
||||
use libc::{sigaltstack, SIGSTKSZ, SS_DISABLE};
|
||||
use libc::{MAP_ANON, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE, SIGSEGV};
|
||||
@ -135,7 +138,7 @@ mod imp {
|
||||
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "linux",)))]
|
||||
let flags = MAP_PRIVATE | MAP_ANON;
|
||||
let stackp =
|
||||
mmap(ptr::null_mut(), SIGSTKSZ + page_size(), PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
mmap64(ptr::null_mut(), SIGSTKSZ + page_size(), PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
if stackp == MAP_FAILED {
|
||||
panic!("failed to allocate an alternative stack: {}", io::Error::last_os_error());
|
||||
}
|
||||
|
@ -658,7 +658,10 @@ pub mod guard {
|
||||
))]
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
pub mod guard {
|
||||
use libc::{mmap, mprotect};
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use libc::{mmap as mmap64, mprotect};
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::{mmap64, mprotect};
|
||||
use libc::{MAP_ANON, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};
|
||||
|
||||
use crate::io;
|
||||
@ -808,7 +811,7 @@ pub mod guard {
|
||||
// read/write permissions and only then mprotect() it to
|
||||
// no permissions at all. See issue #50313.
|
||||
let stackptr = get_stack_start_aligned()?;
|
||||
let result = mmap(
|
||||
let result = mmap64(
|
||||
stackptr,
|
||||
page_size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
|
Loading…
Reference in New Issue
Block a user