Skip to content

Commit

Permalink
minimum changes required to get most tests passing or ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
Lander Brandt committed Mar 10, 2022
1 parent fd0534d commit 6023eb8
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// Helper function used inside the shims of foreign functions to assert that the target OS
/// is based on the Linux kernel. It panics showing a message with the `name` of the foreign function
/// if this is not the case.
fn assert_linux_based_target_os(&self, name: &str) {
fn assert_target_os_is_linux_based(&self, name: &str) {
assert!(
matches!(self.eval_context_ref().tcx.sess.target.os.as_str(), "linux" | "android"),
"`{}` is only available for supported Linux-based targets",
Expand Down
1 change: 1 addition & 0 deletions src/shims/posix/android/dlsym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl Dlsym {
"getrandom" => None, // std falls back to syscall(SYS_getrandom, ...) when this is NULL.
"statx" => None, // std falls back to syscall(SYS_statx, ...) when this is NULL.
"signal" | "bsd_signal" => Some(Dlsym::signal), // these have the same signature/implementation
"android_set_abort_message" => None, // std falls back to just not doing anything when this is NULL.
_ => throw_unsup_format!("unsupported Android dlsym: {}", name),
})
}
Expand Down
1 change: 0 additions & 1 deletion src/shims/posix/android/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_middle::mir;
use rustc_span::Symbol;
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;

use crate::*;
Expand Down
4 changes: 2 additions & 2 deletions src/shims/posix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();

this.assert_linux_based_target_os("statx");
this.assert_target_os_is_linux_based("statx");

let statxbuf_ptr = this.read_pointer(statxbuf_op)?;
let pathname_ptr = this.read_pointer(pathname_op)?;
Expand Down Expand Up @@ -1227,7 +1227,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn linux_readdir64(&mut self, dirp_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();

this.assert_linux_based_target_os("readdir64");
this.assert_target_os_is_linux_based("readdir64");

let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;

Expand Down
15 changes: 12 additions & 3 deletions src/shims/posix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_ret: mir::BasicBlock,
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
let this = self.eval_context_mut();
let target_os = this.tcx.sess.target.os.as_str();

match &*link_name.as_str() {
// errno
Expand All @@ -30,7 +31,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}

// File related shims (but also see "syscall" below for statx)
// These symbols have different names on Linux and macOS, which is the only reason they are not
// These symbols have different names/signatures on Linux and macOS, which is the only reason they are not
// in the `posix` module.
"close" => {
let &[ref fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
Expand Down Expand Up @@ -143,7 +144,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

let sys_getrandom = this.eval_libc("SYS_getrandom")?.to_machine_usize(this)?;

let sys_statx = this.eval_libc("SYS_statx")?.to_machine_usize(this)?;
let sys_statx = if target_os == "android" {
// libc's Android target currently does not support SYS_statx -- fail gracefully
None
} else {
Some(this.eval_libc("SYS_statx")?.to_machine_usize(this)?)
};

let sys_futex = this.eval_libc("SYS_futex")?.to_machine_usize(this)?;

Expand All @@ -167,7 +173,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
// `statx` is used by `libstd` to retrieve metadata information on `linux`
// instead of using `stat`,`lstat` or `fstat` as on `macos`.
id if id == sys_statx => {
//
// the libc crate for android however cannot properly lookup this syscall,
// so we have to make this gracefull fail
id if sys_statx.map(|statx| statx == id).unwrap_or(false) => {
// The first argument is the syscall id, so skip over it.
if args.len() < 6 {
throw_ub_format!(
Expand Down
2 changes: 1 addition & 1 deletion src/shims/posix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_arg5: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_linux_based_target_os("prctl");
this.assert_target_os_is_linux_based("prctl");

let option = this.read_scalar(option)?.to_i32()?;
if option == this.eval_libc_i32("PR_SET_NAME")? {
Expand Down
2 changes: 1 addition & 1 deletion src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();

this.assert_linux_based_target_os("clock_gettime");
this.assert_target_os_is_linux_based("clock_gettime");
this.check_no_isolation("`clock_gettime`")?;

let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;
Expand Down
2 changes: 1 addition & 1 deletion tests/compile-fail/environ-gets-deallocated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore-windows: Windows does not have a global environ list that the program can access directly

#[cfg(target_os="linux")]
#[cfg(any(target_os="linux", target_os="android"))]
fn get_environ() -> *const *const u8 {
extern "C" {
static mut environ: *const *const u8;
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/concurrency/linux-futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// so we need to ignore Windows and macOS instead.
// ignore-macos: Uses Linux-only APIs
// ignore-windows: Uses Linux-only APIs
// ignore-android: `libc` crate does not support `__errno_location` on Android
// compile-flags: -Zmiri-disable-isolation

#![feature(rustc_private)]
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/concurrency/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// ignore-android: `libc` crate does not support `PR_SET_NAME` on Android

use std::thread;

Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/concurrency/sync.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: Concurrency on Windows is not supported yet.
// ignore-android: `libc` crate does not support `gettimeofday()` on Android
// compile-flags: -Zmiri-disable-isolation -Zmiri-check-number-validity

use std::sync::mpsc::{channel, sync_channel};
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/current_dir.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-android: No foreign function support for __errno yet
// compile-flags: -Zmiri-disable-isolation
use std::env;
use std::io::ErrorKind;
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/current_dir_with_isolation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore-android: No foreign function support for __errno yet
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GETCWD"
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SETCWD"
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/fs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: File handling is not implemented yet
// ignore-android: No foreign function support for __errno yet
// compile-flags: -Zmiri-disable-isolation

#![feature(rustc_private)]
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/fs_with_isolation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: File handling is not implemented yet
// ignore-android: No foreign function support for __errno yet
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
// normalize-stderr-test "(stat(x)?)" -> "$$STAT"

Expand Down
2 changes: 2 additions & 0 deletions tests/run-pass/hashmap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-android: libc for Android does not have `SYS_statx`

use std::collections::HashMap;
use std::hash::BuildHasher;

Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/libc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ignore-windows: No libc on Windows
// ignore-android: libc's Android target does not have support for __errno_location yet
// compile-flags: -Zmiri-disable-isolation

#![feature(rustc_private)]
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/linux-getrandom-without-isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// so we need to ignore Windows and macOS instead.
// ignore-macos: Uses Linux-only APIs
// ignore-windows: Uses Linux-only APIs
// ignore-android: libc's android target does not support `getrandom()` yet
// compile-flags: -Zmiri-disable-isolation
#![feature(rustc_private)]
extern crate libc;
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/linux-getrandom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// so we need to ignore Windows and macOS instead.
// ignore-macos: Uses Linux-only APIs
// ignore-windows: Uses Linux-only APIs
// ignore-android: libc's android target does not support `getrandom()` yet
#![feature(rustc_private)]
extern crate libc;

Expand Down

0 comments on commit 6023eb8

Please sign in to comment.