Repository navigation
Conversation
MxcWindowsSandbox::launch() creates wxc-exec.exe suspended, assigns it to the limited Job Object, and then resumes it. resume_process found the executor's suspended thread with CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD), which lists every thread on the system. On a Windows 11 laptop running CrowdStrike that took a median of 61 ms per launch (spawn.resume span, 40-87 ms across runs), and more when the host was busy. Resume through the process handle that std's Child already holds, with NtResumeProcess. Like the old loop, it resumes every thread of the process once, but in one system call. Keeping the main thread handle instead would mean calling CreateProcessW ourselves, because Command does not expose it. NtResumeProcess is not documented by Microsoft, but ntdll has exported it since Windows XP and the Windows SDK's ntdll.lib provides it. The suspended, assign, resume order is unchanged, and so is the failure path: if the resume fails, for example because the executor is already exiting, launch() kills it and returns an error before any user code runs. A new test covers both the resume and the refusal for an exited process. The windows crate's ToolHelp feature is no longer used and is dropped. Co-authored-by: Cursor <[email protected]>
johayang-amd
left a comment
There was a problem hiding this comment.
Thanks Luka, replacing the system-wide thread snapshot with one call on the handle we already hold is a nice simplification, and the test covers both the resume and the refusal for an exited process.
A few requests, none blocking:
- The description has numbers for the resume step only. Could you add end-to-end
axis runmedians formainand this change as a short table in Test Result? DEVELOPMENT.md asks for that on launch-path changes. Ours are below if they help. NtResumeProcessis undocumented. A one-line comment on theexternblock saying so, and that ntdll has exported it since XP, would help the next reader; right now that's only in the commit message.- Optional:
assign_process_to_jobstill reopens the process by PID; it could take the sameBorrowedHandle.
The two failing checks aren't from this PR: Dependency audit is the new url advisory (RUSTSEC-2026-0592), and Test (Linux) is an intermittent failure in a tmpdir test from #107, which we'll fix separately.
Tested on Windows 11 26100: built main 8040824 and this PR on top of it, then ran axis --socket 0.0.0.0:9 run --policy <mxc, block> -- cmd /c exit 0 alternately, 60 rounds each, twice. The median went from 591 to 519 ms and from 578 to 514 ms. axis.exe no longer imports CreateToolhelp32Snapshot.
|
Our Windows numbers as a table, in case you want to reuse them in Test Result. Windows 11 26100,
|
Motivation
On Windows,
axis runstartswxc-exec.exesuspended, puts it in the Job Object, and then resumes it. To find its thread, AXIS took a snapshot of every thread on the machine. That costs about 63 ms per launch which this PR cuts down.Technical Details
Resume the process with one
NtResumeProcesscall on the handlestd::process::Childalready holds. It resumes the same threads as before.NtResumeProcessisn't documented, but ntdll has exported it since Windows XP. Thewindowscrate'sToolHelpfeature is no longer used, so it's removed.Security impact: none. The order is the same (suspended, in the Job Object, then resumed), and if the resume fails, the launch is still refused before the command runs.
Test Plan
cargo fmt,cargo clippyand theaxis-sandboxtests on Windows, including a new test that resumes a suspended process. Rane2e/windows/test_mxc_processcontainer.ps1on a host with BaseContainer. Benchmarkedaxis run --policy minimalwithaxis-bench launchfromfeature/launch-timing, with and without this commit, 30 rounds each, alternating.Test Result