-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
diff --git a/src/shims/unix/freebsd/mod.rs b/src/shims/unix/freebsd/mod.rs | ||
new file mode 100644 | ||
index 00000000..329f2217 | ||
--- /dev/null | ||
+++ b/src/shims/unix/freebsd/mod.rs | ||
@@ -0,0 +1 @@ | ||
+// placeholder | ||
\ No newline at end of file | ||
diff --git a/src/shims/unix/mod.rs b/src/shims/unix/mod.rs | ||
index f40dfaef..4002b056 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 bf5ae982..20a06ffb 100644 | ||
--- a/tests/pass/libc.rs | ||
+++ b/tests/pass/libc.rs | ||
@@ -5,12 +5,12 @@ | ||
|
||
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}; | ||
@@ -40,7 +40,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; | ||
@@ -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")] | ||
+#[cfg(target_os = "linux,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")] | ||
+#[cfg(target_os = "linux,freebsd")] | ||
fn test_clocks() { | ||
let mut tp = std::mem::MaybeUninit::<libc::timespec>::uninit(); | ||
let is_error = unsafe { | ||
@@ -252,11 +252,18 @@ fn test_clocks() { | ||
assert_eq!(is_error, 0); | ||
} | ||
|
||
+#[cfg(target_os = "linux,freebsd,macos")] | ||
+fn test_getpid() { | ||
+ unsafe { | ||
+ assert_eq!(libc::getpid(), std::process::id()); | ||
+ } | ||
+} | ||
+ | ||
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(); | ||
@@ -264,14 +271,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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 { | ||
// 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<Dlsym>> { | ||
Ok(match name { | ||
"getentropy" => Some(Dlsym::getentropy), | ||
_ => throw_unsup_format!("unsupported macOS 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<mir::BasicBlock>, | ||
) -> 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"); | ||
|
||
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)); | ||
this.go_to_block(ret); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod foreign_items; | ||
pub mod dlsym; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ mod thread; | |
|
||
mod linux; | ||
mod macos; | ||
mod freebsd; | ||
|
||
pub use fs::{DirHandler, FileHandler}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters