HLE: preserve ERROR_TLW_WITH_WSCHILD and close relaunch duplicate handle #3317

Open
github-bot wants to merge 1 commit from github-bot/gh-3317 into main AGit
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-26 17:20 UTC · original
mgunes1311-lab:hle-lifecycle-child-relaunch → main · +176 −14 · 1 files · 1 commits · open

Coordination

Claimed in #1633 (HLE: preserve Win32 ERROR_TLW_WITH_WSCHILD on null-parent WS_CHILD windows and close duplicated handle in lifecycle::relaunch). Checked STATUS.md, CLAIMS.md, and forge/main — zero overlapping PRs or diff in crates/victory-hle/src/modules/lifecycle.rs.

Problem

Two Win32 lifecycle edge cases in crates/victory-hle/src/modules/lifecycle.rs:

  1. CreateWindowExW and CreateWindowExA checked let top = parent.is_null(); without checking WS_CHILD. When a caller passed style = WS_CHILD with parent = NULL, substituting HWND_MESSAGE caused Win32 to create a message-only child window and attempt a stand-in window with WS_CHILD (parent = NULL, logging a spurious warning) instead of failing with NULL and ERROR_TLW_WITH_WSCHILD (1406).
  2. relaunch duplicated the current process handle with bInheritHandle = TRUE (DuplicateHandle) for VICTORY_RELAUNCHED_FROM, but never called CloseHandle(me) in the parent after command.spawn() returned (Ok or Err), leaking an inheritable self-process handle on failed or repeated relaunch attempts.

Fix

  • Gate message-only / stand-in substitution on let top = parent.is_null() && style & wm::WS_CHILD == 0; in both CreateWindowExW and CreateWindowExA.
  • Extract relaunch_exe and call CloseHandle(me) immediately after command.spawn() returns, once CreateProcessW has inherited the handle into the child (or failed).

Verification

  • Added null_parent_ws_child_windows_fail_with_win32_error_while_valid_children_succeed testing both CreateWindowExW and CreateWindowExA with WS_CHILD + null parent (NULL + ERROR_TLW_WITH_WSCHILD) and valid parent (GetParent == parent, hooked procedure, no stand-in).
  • Added relaunch_closes_its_duplicated_process_handle verifying process handle count stability across 257 failed spawns and a successful ComSpec /C exit 0 child launch.
  • Ran cargo test -p victory-hle --locked modules::lifecycle::tests:: (14/14 passed), cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, and cargo xtask policy on Windows 11 (x86_64-pc-windows-msvc).

AI-assisted contribution (Google Antigravity); all code and Win32 unit tests were locally executed and verified.

**@⁠mgunes1311-lab** on GitHub · 2026-11-26 17:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3317) `mgunes1311-lab:hle-lifecycle-child-relaunch` → `main` · +176 −14 · 1 files · 1 commits · open ## Coordination Claimed in https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 (`HLE: preserve Win32 ERROR_TLW_WITH_WSCHILD on null-parent WS_CHILD windows and close duplicated handle in lifecycle::relaunch`). Checked `STATUS.md`, `CLAIMS.md`, and `forge/main` — zero overlapping PRs or diff in `crates/victory-hle/src/modules/lifecycle.rs`. ## Problem Two Win32 lifecycle edge cases in `crates/victory-hle/src/modules/lifecycle.rs`: 1. `CreateWindowExW` and `CreateWindowExA` checked `let top = parent.is_null();` without checking `WS_CHILD`. When a caller passed `style = WS_CHILD` with `parent = NULL`, substituting `HWND_MESSAGE` caused Win32 to create a message-only child window and attempt a stand-in window with `WS_CHILD` (`parent = NULL`, logging a spurious warning) instead of failing with `NULL` and `ERROR_TLW_WITH_WSCHILD` (`1406`). 2. `relaunch` duplicated the current process handle with `bInheritHandle = TRUE` (`DuplicateHandle`) for `VICTORY_RELAUNCHED_FROM`, but never called `CloseHandle(me)` in the parent after `command.spawn()` returned (`Ok` or `Err`), leaking an inheritable self-process handle on failed or repeated relaunch attempts. ## Fix - Gate message-only / stand-in substitution on `let top = parent.is_null() && style & wm::WS_CHILD == 0;` in both `CreateWindowExW` and `CreateWindowExA`. - Extract `relaunch_exe` and call `CloseHandle(me)` immediately after `command.spawn()` returns, once `CreateProcessW` has inherited the handle into the child (or failed). ## Verification - Added `null_parent_ws_child_windows_fail_with_win32_error_while_valid_children_succeed` testing both `CreateWindowExW` and `CreateWindowExA` with `WS_CHILD` + null parent (`NULL` + `ERROR_TLW_WITH_WSCHILD`) and valid parent (`GetParent == parent`, hooked procedure, no stand-in). - Added `relaunch_closes_its_duplicated_process_handle` verifying process handle count stability across 257 failed spawns and a successful `ComSpec /C exit 0` child launch. - Ran `cargo test -p victory-hle --locked modules::lifecycle::tests::` (14/14 passed), `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, and `cargo xtask policy` on Windows 11 (`x86_64-pc-windows-msvc`). AI-assisted contribution (Google Antigravity); all code and Win32 unit tests were locally executed and verified.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:20:44 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 17:27 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64:

  • Checking parent.is_null() && style & wm::WS_CHILD == 0 preserves Win32 ERROR_TLW_WITH_WSCHILD instead of turning invalid WS_CHILD windows into message-only windows, and closing the duplicated process handle in relaunch_exe after spawn() prevents handle leaks.
  • cargo test -p victory-hle --lib modules::lifecycle:: -- --test-threads=1: 14 passed, 0 failed (including null_parent_ws_child_windows_fail_with_win32_error_while_valid_children_succeed and relaunch_closes_its_duplicated_process_handle).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 17:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3317#pullrequestreview-6078357640) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Checking `parent.is_null() && style & wm::WS_CHILD == 0` preserves Win32 `ERROR_TLW_WITH_WSCHILD` instead of turning invalid `WS_CHILD` windows into message-only windows, and closing the duplicated process handle in `relaunch_exe` after `spawn()` prevents handle leaks. - `cargo test -p victory-hle --lib modules::lifecycle:: -- --test-threads=1`: 14 passed, 0 failed (including `null_parent_ws_child_windows_fail_with_win32_error_while_valid_children_succeed` and `relaunch_closes_its_duplicated_process_handle`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3317/head:github-bot/gh-3317'
git switch 'github-bot/gh-3317'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3317'
git switch 'github-bot/gh-3317'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3317'
git switch 'github-bot/gh-3317'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3317'
git switch 'main'
git merge --squash 'github-bot/gh-3317'
git switch 'main'
git merge --ff-only 'github-bot/gh-3317'
git switch 'main'
git merge 'github-bot/gh-3317'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3317
No description provided.