runtime: report the native error for null query output #221

Merged
Vonsek merged 1 commit from upstream-pr/224 into main 2026-11-21 18:43:42 +00:00
Vonsek commented 2026-11-21 18:36:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:36:31Z.


Change

When a caller gives desktop XMemVirtualQuery a null output pointer, xmem.dll returns FALSE and sets the Windows last error to ERROR_NOACCESS. Previously the export always reported ERROR_BAD_LENGTH even though its fixed 64-byte result capacity was sufficient. The shared query handler checks the supplied length first, matching the Windows error for null outputs shorter than MEMORY_BASIC_INFORMATION.

Verification

Windows x64 build 26200, MSVC 19.44.35230, Debug, based on f02c237.

. ./tools/dev.ps1
cmake --preset dev
cmake --build --preset dev --target era_query_check xmem_shim_check memory_query_check
ctest --preset dev --no-tests=error -R '^(era_query_.*|xmem_shim_.*|desktop_memory_query)$' -V

All nine selected cases passed, with zero skips. The direct handler fixture compares the return value and last error with VirtualQueryEx in the same process. The named DLL import exercises the 64-byte case independently.

Null output with supplied capacity Win32 last error Previous handler Updated handler
47 bytes 24 24 24
48 bytes 998 24 998
64 bytes (also used by the DLL export) 998 24 998

With the tests added and the previous implementation, ctest --preset dev --no-tests=error -R '^(era_query_short|xmem_shim_query)$' -V failed both tests. The first handler mismatch was null_query_length=48 native_error=998 shim_error=24. The separate DLL fixture reported null_output_error=24.

Evidence and follow-up

The fixture uses a valid address in its own process and a null output. Existing cases check a short non-null buffer stays untouched and an exactly sized non-null buffer succeeds. These measurements describe the desktop shim contract. They do not establish console last-error behavior.

This contribution was AI-assisted.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated the era_query_short experiment in docs/experiments.md.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532827300 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/224). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T18:36:31Z. --- ## Change When a caller gives desktop `XMemVirtualQuery` a null output pointer, `xmem.dll` returns `FALSE` and sets the Windows last error to `ERROR_NOACCESS`. Previously the export always reported `ERROR_BAD_LENGTH` even though its fixed 64-byte result capacity was sufficient. The shared query handler checks the supplied length first, matching the Windows error for null outputs shorter than `MEMORY_BASIC_INFORMATION`. ## Verification Windows x64 build 26200, MSVC 19.44.35230, Debug, based on `f02c237`. ```powershell . ./tools/dev.ps1 cmake --preset dev cmake --build --preset dev --target era_query_check xmem_shim_check memory_query_check ctest --preset dev --no-tests=error -R '^(era_query_.*|xmem_shim_.*|desktop_memory_query)$' -V ``` All nine selected cases passed, with zero skips. The direct handler fixture compares the return value and last error with `VirtualQueryEx` in the same process. The named DLL import exercises the 64-byte case independently. | Null output with supplied capacity | Win32 last error | Previous handler | Updated handler | |---|---:|---:|---:| | 47 bytes | 24 | 24 | 24 | | 48 bytes | 998 | 24 | 998 | | 64 bytes (also used by the DLL export) | 998 | 24 | 998 | With the tests added and the previous implementation, `ctest --preset dev --no-tests=error -R '^(era_query_short|xmem_shim_query)$' -V` failed both tests. The first handler mismatch was `null_query_length=48 native_error=998 shim_error=24`. The separate DLL fixture reported `null_output_error=24`. ## Evidence and follow-up The fixture uses a valid address in its own process and a null output. Existing cases check a short non-null buffer stays untouched and an exactly sized non-null buffer succeeds. These measurements describe the desktop shim contract. They do not establish console last-error behavior. This contribution was AI-assisted. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated the `era_query_short` experiment in `docs/experiments.md`. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:41:53 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:36:41Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:38:30.188298Z 216df14 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067381533 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/224#issuecomment-7067381533). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T18:36:41Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"216df144d5ba4c52152ba2570412240d8dd72efa","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T18:38:30.188298Z">2026-11-21T18:38:30.188298Z</relative-time> | `216df14` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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
R0Y00/Xbox2Windows!221
No description provided.