user: implement UnregisterClassA and UnregisterClassW #1129

Open
Ivankiosan wants to merge 1 commit from upstream-pr/1138 into main
Ivankiosan commented 2026-11-24 12:24:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ivankiosan on 2026-11-24T12:24:47Z.


The console's minuserx.dll / ext-ms-win-rtcore-ntuser-window-* family implements window creation, window procedures, and class lifecycle for console titles. While RegisterClassExA was implemented in crates/xcl/src/hle/user.rs, the corresponding unregistration entrypoints (UnregisterClassA and UnregisterClassW) were not implemented. Titles or engine sub-frameworks unregistering window classes during teardown or re-initialization would drop to fallback stubs or fail unexpectedly.

What is in it

  • crates/xcl/src/hle/user.rs:
    • Implements UnregisterClassA: validates class_name pointer (reporting ERROR_INVALID_PARAMETER when null, matching native Win32 semantics), converts ANSI class/atom name via
      ame(), and forwards to UnregisterClassW.
    • Implements unregister_class_w: validates class_name pointer (reporting ERROR_INVALID_PARAMETER when null) and invokes native UnregisterClassW.
    • Exports UnregisterClassA and UnregisterClassW in exports().
    • Unit test unregister_class_unregisters_registered_classes_and_rejects_null: verifies null pointer handling with ERROR_INVALID_PARAMETER, registers both ANSI and Unicode classes, and verifies clean unregistration.

Tested

  • Windows 11 build 26100, AMD Radeon RX 7600 (8152 MiB VRAM), driver 32.0.12028.1005, rustc 1.100.0 MSVC.
  • cargo test -p xcl --lib hle::user: 4 passed, 0 failed, 0 ignored.
  • cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored (0 SKIPPED).

Regression run

main:
xcl-smoke v1 commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 7754 MB

PR head:
xcl-smoke v1 commit: e640169179815062df69db38f997336a18c26851 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 8172 MB

Not tested

  • Unregistering window classes created in separate processes or invalid hInstance boundaries.

AI use

  • Claude Code / Claude Opus 4.6 identified the missing unregister entrypoints, implemented both ANSI and Unicode functions with Win32 parameter validation, added unit tests, and drafted the PR description; tests and regression runs executed on AMD Radeon hardware.
<!-- greyfinch-sync:ivall/xcl:issue:5472094757 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1138). Originally posted by [Ivankiosan](https://github.com/Ivankiosan) on 2026-11-24T12:24:47Z. --- The console's minuserx.dll / ext-ms-win-rtcore-ntuser-window-* family implements window creation, window procedures, and class lifecycle for console titles. While RegisterClassExA was implemented in crates/xcl/src/hle/user.rs, the corresponding unregistration entrypoints (UnregisterClassA and UnregisterClassW) were not implemented. Titles or engine sub-frameworks unregistering window classes during teardown or re-initialization would drop to fallback stubs or fail unexpectedly. **What is in it** - crates/xcl/src/hle/user.rs: - Implements UnregisterClassA: validates class_name pointer (reporting ERROR_INVALID_PARAMETER when null, matching native Win32 semantics), converts ANSI class/atom name via ame(), and forwards to UnregisterClassW. - Implements unregister_class_w: validates class_name pointer (reporting ERROR_INVALID_PARAMETER when null) and invokes native UnregisterClassW. - Exports UnregisterClassA and UnregisterClassW in exports(). - Unit test unregister_class_unregisters_registered_classes_and_rejects_null: verifies null pointer handling with ERROR_INVALID_PARAMETER, registers both ANSI and Unicode classes, and verifies clean unregistration. **Tested** - Windows 11 build 26100, AMD Radeon RX 7600 (8152 MiB VRAM), driver 32.0.12028.1005, rustc 1.100.0 MSVC. - cargo test -p xcl --lib hle::user: **4 passed, 0 failed, 0 ignored**. - cargo test --workspace -- --test-threads=4: **742 passed, 0 failed, 41 ignored** (0 SKIPPED). **Regression run** main: ` xcl-smoke v1 commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 7754 MB ` PR head: ` xcl-smoke v1 commit: e640169179815062df69db38f997336a18c26851 gpu: AMD Radeon RX 7600 title: 419239bf seconds: 10 exit: 0x0 frames shown: 1 (PresentX 1) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 8172 MB ` **Not tested** - Unregistering window classes created in separate processes or invalid hInstance boundaries. **AI use** - Claude Code / Claude Opus 4.6 identified the missing unregister entrypoints, implemented both ANSI and Unicode functions with Win32 parameter validation, added unit tests, and drafted the PR description; tests and regression runs executed on AMD Radeon hardware.
DavidM1911 commented 2026-11-24 13:03:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T12:57:39Z.


Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.

  • cargo test -p xcl --lib user::: 4 passed, 0 failed — includes the new unregister_class_unregisters_registered_classes_and_rejects_null plus the existing register-class validation tests.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

<!-- greyfinch-sync:ivall/xcl:comment:7132153191 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1138#issuecomment-7132153191). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T12:57:39Z. --- Independent verification on current `main` `384f7f7` (branch already contains it — clean). **Machine:** Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug. - `cargo test -p xcl --lib user::`: **4 passed, 0 failed** — includes the new `unregister_class_unregisters_registered_classes_and_rejects_null` plus the existing register-class validation tests. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
JoaoPauluu commented 2026-11-24 15:05:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:34:56Z.


A run on Linux under Wine.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. e640169 as it is (based on 47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact). RegisterClass* / UnregisterClass* are Wine's user32 here.
  • hle::user::tests::unregister_class_unregisters_registered_classes_and_rejects_null: ok, no SKIPPED.

Not tested

  • whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
<!-- greyfinch-sync:ivall/xcl:comment:7134610962 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1138#issuecomment-7134610962). Originally posted by [JoaoPauluu](https://github.com/JoaoPauluu) on 2026-11-24T14:34:56Z. --- A run on Linux under Wine. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `e640169` as it is (based on `47efa2e`), no uncommitted changes. The lib test binary runs under Wine, one test per process (`--exact`). `RegisterClass*` / `UnregisterClass*` are Wine's user32 here. - `hle::user::tests::unregister_class_unregisters_registered_classes_and_rejects_null`: **ok**, no SKIPPED. **Not tested** - whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows. **AI use** - Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
gut0to commented 2026-11-26 16:16:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:16:45Z.

Review: COMMENTED


AI-assisted review: I inspected this diff and its tests; I did not run the test suite. I found an ANSI class-atom case that is not covered.

<!-- greyfinch-sync:ivall/xcl:review:6077409507 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1138#pullrequestreview-6077409507). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:16:45Z. **Review:** COMMENTED --- AI-assisted review: I inspected this diff and its tests; I did not run the test suite. I found an ANSI class-atom case that is not covered.
gut0to commented 2026-11-26 16:16:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:16:45Z.

Code review location: crates/xcl/src/hle/user.rs; line 105

@@ -94,6 +96,24 @@ pub unsafe extern "system" fn RegisterClassExA(c: *const WndClassEx<u8>) -> u16
     RegisterClassExW(&w)
 }
 
+pub unsafe extern "system" fn UnregisterClassA(class_name: *const u8, instance: usize) -> i32 {
+    if class_name.is_null() {
+        windows_sys::Win32::Foundation::SetLastError(windows_sys::Win32::Foundation::ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+    let mut keep = Vec::new();
+    let name = name(class_name, &mut keep);

Could this preserve integer atoms before calling name? UnregisterClassA accepts either a string or a class atom (the atom is a pointer-sized value with only its low word set). Passing the atom returned by RegisterClassExA here makes name treat it as an ANSI string and dereference it, instead of forwarding the atom to UnregisterClassW. Please add a regression that unregisters a class using MAKEINTATOM(atom_a) (or the equivalent pointer cast). AI-assisted review; I inspected the diff and tests but did not run them.

<!-- greyfinch-sync:ivall/xcl:review-comment:4710989906 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1138#discussion_r4710989906). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:16:45Z. **Code review location:** `crates/xcl/src/hle/user.rs`; line 105 ~~~~diff @@ -94,6 +96,24 @@ pub unsafe extern "system" fn RegisterClassExA(c: *const WndClassEx<u8>) -> u16 RegisterClassExW(&w) } +pub unsafe extern "system" fn UnregisterClassA(class_name: *const u8, instance: usize) -> i32 { + if class_name.is_null() { + windows_sys::Win32::Foundation::SetLastError(windows_sys::Win32::Foundation::ERROR_INVALID_PARAMETER); + return 0; + } + let mut keep = Vec::new(); + let name = name(class_name, &mut keep); ~~~~ --- Could this preserve integer atoms before calling `name`? `UnregisterClassA` accepts either a string or a class atom (the atom is a pointer-sized value with only its low word set). Passing the atom returned by `RegisterClassExA` here makes `name` treat it as an ANSI string and dereference it, instead of forwarding the atom to `UnregisterClassW`. Please add a regression that unregisters a class using `MAKEINTATOM(atom_a)` (or the equivalent pointer cast). AI-assisted review; I inspected the diff and tests but did not run them.
github-actions[bot] commented 2026-12-01 02:35:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:35:07Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298773847 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1138#issuecomment-7298773847). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:35:07Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:53:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:53:48Z.


Triage (#1607) – head e640169

No open or merged PR adds UnregisterClassA/W. #1131, #1436 and #794 only call UnregisterClassW from their tests.
The description says these entry points dropped to stubs, but they did not: user32 imports that hle::user::exports() does not list already resolve to Windows' user32.dll (see resolver.rs, console_user32_and_legacy_dlls_reach_the_pc_functions). In practice the PR adds a null-pointer check, and UnregisterClassA now converts the name the same way RegisterClassExA does. Please correct the description.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301213388 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1138#issuecomment-7301213388). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:53:48Z. --- **Triage (#1607)** – head e640169 No open or merged PR adds UnregisterClassA/W. #1131, #1436 and #794 only call UnregisterClassW from their tests. The description says these entry points dropped to stubs, but they did not: user32 imports that `hle::user::exports()` does not list already resolve to Windows' user32.dll (see `resolver.rs`, `console_user32_and_legacy_dlls_reach_the_pc_functions`). In practice the PR adds a null-pointer check, and UnregisterClassA now converts the name the same way RegisterClassExA does. Please correct the description. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1138:upstream-pr/1138'
git switch 'upstream-pr/1138'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1138'
git switch 'upstream-pr/1138'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1138'
git switch 'upstream-pr/1138'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1138'
git switch 'main'
git merge --squash 'upstream-pr/1138'
git switch 'main'
git merge --ff-only 'upstream-pr/1138'
git switch 'main'
git merge 'upstream-pr/1138'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
xcl-dev/xcl!1129
No description provided.