From 97a512070aa6d648ddde025a7cc9784fad7624f9 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Thu, 9 Jun 2022 16:50:34 +0200 Subject: [PATCH] Fix pending reviews --- src/shims/unix/dlsym.rs | 7 ++++--- src/shims/unix/freebsd/dlsym.rs | 5 +---- src/shims/unix/freebsd/foreign_items.rs | 2 +- src/shims/unix/freebsd/mod.rs | 2 +- src/shims/unix/macos/dlsym.rs | 7 +++++-- src/shims/unix/mod.rs | 2 +- tests/pass/libc.rs | 20 ++++++++++---------- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/shims/unix/dlsym.rs b/src/shims/unix/dlsym.rs index f183971b59a..e1f819fb856 100644 --- a/src/shims/unix/dlsym.rs +++ b/src/shims/unix/dlsym.rs @@ -2,15 +2,15 @@ use rustc_middle::mir; use rustc_target::spec::abi::Abi; use crate::*; +use shims::unix::freebsd::dlsym as freebsd; use shims::unix::linux::dlsym as linux; use shims::unix::macos::dlsym as macos; -use shims::unix::freebsd::dlsym as freebsd; #[derive(Debug, Copy, Clone)] pub enum Dlsym { Linux(linux::Dlsym), MacOs(macos::Dlsym), - FreeBSD(freebsd::Dlsym) + FreeBSD(freebsd::Dlsym), } impl Dlsym { @@ -43,7 +43,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx match dlsym { Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret), Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret), - Dlsym::FreeBSD(dlsym) => freebsd::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret) + Dlsym::FreeBSD(dlsym) => + freebsd::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret), } } } diff --git a/src/shims/unix/freebsd/dlsym.rs b/src/shims/unix/freebsd/dlsym.rs index 57125c14fa0..18347d274e9 100644 --- a/src/shims/unix/freebsd/dlsym.rs +++ b/src/shims/unix/freebsd/dlsym.rs @@ -1,13 +1,10 @@ use rustc_middle::mir; use crate::*; -use helpers::check_arg_count; #[derive(Debug, Copy, Clone)] #[allow(non_camel_case_types)] -pub enum Dlsym { - getentropy, -} +pub enum Dlsym {} impl Dlsym { // Returns an error for unsupported symbols, and None if this symbol diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index ac261cecc2e..71272523886 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -20,4 +20,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // match Ok(EmulateByNameResult::NeedsJumping) } -} \ No newline at end of file +} diff --git a/src/shims/unix/freebsd/mod.rs b/src/shims/unix/freebsd/mod.rs index 428d997d787..434f5f30b5a 100644 --- a/src/shims/unix/freebsd/mod.rs +++ b/src/shims/unix/freebsd/mod.rs @@ -1,2 +1,2 @@ +pub mod dlsym; pub mod foreign_items; -pub mod dlsym; \ No newline at end of file diff --git a/src/shims/unix/macos/dlsym.rs b/src/shims/unix/macos/dlsym.rs index ee0ff01c05e..2e97b7918e9 100644 --- a/src/shims/unix/macos/dlsym.rs +++ b/src/shims/unix/macos/dlsym.rs @@ -3,10 +3,12 @@ use rustc_middle::mir; use log::trace; use crate::*; +use helpers::check_arg_count; #[derive(Debug, Copy, Clone)] #[allow(non_camel_case_types)] pub enum Dlsym { + getentropy, } impl Dlsym { @@ -14,7 +16,8 @@ impl Dlsym { // should become a NULL pointer (pretend it does not exist). pub fn from_str<'tcx>(name: &str) -> InterpResult<'tcx, Option> { Ok(match name { - _ => throw_unsup_format!("unsupported freebsd dlsym: {}", name), + "getentropy" => Some(Dlsym::getentropy), + _ => throw_unsup_format!("unsupported macOS dlsym: {}", name), }) } } @@ -30,7 +33,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let ret = ret.expect("we don't support any diverging dlsym"); - assert!(this.tcx.sess.target.os == "freebsd"); + assert!(this.tcx.sess.target.os == "macos"); match dlsym { Dlsym::getentropy => { diff --git a/src/shims/unix/mod.rs b/src/shims/unix/mod.rs index 4002b056b4b..8e8c70bbd0f 100644 --- a/src/shims/unix/mod.rs +++ b/src/shims/unix/mod.rs @@ -5,8 +5,8 @@ mod fs; mod sync; mod thread; +mod freebsd; mod linux; mod macos; -mod freebsd; pub use fs::{DirHandler, FileHandler}; diff --git a/tests/pass/libc.rs b/tests/pass/libc.rs index 0b6bc643953..e73e796449c 100644 --- a/tests/pass/libc.rs +++ b/tests/pass/libc.rs @@ -5,14 +5,14 @@ extern crate libc; -#[cfg(target_os = "linux, freebsd")] +#[cfg(any(target_os = "linux", target_os = "freebsd"))] fn tmp() -> std::path::PathBuf { std::env::var("MIRI_TEMP") .map(std::path::PathBuf::from) .unwrap_or_else(|_| std::env::temp_dir()) } -#[cfg(target_os = "linux, freebsd")] +#[cfg(any(target_os = "linux", target_os = "freebsd"))] fn test_posix_fadvise() { use std::convert::TryInto; use std::fs::{remove_file, File}; @@ -42,7 +42,7 @@ fn test_posix_fadvise() { assert_eq!(result, 0); } -#[cfg(target_os = "linux, freebsd")] +#[cfg(any(target_os = "linux", target_os = "freebsd"))] fn test_sync_file_range() { use std::fs::{remove_file, File}; use std::io::Write; @@ -208,7 +208,7 @@ fn test_rwlock_libc_static_initializer() { /// Test whether the `prctl` shim correctly sets the thread name. /// /// Note: `prctl` exists only on Linux. -#[cfg(target_os = "linux,freebsd")] +#[cfg(any(target_os = "linux", target_os = "freebsd"))] fn test_prctl_thread_name() { use libc::c_long; use std::ffi::CString; @@ -277,7 +277,7 @@ fn test_thread_local_errno() { } /// Tests whether clock support exists at all -#[cfg(target_os = "linux,freebsd")] +#[cfg(any(target_os = "linux", target_os = "freebsd"))] fn test_clocks() { let mut tp = std::mem::MaybeUninit::::uninit(); let is_error = unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, tp.as_mut_ptr()) }; @@ -291,10 +291,10 @@ fn test_clocks() { } fn main() { - #[cfg(target_os = "linux,freebsd")] + #[cfg(any(target_os = "linux", target_os = "freebsd"))] test_posix_fadvise(); - #[cfg(target_os = "linux,freebsd")] + #[cfg(any(target_os = "linux", target_os = "freebsd"))] test_sync_file_range(); test_mutex_libc_init_recursive(); @@ -302,14 +302,14 @@ fn main() { test_mutex_libc_init_errorcheck(); test_rwlock_libc_static_initializer(); - #[cfg(target_os = "linux,freebsd")] + #[cfg(any(target_os = "linux", target_os = "freebsd"))] test_mutex_libc_static_initializer_recursive(); - #[cfg(target_os = "linux,freebsd")] + #[cfg(any(target_os = "linux", target_os = "freebsd"))] test_prctl_thread_name(); test_thread_local_errno(); - #[cfg(target_os = "linux,freebsd")] + #[cfg(any(target_os = "linux", target_os = "freebsd"))] test_clocks(); }