From 993d45335b265f5705c4d994739a7fe2eb2b1af2 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 | 18 ++++-------------- src/shims/unix/freebsd/foreign_items.rs | 2 +- src/shims/unix/freebsd/mod.rs | 2 +- src/shims/unix/macos/dlsym.rs | 14 ++++++++++++-- src/shims/unix/mod.rs | 2 +- tests/pass/libc.rs | 20 ++++++++++---------- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/shims/unix/dlsym.rs b/src/shims/unix/dlsym.rs index f183971b59..e1f819fb85 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 2e97b7918e..c9585be7e1 100644 --- a/src/shims/unix/freebsd/dlsym.rs +++ b/src/shims/unix/freebsd/dlsym.rs @@ -3,21 +3,17 @@ 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, -} +pub enum Dlsym {} impl Dlsym { // Returns an error for unsupported symbols, and None if this symbol // should become a NULL pointer (pretend it does not exist). pub fn from_str<'tcx>(name: &str) -> InterpResult<'tcx, Option> { Ok(match name { - "getentropy" => Some(Dlsym::getentropy), - _ => throw_unsup_format!("unsupported macOS dlsym: {}", name), + _ => throw_unsup_format!("unsupported FreeBSD dlsym: {}", name), }) } } @@ -33,16 +29,10 @@ 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 == "macos"); + assert!(this.tcx.sess.target.os == "freebsd"); match dlsym { - Dlsym::getentropy => { - let [ptr, len] = check_arg_count(args)?; - let ptr = this.read_pointer(ptr)?; - let len = this.read_scalar(len)?.to_machine_usize(this)?; - this.gen_random(ptr, len)?; - this.write_null(dest)?; - } + _ => {} } trace!("{:?}", this.dump_place(**dest)); diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index ac261cecc2..7127252388 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 428d997d78..434f5f30b5 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 2b478a4df2..73c68ad1ba 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,9 +33,16 @@ 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 => { + let [ptr, len] = check_arg_count(args)?; + let ptr = this.read_pointer(ptr)?; + let len = this.read_scalar(len)?.to_machine_usize(this)?; + this.gen_random(ptr, len)?; + this.write_null(dest)?; + } _ => {} } diff --git a/src/shims/unix/mod.rs b/src/shims/unix/mod.rs index 4002b056b4..8e8c70bbd0 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 20a06ffb2f..f407a7f87a 100644 --- a/tests/pass/libc.rs +++ b/tests/pass/libc.rs @@ -5,12 +5,12 @@ 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}; @@ -40,7 +40,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; @@ -191,7 +191,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 std::ffi::CString; use libc::c_long; @@ -231,7 +231,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 { @@ -260,10 +260,10 @@ fn test_getpid() { } 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(); @@ -271,14 +271,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(); }