Skip to content

runtime/shims: shim PSM app-notification and WER file registration APIs (RT-PSM-APPNOTIFY-WER) - #1240

Open
piyonchu wants to merge 1 commit into
ProjectLeonida:mainfrom
piyonchu:pr/psm-appnotify-wer-shims
Open

piyonchu wants to merge 1 commit into
ProjectLeonida:mainfrom
piyonchu:pr/psm-appnotify-wer-shims

Conversation

@piyonchu

@piyonchu piyonchu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Claim ID: RT-PSM-APPNOTIFY-WER

Adds runtime/shims/appnotify.cpp and runtime/test/appnotify_test.cpp (wired into runtime/CMakeLists.txt and scripts/build_runtime.ps1):

  • Shims RegisterAppConstrainedChangeNotification and UnregisterAppConstrainedChangeNotification across kernel32.dll, kernelbase.dll, twinapi.appcore.dll, and api-ms-win-core-psm-appnotify-l1-1-0/1.dll, returning distinct tracked registration handles, ignoring nullptr/foreign/already-freed handles cleanly on unregister, and using constant-initialized SRWLOCK + raw lists to avoid MSVC TLS init guards. (RegisterAppStateChangeNotification and UnregisterAppStateChangeNotification are left out so they do not collide with #769.)
  • Shims WerRegisterFile / WerUnregisterFile across kernel32.dll, kernelbase.dll, wer.dll, and api-ms-win-core-windowserrorreporting-l1-1-0/1.dll, tracking normalized GAME:/G:/T: and host paths in-process without mutating host WER state or creating files on disk.
  • Adds unit tests in runtime/test/appnotify_test.cpp executed via rt::shims::find.

Verification

  • Host: Windows 11 (10.0.26100 SDK), MSVC (RelWithDebInfo), rebased onto cont/main (871e4b8b9), commit b607337fd.
  • ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure: 100% tests passed out of 148 (including #83 appnotify), with 7 game-data tests skipped (LEONIDA_GAME_DIR unset) and 2 gameinput tests disabled (no SDL3).
  • python -I tests/test_build_runtime_fallback.py: passed (10/10).
  • python -I scripts/check_no_game_data.py ... and git diff --check cont/main..HEAD: clean.
  • No game files used; CPU runtime test only (no GPU required). AI-assisted.

@aslan2142

Copy link
Copy Markdown
Collaborator

@piyonchu one overlap to sort out before this can go in:

AI-assisted (Claude Code, Claude Opus 5.5).

@piyonchu
piyonchu force-pushed the pr/psm-appnotify-wer-shims branch from 875fa5c to b607337 Compare November 25, 2026 02:08
@piyonchu

Copy link
Copy Markdown
Contributor Author

Thanks for catching the #769 overlap, @aslan2142! Updated #1240 (b607337fd) and rebased cleanly onto main (871e4b8b9):

  • Dropped RegisterAppStateChangeNotification and UnregisterAppStateChangeNotification from runtime/shims/appnotify.cpp and runtime/test/appnotify_test.cpp so there is no SHIM_TABLE registry collision with #769.
  • Kept RegisterAppConstrainedChangeNotification, UnregisterAppConstrainedChangeNotification, WerRegisterFile, and WerUnregisterFile, plus re-tested ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure (100% passed out of 148, #83 appnotify passed) and python -I tests/test_build_runtime_fallback.py (10/10 passed).

I also left a brief note on #769 with the negative test cases (nullptr registration pointer, null callback zeroing *Registration, nullptr/foreign-handle unregister) in case they are useful for lifecycle_test.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@piyonchu
piyonchu force-pushed the pr/psm-appnotify-wer-shims branch from b607337 to cdee0f8 Compare November 25, 2026 14:28
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 26, 2026
@piyonchu

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (fac8b4bb9, head commit 677379b01), resolving the scripts/build_runtime.ps1 fallback file list conflict cleanly (shims\xapu_queue.cpp + shims\appnotify.cpp).

Verified locally after rebase:

  • git diff --check cont/main..HEAD
  • python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/appnotify.cpp runtime/test/appnotify_test.cpp scripts/build_runtime.ps1
  • cmake --build runtime/build --config RelWithDebInfo --target gta6rt appnotify_test
  • ctest --test-dir runtime/build -C RelWithDebInfo -R "^appnotify$" --output-on-failure (1/1 passed)

@piyonchu
piyonchu force-pushed the pr/psm-appnotify-wer-shims branch from cdee0f8 to 677379b Compare November 26, 2026 21:40
@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Independent Verification Report — 677379b018 + origin/main (a8465211fb)

Environment: Windows 11 (26200), AMD Ryzen 9 5950X, MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8, Debug /Od /MDd & Release /O2 /MD, /link /OPT:NOREF).
Verdict: C++ shim & appnotify_test PASS (46/46); 2 minor hygiene/SDK items noted below — clean Git merge with origin/main (8690b4f8adf8).

1. Red -> Green Verification

  • Red (origin/main registry.cpp + #1240 appnotify_test.cpp): Fails immediately (rt::shims::find returns nullptr for RegisterAppConstrainedChangeNotification, UnregisterAppConstrainedChangeNotification, WerRegisterFile, and WerUnregisterFile).
  • Green (677379b018 + origin/main):
    • appnotify_test (Debug /Od /MDd & Release /O2 /MD): PASS (46 check(s), 0 failure(s)), 0 warnings under /W4 /permissive- (verifying SHIM_TABLE resolution across all 5 appnotify and 5 WER DLL names, null/sentinel/foreign/double unregister safety, 4-thread x 64-iteration concurrent register/unregister stress, and GAME:/G:/T:/.. traversal normalization).
    • python -I tests/test_ctest_registration.py & python -I tests/test_docs_encoding.py: PASS.
    • Verified zero SHIM_TABLE symbol overlap with lifecycle.cpp (RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification remain solely in lifecycle.cpp).

2. Non-Blocking Hygiene & SDK Notes

  1. Accidental UTF-8 BOM in scripts/build_runtime.ps1:1: On origin/main, scripts/build_runtime.ps1 has no BOM (23 20 42...), whereas 677379b018 prepends a 3-byte UTF-8 BOM (ef bb bf 23 20 42...). Stripping those 3 leading bytes keeps git diff clean.
  2. WER_FILE_COMPRESSED (0x4) in wer_register_file (runtime/shims/appnotify.cpp:202): Windows SDK 10.0.26100.0 <werapi.h> defines WER_FILE_DELETE_WHEN_DONE = 0x1, WER_FILE_ANONYMOUS_DATA = 0x2, and WER_FILE_COMPRESSED = 0x4. Widening kWerKnownFlagsMask from 0x3u to 0x7u avoids returning E_INVALIDARG if a title passes WER_FILE_COMPRESSED.

AI-assisted.

@piyonchu

Copy link
Copy Markdown
Contributor Author

Addressed both items and rebased onto cont/main (16f505304, head a3b3fe054), thanks @zmasi!

  1. UTF-8 BOM (scripts/build_runtime.ps1): Stripped the 3-byte UTF-8 BOM from scripts/build_runtime.ps1.
  2. WER_FILE_COMPRESSED (runtime/shims/appnotify.cpp, runtime/test/appnotify_test.cpp): Widened kWerKnownFlagsMask from 0x3u to 0x7u (supporting WER_FILE_COMPRESSED = 0x4) and added a corresponding test check in appnotify_test.cpp.

Verified locally after a3b3fe054:

  • python -I tests/test_text_encoding.py: Ran 2 tests ... OK
  • python -I tests/test_docs_encoding.py: Ran 1 test ... OK
  • python -I tests/test_ctest_registration.py: Ran 7 tests ... OK
  • ctest --test-dir runtime/build -C RelWithDebInfo -R "^appnotify$" --output-on-failure: 1/1 passed

@piyonchu
piyonchu force-pushed the pr/psm-appnotify-wer-shims branch from 677379b to a3b3fe0 Compare November 29, 2026 01:14
@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR

  • Base: main 5825b02ff + PR head a3b3fe054 (tested as a merge)
  • Test: ctest -R ^appnotify$
  • Red on main: n/a (new shim; the test needs shims/appnotify.cpp, absent on main)
  • Green with the PR: appnotify passes; gta6rt links with the new shim
  • gta6rt link: OK (gta6rt.exe builds and links; dumpbin /dependents shows the same DLLs as main, no network DLL)
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

#1240 | head a3b3fe0 (merged cleanly onto origin/main c8bf0e7) | Windows 11 (10.0.26200.9974), MSVC 19.44.35228 (x64), Python 3.12.10 | AI-assisted: yes

Summary — PASS (Re-verification of updated head a3b3fe054265)

Re-verified a3b3fe05426578493027567eb6acb7de0dc9a7de merged cleanly onto origin/main (c8bf0e7b6568f471b42540010e335ca6413d4c58, git merge-tree --write-tree exit 0) on native Windows 11 (x64).

Red -> Green Verification

  1. Red (origin/main c8bf0e7b65):
    • runtime/shims/appnotify.cpp and runtime/test/appnotify_test.cpp are absent on origin/main.
  2. Green (origin/main + #1240):
    • MSVC 19.44.35228 build (/std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8 /link /OPT:NOREF):
      • appnotify_test.cpp + appnotify.cpp + registry.cpp compiled cleanly with 0 warnings.
    • Native Windows 11 execution:
      • appnotify_test.exe -> 48 check(s), 0 failure(s) (export resolution across DLL sets, RegisterAppConstrainedChangeNotification / UnregisterAppConstrainedChangeNotification null/foreign/double-unregister and multi-threaded concurrent registration, plus WerRegisterFile / WerUnregisterFile argument validation, GAME: / G: / T: root-traversal rejection, normalized dot-dot path matching, WER_FILE_COMPRESSED, and ERROR_NOT_FOUND after removal).
    • CMake Gate:
      • python tests/test_ctest_registration.py -> OK

Cross-PR Note (#1242)

  • Merges cleanly (rc=0) with origin/main (c8bf0e7b65) and #1931. Co-merging alongside sibling PR #1242 touches the same source/target registration lines in runtime/CMakeLists.txt and scripts/build_runtime.ps1 (runtime/README.md auto-merges cleanly), so whichever lands second will need a small 2-file merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants