Auto merge of #3794 - RalfJung:getuid, r=RalfJung

allow all code to call getuid()

Fixes https://github.com/rust-lang/miri/issues/3753
This commit is contained in:
bors 2024-08-07 13:29:17 +00:00
commit dc9f4e8c4c
2 changed files with 11 additions and 9 deletions

View file

@ -815,6 +815,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.handle_miri_start_unwind(payload)?;
return Ok(EmulateItemResult::NeedsUnwind);
}
"getuid" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
// For now, just pretend we always have this fixed UID.
this.write_int(UID, dest)?;
}
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
// These shims are enabled only when the caller is in the standard library.
@ -877,13 +882,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_null(dest)?;
}
"getuid"
if this.frame_in_std() => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
// For now, just pretend we always have this fixed UID.
this.write_int(super::UID, dest)?;
}
"getpwuid_r" | "__posix_getpwuid_r"
if this.frame_in_std() => {
// getpwuid_r is the standard name, __posix_getpwuid_r is used on solarish
@ -898,7 +896,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let result = this.deref_pointer(result)?;
// Must be for "us".
if uid != crate::shims::unix::UID {
if uid != UID {
throw_unsup_format!("`getpwuid_r` on other users is not supported");
}

View file

@ -75,11 +75,15 @@ fn test_dlsym() {
assert_eq!(errno, libc::EBADF);
}
fn test_getuid() {
let _val = unsafe { libc::getuid() };
}
fn main() {
test_thread_local_errno();
test_environ();
test_dlsym();
test_getuid();
#[cfg(target_os = "linux")]
test_sigrt();