From 9130034337b30e975beb2c265e309187c574561e Mon Sep 17 00:00:00 2001 From: infrandomness Date: Thu, 9 Jun 2022 16:06:07 +0200 Subject: [PATCH 1/9] Initial freebsd work --- ci.sh | 1 + src/helpers.rs | 2 +- src/shims/unix/dlsym.rs | 4 +++ src/shims/unix/foreign_items.rs | 1 + src/shims/unix/freebsd/dlsym.rs | 35 +++++++++++++++++++++++++ src/shims/unix/freebsd/foreign_items.rs | 23 ++++++++++++++++ src/shims/unix/freebsd/mod.rs | 2 ++ src/shims/unix/macos/dlsym.rs | 7 ++--- src/shims/unix/mod.rs | 1 + tests/pass/libc.rs | 20 +++++++------- 10 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 src/shims/unix/freebsd/dlsym.rs create mode 100644 src/shims/unix/freebsd/foreign_items.rs create mode 100644 src/shims/unix/freebsd/mod.rs diff --git a/ci.sh b/ci.sh index 01b86ff2f9..f436e0179a 100755 --- a/ci.sh +++ b/ci.sh @@ -50,6 +50,7 @@ case $HOST_TARGET in MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests MIRI_TEST_TARGET=aarch64-apple-darwin run_tests MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests + MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests ;; x86_64-apple-darwin) MIRI_TEST_TARGET=mips64-unknown-linux-gnuabi64 run_tests # big-endian architecture diff --git a/src/helpers.rs b/src/helpers.rs index 134f556bf1..86823f2817 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -910,5 +910,5 @@ impl std::fmt::Display for HexRange { /// Helper function used inside the shims of foreign functions to check that /// `target_os` is a supported UNIX OS. pub fn target_os_is_unix(target_os: &str) -> bool { - matches!(target_os, "linux" | "macos") + matches!(target_os, "linux" | "macos" | "freebsd") } diff --git a/src/shims/unix/dlsym.rs b/src/shims/unix/dlsym.rs index 578ae488a9..f183971b59 100644 --- a/src/shims/unix/dlsym.rs +++ b/src/shims/unix/dlsym.rs @@ -4,11 +4,13 @@ use rustc_target::spec::abi::Abi; use crate::*; 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) } impl Dlsym { @@ -18,6 +20,7 @@ impl Dlsym { Ok(match target_os { "linux" => linux::Dlsym::from_str(name)?.map(Dlsym::Linux), "macos" => macos::Dlsym::from_str(name)?.map(Dlsym::MacOs), + "freebsd" => freebsd::Dlsym::from_str(name)?.map(Dlsym::FreeBSD), _ => unreachable!(), }) } @@ -40,6 +43,7 @@ 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) } } } diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index d002ab75b9..d789b0c640 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -485,6 +485,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx match this.tcx.sess.target.os.as_ref() { "linux" => return shims::unix::linux::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest, ret), "macos" => return shims::unix::macos::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest, ret), + "freebsd" => return shims::unix::freebsd::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest, ret), _ => unreachable!(), } } diff --git a/src/shims/unix/freebsd/dlsym.rs b/src/shims/unix/freebsd/dlsym.rs new file mode 100644 index 0000000000..57125c14fa --- /dev/null +++ b/src/shims/unix/freebsd/dlsym.rs @@ -0,0 +1,35 @@ +use rustc_middle::mir; + +use crate::*; +use helpers::check_arg_count; + +#[derive(Debug, Copy, Clone)] +#[allow(non_camel_case_types)] +pub enum Dlsym { + getentropy, +} + +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> { + throw_unsup_format!("unsupported FreeBSD dlsym: {}", name) + } +} + +impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} +pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { + fn call_dlsym( + &mut self, + dlsym: Dlsym, + _args: &[OpTy<'tcx, Tag>], + _dest: &PlaceTy<'tcx, Tag>, + ret: Option, + ) -> 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"); + + match dlsym {} + } +} diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs new file mode 100644 index 0000000000..ac261cecc2 --- /dev/null +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -0,0 +1,23 @@ +use rustc_middle::mir; +use rustc_span::Symbol; +use rustc_target::spec::abi::Abi; + +use crate::*; +use shims::foreign_items::EmulateByNameResult; + +impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} + +pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { + fn emulate_foreign_item_by_name( + &mut self, + link_name: Symbol, + abi: Abi, + args: &[OpTy<'tcx, Tag>], + dest: &PlaceTy<'tcx, Tag>, + _ret: mir::BasicBlock, + ) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { + let this = self.eval_context_mut(); + // 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 new file mode 100644 index 0000000000..428d997d78 --- /dev/null +++ b/src/shims/unix/freebsd/mod.rs @@ -0,0 +1,2 @@ +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 2e97b7918e..ee0ff01c05 100644 --- a/src/shims/unix/macos/dlsym.rs +++ b/src/shims/unix/macos/dlsym.rs @@ -3,12 +3,10 @@ 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 { @@ -16,8 +14,7 @@ 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 { - "getentropy" => Some(Dlsym::getentropy), - _ => throw_unsup_format!("unsupported macOS dlsym: {}", name), + _ => throw_unsup_format!("unsupported freebsd dlsym: {}", name), }) } } @@ -33,7 +30,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 == "macos"); + assert!(this.tcx.sess.target.os == "freebsd"); match dlsym { Dlsym::getentropy => { diff --git a/src/shims/unix/mod.rs b/src/shims/unix/mod.rs index f40dfaefb9..4002b056b4 100644 --- a/src/shims/unix/mod.rs +++ b/src/shims/unix/mod.rs @@ -7,5 +7,6 @@ mod thread; mod linux; mod macos; +mod freebsd; pub use fs::{DirHandler, FileHandler}; diff --git a/tests/pass/libc.rs b/tests/pass/libc.rs index f97b9dd2b9..0b6bc64395 100644 --- a/tests/pass/libc.rs +++ b/tests/pass/libc.rs @@ -5,14 +5,14 @@ extern crate libc; -#[cfg(target_os = "linux")] +#[cfg(target_os = "linux, 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")] +#[cfg(target_os = "linux, 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")] +#[cfg(target_os = "linux, 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")] +#[cfg(target_os = "linux,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")] +#[cfg(target_os = "linux,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")] + #[cfg(target_os = "linux,freebsd")] test_posix_fadvise(); - #[cfg(target_os = "linux")] + #[cfg(target_os = "linux,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")] + #[cfg(target_os = "linux,freebsd")] test_mutex_libc_static_initializer_recursive(); - #[cfg(target_os = "linux")] + #[cfg(target_os = "linux,freebsd")] test_prctl_thread_name(); test_thread_local_errno(); - #[cfg(target_os = "linux")] + #[cfg(target_os = "linux,freebsd")] test_clocks(); } From 97a512070aa6d648ddde025a7cc9784fad7624f9 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Thu, 9 Jun 2022 16:50:34 +0200 Subject: [PATCH 2/9] 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 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 57125c14fa..18347d274e 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 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 ee0ff01c05..2e97b7918e 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 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 0b6bc64395..e73e796449 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(); } From e89b4d6df22e2056f2651d685f67d666908d079a Mon Sep 17 00:00:00 2001 From: infrandomness Date: Fri, 10 Jun 2022 12:12:20 +0200 Subject: [PATCH 3/9] Fix panicking ui_tests framework --- src/shims/unix/freebsd/foreign_items.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index 7127252388..0efc44af82 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -17,7 +17,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx _ret: mir::BasicBlock, ) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { let this = self.eval_context_mut(); - // match + match link_name.as_str() { + _ => return Ok(EmulateByNameResult::NotSupported), + } Ok(EmulateByNameResult::NeedsJumping) } } From f2cbd3e2bc732186d8aafea9f930fcc3b0c34ce0 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Sun, 12 Jun 2022 11:47:43 +0200 Subject: [PATCH 4/9] Add `pthread_attr_getstack` shim --- src/shims/unix/freebsd/foreign_items.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index 0efc44af82..4ff588e51a 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -18,6 +18,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { let this = self.eval_context_mut(); match link_name.as_str() { + // Querying system information + "pthread_attr_getstack" => { + // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. + let [attr_place, addr_place, size_place] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + this.deref_operand(attr_place)?; + let addr_place = this.deref_operand(addr_place)?; + let size_place = this.deref_operand(size_place)?; + + this.write_scalar( + Scalar::from_uint(STACK_ADDR, this.pointer_size()), + &addr_place.into(), + )?; + this.write_scalar( + Scalar::from_uint(STACK_SIZE, this.pointer_size()), + &size_place.into(), + )?; + + // Return success (`0`). + this.write_null(dest)?; + } _ => return Ok(EmulateByNameResult::NotSupported), } Ok(EmulateByNameResult::NeedsJumping) From 93c61f3905d9ee123dd3ff2e07a48ed428a52e72 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Sun, 12 Jun 2022 11:47:59 +0200 Subject: [PATCH 5/9] Add `pthread_attr_get_np` shim --- src/shims/unix/freebsd/foreign_items.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index 4ff588e51a..b1d0eed2c0 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -39,6 +39,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Return success (`0`). this.write_null(dest)?; } + + // Linux's `pthread_getattr_np` equivalent + "pthread_attr_get_np" if this.frame_in_std() => { + let [_thread, _attr] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + this.write_null(dest)?; + } _ => return Ok(EmulateByNameResult::NotSupported), } Ok(EmulateByNameResult::NeedsJumping) From aaa8ebb5765146665cb5b8fdc88d12c9b67d0ca5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 26 Jun 2022 16:20:37 -0400 Subject: [PATCH 6/9] only test a few tests on FreeBSD --- ci.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ci.sh b/ci.sh index f436e0179a..1fa67f5213 100755 --- a/ci.sh +++ b/ci.sh @@ -42,6 +42,16 @@ function run_tests { echo } +function run_tests_minimal { + if [ -n "${MIRI_TEST_TARGET+exists}" ]; then + echo "Testing MINIMAL foreign architecture $MIRI_TEST_TARGET: only testing $@" + else + echo "Testing MINIMAL host architecture: only testing $@" + fi + + ./miri test --locked -- "$@" +} + # host run_tests @@ -50,7 +60,7 @@ case $HOST_TARGET in MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests MIRI_TEST_TARGET=aarch64-apple-darwin run_tests MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests - MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests + MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec ;; x86_64-apple-darwin) MIRI_TEST_TARGET=mips64-unknown-linux-gnuabi64 run_tests # big-endian architecture From 84a02787d8cc81f10bc9119dec5239c687915210 Mon Sep 17 00:00:00 2001 From: infrandomness Date: Mon, 27 Jun 2022 01:13:13 +0200 Subject: [PATCH 7/9] Address code review - Merge pthread_attr_getstack shim to unix/foreign_items.rs --- src/shims/unix/foreign_items.rs | 22 ++++++++++++++++++++++ src/shims/unix/freebsd/foreign_items.rs | 22 ---------------------- src/shims/unix/linux/foreign_items.rs | 22 +--------------------- 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index d789b0c640..4993690767 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -461,6 +461,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_null(dest)?; } + // Querying system information + "pthread_attr_getstack" => { + // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. + let [attr_place, addr_place, size_place] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + this.deref_operand(attr_place)?; + let addr_place = this.deref_operand(addr_place)?; + let size_place = this.deref_operand(size_place)?; + + this.write_scalar( + Scalar::from_uint(STACK_ADDR, this.pointer_size()), + &addr_place.into(), + )?; + this.write_scalar( + Scalar::from_uint(STACK_SIZE, this.pointer_size()), + &size_place.into(), + )?; + + // Return success (`0`). + this.write_null(dest)?; + } + | "signal" | "sigaltstack" if this.frame_in_std() => { diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index b1d0eed2c0..cad1192337 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -18,28 +18,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> { let this = self.eval_context_mut(); match link_name.as_str() { - // Querying system information - "pthread_attr_getstack" => { - // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. - let [attr_place, addr_place, size_place] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - this.deref_operand(attr_place)?; - let addr_place = this.deref_operand(addr_place)?; - let size_place = this.deref_operand(size_place)?; - - this.write_scalar( - Scalar::from_uint(STACK_ADDR, this.pointer_size()), - &addr_place.into(), - )?; - this.write_scalar( - Scalar::from_uint(STACK_SIZE, this.pointer_size()), - &size_place.into(), - )?; - - // Return success (`0`). - this.write_null(dest)?; - } - // Linux's `pthread_getattr_np` equivalent "pthread_attr_get_np" if this.frame_in_std() => { let [_thread, _attr] = diff --git a/src/shims/unix/linux/foreign_items.rs b/src/shims/unix/linux/foreign_items.rs index ab3f39147c..500250745c 100644 --- a/src/shims/unix/linux/foreign_items.rs +++ b/src/shims/unix/linux/foreign_items.rs @@ -80,27 +80,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::from_i32(result), dest)?; } - // Querying system information - "pthread_attr_getstack" => { - // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. - let [attr_place, addr_place, size_place] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - this.deref_operand(attr_place)?; - let addr_place = this.deref_operand(addr_place)?; - let size_place = this.deref_operand(size_place)?; - - this.write_scalar( - Scalar::from_uint(STACK_ADDR, this.pointer_size()), - &addr_place.into(), - )?; - this.write_scalar( - Scalar::from_uint(STACK_SIZE, this.pointer_size()), - &size_place.into(), - )?; - - // Return success (`0`). - this.write_null(dest)?; - } + // Threading "prctl" => { From aa072d72ccf79e313ef28b73a8bced367d9a4a6f Mon Sep 17 00:00:00 2001 From: infrandomness Date: Mon, 27 Jun 2022 01:22:13 +0200 Subject: [PATCH 8/9] Cargo fmt --- src/shims/unix/linux/foreign_items.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shims/unix/linux/foreign_items.rs b/src/shims/unix/linux/foreign_items.rs index 500250745c..48abe9bf08 100644 --- a/src/shims/unix/linux/foreign_items.rs +++ b/src/shims/unix/linux/foreign_items.rs @@ -80,8 +80,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::from_i32(result), dest)?; } - - // Threading "prctl" => { // prctl is variadic. (It is not documented like that in the manpage, but defined like that in the libc crate.) From 5719897fb0ba0a91fd1b094019c5caf7f58e6e9f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 27 Jun 2022 13:38:32 -0400 Subject: [PATCH 9/9] improve old comment --- src/shims/unix/foreign_items.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 4993690767..d0c93ef4cd 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -463,10 +463,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Querying system information "pthread_attr_getstack" => { - // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. + // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. Hence we can mostly ignore the input `attr_place`. let [attr_place, addr_place, size_place] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - this.deref_operand(attr_place)?; + let _attr_place = this.deref_operand(attr_place)?; let addr_place = this.deref_operand(addr_place)?; let size_place = this.deref_operand(size_place)?;