Skip to content

std::sys::windows::process::Command::spawn: mem::size_of::<c::STARTUPINFOW> as c::DWORD compiles to a garbage value #115511

Closed
@Fulgen301

Description

@Fulgen301

Code

use std::process::Command;

fn main() {
    Command::new("cmd")
        .args(["/C", "echo hello"])
        .spawn()
        .unwrap();
}

The Windows implementation of spawning a process creates a STARTUPINFOW structure and sets its cb member to the size of the structure:

si.cb = mem::size_of::<c::STARTUPINFOW> as c::DWORD;

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:

lea     rax, [rust_startupinfow_cb!core::mem::size_of<std::sys::windows::c::windows_sys::STARTUPINFOW> (7ff6d0436740)]
mov     dword ptr [rbp+580h], eax

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 the STARTUPINFOW structure on the stack (e.g. setting a breakpoint on KERNELBASE!CreateProcessInternalW and reinterpreting r11 + 0x48 as STARTUPINFOW **).

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:

rustc 1.74.0-nightly (9f5fc1bd4 2023-09-02)
binary: rustc
commit-hash: 9f5fc1bd443f59583e7af0d94d289f95fe1e20c4
commit-date: 2023-09-02
host: x86_64-pc-windows-msvc
release: 1.74.0-nightly
LLVM version: 17.0.0

@rustbot modify labels: +regression-from-beta-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.O-windowsOperating system: Windowsregression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions