Skip to content

Commit

Permalink
Fix pending reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ncMN committed Jun 9, 2022
1 parent 5f1ef76 commit dc3da65
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/shims/unix/dlsym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
}
}
15 changes: 3 additions & 12 deletions src/shims/unix/freebsd/dlsym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ 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),
_ => throw_unsup_format!("unsupported FreeBSD dlsym: {}", name),
})
}
}
Expand All @@ -33,16 +30,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));
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/freebsd/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// match
Ok(EmulateByNameResult::NeedsJumping)
}
}
}
2 changes: 1 addition & 1 deletion src/shims/unix/freebsd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod dlsym;
pub mod foreign_items;
pub mod dlsym;
14 changes: 12 additions & 2 deletions src/shims/unix/macos/dlsym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ 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 {
_ => throw_unsup_format!("unsupported freebsd dlsym: {}", name),
"getentropy" => Some(Dlsym::getentropy),
_ => throw_unsup_format!("unsupported macOS dlsym: {}", name),
})
}
}
Expand All @@ -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)?;
}
_ => {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ mod fs;
mod sync;
mod thread;

mod freebsd;
mod linux;
mod macos;
mod freebsd;

pub use fs::{DirHandler, FileHandler};
20 changes: 10 additions & 10 deletions tests/pass/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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::<libc::timespec>::uninit();
let is_error = unsafe {
Expand Down Expand Up @@ -260,25 +260,25 @@ 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();
test_mutex_libc_init_normal();
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();
}

0 comments on commit dc3da65

Please sign in to comment.