Skip to content

Commit 263bfda

Browse files
committed
Fix pending reviews
1 parent ee9146b commit 263bfda

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

src/shims/unix/dlsym.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use rustc_middle::mir;
22
use rustc_target::spec::abi::Abi;
33

44
use crate::*;
5+
use shims::unix::freebsd::dlsym as freebsd;
56
use shims::unix::linux::dlsym as linux;
67
use shims::unix::macos::dlsym as macos;
7-
use shims::unix::freebsd::dlsym as freebsd;
88

99
#[derive(Debug, Copy, Clone)]
1010
pub enum Dlsym {
1111
Linux(linux::Dlsym),
1212
MacOs(macos::Dlsym),
13-
FreeBSD(freebsd::Dlsym)
13+
FreeBSD(freebsd::Dlsym),
1414
}
1515

1616
impl Dlsym {
@@ -43,7 +43,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4343
match dlsym {
4444
Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret),
4545
Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret),
46-
Dlsym::FreeBSD(dlsym) => freebsd::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret)
46+
Dlsym::FreeBSD(dlsym) =>
47+
freebsd::EvalContextExt::call_dlsym(this, dlsym, args, dest, ret),
4748
}
4849
}
4950
}

src/shims/unix/freebsd/dlsym.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@ use rustc_middle::mir;
33
use log::trace;
44

55
use crate::*;
6-
use helpers::check_arg_count;
76

87
#[derive(Debug, Copy, Clone)]
98
#[allow(non_camel_case_types)]
10-
pub enum Dlsym {
11-
getentropy,
12-
}
9+
pub enum Dlsym {}
1310

1411
impl Dlsym {
1512
// Returns an error for unsupported symbols, and None if this symbol
1613
// should become a NULL pointer (pretend it does not exist).
1714
pub fn from_str<'tcx>(name: &str) -> InterpResult<'tcx, Option<Dlsym>> {
1815
Ok(match name {
19-
"getentropy" => Some(Dlsym::getentropy),
20-
_ => throw_unsup_format!("unsupported macOS dlsym: {}", name),
16+
_ => throw_unsup_format!("unsupported FreeBSD dlsym: {}", name),
2117
})
2218
}
2319
}
@@ -33,16 +29,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3329
) -> InterpResult<'tcx> {
3430
let this = self.eval_context_mut();
3531
let ret = ret.expect("we don't support any diverging dlsym");
36-
assert!(this.tcx.sess.target.os == "macos");
32+
assert!(this.tcx.sess.target.os == "freebsd");
3733

3834
match dlsym {
39-
Dlsym::getentropy => {
40-
let [ptr, len] = check_arg_count(args)?;
41-
let ptr = this.read_pointer(ptr)?;
42-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
43-
this.gen_random(ptr, len)?;
44-
this.write_null(dest)?;
45-
}
35+
_ => {}
4636
}
4737

4838
trace!("{:?}", this.dump_place(**dest));

src/shims/unix/freebsd/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2020
// match
2121
Ok(EmulateByNameResult::NeedsJumping)
2222
}
23-
}
23+
}

src/shims/unix/freebsd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
pub mod dlsym;
12
pub mod foreign_items;
2-
pub mod dlsym;

src/shims/unix/macos/dlsym.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ use rustc_middle::mir;
33
use log::trace;
44

55
use crate::*;
6+
use helpers::check_arg_count;
67

78
#[derive(Debug, Copy, Clone)]
89
#[allow(non_camel_case_types)]
910
pub enum Dlsym {
11+
getentropy,
1012
}
1113

1214
impl Dlsym {
1315
// Returns an error for unsupported symbols, and None if this symbol
1416
// should become a NULL pointer (pretend it does not exist).
1517
pub fn from_str<'tcx>(name: &str) -> InterpResult<'tcx, Option<Dlsym>> {
1618
Ok(match name {
17-
_ => throw_unsup_format!("unsupported freebsd dlsym: {}", name),
19+
"getentropy" => Some(Dlsym::getentropy),
20+
_ => throw_unsup_format!("unsupported macOS dlsym: {}", name),
1821
})
1922
}
2023
}
@@ -30,9 +33,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3033
) -> InterpResult<'tcx> {
3134
let this = self.eval_context_mut();
3235
let ret = ret.expect("we don't support any diverging dlsym");
33-
assert!(this.tcx.sess.target.os == "freebsd");
36+
assert!(this.tcx.sess.target.os == "macos");
3437

3538
match dlsym {
39+
Dlsym::getentropy => {
40+
let [ptr, len] = check_arg_count(args)?;
41+
let ptr = this.read_pointer(ptr)?;
42+
let len = this.read_scalar(len)?.to_machine_usize(this)?;
43+
this.gen_random(ptr, len)?;
44+
this.write_null(dest)?;
45+
}
3646
_ => {}
3747
}
3848

src/shims/unix/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mod fs;
55
mod sync;
66
mod thread;
77

8+
mod freebsd;
89
mod linux;
910
mod macos;
10-
mod freebsd;
1111

1212
pub use fs::{DirHandler, FileHandler};

tests/pass/libc.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
extern crate libc;
77

8-
#[cfg(target_os = "linux, freebsd")]
8+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
99
fn tmp() -> std::path::PathBuf {
1010
std::env::var("MIRI_TEMP").map(std::path::PathBuf::from).unwrap_or_else(|_| std::env::temp_dir())
1111
}
1212

13-
#[cfg(target_os = "linux, freebsd")]
13+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
1414
fn test_posix_fadvise() {
1515
use std::convert::TryInto;
1616
use std::fs::{remove_file, File};
@@ -40,7 +40,7 @@ fn test_posix_fadvise() {
4040
assert_eq!(result, 0);
4141
}
4242

43-
#[cfg(target_os = "linux, freebsd")]
43+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
4444
fn test_sync_file_range() {
4545
use std::fs::{remove_file, File};
4646
use std::io::Write;
@@ -191,7 +191,7 @@ fn test_rwlock_libc_static_initializer() {
191191
/// Test whether the `prctl` shim correctly sets the thread name.
192192
///
193193
/// Note: `prctl` exists only on Linux.
194-
#[cfg(target_os = "linux,freebsd")]
194+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
195195
fn test_prctl_thread_name() {
196196
use std::ffi::CString;
197197
use libc::c_long;
@@ -231,7 +231,7 @@ fn test_thread_local_errno() {
231231
}
232232

233233
/// Tests whether clock support exists at all
234-
#[cfg(target_os = "linux,freebsd")]
234+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
235235
fn test_clocks() {
236236
let mut tp = std::mem::MaybeUninit::<libc::timespec>::uninit();
237237
let is_error = unsafe {
@@ -260,25 +260,25 @@ fn test_getpid() {
260260
}
261261

262262
fn main() {
263-
#[cfg(target_os = "linux,freebsd")]
263+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
264264
test_posix_fadvise();
265265

266-
#[cfg(target_os = "linux,freebsd")]
266+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
267267
test_sync_file_range();
268268

269269
test_mutex_libc_init_recursive();
270270
test_mutex_libc_init_normal();
271271
test_mutex_libc_init_errorcheck();
272272
test_rwlock_libc_static_initializer();
273273

274-
#[cfg(target_os = "linux,freebsd")]
274+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
275275
test_mutex_libc_static_initializer_recursive();
276276

277-
#[cfg(target_os = "linux,freebsd")]
277+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
278278
test_prctl_thread_name();
279279

280280
test_thread_local_errno();
281281

282-
#[cfg(target_os = "linux,freebsd")]
282+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
283283
test_clocks();
284284
}

0 commit comments

Comments
 (0)