From ad2618daac52e09b7994da9529c3d919f5827936 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 9 Nov 2025 12:39:18 -0500 Subject: [PATCH 01/12] rustc_target: hide TargetOptions::vendor --- src/machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.rs b/src/machine.rs index 304ae00b01..a4f8e9ccaa 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -715,7 +715,7 @@ impl<'tcx> MiriMachine<'tcx> { match target.arch { Arch::Wasm32 | Arch::Wasm64 => 64 * 1024, // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances Arch::AArch64 => { - if target.options.vendor.as_ref() == "apple" { + if target.is_like_darwin { // No "definitive" source, but see: // https://www.wwdcnotes.com/notes/wwdc20/10214/ // https://github.com/ziglang/zig/issues/11308 etc. From 094557317581dd6b6ffd1b3005020fd08e162936 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 27 May 2025 16:12:28 +0200 Subject: [PATCH 02/12] Allow `function_casts_as_integer` in non-related miri tests --- tests/pass/backtrace/backtrace-api-v1.rs | 2 ++ tests/pass/backtrace/backtrace-api-v1.stdout | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/pass/backtrace/backtrace-api-v1.rs b/tests/pass/backtrace/backtrace-api-v1.rs index a3060abc39..cf6f43dbbf 100644 --- a/tests/pass/backtrace/backtrace-api-v1.rs +++ b/tests/pass/backtrace/backtrace-api-v1.rs @@ -1,5 +1,7 @@ //@normalize-stderr-test: "::<.*>" -> "" +#![allow(function_casts_as_integer)] + #[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::() diff --git a/tests/pass/backtrace/backtrace-api-v1.stdout b/tests/pass/backtrace/backtrace-api-v1.stdout index 5c2995e132..b3a4beb4e8 100644 --- a/tests/pass/backtrace/backtrace-api-v1.stdout +++ b/tests/pass/backtrace/backtrace-api-v1.stdout @@ -1,5 +1,5 @@ -tests/pass/backtrace/backtrace-api-v1.rs:27:9 (func_d) -tests/pass/backtrace/backtrace-api-v1.rs:14:9 (func_c) -tests/pass/backtrace/backtrace-api-v1.rs:9:5 (func_b::) -tests/pass/backtrace/backtrace-api-v1.rs:5:5 (func_a) -tests/pass/backtrace/backtrace-api-v1.rs:34:18 (main) +tests/pass/backtrace/backtrace-api-v1.rs:29:9 (func_d) +tests/pass/backtrace/backtrace-api-v1.rs:16:9 (func_c) +tests/pass/backtrace/backtrace-api-v1.rs:11:5 (func_b::) +tests/pass/backtrace/backtrace-api-v1.rs:7:5 (func_a) +tests/pass/backtrace/backtrace-api-v1.rs:36:18 (main) From a112cb257dee61497ac3dd3855d081819a5e836d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 14 Oct 2025 15:15:37 +0200 Subject: [PATCH 03/12] Allow `function_casts_as_integer` in miri source code --- src/shims/native_lib/trace/parent.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shims/native_lib/trace/parent.rs b/src/shims/native_lib/trace/parent.rs index 335188b331..f6ebbc469f 100644 --- a/src/shims/native_lib/trace/parent.rs +++ b/src/shims/native_lib/trace/parent.rs @@ -500,7 +500,8 @@ fn handle_segfault( capstone_disassemble(&instr, addr, cs, acc_events).expect("Failed to disassemble instruction"); // Move the instr ptr into the deprotection code. - #[expect(clippy::as_conversions)] + #[allow(unknown_lints)] + #[expect(clippy::as_conversions, function_casts_as_integer)] new_regs.set_ip(mempr_off as usize); // Don't mess up the stack by accident! new_regs.set_sp(stack_ptr); @@ -552,7 +553,8 @@ fn handle_segfault( new_regs = regs_bak; // Reprotect everything and continue. - #[expect(clippy::as_conversions)] + #[allow(unknown_lints)] + #[expect(clippy::as_conversions, function_casts_as_integer)] new_regs.set_ip(mempr_on as usize); new_regs.set_sp(stack_ptr); ptrace::setregs(pid, new_regs).unwrap(); From 053236491029f0cd3f7e4de4fed7be76b33e2f7a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 11 Nov 2025 20:16:15 +0100 Subject: [PATCH 04/12] Simplify jemalloc setup Using the new `override_allocator_on_supported_platforms` feature in `tikv-jemalloc-sys v0.6.1` we can avoid the manual statics. --- Cargo.toml | 4 ++-- src/bin/miri.rs | 46 +++++----------------------------------------- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8bb4f1c160..5341b3a486 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,8 @@ serde_json = { version = "1.0", optional = true } # But only for some targets, it fails for others. Rustc configures this in its CI, but we can't # easily use that since we support of-tree builds. [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys] -version = "0.6.0" -features = ['unprefixed_malloc_on_supported_platforms'] +version = "0.6.1" +features = ['override_allocator_on_supported_platforms'] [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 920fc29481..8b4445e379 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -20,6 +20,11 @@ extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; +/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs +/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement. +#[cfg(any(target_os = "linux", target_os = "macos"))] +use tikv_jemalloc_sys as _; + mod log; use std::env; @@ -392,48 +397,7 @@ fn parse_range(val: &str) -> Result, &'static str> { Ok(from..to) } -#[cfg(any(target_os = "linux", target_os = "macos"))] -fn jemalloc_magic() { - // These magic runes are copied from - // . - // See there for further comments. - use std::os::raw::{c_int, c_void}; - - use tikv_jemalloc_sys as jemalloc_sys; - - #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; - #[used] - static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; - #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; - #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; - #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; - #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; - - // On OSX, jemalloc doesn't directly override malloc/free, but instead - // registers itself with the allocator's zone APIs in a ctor. However, - // the linker doesn't seem to consider ctors as "used" when statically - // linking, so we need to explicitly depend on the function. - #[cfg(target_os = "macos")] - { - unsafe extern "C" { - fn _rjem_je_zone_register(); - } - - #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; - } -} - fn main() { - #[cfg(any(target_os = "linux", target_os = "macos"))] - jemalloc_magic(); - let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); // Snapshot a copy of the environment before `rustc` starts messing with it. From 5a0893c5305097e6c14b6d512ece0a7b4c6a84a6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 6 Nov 2025 23:56:29 -0500 Subject: [PATCH 05/12] rustc_target: rename Arch::{Uknown,Other} Prepare for additional enums like Vendor and Os which have true `Unknown` variants. We want to use the same name for the escape hatch for all of these, thus rename this one. --- src/shims/alloc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shims/alloc.rs b/src/shims/alloc.rs index 217069b8b5..7163d96d93 100644 --- a/src/shims/alloc.rs +++ b/src/shims/alloc.rs @@ -54,7 +54,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | Arch::Nvptx64 | Arch::PowerPC64LE | Arch::SpirV - | Arch::Unknown(_)) => bug!("unsupported target architecture for malloc: `{arch}`"), + | Arch::Other(_)) => bug!("unsupported target architecture for malloc: `{arch}`"), }; // The C standard only requires sufficient alignment for any *type* with size less than or // equal to the size requested. Types one can define in standard C seem to never have an alignment From 64bc20690d1e2d454a0fbe5392c3047e962dc77e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 5 Nov 2025 12:37:09 -0500 Subject: [PATCH 06/12] rustc_target: introduce Env Improve type safety by using an enum rather than strings. --- src/shims/windows/foreign_items.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 21c9022737..c824147ad4 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -6,7 +6,7 @@ use rustc_abi::{Align, CanonAbi, Size, X86Call}; use rustc_middle::ty::Ty; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; -use rustc_target::spec::Arch; +use rustc_target::spec::{Arch, Env}; use self::shims::windows::handle::{Handle, PseudoHandle}; use crate::shims::os_str::bytes_to_os_str; @@ -826,7 +826,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // It was originally specified as part of the Itanium C++ ABI: // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-throw. // MinGW implements _Unwind_RaiseException on top of SEH exceptions. - if this.tcx.sess.target.env != "gnu" { + if this.tcx.sess.target.env != Env::Gnu { throw_unsup_format!( "`_Unwind_RaiseException` is not supported on non-MinGW Windows", ); From 6e74aa02640e2828b6183eb6489dc7b183e2d635 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 5 Nov 2025 16:32:20 -0500 Subject: [PATCH 07/12] rustc_target: introduce Os Improve type safety by using an enum rather than strings. --- src/concurrency/thread.rs | 3 +- src/eval.rs | 3 +- src/helpers.rs | 15 +++---- src/machine.rs | 4 +- src/shims/alloc.rs | 8 ++-- src/shims/env.rs | 5 ++- src/shims/extern_static.rs | 14 ++++--- src/shims/foreign_items.rs | 10 ++--- src/shims/os_str.rs | 5 ++- src/shims/time.rs | 21 +++++----- src/shims/tls.rs | 7 ++-- src/shims/unix/env.rs | 3 +- src/shims/unix/fd.rs | 3 +- src/shims/unix/foreign_items.rs | 52 ++++++++++++------------ src/shims/unix/fs.rs | 29 ++++++------- src/shims/unix/mem.rs | 3 +- src/shims/unix/solarish/foreign_items.rs | 9 ++-- src/shims/unix/sync.rs | 43 ++++++++++---------- src/shims/unix/unnamed_socket.rs | 4 +- src/shims/windows/env.rs | 17 ++++---- src/shims/windows/fs.rs | 7 ++-- 21 files changed, 142 insertions(+), 123 deletions(-) diff --git a/src/concurrency/thread.rs b/src/concurrency/thread.rs index 6178f87d78..7838bd2143 100644 --- a/src/concurrency/thread.rs +++ b/src/concurrency/thread.rs @@ -15,6 +15,7 @@ use rustc_index::{Idx, IndexVec}; use rustc_middle::mir::Mutability; use rustc_middle::ty::layout::TyAndLayout; use rustc_span::Span; +use rustc_target::spec::Os; use crate::concurrency::GlobalDataRaceHandler; use crate::shims::tls; @@ -471,7 +472,7 @@ impl<'tcx> ThreadManager<'tcx> { ) { ecx.machine.threads.threads[ThreadId::MAIN_THREAD].on_stack_empty = Some(on_main_stack_empty); - if ecx.tcx.sess.target.os.as_ref() != "windows" { + if ecx.tcx.sess.target.os != Os::Windows { // The main thread can *not* be joined on except on windows. ecx.machine.threads.threads[ThreadId::MAIN_THREAD].join_status = ThreadJoinStatus::Detached; diff --git a/src/eval.rs b/src/eval.rs index 20b506bad9..6daee0ba69 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -14,6 +14,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutCx}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::config::EntryFnType; +use rustc_target::spec::Os; use crate::concurrency::GenmcCtx; use crate::concurrency::thread::TlsAllocAction; @@ -341,7 +342,7 @@ pub fn create_ecx<'tcx>( ecx.machine.argv = Some(argv_place.ptr()); } // Store command line as UTF-16 for Windows `GetCommandLineW`. - if tcx.sess.target.os == "windows" { + if tcx.sess.target.os == Os::Windows { // Construct a command string with all the arguments. let cmd_utf16: Vec = args_to_utf16_command_string(config.args.iter()); diff --git a/src/helpers.rs b/src/helpers.rs index 18e16ddf1a..383a4e2ea4 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -19,6 +19,7 @@ use rustc_middle::ty::{self, IntTy, Ty, TyCtxt, UintTy}; use rustc_session::config::CrateType; use rustc_span::{Span, Symbol}; use rustc_symbol_mangling::mangle_internal_symbol; +use rustc_target::spec::Os; use crate::*; @@ -234,7 +235,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function to get a `libc` constant as a `Scalar`. fn eval_libc(&self, name: &str) -> Scalar { - if self.eval_context_ref().tcx.sess.target.os == "windows" { + if self.eval_context_ref().tcx.sess.target.os == Os::Windows { panic!( "`libc` crate is not reliably available on Windows targets; Miri should not use it there" ); @@ -290,7 +291,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function to get the `TyAndLayout` of a `libc` type fn libc_ty_layout(&self, name: &str) -> TyAndLayout<'tcx> { let this = self.eval_context_ref(); - if this.tcx.sess.target.os == "windows" { + if this.tcx.sess.target.os == Os::Windows { panic!( "`libc` crate is not reliably available on Windows targets; Miri should not use it there" ); @@ -669,7 +670,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function used inside the shims of foreign functions to assert that the target OS /// is `target_os`. It panics showing a message with the `name` of the foreign function /// if this is not the case. - fn assert_target_os(&self, target_os: &str, name: &str) { + fn assert_target_os(&self, target_os: Os, name: &str) { assert_eq!( self.eval_context_ref().tcx.sess.target.os, target_os, @@ -680,9 +681,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function used inside shims of foreign functions to check that the target OS /// is one of `target_oses`. It returns an error containing the `name` of the foreign function /// in a message if this is not the case. - fn check_target_os(&self, target_oses: &[&str], name: Symbol) -> InterpResult<'tcx> { - let target_os = self.eval_context_ref().tcx.sess.target.os.as_ref(); - if !target_oses.contains(&target_os) { + fn check_target_os(&self, target_oses: &[Os], name: Symbol) -> InterpResult<'tcx> { + let target_os = &self.eval_context_ref().tcx.sess.target.os; + if !target_oses.contains(target_os) { throw_unsup_format!("`{name}` is not supported on {target_os}"); } interp_ok(()) @@ -918,7 +919,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Always returns a `Vec` no matter the size of `wchar_t`. fn read_wchar_t_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec> { let this = self.eval_context_ref(); - let wchar_t = if this.tcx.sess.target.os == "windows" { + let wchar_t = if this.tcx.sess.target.os == Os::Windows { // We don't have libc on Windows so we have to hard-code the type ourselves. this.machine.layouts.u16 } else { diff --git a/src/machine.rs b/src/machine.rs index a4f8e9ccaa..4ffee208f4 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -31,7 +31,7 @@ use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::{Span, SpanData, Symbol}; use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::callconv::FnAbi; -use rustc_target::spec::Arch; +use rustc_target::spec::{Arch, Os}; use crate::alloc_addresses::EvalContextExt; use crate::concurrency::cpu_affinity::{self, CpuAffinityMask}; @@ -739,7 +739,7 @@ impl<'tcx> MiriMachine<'tcx> { ); let threads = ThreadManager::new(config); let mut thread_cpu_affinity = FxHashMap::default(); - if matches!(&*tcx.sess.target.os, "linux" | "freebsd" | "android") { + if matches!(&tcx.sess.target.os, Os::Linux | Os::FreeBsd | Os::Android) { thread_cpu_affinity .insert(threads.active_thread(), CpuAffinityMask::new(&layout_cx, config.num_cpus)); } diff --git a/src/shims/alloc.rs b/src/shims/alloc.rs index 7163d96d93..94649dde47 100644 --- a/src/shims/alloc.rs +++ b/src/shims/alloc.rs @@ -3,7 +3,7 @@ use rustc_ast::expand::allocator::SpecialAllocatorMethod; use rustc_middle::ty::Ty; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; -use rustc_target::spec::Arch; +use rustc_target::spec::{Arch, Os}; use crate::*; @@ -19,10 +19,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // This is given by `alignof(max_align_t)`. The following list is taken from // `library/std/src/sys/alloc/mod.rs` (where this is called `MIN_ALIGN`) and should // be kept in sync. - let os = this.tcx.sess.target.os.as_ref(); + let os = &this.tcx.sess.target.os; let max_fundamental_align = match &this.tcx.sess.target.arch { - Arch::RiscV32 if matches!(os, "espidf" | "zkvm") => 4, - Arch::Xtensa if matches!(os, "espidf") => 4, + Arch::RiscV32 if matches!(os, Os::EspIdf | Os::Zkvm) => 4, + Arch::Xtensa if matches!(os, Os::EspIdf) => 4, Arch::X86 | Arch::Arm | Arch::M68k diff --git a/src/shims/env.rs b/src/shims/env.rs index b9fb9192df..6915924f2a 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -1,6 +1,7 @@ use std::ffi::{OsStr, OsString}; use rustc_data_structures::fx::FxHashMap; +use rustc_target::spec::Os; use self::shims::unix::UnixEnvVars; use self::shims::windows::WindowsEnvVars; @@ -48,7 +49,7 @@ impl<'tcx> EnvVars<'tcx> { let env_vars = if ecx.target_os_is_unix() { EnvVars::Unix(UnixEnvVars::new(ecx, env_vars)?) - } else if ecx.tcx.sess.target.os == "windows" { + } else if ecx.tcx.sess.target.os == Os::Windows { EnvVars::Windows(WindowsEnvVars::new(ecx, env_vars)?) } else { // For "none" targets (i.e., without an OS). @@ -118,7 +119,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let this = self.eval_context_ref(); let index = thread.to_u32(); let target_os = &this.tcx.sess.target.os; - if target_os == "linux" || target_os == "netbsd" { + if matches!(target_os, Os::Linux | Os::NetBsd) { // On Linux, the main thread has PID == TID so we uphold this. NetBSD also appears // to exhibit the same behavior, though I can't find a citation. this.get_pid().strict_add(index) diff --git a/src/shims/extern_static.rs b/src/shims/extern_static.rs index c2527bf8e2..fc99716410 100644 --- a/src/shims/extern_static.rs +++ b/src/shims/extern_static.rs @@ -1,5 +1,7 @@ //! Provides the `extern static` that this platform expects. +use rustc_target::spec::Os; + use crate::*; impl<'tcx> MiriMachine<'tcx> { @@ -49,28 +51,28 @@ impl<'tcx> MiriMachine<'tcx> { Self::add_extern_static(ecx, "environ", environ); } - match ecx.tcx.sess.target.os.as_ref() { - "linux" => { + match &ecx.tcx.sess.target.os { + Os::Linux => { Self::null_ptr_extern_statics( ecx, &["__cxa_thread_atexit_impl", "__clock_gettime64"], )?; Self::weak_symbol_extern_statics(ecx, &["getrandom", "gettid", "statx"])?; } - "freebsd" => { + Os::FreeBsd => { Self::null_ptr_extern_statics(ecx, &["__cxa_thread_atexit_impl"])?; } - "android" => { + Os::Android => { Self::null_ptr_extern_statics(ecx, &["bsd_signal"])?; Self::weak_symbol_extern_statics(ecx, &["signal", "getrandom", "gettid"])?; } - "windows" => { + Os::Windows => { // "_tls_used" // This is some obscure hack that is part of the Windows TLS story. It's a `u8`. let val = ImmTy::from_int(0, ecx.machine.layouts.u8); Self::alloc_extern_static(ecx, "_tls_used", val)?; } - "illumos" | "solaris" => { + Os::Illumos | Os::Solaris => { Self::weak_symbol_extern_statics(ecx, &["pthread_setname_np"])?; } _ => {} // No "extern statics" supported on this target diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index bffe633f77..69a028e485 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -15,7 +15,7 @@ use rustc_middle::{mir, ty}; use rustc_session::config::OomStrategy; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; -use rustc_target::spec::Arch; +use rustc_target::spec::{Os, Arch}; use super::alloc::EvalContextExt as _; use super::backtrace::EvalContextExt as _; @@ -101,9 +101,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn is_dyn_sym(&self, name: &str) -> bool { let this = self.eval_context_ref(); - match this.tcx.sess.target.os.as_ref() { + match &this.tcx.sess.target.os { os if this.target_os_is_unix() => shims::unix::foreign_items::is_dyn_sym(name, os), - "windows" => shims::windows::foreign_items::is_dyn_sym(name), + Os::Windows => shims::windows::foreign_items::is_dyn_sym(name), _ => false, } } @@ -842,12 +842,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { } // Platform-specific shims - return match this.tcx.sess.target.os.as_ref() { + return match &this.tcx.sess.target.os { _ if this.target_os_is_unix() => shims::unix::foreign_items::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), - "windows" => + Os::Windows => shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), diff --git a/src/shims/os_str.rs b/src/shims/os_str.rs index b9391a0ffe..28b03ffb88 100644 --- a/src/shims/os_str.rs +++ b/src/shims/os_str.rs @@ -7,6 +7,7 @@ use std::os::windows::ffi::{OsStrExt, OsStringExt}; use std::path::{Path, PathBuf}; use rustc_middle::ty::Ty; +use rustc_target::spec::Os; use crate::*; @@ -329,7 +330,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Below we assume that everything non-Windows works like Unix, at least // when it comes to file system path conventions. #[cfg(windows)] - return if target_os == "windows" { + return if *target_os == Os::Windows { // Windows-on-Windows, all fine. os_str } else { @@ -346,7 +347,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Cow::Owned(OsString::from_wide(&path)) }; #[cfg(unix)] - return if target_os == "windows" { + return if *target_os == Os::Windows { // Windows target, Unix host. let mut path: Vec = os_str.into_owned().into_encoded_bytes(); match direction { diff --git a/src/shims/time.rs b/src/shims/time.rs index 6e56fdfe35..614cc75c6d 100644 --- a/src/shims/time.rs +++ b/src/shims/time.rs @@ -5,6 +5,7 @@ use std::time::{Duration, SystemTime}; use chrono::{DateTime, Datelike, Offset, Timelike, Utc}; use chrono_tz::Tz; +use rustc_target::spec::Os; use crate::*; @@ -31,8 +32,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } // Some further platform-specific names we support. - match this.tcx.sess.target.os.as_ref() { - "linux" | "freebsd" | "android" => { + match &this.tcx.sess.target.os { + Os::Linux | Os::FreeBsd | Os::Android => { // Linux further distinguishes regular and "coarse" clocks, but the "coarse" version // is just specified to be "faster and less precise", so we treat it like normal // clocks. @@ -42,7 +43,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { return Some(TimeoutClock::Monotonic); } } - "macos" => { + Os::MacOs => { // `CLOCK_UPTIME_RAW` supposed to not increment while the system is asleep... but // that's not really something a program running inside Miri can tell, anyway. // We need to support it because std uses it. @@ -176,7 +177,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // solaris/illumos system tm struct does not have // the additional tm_zone/tm_gmtoff fields. // https://docs.oracle.com/cd/E36784_01/html/E36874/localtime-r-3c.html - if !matches!(&*this.tcx.sess.target.os, "solaris" | "illumos") { + if !matches!(&this.tcx.sess.target.os, Os::Solaris | Os::Illumos) { // tm_zone represents the timezone value in the form of: +0730, +08, -0730 or -08. // This may not be consistent with libc::localtime_r's result. @@ -215,7 +216,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - this.assert_target_os("windows", shim_name); + this.assert_target_os(Os::Windows, shim_name); this.check_no_isolation(shim_name)?; let filetime = this.deref_pointer_as(LPFILETIME_op, this.windows_ty_layout("FILETIME"))?; @@ -237,7 +238,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "QueryPerformanceCounter"); + this.assert_target_os(Os::Windows, "QueryPerformanceCounter"); // QueryPerformanceCounter uses a hardware counter as its basis. // Miri will emulate a counter with a resolution of 1 nanosecond. @@ -260,7 +261,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "QueryPerformanceFrequency"); + this.assert_target_os(Os::Windows, "QueryPerformanceFrequency"); // Retrieves the frequency of the hardware performance counter. // The frequency of the performance counter is fixed at system boot and @@ -301,7 +302,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn mach_absolute_time(&self) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); - this.assert_target_os("macos", "mach_absolute_time"); + this.assert_target_os(Os::MacOs, "mach_absolute_time"); // This returns a u64, with time units determined dynamically by `mach_timebase_info`. // We return plain nanoseconds. @@ -316,7 +317,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn mach_timebase_info(&mut self, info_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("macos", "mach_timebase_info"); + this.assert_target_os(Os::MacOs, "mach_timebase_info"); let info = this.deref_pointer_as(info_op, this.libc_ty_layout("mach_timebase_info"))?; @@ -418,7 +419,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn Sleep(&mut self, timeout: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "Sleep"); + this.assert_target_os(Os::Windows, "Sleep"); let timeout_ms = this.read_scalar(timeout)?.to_u32()?; diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 9dc829d7a1..2159c41ab1 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -6,6 +6,7 @@ use std::task::Poll; use rustc_abi::{ExternAbi, HasDataLayout, Size}; use rustc_middle::ty; +use rustc_target::spec::Os; use crate::*; @@ -234,8 +235,8 @@ impl<'tcx> TlsDtorsState<'tcx> { let new_state = 'new_state: { match &mut self.0 { Init => { - match this.tcx.sess.target.os.as_ref() { - "macos" => { + match this.tcx.sess.target.os { + Os::MacOs => { // macOS has a _tlv_atexit function that allows // registering destructors without associated keys. // These are run first. @@ -245,7 +246,7 @@ impl<'tcx> TlsDtorsState<'tcx> { // All other Unixes directly jump to running the pthread dtors. break 'new_state PthreadDtors(Default::default()); } - "windows" => { + Os::Windows => { // Determine which destructors to run. let dtors = this.lookup_windows_tls_dtors()?; // And move to the next state, that runs them. diff --git a/src/shims/unix/env.rs b/src/shims/unix/env.rs index eb4365e200..41bf70c346 100644 --- a/src/shims/unix/env.rs +++ b/src/shims/unix/env.rs @@ -6,6 +6,7 @@ use rustc_abi::{FieldIdx, Size}; use rustc_data_structures::fx::FxHashMap; use rustc_index::IndexVec; use rustc_middle::ty::Ty; +use rustc_target::spec::Os; use crate::*; @@ -281,7 +282,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { tid_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("macos", "pthread_threadip_np"); + this.assert_target_os(Os::MacOs, "pthread_threadip_np"); let tid_dest = this.read_pointer(tid_op)?; if this.ptr_is_null(tid_dest)? { diff --git a/src/shims/unix/fd.rs b/src/shims/unix/fd.rs index 95e26ef5d5..4f1d88b799 100644 --- a/src/shims/unix/fd.rs +++ b/src/shims/unix/fd.rs @@ -6,6 +6,7 @@ use std::io::ErrorKind; use rand::Rng; use rustc_abi::Size; +use rustc_target::spec::Os; use crate::shims::files::FileDescription; use crate::shims::sig::check_min_vararg_count; @@ -197,7 +198,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fd.set_flags(flag, this) } - cmd if this.tcx.sess.target.os == "macos" + cmd if this.tcx.sess.target.os == Os::MacOs && cmd == this.eval_libc_i32("F_FULLFSYNC") => { // Reject if isolation is enabled. diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 1f8e60484e..e2d27e5702 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -5,6 +5,7 @@ use rustc_abi::{CanonAbi, Size}; use rustc_middle::ty::Ty; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; +use rustc_target::spec::Os; use self::shims::unix::android::foreign_items as android; use self::shims::unix::freebsd::foreign_items as freebsd; @@ -16,7 +17,7 @@ use crate::shims::alloc::EvalContextExt as _; use crate::shims::unix::*; use crate::{shim_sig, *}; -pub fn is_dyn_sym(name: &str, target_os: &str) -> bool { +pub fn is_dyn_sym(name: &str, target_os: &Os) -> bool { match name { // Used for tests. "isatty" => true, @@ -26,15 +27,14 @@ pub fn is_dyn_sym(name: &str, target_os: &str) -> bool { // needed at least on macOS to avoid file-based fallback in getrandom "getentropy" | "getrandom" => true, // Give specific OSes a chance to allow their symbols. - _ => - match target_os { - "android" => android::is_dyn_sym(name), - "freebsd" => freebsd::is_dyn_sym(name), - "linux" => linux::is_dyn_sym(name), - "macos" => macos::is_dyn_sym(name), - "solaris" | "illumos" => solarish::is_dyn_sym(name), - _ => false, - }, + _ => match *target_os { + Os::Android => android::is_dyn_sym(name), + Os::FreeBsd => freebsd::is_dyn_sym(name), + Os::Linux => linux::is_dyn_sym(name), + Os::MacOs => macos::is_dyn_sym(name), + Os::Solaris | Os::Illumos => solarish::is_dyn_sym(name), + _ => false, + }, } } @@ -302,7 +302,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } "flock" => { // Currently this function does not exist on all Unixes, e.g. on Solaris. - this.check_target_os(&["linux", "freebsd", "macos", "illumos"], link_name)?; + this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::MacOs, Os::Illumos], link_name)?; let [fd, op] = this.check_shim_sig( shim_sig!(extern "C" fn(i32, i32) -> i32), link_name, @@ -530,7 +530,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } "pipe2" => { // Currently this function does not exist on all Unixes, e.g. on macOS. - this.check_target_os(&["linux", "freebsd", "solaris", "illumos"], link_name)?; + this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::Solaris, Os::Illumos], link_name)?; let [pipefd, flags] = this.check_shim_sig( shim_sig!(extern "C" fn(*mut _, i32) -> i32), link_name, @@ -596,7 +596,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "reallocarray" => { // Currently this function does not exist on all Unixes, e.g. on macOS. - this.check_target_os(&["linux", "freebsd", "android"], link_name)?; + this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::Android], link_name)?; let [ptr, nmemb, size] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let ptr = this.read_pointer(ptr)?; @@ -861,7 +861,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "clock_nanosleep" => { // Currently this function does not exist on all Unixes, e.g. on macOS. this.check_target_os( - &["freebsd", "linux", "android", "solaris", "illumos"], + &[Os::FreeBsd, Os::Linux, Os::Android, Os::Solaris, Os::Illumos], link_name, )?; let [clock_id, flags, req, rem] = @@ -871,7 +871,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } "sched_getaffinity" => { // Currently this function does not exist on all Unixes, e.g. on macOS. - this.check_target_os(&["linux", "freebsd", "android"], link_name)?; + this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::Android], link_name)?; let [pid, cpusetsize, mask] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let pid = this.read_scalar(pid)?.to_u32()?; @@ -909,7 +909,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } "sched_setaffinity" => { // Currently this function does not exist on all Unixes, e.g. on macOS. - this.check_target_os(&["linux", "freebsd", "android"], link_name)?; + this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::Android], link_name)?; let [pid, cpusetsize, mask] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let pid = this.read_scalar(pid)?.to_u32()?; @@ -968,7 +968,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // This function is non-standard but exists with the same signature and behavior on // Linux, macOS, FreeBSD and Solaris/Illumos. this.check_target_os( - &["linux", "macos", "freebsd", "illumos", "solaris", "android"], + &[Os::Linux, Os::MacOs, Os::FreeBsd, Os::Illumos, Os::Solaris, Os::Android], link_name, )?; let [buf, bufsize] = @@ -1000,7 +1000,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // This function is non-standard but exists with the same signature and behavior on // Linux, FreeBSD and Solaris/Illumos. this.check_target_os( - &["linux", "freebsd", "illumos", "solaris", "android"], + &[Os::Linux, Os::FreeBsd, Os::Illumos, Os::Solaris, Os::Android], link_name, )?; let [ptr, len, flags] = @@ -1015,7 +1015,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "arc4random_buf" => { // This function is non-standard but exists with the same signature and // same behavior (eg never fails) on FreeBSD and Solaris/Illumos. - this.check_target_os(&["freebsd", "illumos", "solaris"], link_name)?; + this.check_target_os(&[Os::FreeBsd, Os::Illumos, Os::Solaris], link_name)?; let [ptr, len] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let ptr = this.read_pointer(ptr)?; let len = this.read_target_usize(len)?; @@ -1036,7 +1036,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // `_Unwind_RaiseException` impl in miri should work: // https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst this.check_target_os( - &["linux", "freebsd", "illumos", "solaris", "android", "macos"], + &[Os::Linux, Os::FreeBsd, Os::Illumos, Os::Solaris, Os::Android, Os::MacOs], link_name, )?; // This function looks and behaves excatly like miri_start_unwind. @@ -1146,25 +1146,25 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Platform-specific shims _ => { - let target_os = &*this.tcx.sess.target.os; + let target_os = &this.tcx.sess.target.os; return match target_os { - "android" => + Os::Android => android::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), - "freebsd" => + Os::FreeBsd => freebsd::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), - "linux" => + Os::Linux => linux::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), - "macos" => + Os::MacOs => macos::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), - "solaris" | "illumos" => + Os::Solaris | Os::Illumos => solarish::EvalContextExt::emulate_foreign_item_inner( this, link_name, abi, args, dest, ), diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 22bec9bd83..0760125917 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -11,6 +11,7 @@ use std::time::SystemTime; use rustc_abi::Size; use rustc_data_structures::fx::FxHashMap; +use rustc_target::spec::Os; use self::shims::time::system_time_to_duration; use crate::shims::files::FileHandle; @@ -149,7 +150,7 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> { &buf, )?; - if matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { + if matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd) { this.write_int_fields_named( &[ ("st_atime_nsec", access_nsec.into()), @@ -164,7 +165,7 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> { )?; } - if matches!(&*this.tcx.sess.target.os, "solaris" | "illumos") { + if matches!(&this.tcx.sess.target.os, Os::Solaris | Os::Illumos) { let st_fstype = this.project_field_named(&buf, "st_fstype")?; // This is an array; write 0 into first element so that it encodes the empty string. this.write_int(0, &this.project_index(&st_fstype, 0)?)?; @@ -390,7 +391,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // (Technically we do not support *not* setting this flag, but we ignore that.) mirror |= o_cloexec; } - if this.tcx.sess.target.os == "linux" { + if this.tcx.sess.target.os == Os::Linux { let o_tmpfile = this.eval_libc_i32("O_TMPFILE"); if flag & o_tmpfile == o_tmpfile { // if the flag contains `O_TMPFILE` then we return a graceful error @@ -529,7 +530,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { panic!("`macos_fbsd_solaris_stat` should not be called on {}", this.tcx.sess.target.os); } @@ -559,7 +560,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { panic!( "`macos_fbsd_solaris_lstat` should not be called on {}", this.tcx.sess.target.os @@ -590,7 +591,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { panic!( "`macos_fbsd_solaris_fstat` should not be called on {}", this.tcx.sess.target.os @@ -623,7 +624,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("linux", "statx"); + this.assert_target_os(Os::Linux, "statx"); let dirfd = this.read_scalar(dirfd_op)?.to_i32()?; let pathname_ptr = this.read_pointer(pathname_op)?; @@ -824,7 +825,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let this = self.eval_context_mut(); #[cfg_attr(not(unix), allow(unused_variables))] - let mode = if matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { + let mode = if matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd) { u32::from(this.read_scalar(mode_op)?.to_u16()?) } else { this.read_scalar(mode_op)?.to_u32()? @@ -903,7 +904,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn readdir64(&mut self, dirent_type: &str, dirp_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&*this.tcx.sess.target.os, "linux" | "solaris" | "illumos" | "freebsd") { + if !matches!(&this.tcx.sess.target.os, Os::Linux | Os::Solaris | Os::Illumos | Os::FreeBsd) { panic!("`linux_solaris_readdir64` should not be called on {}", this.tcx.sess.target.os); } @@ -981,7 +982,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Write common fields let ino_name = - if this.tcx.sess.target.os == "freebsd" { "d_fileno" } else { "d_ino" }; + if this.tcx.sess.target.os == Os::FreeBsd { "d_fileno" } else { "d_ino" }; this.write_int_fields_named( &[(ino_name, ino.into()), ("d_reclen", size.into())], &entry, @@ -1034,7 +1035,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd) { panic!("`macos_fbsd_readdir_r` should not be called on {}", this.tcx.sess.target.os); } @@ -1102,8 +1103,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &entry_place, )?; // Special fields. - match &*this.tcx.sess.target.os { - "macos" => { + match this.tcx.sess.target.os { + Os::MacOs => { #[rustfmt::skip] this.write_int_fields_named( &[ @@ -1113,7 +1114,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &entry_place, )?; } - "freebsd" => { + Os::FreeBsd => { #[rustfmt::skip] this.write_int_fields_named( &[ diff --git a/src/shims/unix/mem.rs b/src/shims/unix/mem.rs index 1738de4dd4..01aa5afafc 100644 --- a/src/shims/unix/mem.rs +++ b/src/shims/unix/mem.rs @@ -15,6 +15,7 @@ //! report UB. use rustc_abi::Size; +use rustc_target::spec::Os; use crate::*; @@ -46,7 +47,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // This is a horrible hack, but on MacOS and Solarish the guard page mechanism uses mmap // in a way we do not support. We just give it the return value it expects. if this.frame_in_std() - && matches!(&*this.tcx.sess.target.os, "macos" | "solaris" | "illumos") + && matches!(&this.tcx.sess.target.os, Os::MacOs | Os::Solaris | Os::Illumos) && (flags & map_fixed) != 0 { return interp_ok(Scalar::from_maybe_pointer(Pointer::without_provenance(addr), this)); diff --git a/src/shims/unix/solarish/foreign_items.rs b/src/shims/unix/solarish/foreign_items.rs index 31269bf00c..6335e6bc96 100644 --- a/src/shims/unix/solarish/foreign_items.rs +++ b/src/shims/unix/solarish/foreign_items.rs @@ -2,6 +2,7 @@ use rustc_abi::CanonAbi; use rustc_middle::ty::Ty; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; +use rustc_target::spec::Os; use crate::shims::unix::foreign_items::EvalContextExt as _; use crate::shims::unix::linux_like::epoll::EvalContextExt as _; @@ -26,26 +27,26 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { match link_name.as_str() { // epoll, eventfd (NOT available on Solaris!) "epoll_create1" => { - this.assert_target_os("illumos", "epoll_create1"); + this.assert_target_os(Os::Illumos, "epoll_create1"); let [flag] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let result = this.epoll_create1(flag)?; this.write_scalar(result, dest)?; } "epoll_ctl" => { - this.assert_target_os("illumos", "epoll_ctl"); + this.assert_target_os(Os::Illumos, "epoll_ctl"); let [epfd, op, fd, event] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let result = this.epoll_ctl(epfd, op, fd, event)?; this.write_scalar(result, dest)?; } "epoll_wait" => { - this.assert_target_os("illumos", "epoll_wait"); + this.assert_target_os(Os::Illumos, "epoll_wait"); let [epfd, events, maxevents, timeout] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; this.epoll_wait(epfd, events, maxevents, timeout, dest)?; } "eventfd" => { - this.assert_target_os("illumos", "eventfd"); + this.assert_target_os(Os::Illumos, "eventfd"); let [val, flag] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; let result = this.eventfd(val, flag)?; this.write_scalar(result, dest)?; diff --git a/src/shims/unix/sync.rs b/src/shims/unix/sync.rs index 57dbe2cd33..39014f34c8 100644 --- a/src/shims/unix/sync.rs +++ b/src/shims/unix/sync.rs @@ -1,4 +1,5 @@ use rustc_abi::Size; +use rustc_target::spec::Os; use crate::concurrency::sync::{AccessKind, SyncObj}; use crate::*; @@ -29,8 +30,8 @@ const PTHREAD_INIT: u8 = 1; #[inline] fn mutexattr_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> { - interp_ok(match &*ecx.tcx.sess.target.os { - "linux" | "illumos" | "solaris" | "macos" | "freebsd" | "android" => 0, + interp_ok(match &ecx.tcx.sess.target.os { + Os::Linux | Os::Illumos | Os::Solaris | Os::MacOs | Os::FreeBsd | Os::Android => 0, os => throw_unsup_format!("`pthread_mutexattr` is not supported on {os}"), }) } @@ -128,10 +129,10 @@ impl SyncObj for PthreadMutex { /// a statically initialized mutex that is used the first time, we pick some offset within /// `pthread_mutex_t` and use it as an "initialized" flag. fn mutex_init_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, Size> { - let offset = match &*ecx.tcx.sess.target.os { - "linux" | "illumos" | "solaris" | "freebsd" | "android" => 0, + let offset = match &ecx.tcx.sess.target.os { + Os::Linux | Os::Illumos | Os::Solaris | Os::FreeBsd | Os::Android => 0, // macOS stores a signature in the first bytes, so we move to offset 4. - "macos" => 4, + Os::MacOs => 4, os => throw_unsup_format!("`pthread_mutex` is not supported on {os}"), }; let offset = Size::from_bytes(offset); @@ -152,13 +153,13 @@ fn mutex_init_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, Size> check_static_initializer("PTHREAD_MUTEX_INITIALIZER"); // Check non-standard initializers. - match &*ecx.tcx.sess.target.os { - "linux" => { + match &ecx.tcx.sess.target.os { + Os::Linux => { check_static_initializer("PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP"); check_static_initializer("PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP"); check_static_initializer("PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP"); } - "illumos" | "solaris" | "macos" | "freebsd" | "android" => { + Os::Illumos | Os::Solaris | Os::MacOs | Os::FreeBsd | Os::Android => { // No non-standard initializers. } os => throw_unsup_format!("`pthread_mutex` is not supported on {os}"), @@ -215,8 +216,8 @@ fn mutex_kind_from_static_initializer<'tcx>( return interp_ok(MutexKind::Default); } // Support additional platform-specific initializers. - match &*ecx.tcx.sess.target.os { - "linux" => + match &ecx.tcx.sess.target.os { + Os::Linux => if is_initializer("PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP")? { return interp_ok(MutexKind::Recursive); } else if is_initializer("PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP")? { @@ -254,10 +255,10 @@ impl SyncObj for PthreadRwLock { } fn rwlock_init_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, Size> { - let offset = match &*ecx.tcx.sess.target.os { - "linux" | "illumos" | "solaris" | "freebsd" | "android" => 0, + let offset = match &ecx.tcx.sess.target.os { + Os::Linux | Os::Illumos | Os::Solaris | Os::FreeBsd | Os::Android => 0, // macOS stores a signature in the first bytes, so we move to offset 4. - "macos" => 4, + Os::MacOs => 4, os => throw_unsup_format!("`pthread_rwlock` is not supported on {os}"), }; let offset = Size::from_bytes(offset); @@ -311,8 +312,8 @@ where #[inline] fn condattr_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> { - interp_ok(match &*ecx.tcx.sess.target.os { - "linux" | "illumos" | "solaris" | "freebsd" | "android" => 0, + interp_ok(match &ecx.tcx.sess.target.os { + Os::Linux | Os::Illumos | Os::Solaris | Os::FreeBsd | Os::Android => 0, // macOS does not have a clock attribute. os => throw_unsup_format!("`pthread_condattr` clock field is not supported on {os}"), }) @@ -349,10 +350,10 @@ fn condattr_set_clock_id<'tcx>( // - init: u8 fn cond_init_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, Size> { - let offset = match &*ecx.tcx.sess.target.os { - "linux" | "illumos" | "solaris" | "freebsd" | "android" => 0, + let offset = match &ecx.tcx.sess.target.os { + Os::Linux | Os::Illumos | Os::Solaris | Os::FreeBsd | Os::Android => 0, // macOS stores a signature in the first bytes, so we move to offset 4. - "macos" => 4, + Os::MacOs => 4, os => throw_unsup_format!("`pthread_cond` is not supported on {os}"), }; let offset = Size::from_bytes(offset); @@ -748,7 +749,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let this = self.eval_context_mut(); // no clock attribute on macOS - if this.tcx.sess.target.os != "macos" { + if this.tcx.sess.target.os != Os::MacOs { // The default value of the clock attribute shall refer to the system // clock. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_condattr_setclock.html @@ -798,7 +799,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Destroying an uninit pthread_condattr is UB, so check to make sure it's not uninit. // There's no clock attribute on macOS. - if this.tcx.sess.target.os != "macos" { + if this.tcx.sess.target.os != Os::MacOs { condattr_get_clock_id(this, attr_op)?; } @@ -820,7 +821,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let attr = this.read_pointer(attr_op)?; // Default clock if `attr` is null, and on macOS where there is no clock attribute. - let clock_id = if this.ptr_is_null(attr)? || this.tcx.sess.target.os == "macos" { + let clock_id = if this.ptr_is_null(attr)? || this.tcx.sess.target.os == Os::MacOs { this.eval_libc("CLOCK_REALTIME") } else { condattr_get_clock_id(this, attr_op)? diff --git a/src/shims/unix/unnamed_socket.rs b/src/shims/unix/unnamed_socket.rs index 81703d6e17..4f4ec7183c 100644 --- a/src/shims/unix/unnamed_socket.rs +++ b/src/shims/unix/unnamed_socket.rs @@ -7,6 +7,8 @@ use std::collections::VecDeque; use std::io; use std::io::ErrorKind; +use rustc_target::spec::Os; + use crate::concurrency::VClock; use crate::shims::files::{ EvalContextExt as _, FileDescription, FileDescriptionRef, WeakFileDescriptionRef, @@ -448,7 +450,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Interpret the flag. Every flag we recognize is "subtracted" from `flags`, so // if there is anything left at the end, that's an unsupported flag. - if this.tcx.sess.target.os == "linux" { + if this.tcx.sess.target.os == Os::Linux { // SOCK_NONBLOCK only exists on Linux. let sock_nonblock = this.eval_libc_i32("SOCK_NONBLOCK"); let sock_cloexec = this.eval_libc_i32("SOCK_CLOEXEC"); diff --git a/src/shims/windows/env.rs b/src/shims/windows/env.rs index a7c26d601e..aabace4b7c 100644 --- a/src/shims/windows/env.rs +++ b/src/shims/windows/env.rs @@ -3,6 +3,7 @@ use std::ffi::{OsStr, OsString}; use std::io::ErrorKind; use rustc_data_structures::fx::FxHashMap; +use rustc_target::spec::Os; use self::helpers::windows_check_buffer_size; use crate::*; @@ -45,7 +46,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // ^ Returns DWORD (u32 on Windows) let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetEnvironmentVariableW"); + this.assert_target_os(Os::Windows, "GetEnvironmentVariableW"); let name_ptr = this.read_pointer(name_op)?; let buf_ptr = this.read_pointer(buf_op)?; @@ -73,7 +74,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn GetEnvironmentStringsW(&mut self) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetEnvironmentStringsW"); + this.assert_target_os(Os::Windows, "GetEnvironmentStringsW"); // Info on layout of environment blocks in Windows: // https://docs.microsoft.com/en-us/windows/win32/procthread/environment-variables @@ -95,7 +96,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn FreeEnvironmentStringsW(&mut self, env_block_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "FreeEnvironmentStringsW"); + this.assert_target_os(Os::Windows, "FreeEnvironmentStringsW"); let env_block_ptr = this.read_pointer(env_block_op)?; this.deallocate_ptr(env_block_ptr, None, MiriMemoryKind::Runtime.into())?; @@ -110,7 +111,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { value_op: &OpTy<'tcx>, // LPCWSTR ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "SetEnvironmentVariableW"); + this.assert_target_os(Os::Windows, "SetEnvironmentVariableW"); let name_ptr = this.read_pointer(name_op)?; let value_ptr = this.read_pointer(value_op)?; @@ -143,7 +144,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { buf_op: &OpTy<'tcx>, // LPTSTR ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetCurrentDirectoryW"); + this.assert_target_os(Os::Windows, "GetCurrentDirectoryW"); let size = u64::from(this.read_scalar(size_op)?.to_u32()?); let buf = this.read_pointer(buf_op)?; @@ -176,7 +177,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // ^ Returns BOOL (i32 on Windows) let this = self.eval_context_mut(); - this.assert_target_os("windows", "SetCurrentDirectoryW"); + this.assert_target_os(Os::Windows, "SetCurrentDirectoryW"); let path = this.read_path_from_wide_str(this.read_pointer(path_op)?)?; @@ -199,7 +200,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn GetCurrentProcessId(&mut self) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetCurrentProcessId"); + this.assert_target_os(Os::Windows, "GetCurrentProcessId"); interp_ok(Scalar::from_u32(this.get_pid())) } @@ -213,7 +214,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> // returns BOOL { let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetUserProfileDirectoryW"); + this.assert_target_os(Os::Windows, "GetUserProfileDirectoryW"); this.check_no_isolation("`GetUserProfileDirectoryW`")?; let token = this.read_target_isize(token)?; diff --git a/src/shims/windows/fs.rs b/src/shims/windows/fs.rs index e4ec1b0130..e36ed7bd70 100644 --- a/src/shims/windows/fs.rs +++ b/src/shims/windows/fs.rs @@ -5,6 +5,7 @@ use std::path::PathBuf; use std::time::SystemTime; use bitflags::bitflags; +use rustc_target::spec::Os; use crate::shims::files::{FileDescription, FileHandle}; use crate::shims::windows::handle::{EvalContextExt as _, Handle}; @@ -164,7 +165,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { use CreationDisposition::*; let this = self.eval_context_mut(); - this.assert_target_os("windows", "CreateFileW"); + this.assert_target_os(Os::Windows, "CreateFileW"); this.check_no_isolation("`CreateFileW`")?; // This function appears to always set the error to 0. This is important for some flag @@ -309,7 +310,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { // ^ Returns BOOL (i32 on Windows) let this = self.eval_context_mut(); - this.assert_target_os("windows", "GetFileInformationByHandle"); + this.assert_target_os(Os::Windows, "GetFileInformationByHandle"); this.check_no_isolation("`GetFileInformationByHandle`")?; let file = this.read_handle(file, "GetFileInformationByHandle")?; @@ -379,7 +380,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { // ^ Returns BOOL (i32 on Windows) let this = self.eval_context_mut(); - this.assert_target_os("windows", "DeleteFileW"); + this.assert_target_os(Os::Windows, "DeleteFileW"); this.check_no_isolation("`DeleteFileW`")?; let file_name = this.read_path_from_wide_str(this.read_pointer(file_name)?)?; From 87cec6283f912315defc71a0d3a8f92d0d5b6493 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Wed, 12 Nov 2025 04:54:23 +0000 Subject: [PATCH 08/12] Prepare for merging from rust-lang/rust This updates the rust-version file to 0b329f801a09004dacb19aaf09d5cb8b4c51d3f8. --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 04d41c96f5..7dde150d1e 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -8401398e1f14a24670ee1a3203713dc2f0f8b3a8 +0b329f801a09004dacb19aaf09d5cb8b4c51d3f8 From 05843bcba0d4b3d5d42f96e3cb5dab0afffd201a Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Wed, 12 Nov 2025 05:02:50 +0000 Subject: [PATCH 09/12] fmt --- src/shims/foreign_items.rs | 2 +- src/shims/unix/foreign_items.rs | 22 +++++++++++++--------- src/shims/unix/fs.rs | 12 ++++++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 69a028e485..440388673e 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -15,7 +15,7 @@ use rustc_middle::{mir, ty}; use rustc_session::config::OomStrategy; use rustc_span::Symbol; use rustc_target::callconv::FnAbi; -use rustc_target::spec::{Os, Arch}; +use rustc_target::spec::{Arch, Os}; use super::alloc::EvalContextExt as _; use super::backtrace::EvalContextExt as _; diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index e2d27e5702..a37a34f8df 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -27,14 +27,15 @@ pub fn is_dyn_sym(name: &str, target_os: &Os) -> bool { // needed at least on macOS to avoid file-based fallback in getrandom "getentropy" | "getrandom" => true, // Give specific OSes a chance to allow their symbols. - _ => match *target_os { - Os::Android => android::is_dyn_sym(name), - Os::FreeBsd => freebsd::is_dyn_sym(name), - Os::Linux => linux::is_dyn_sym(name), - Os::MacOs => macos::is_dyn_sym(name), - Os::Solaris | Os::Illumos => solarish::is_dyn_sym(name), - _ => false, - }, + _ => + match *target_os { + Os::Android => android::is_dyn_sym(name), + Os::FreeBsd => freebsd::is_dyn_sym(name), + Os::Linux => linux::is_dyn_sym(name), + Os::MacOs => macos::is_dyn_sym(name), + Os::Solaris | Os::Illumos => solarish::is_dyn_sym(name), + _ => false, + }, } } @@ -530,7 +531,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } "pipe2" => { // Currently this function does not exist on all Unixes, e.g. on macOS. - this.check_target_os(&[Os::Linux, Os::FreeBsd, Os::Solaris, Os::Illumos], link_name)?; + this.check_target_os( + &[Os::Linux, Os::FreeBsd, Os::Solaris, Os::Illumos], + link_name, + )?; let [pipefd, flags] = this.check_shim_sig( shim_sig!(extern "C" fn(*mut _, i32) -> i32), link_name, diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 0760125917..137e60aaba 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -530,7 +530,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) + { panic!("`macos_fbsd_solaris_stat` should not be called on {}", this.tcx.sess.target.os); } @@ -560,7 +561,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) + { panic!( "`macos_fbsd_solaris_lstat` should not be called on {}", this.tcx.sess.target.os @@ -591,7 +593,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) { + if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd | Os::Solaris | Os::Illumos) + { panic!( "`macos_fbsd_solaris_fstat` should not be called on {}", this.tcx.sess.target.os @@ -904,7 +907,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn readdir64(&mut self, dirent_type: &str, dirp_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - if !matches!(&this.tcx.sess.target.os, Os::Linux | Os::Solaris | Os::Illumos | Os::FreeBsd) { + if !matches!(&this.tcx.sess.target.os, Os::Linux | Os::Solaris | Os::Illumos | Os::FreeBsd) + { panic!("`linux_solaris_readdir64` should not be called on {}", this.tcx.sess.target.os); } From 29bfe95cb43973424b870d8086bf109413e5647c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Nov 2025 08:06:41 +0100 Subject: [PATCH 10/12] update lockfile --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d66529a464..a2b02f286d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,9 +1519,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b" dependencies = [ "cc", "libc", From 205a2875abbc8db5f4a665361adab53530d998b4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Nov 2025 08:06:51 +0100 Subject: [PATCH 11/12] fix function_casts_as_integer lint --- src/shims/native_lib/trace/parent.rs | 10 ++++------ tests/pass/backtrace/backtrace-api-v1.rs | 2 -- tests/pass/backtrace/backtrace-api-v1.stdout | 10 +++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/shims/native_lib/trace/parent.rs b/src/shims/native_lib/trace/parent.rs index f6ebbc469f..5476cccc02 100644 --- a/src/shims/native_lib/trace/parent.rs +++ b/src/shims/native_lib/trace/parent.rs @@ -500,9 +500,8 @@ fn handle_segfault( capstone_disassemble(&instr, addr, cs, acc_events).expect("Failed to disassemble instruction"); // Move the instr ptr into the deprotection code. - #[allow(unknown_lints)] - #[expect(clippy::as_conversions, function_casts_as_integer)] - new_regs.set_ip(mempr_off as usize); + #[expect(clippy::as_conversions)] + new_regs.set_ip(mempr_off as *const () as usize); // Don't mess up the stack by accident! new_regs.set_sp(stack_ptr); @@ -553,9 +552,8 @@ fn handle_segfault( new_regs = regs_bak; // Reprotect everything and continue. - #[allow(unknown_lints)] - #[expect(clippy::as_conversions, function_casts_as_integer)] - new_regs.set_ip(mempr_on as usize); + #[expect(clippy::as_conversions)] + new_regs.set_ip(mempr_on as *const () as usize); new_regs.set_sp(stack_ptr); ptrace::setregs(pid, new_regs).unwrap(); wait_for_signal(Some(pid), signal::SIGSTOP, InitialCont::Yes)?; diff --git a/tests/pass/backtrace/backtrace-api-v1.rs b/tests/pass/backtrace/backtrace-api-v1.rs index cf6f43dbbf..a3060abc39 100644 --- a/tests/pass/backtrace/backtrace-api-v1.rs +++ b/tests/pass/backtrace/backtrace-api-v1.rs @@ -1,7 +1,5 @@ //@normalize-stderr-test: "::<.*>" -> "" -#![allow(function_casts_as_integer)] - #[inline(never)] fn func_a() -> Box<[*mut ()]> { func_b::() diff --git a/tests/pass/backtrace/backtrace-api-v1.stdout b/tests/pass/backtrace/backtrace-api-v1.stdout index b3a4beb4e8..5c2995e132 100644 --- a/tests/pass/backtrace/backtrace-api-v1.stdout +++ b/tests/pass/backtrace/backtrace-api-v1.stdout @@ -1,5 +1,5 @@ -tests/pass/backtrace/backtrace-api-v1.rs:29:9 (func_d) -tests/pass/backtrace/backtrace-api-v1.rs:16:9 (func_c) -tests/pass/backtrace/backtrace-api-v1.rs:11:5 (func_b::) -tests/pass/backtrace/backtrace-api-v1.rs:7:5 (func_a) -tests/pass/backtrace/backtrace-api-v1.rs:36:18 (main) +tests/pass/backtrace/backtrace-api-v1.rs:27:9 (func_d) +tests/pass/backtrace/backtrace-api-v1.rs:14:9 (func_c) +tests/pass/backtrace/backtrace-api-v1.rs:9:5 (func_b::) +tests/pass/backtrace/backtrace-api-v1.rs:5:5 (func_a) +tests/pass/backtrace/backtrace-api-v1.rs:34:18 (main) From 76ed8877fd79f0d62352019870dbbbd9484ad15d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Nov 2025 08:22:58 +0100 Subject: [PATCH 12/12] try to be more robust against short hickups in the Ubuntu Ports mirrors --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27d2f4a6df..a61a467ebc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,10 @@ jobs: sudo bash -c "echo 'https://ports.ubuntu.com/ priority:4' >> /etc/apt/apt-mirrors.txt" # Add architecture sudo dpkg --add-architecture ${{ matrix.multiarch }} - sudo apt update + # Ubuntu Ports often has outdated mirrors so try a few times to get the apt repo + for TRY in $(seq 3); do + { sudo apt update && break; } || sleep 30 + done # Install needed packages sudo apt install $(echo "libatomic1: zlib1g-dev:" | sed 's/:/:${{ matrix.multiarch }}/g') - uses: ./.github/workflows/setup