From d09853e36532e5367e4cf1859ab0972ee10306c5 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 18 Nov 2020 23:15:32 +0100 Subject: [PATCH] Make weak syscalls in std work. std now looks up `getrandom` and `statx` with `dlsym` before attempting to use `syscall(SYS_.., ..)`. It also now passes all arguments as a machine-sized word, instead of their original types. --- src/shims/posix/linux/dlsym.rs | 2 ++ src/shims/posix/linux/foreign_items.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/shims/posix/linux/dlsym.rs b/src/shims/posix/linux/dlsym.rs index ca5cf3ffe8..2685a93726 100644 --- a/src/shims/posix/linux/dlsym.rs +++ b/src/shims/posix/linux/dlsym.rs @@ -12,6 +12,8 @@ impl Dlsym { pub fn from_str(name: &str) -> InterpResult<'static, Option> { Ok(match &*name { "__pthread_get_minstack" => None, + "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. _ => throw_unsup_format!("unsupported Linux dlsym: {}", name), }) } diff --git a/src/shims/posix/linux/foreign_items.rs b/src/shims/posix/linux/foreign_items.rs index 04efa79b9d..21d765621f 100644 --- a/src/shims/posix/linux/foreign_items.rs +++ b/src/shims/posix/linux/foreign_items.rs @@ -208,7 +208,11 @@ fn getrandom<'tcx>( // The only supported flags are GRND_RANDOM and GRND_NONBLOCK, // neither of which have any effect on our current PRNG. - this.read_scalar(flags)?.to_i32()?; + let flags = this.read_scalar(flags)?; + // Either `i32` or `isize` is fine. + if flags.to_machine_isize(this).is_err() { + flags.to_i32()?; + } this.gen_random(ptr, len)?; this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;