Skip to content

Commit 9c21872

Browse files
committed
Auto merge of rust-lang#3716 - cgettys-microsoft:dev/cgettys/process_id_fixup-03, r=RalfJung
Remove GetCurrentProcessId's frame_in_std check Most of the support required to close rust-lang#1727 was actually added a while back, in rust-lang#2215. However, for some reason, even though the Unix/Linux syscall equivalent has no `frame_in_std()` check, the Windows `GetCurrentProcessId` check did. While the vast majority of use cases use `std::process::id`, there's no particular reason to penalize any Windows code that is no_std or for whatever other reason choses to call the function directly (e.g. via the generated [windows-sys](https://docs.rs/windows-sys/latest/windows_sys/Win32/System/Threading/fn.GetCurrentProcessId.html) method). The emulation should still work fine. Given there's no reason not to, we might as well simplify the code a tiny bit and save that branch / frame check during runtime too. This PR removes the `frame_in_std` restriction for `GetCurrentProcessId`, and also moves it into the environment related shim section per discussion in rust-lang/miri#1727 (comment). Still passes existing tests/pass/getpid.rs test. Closes rust-lang#1727 unless we wish to give a dummy value when isolated, which we don't seem to want to do at this time.
2 parents b280af4 + 9d69154 commit 9c21872

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
138138
let result = this.GetUserProfileDirectoryW(token, buf, size)?;
139139
this.write_scalar(result, dest)?;
140140
}
141+
"GetCurrentProcessId" => {
142+
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
143+
let result = this.GetCurrentProcessId()?;
144+
this.write_int(result, dest)?;
145+
}
141146

142147
// File related shims
143148
"NtWriteFile" => {
@@ -743,11 +748,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
743748
// Any non zero value works for the stdlib. This is just used for stack overflows anyway.
744749
this.write_int(1, dest)?;
745750
}
746-
"GetCurrentProcessId" if this.frame_in_std() => {
747-
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
748-
let result = this.GetCurrentProcessId()?;
749-
this.write_int(result, dest)?;
750-
}
751751
// this is only callable from std because we know that std ignores the return value
752752
"SwitchToThread" if this.frame_in_std() => {
753753
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;

0 commit comments

Comments
 (0)