Skip to content

Commit

Permalink
Auto merge of rust-lang#3794 - RalfJung:getuid, r=RalfJung
Browse files Browse the repository at this point in the history
allow all code to call getuid()

Fixes rust-lang/miri#3753
  • Loading branch information
bors committed Aug 7, 2024
2 parents 2f405eb + d480954 commit dc9f4e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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");
}

Expand Down
6 changes: 5 additions & 1 deletion src/tools/miri/tests/pass-dep/libc/libc-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit dc9f4e8

Please sign in to comment.