-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std::sys::windows::process::Command::spawn
: mem::size_of::<c::STARTUPINFOW> as c::DWORD
compiles to a garbage value
#115511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
rust/library/std/src/sys/windows/process.rs Line 355 in 53a0397
Ah, sorry I missed the lack of |
Also cc @michaelvanstraten |
Heh, missed that too, explains the (How is casting a function pointer, which is 64bit, to a |
Yeah |
Can't believe this compiled, didn't know that you could cast a function to an Really sorry for this <3 |
It's ok. It's subtle and we both missed it. An |
Maybe we should make a clippy lint for this. |
@Fulgen301 Just out of interest, how did you discover this? |
At least one clippy lint already exists, and it warns by default https://rust-lang.github.io/rust-clippy/master/index.html#/fn_to_numeric_cast_with_truncation Though the lint I would prefer here is warning against ever taking the address of a generic function. |
@michaelvanstraten I was actually trying to get some handle information about the handles |
It's a cast that doesn't make any sense though - on a 64bit platform, a Rust function pointer can never fit into 32 bits, so requiring it to go through an intermediary, e.g. |
|
Command::spawn: Fix STARTUPINFOW.cb being initialized with the address of size_of Fixes rust-lang#115511.
Code
The Windows implementation of spawning a process creates a
STARTUPINFOW
structure and sets itscb
member to the size of the structure:rust/library/std/src/sys/windows/process.rs
Line 355 in 53a0397
On stable and beta, this works correctly and the size is set to 0x68. However, on nightly, the compiler compiles the
size_of
to a garbage value:Note that that value (
0xd0436740
in the example above) changes with each rebuild of the program in question.This can be verified by setting a breakpoint on the call to
CreateProcessW
or one of the functions that it calls and examining theSTARTUPINFOW
structure on the stack (e.g. setting a breakpoint onKERNELBASE!CreateProcessInternalW
and reinterpretingr11 + 0x48
asSTARTUPINFOW **
).Version it worked on
It most recently worked on: rustc 1.73.0-beta.4 (9f37cd4 2023-09-01)
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-beta-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: