Skip to content

Commit 6023eb8

Browse files
author
Lander Brandt
committed
minimum changes required to get most tests passing or ignored
1 parent fd0534d commit 6023eb8

19 files changed

+31
-10
lines changed

src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
440440
/// Helper function used inside the shims of foreign functions to assert that the target OS
441441
/// is based on the Linux kernel. It panics showing a message with the `name` of the foreign function
442442
/// if this is not the case.
443-
fn assert_linux_based_target_os(&self, name: &str) {
443+
fn assert_target_os_is_linux_based(&self, name: &str) {
444444
assert!(
445445
matches!(self.eval_context_ref().tcx.sess.target.os.as_str(), "linux" | "android"),
446446
"`{}` is only available for supported Linux-based targets",

src/shims/posix/android/dlsym.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl Dlsym {
1919
"getrandom" => None, // std falls back to syscall(SYS_getrandom, ...) when this is NULL.
2020
"statx" => None, // std falls back to syscall(SYS_statx, ...) when this is NULL.
2121
"signal" | "bsd_signal" => Some(Dlsym::signal), // these have the same signature/implementation
22+
"android_set_abort_message" => None, // std falls back to just not doing anything when this is NULL.
2223
_ => throw_unsup_format!("unsupported Android dlsym: {}", name),
2324
})
2425
}

src/shims/posix/android/foreign_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_middle::mir;
22
use rustc_span::Symbol;
3-
use rustc_target::abi::{Align, Size};
43
use rustc_target::spec::abi::Abi;
54

65
use crate::*;

src/shims/posix/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
937937
) -> InterpResult<'tcx, i32> {
938938
let this = self.eval_context_mut();
939939

940-
this.assert_linux_based_target_os("statx");
940+
this.assert_target_os_is_linux_based("statx");
941941

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

1230-
this.assert_linux_based_target_os("readdir64");
1230+
this.assert_target_os_is_linux_based("readdir64");
12311231

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

src/shims/posix/linux/foreign_items.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2020
_ret: mir::BasicBlock,
2121
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
2222
let this = self.eval_context_mut();
23+
let target_os = this.tcx.sess.target.os.as_str();
2324

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

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

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

146-
let sys_statx = this.eval_libc("SYS_statx")?.to_machine_usize(this)?;
147+
let sys_statx = if target_os == "android" {
148+
// libc's Android target currently does not support SYS_statx -- fail gracefully
149+
None
150+
} else {
151+
Some(this.eval_libc("SYS_statx")?.to_machine_usize(this)?)
152+
};
147153

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

@@ -167,7 +173,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
167173
}
168174
// `statx` is used by `libstd` to retrieve metadata information on `linux`
169175
// instead of using `stat`,`lstat` or `fstat` as on `macos`.
170-
id if id == sys_statx => {
176+
//
177+
// the libc crate for android however cannot properly lookup this syscall,
178+
// so we have to make this gracefull fail
179+
id if sys_statx.map(|statx| statx == id).unwrap_or(false) => {
171180
// The first argument is the syscall id, so skip over it.
172181
if args.len() < 6 {
173182
throw_ub_format!(

src/shims/posix/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
106106
_arg5: &OpTy<'tcx, Tag>,
107107
) -> InterpResult<'tcx, i32> {
108108
let this = self.eval_context_mut();
109-
this.assert_linux_based_target_os("prctl");
109+
this.assert_target_os_is_linux_based("prctl");
110110

111111
let option = this.read_scalar(option)?.to_i32()?;
112112
if option == this.eval_libc_i32("PR_SET_NAME")? {

src/shims/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2020
) -> InterpResult<'tcx, i32> {
2121
let this = self.eval_context_mut();
2222

23-
this.assert_linux_based_target_os("clock_gettime");
23+
this.assert_target_os_is_linux_based("clock_gettime");
2424
this.check_no_isolation("`clock_gettime`")?;
2525

2626
let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;

tests/compile-fail/environ-gets-deallocated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-windows: Windows does not have a global environ list that the program can access directly
22

3-
#[cfg(target_os="linux")]
3+
#[cfg(any(target_os="linux", target_os="android"))]
44
fn get_environ() -> *const *const u8 {
55
extern "C" {
66
static mut environ: *const *const u8;

tests/run-pass/concurrency/linux-futex.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// so we need to ignore Windows and macOS instead.
33
// ignore-macos: Uses Linux-only APIs
44
// ignore-windows: Uses Linux-only APIs
5+
// ignore-android: `libc` crate does not support `__errno_location` on Android
56
// compile-flags: -Zmiri-disable-isolation
67

78
#![feature(rustc_private)]

tests/run-pass/concurrency/simple.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// ignore-android: `libc` crate does not support `PR_SET_NAME` on Android
23

34
use std::thread;
45

tests/run-pass/concurrency/sync.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// ignore-android: `libc` crate does not support `gettimeofday()` on Android
23
// compile-flags: -Zmiri-disable-isolation -Zmiri-check-number-validity
34

45
use std::sync::mpsc::{channel, sync_channel};

tests/run-pass/current_dir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-android: No foreign function support for __errno yet
12
// compile-flags: -Zmiri-disable-isolation
23
use std::env;
34
use std::io::ErrorKind;

tests/run-pass/current_dir_with_isolation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-android: No foreign function support for __errno yet
12
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
23
// normalize-stderr-test "(getcwd|GetCurrentDirectoryW)" -> "$$GETCWD"
34
// normalize-stderr-test "(chdir|SetCurrentDirectoryW)" -> "$$SETCWD"

tests/run-pass/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: File handling is not implemented yet
2+
// ignore-android: No foreign function support for __errno yet
23
// compile-flags: -Zmiri-disable-isolation
34

45
#![feature(rustc_private)]

tests/run-pass/fs_with_isolation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: File handling is not implemented yet
2+
// ignore-android: No foreign function support for __errno yet
23
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace
34
// normalize-stderr-test "(stat(x)?)" -> "$$STAT"
45

tests/run-pass/hashmap.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-android: libc for Android does not have `SYS_statx`
2+
13
use std::collections::HashMap;
24
use std::hash::BuildHasher;
35

tests/run-pass/libc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: No libc on Windows
2+
// ignore-android: libc's Android target does not have support for __errno_location yet
23
// compile-flags: -Zmiri-disable-isolation
34

45
#![feature(rustc_private)]

tests/run-pass/linux-getrandom-without-isolation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// so we need to ignore Windows and macOS instead.
33
// ignore-macos: Uses Linux-only APIs
44
// ignore-windows: Uses Linux-only APIs
5+
// ignore-android: libc's android target does not support `getrandom()` yet
56
// compile-flags: -Zmiri-disable-isolation
67
#![feature(rustc_private)]
78
extern crate libc;

tests/run-pass/linux-getrandom.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// so we need to ignore Windows and macOS instead.
33
// ignore-macos: Uses Linux-only APIs
44
// ignore-windows: Uses Linux-only APIs
5+
// ignore-android: libc's android target does not support `getrandom()` yet
56
#![feature(rustc_private)]
67
extern crate libc;
78

0 commit comments

Comments
 (0)