From d85cf09a960263c98a1e9a0784b37f5271e41b9e Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Tue, 20 May 2025 11:00:43 +0200 Subject: [PATCH] fix macos build and add rust-toolchain file to specify nightly --- rust-toolchain.toml | 2 ++ src/sys/unix.rs | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000000..5d56faf9ae08 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" diff --git a/src/sys/unix.rs b/src/sys/unix.rs index be80c5954372..9f5701f31705 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -10,7 +10,7 @@ use std::ffi::{CStr, c_int, c_void}; use std::fs::{self, File}; use std::mem::{self, MaybeUninit}; use std::os::fd::{AsRawFd as _, FromRawFd as _}; -use std::ptr::{self, NonNull, null, null_mut}; +use std::ptr::{self, NonNull, null_mut}; use std::{thread, time}; use crate::arena::{Arena, ArenaString, scratch_arena}; @@ -195,11 +195,20 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Duration) -> Option Option break, libc::EAGAIN if timeout == time::Duration::ZERO => break, libc::EINTR | libc::EAGAIN => {} @@ -304,7 +313,7 @@ pub fn write_stdout(text: &str) { continue; } - let err = unsafe { *libc::__errno_location() }; + let err = get_errno(); if err != libc::EINTR { return; } @@ -407,7 +416,7 @@ pub unsafe fn virtual_commit(base: NonNull, size: usize) -> apperr::Result<( unsafe fn load_library(name: &CStr) -> apperr::Result> { unsafe { NonNull::new(libc::dlopen(name.as_ptr(), libc::RTLD_LAZY)) - .ok_or_else(|| errno_to_apperr(libc::ELIBACC)) + .ok_or_else(|| errno_to_apperr(libc::ENOENT)) } } @@ -423,7 +432,7 @@ pub unsafe fn get_proc_address(handle: NonNull, name: &CStr) -> apper unsafe { let sym = libc::dlsym(handle.as_ptr(), name.as_ptr()); if sym.is_null() { - Err(errno_to_apperr(libc::ELIBACC)) + Err(errno_to_apperr(libc::ENOENT)) } else { Ok(mem::transmute_copy(&sym)) } @@ -565,5 +574,15 @@ const fn errno_to_apperr(no: c_int) -> apperr::Error { } fn check_int_return(ret: libc::c_int) -> apperr::Result { - if ret < 0 { Err(errno_to_apperr(unsafe { *libc::__errno_location() })) } else { Ok(ret) } + if ret < 0 { Err(errno_to_apperr(get_errno())) } else { Ok(ret) } +} + +#[cfg(target_os = "macos")] +pub fn get_errno() -> libc::c_int { + unsafe { *libc::__error() } +} + +#[cfg(not(target_os = "macos"))] +pub fn get_errno() -> libc::c_int { + unsafe { *libc::__errno_location() }; }