Skip to content

Commit cdb7adb

Browse files
m-ou-seRalfJung
authored andcommitted
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.
1 parent 4de113a commit cdb7adb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/shims/posix/linux/dlsym.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ impl Dlsym {
1212
pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
1313
Ok(match &*name {
1414
"__pthread_get_minstack" => None,
15+
"getrandom" => None, // std falls back to syscall(SYS_getrandom, ...) when this is NULL.
16+
"statx" => None, // std falls back to syscall(SYS_statx, ...) when this is NULL.
1517
_ => throw_unsup_format!("unsupported Linux dlsym: {}", name),
1618
})
1719
}

src/shims/posix/linux/foreign_items.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ fn getrandom<'tcx>(
208208

209209
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
210210
// neither of which have any effect on our current PRNG.
211-
this.read_scalar(flags)?.to_i32()?;
211+
let flags = this.read_scalar(flags)?;
212+
// Either `i32` or `isize` is fine.
213+
if flags.to_machine_isize(this).is_err() {
214+
flags.to_i32()?;
215+
}
212216

213217
this.gen_random(ptr, len)?;
214218
this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;

0 commit comments

Comments
 (0)