diff options
| author | bors <bors@rust-lang.org> | 2024-08-07 13:29:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-07 13:29:17 +0000 |
| commit | dc9f4e8c4c6be7da1220e29434bef91ef774ab15 (patch) | |
| tree | 52c26c1e9a9d9e8633f9b61b4c703d5fde05f3a9 /src | |
| parent | 2f405ebc45783e177a307168058e2f440f33645e (diff) | |
| parent | d4809545eecb8f411415cd45dc0153967a5e5fec (diff) | |
| download | rust-dc9f4e8c4c6be7da1220e29434bef91ef774ab15.tar.gz rust-dc9f4e8c4c6be7da1220e29434bef91ef774ab15.zip | |
Auto merge of #3794 - RalfJung:getuid, r=RalfJung
allow all code to call getuid() Fixes https://github.com/rust-lang/miri/issues/3753
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/shims/unix/foreign_items.rs | 14 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass-dep/libc/libc-misc.rs | 6 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/tools/miri/src/shims/unix/foreign_items.rs b/src/tools/miri/src/shims/unix/foreign_items.rs index 57930f9807d..6c35281ecf2 100644 --- a/src/tools/miri/src/shims/unix/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/foreign_items.rs @@ -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"); } diff --git a/src/tools/miri/tests/pass-dep/libc/libc-misc.rs b/src/tools/miri/tests/pass-dep/libc/libc-misc.rs index f7e1d9faa6a..a5b944e9d42 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-misc.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-misc.rs @@ -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(); |
