Skip to content

Commit ad8aa16

Browse files
committed
Auto merge of rust-lang#3794 - RalfJung:getuid, r=RalfJung
allow all code to call getuid() Fixes rust-lang/miri#3753
2 parents 05534a3 + d3d6dc1 commit ad8aa16

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/tools/miri/src/shims/unix/foreign_items.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
815815
this.handle_miri_start_unwind(payload)?;
816816
return Ok(EmulateItemResult::NeedsUnwind);
817817
}
818+
"getuid" => {
819+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
820+
// For now, just pretend we always have this fixed UID.
821+
this.write_int(UID, dest)?;
822+
}
818823

819824
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
820825
// These shims are enabled only when the caller is in the standard library.
@@ -877,13 +882,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
877882
this.write_null(dest)?;
878883
}
879884

880-
"getuid"
881-
if this.frame_in_std() => {
882-
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
883-
// For now, just pretend we always have this fixed UID.
884-
this.write_int(super::UID, dest)?;
885-
}
886-
887885
"getpwuid_r" | "__posix_getpwuid_r"
888886
if this.frame_in_std() => {
889887
// getpwuid_r is the standard name, __posix_getpwuid_r is used on solarish
@@ -898,7 +896,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
898896
let result = this.deref_pointer(result)?;
899897

900898
// Must be for "us".
901-
if uid != crate::shims::unix::UID {
899+
if uid != UID {
902900
throw_unsup_format!("`getpwuid_r` on other users is not supported");
903901
}
904902

src/tools/miri/tests/pass-dep/libc/libc-misc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ fn test_dlsym() {
7575
assert_eq!(errno, libc::EBADF);
7676
}
7777

78+
fn test_getuid() {
79+
let _val = unsafe { libc::getuid() };
80+
}
81+
7882
fn main() {
7983
test_thread_local_errno();
8084
test_environ();
81-
8285
test_dlsym();
86+
test_getuid();
8387

8488
#[cfg(target_os = "linux")]
8589
test_sigrt();

0 commit comments

Comments
 (0)