Forward thread attach and detach to mapped images #138

Merged
Leyukaka merged 3 commits from upstream-pr/139 into main 2026-11-21 20:25:39 +00:00
Leyukaka commented 2026-11-21 16:53:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T16:53:42Z.


Change

This follows up on #78, which listed thread notifications as open. pe_map.dll is itself loaded by Windows, so its own DllMain receives DLL_THREAD_ATTACH and DLL_THREAD_DETACH. It now forwards both to every image that pe_map_image mapped and attached:

  • the TLS callback list is re-read, as on release;
  • the order is TLS callbacks, then the entry point, with a null reserved argument.

Registration and forwarding:

  • Registration: a mapped image is registered after its process attach succeeds and unregistered at the start of pe_map_release, before its process detach.
  • Locking: the forwarding holds a shared SRW lock, released through RAII on every exit path, and an allocation failure while re-reading the list cannot escape DllMain. Registration takes the lock exclusively, so pe_map_release waits for in-flight notifications.
  • Restriction: a thread-notification callback must not map or release any image, or wait for a thread that does. The restriction is documented in the code and in the docs.

Measured with tls_route loaded by LoadLibraryW on Windows 11 build 26300. For a new thread, the TLS callback and then the entry point are called with DLL_THREAD_ATTACH on that thread, then the same pair with DLL_THREAD_DETACH, all with a null reserved argument.

Test changes:

  • cpu_tls_sink.dll now records the calling thread. Unrelated threads in the process, such as loader workers, are then ignored.
  • cpu_native_tls starts and joins one thread, whose start routine is kernel32!Sleep, between attach and release, under both loaders, and compares the notifications on that thread.

Verification

At the head of this branch on a2a62ee (Windows 11 build 26300, VS Build Tools 17.14, Python 3.14.10):

ctest --preset dev --no-tests=error -R '^cpu_native_tls$' -V
native and mapped: TLS callback then entry point on process attach, on a new thread's attach and detach, and on process detach, reserved null; a FALSE entry point is followed by a full detach and the load fails

The full suite gives 78 tests and 0 failures; only bvh_wave64_hardware and bvh_wave64_warp are skipped. As a one-off manual check (not in CI), I removed the forwarding loop; cpu_native_tls then fails because the mapped image gets no thread notifications.

Evidence and follow-up

The fixtures are built from this repository; there is no game data. Two points are not measured:

  • the order across several mapped images (the test maps one);
  • a thread that existed before mapping receives the detach without the attach. That matches Windows by construction, but no test covers it.

CI runs Python 3.12; I only ran 3.14 locally.

Refs #78

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531719535 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T16:53:42Z. --- ## Change This follows up on #78, which listed thread notifications as open. `pe_map.dll` is itself loaded by Windows, so its own `DllMain` receives `DLL_THREAD_ATTACH` and `DLL_THREAD_DETACH`. It now forwards both to every image that `pe_map_image` mapped and attached: - the TLS callback list is re-read, as on release; - the order is TLS callbacks, then the entry point, with a null reserved argument. Registration and forwarding: - **Registration:** a mapped image is registered after its process attach succeeds and unregistered at the start of `pe_map_release`, before its process detach. - **Locking:** the forwarding holds a shared SRW lock, released through RAII on every exit path, and an allocation failure while re-reading the list cannot escape `DllMain`. Registration takes the lock exclusively, so `pe_map_release` waits for in-flight notifications. - **Restriction:** a thread-notification callback must not map or release any image, or wait for a thread that does. The restriction is documented in the code and in the docs. Measured with `tls_route` loaded by `LoadLibraryW` on Windows 11 build 26300. For a new thread, the TLS callback and then the entry point are called with `DLL_THREAD_ATTACH` on that thread, then the same pair with `DLL_THREAD_DETACH`, all with a null reserved argument. Test changes: - `cpu_tls_sink.dll` now records the calling thread. Unrelated threads in the process, such as loader workers, are then ignored. - `cpu_native_tls` starts and joins one thread, whose start routine is `kernel32!Sleep`, between attach and release, under both loaders, and compares the notifications on that thread. ## Verification At the head of this branch on `a2a62ee` (Windows 11 build 26300, VS Build Tools 17.14, Python 3.14.10): ``` ctest --preset dev --no-tests=error -R '^cpu_native_tls$' -V native and mapped: TLS callback then entry point on process attach, on a new thread's attach and detach, and on process detach, reserved null; a FALSE entry point is followed by a full detach and the load fails ``` The full suite gives 78 tests and 0 failures; only `bvh_wave64_hardware` and `bvh_wave64_warp` are skipped. As a one-off manual check (not in CI), I removed the forwarding loop; `cpu_native_tls` then fails because the mapped image gets no thread notifications. ## Evidence and follow-up The fixtures are built from this repository; there is no game data. Two points are not measured: - the order across several mapped images (the test maps one); - a thread that existed before mapping receives the detach without the attach. That matches Windows by construction, but no test covers it. CI runs Python 3.12; I only ran 3.14 locally. Refs #78 _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:41:30 +00:00
R0Y00 commented 2026-11-24 06:47:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:17:50Z.


The new shared registry lock is held while invoking guest callbacks under DllMain. The patch notes that a callback that maps or releases an image can deadlock. Please keep user callbacks outside the registry lock with a defined image-lifetime protocol, or enforce and test a fail-fast reentrancy contract. Please cover multiple mapped images and removal during notification.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066368012 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066368012). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:17:50Z. --- The new shared registry lock is held while invoking guest callbacks under DllMain. The patch notes that a callback that maps or releases an image can deadlock. Please keep user callbacks outside the registry lock with a defined image-lifetime protocol, or enforce and test a fail-fast reentrancy contract. Please cover multiple mapped images and removal during notification.
Leyukaka commented 2026-11-24 06:47:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T17:41:52Z.


Thanks. Guest callbacks now run outside the registry lock, under a defined image-lifetime protocol, and the branch is synced on 245b207.

Protocol (tools/pe_map.cpp, top of the registry section):

  • Each mapped image holds one reference for its registration and one per thread notification in flight.
  • DllMain takes those references under the shared registry lock and calls the guest callbacks after releasing it. A callback may therefore map or release any image, its own included.
  • pe_map_release unregisters the image, marks it released and returns 1 without waiting. It returns 0 for an unknown pointer or a second release. The image's process detach and unmapping run exactly once, when the last reference goes: inside pe_map_release, or on the thread that finishes the last notification.
  • No notification that starts after the release reaches the image. A notification already in progress finishes, so when an image's TLS callback releases that image, its entry point still gets the same thread attach.
  • Attach goes in mapping order and detach in reverse. A native run with two LoadLibraryW copies on Windows 11 build 26300 does the same (attach A, B; detach B, A).

Tests: cpu_native_lifetime runs one child process per case.

  • two-images-native: two LoadLibraryW copies, asserting the attach/detach order above on each run.
  • two-images: two pe_map copies with the same order. Releasing B and then A gives one process detach each.
  • release-other-during-notification: A's TLS callback calls pe_map_release(B), through a one-shot hook in cpu_tls_sink armed for that thread only. B gets no thread notification, its process detach is recorded once, right after A's attach, and a later release of B returns 0.
  • release-self-during-notification: A's TLS callback releases A. A's thread attach completes, its process detach follows once, no thread detach reaches it, and a later release returns 0.

Manual mutations (not in CI) each fail the test:

  • calling the callbacks under the lock, as before: release-other times out after 60 s;
  • ignoring the released flag;
  • finalizing immediately in pe_map_release;
  • reversing the attach order;
  • not reversing the detach order.

cpu_native_tls still passes; all cpu_native_* tests pass, and the full suite has 83 tests with 0 failures.

Not covered: a release from a different thread while a callback is running. It is safe by construction under this protocol, since finalization is deferred to the notifying thread, but there is no test for it yet. I can add one with a small blocking helper if you want it in this PR.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066676180 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066676180). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T17:41:52Z. --- Thanks. Guest callbacks now run outside the registry lock, under a defined image-lifetime protocol, and the branch is synced on `245b207`. **Protocol** (`tools/pe_map.cpp`, top of the registry section): - Each mapped image holds one reference for its registration and one per thread notification in flight. - `DllMain` takes those references under the shared registry lock and calls the guest callbacks after releasing it. A callback may therefore map or release any image, its own included. - `pe_map_release` unregisters the image, marks it released and returns 1 without waiting. It returns 0 for an unknown pointer or a second release. The image's process detach and unmapping run exactly once, when the last reference goes: inside `pe_map_release`, or on the thread that finishes the last notification. - No notification that starts after the release reaches the image. A notification already in progress finishes, so when an image's TLS callback releases that image, its entry point still gets the same thread attach. - Attach goes in mapping order and detach in reverse. A native run with two `LoadLibraryW` copies on Windows 11 build 26300 does the same (attach A, B; detach B, A). **Tests:** `cpu_native_lifetime` runs one child process per case. - `two-images-native`: two `LoadLibraryW` copies, asserting the attach/detach order above on each run. - `two-images`: two `pe_map` copies with the same order. Releasing B and then A gives one process detach each. - `release-other-during-notification`: A's TLS callback calls `pe_map_release(B)`, through a one-shot hook in `cpu_tls_sink` armed for that thread only. B gets no thread notification, its process detach is recorded once, right after A's attach, and a later release of B returns 0. - `release-self-during-notification`: A's TLS callback releases A. A's thread attach completes, its process detach follows once, no thread detach reaches it, and a later release returns 0. Manual mutations (not in CI) each fail the test: - calling the callbacks under the lock, as before: `release-other` times out after 60 s; - ignoring the released flag; - finalizing immediately in `pe_map_release`; - reversing the attach order; - not reversing the detach order. `cpu_native_tls` still passes; all `cpu_native_*` tests pass, and the full suite has 83 tests with 0 failures. Not covered: a release from a *different* thread while a callback is running. It is safe by construction under this protocol, since finalization is deferred to the notifying thread, but there is no test for it yet. I can add one with a small blocking helper if you want it in this PR. _AI-assisted._
R0Y00 commented 2026-11-24 06:47:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:58:55Z.


The latest revision moves guest callbacks outside the registry lock and adds lifetime tests. GitHub still reports a merge conflict after the mapper changes landed. Please reconcile tools/pe_map.cpp and the test registrations with current main, preserving the delay-import changes from #127, and rerun the lifetime, TLS and delay-import checks together.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066911617 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066911617). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:58:55Z. --- The latest revision moves guest callbacks outside the registry lock and adds lifetime tests. GitHub still reports a merge conflict after the mapper changes landed. Please reconcile tools/pe_map.cpp and the test registrations with current main, preserving the delay-import changes from #127, and rerun the lifetime, TLS and delay-import checks together.
Leyukaka commented 2026-11-24 06:47:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T18:01:13Z.


Synced on ccfa703 after the latest merges. The only conflict was the CMakeLists.txt block next to the new frame and delay fixtures, and both were kept. The cpu_tls_sink change, which adds the calling thread and the one-shot hook, keeps the sink_record signature that tls_route.asm and the frame guest use.

All nine cpu_native_* tests pass on Windows 11 build 26300, including cpu_native_delay, cpu_native_frame_warp/_hardware and cpu_native_lifetime. The full suite has 103 tests with 0 failures.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066940038 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066940038). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T18:01:13Z. --- Synced on `ccfa703` after the latest merges. The only conflict was the `CMakeLists.txt` block next to the new frame and delay fixtures, and both were kept. The `cpu_tls_sink` change, which adds the calling thread and the one-shot hook, keeps the `sink_record` signature that `tls_route.asm` and the frame guest use. All nine `cpu_native_*` tests pass on Windows 11 build 26300, including `cpu_native_delay`, `cpu_native_frame_warp`/`_hardware` and `cpu_native_lifetime`. The full suite has 103 tests with 0 failures. _AI-assisted._
R0Y00 commented 2026-11-24 06:47:45 +00:00 (Migrated from github.com)

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


The rebase retains the delay-import cases and the author reports all nine native tests passed. The new int pe_map_release result and deferred teardown intersect the API decision in #164. This is now waiting on the lead developer there.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067046014 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7067046014). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:09:36Z. --- The rebase retains the delay-import cases and the author reports all nine native tests passed. The new `int pe_map_release` result and deferred teardown intersect the API decision in #164. This is now waiting on the lead developer there.
R0Y00 commented 2026-11-24 06:47:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:04:43Z.


The live-base registry in this PR is the approved design for #164. Keep the C symbol and pointer parameter, with an explicit int return in declarations and ctypes bindings. Exactly one caller can claim a live mapping, including concurrent releases of the same base. Returning 1 means the image has been unregistered and the caller must stop using it and its exports. Null, interior, foreign and already-released addresses return 0 without reading the address or changing anything. Once an address has been reused, a stale pointer cannot identify the earlier instance.

Without an outstanding notification, process detach, removal of registered unwind tables and unmapping must finish before return. An already-admitted notification may finish, with the last reference performing teardown exactly once. Admit no further notifications after unregistering. Run guest callbacks outside the registry lock so self-release never waits on itself.

d18809a5 already covers self-release and repeat release. Please resolve the current merge conflict against main, preserve both sides' fixtures, and add the missing null, interior and foreign-base assertions. On the rebased SHA, please report the lifetime, TLS and SEH Windows results, including evidence for one winner on concurrent release, in-flight teardown and unwind-table removal. Reuse the existing controls wherever they already cover a case.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067743646 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7067743646). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:04:43Z. --- The live-base registry in this PR is the approved design for #164. Keep the C symbol and pointer parameter, with an explicit `int` return in declarations and ctypes bindings. Exactly one caller can claim a live mapping, including concurrent releases of the same base. Returning 1 means the image has been unregistered and the caller must stop using it and its exports. Null, interior, foreign and already-released addresses return 0 without reading the address or changing anything. Once an address has been reused, a stale pointer cannot identify the earlier instance. Without an outstanding notification, process detach, removal of registered unwind tables and unmapping must finish before return. An already-admitted notification may finish, with the last reference performing teardown exactly once. Admit no further notifications after unregistering. Run guest callbacks outside the registry lock so self-release never waits on itself. `d18809a5` already covers self-release and repeat release. Please resolve the current merge conflict against main, preserve both sides' fixtures, and add the missing null, interior and foreign-base assertions. On the rebased SHA, please report the lifetime, TLS and SEH Windows results, including evidence for one winner on concurrent release, in-flight teardown and unwind-table removal. Reuse the existing controls wherever they already cover a case.
Leyukaka commented 2026-11-24 06:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T19:47:16Z.


The branch is rebased on 7233cec. The only conflict was the TLS paragraph in docs/experiments.md, where the thread-notification text and the pe_map_export readability sentence from main are both kept. b90d1a0 adds three cases for the #164 contract to cpu_native_lifetime. Like the existing cases, each runs in its own child process.

  • release-unowned-addresses. Each of these releases returns 0:

    • null;
    • base + 0x10 and base + 1;
    • an interior page of the image (.rsrc, which no notification touches) after it is made PAGE_NOACCESS;
    • a foreign PAGE_NOACCESS page;
    • a foreign read-write buffer.

    Because the two unreadable pages would fault on any read, they show that the argument is not dereferenced. The buffer keeps its bytes and its MEM_COMMIT/PAGE_READWRITE state, and no process detach is recorded. The base is then released with result 1. Before that call returns, the process detach is recorded, RtlLookupFunctionEntry stops finding the entry point's function, and the base is no longer committed. A second release returns 0.

  • concurrent-release. cpu_tls_sink gains sink_race_release, which starts eight native threads that spin on one flag and then release the same image together. It returns only after every thread has exited, thread detach included. In 50 rounds, every round has seven 0 results, one 1, one process detach and no unwind entry left.

    Addresses are the only identity, as the registry comment and the docs now state. After the rounds, the test maps a new copy, asserts that it took the freed address, and releases it through the stale pointer.

  • release-during-notification-on-another-thread. A worker's TLS callback blocks inside its thread attach, and the main thread releases the image. The first release returns 1 at once and a second returns 0. At that point the unwind entry is still present and no process detach has run. Once the callback is unblocked:

    • the entry point receives the admitted attach;
    • the worker performs the process detach and the table removal exactly once;
    • the thread detach is not delivered.

Admission is defined as taking the reference under the registry lock. An admitted notification skips an image already marked released, but a callback that has already started finishes.

Results on Windows 11 build 26300.9974, MSVC 14.44.35207, at b90d1a0:

cpu_native_lifetime ... Passed   (7 cases, including the 3 above)
cpu_native_tls ........ Passed
cpu_native_seh ........ Passed

The full suite passes 122 of 122 tests. Three hardware or WARP capability checks are skipped.

Mutations of tools/pe_map.cpp at b90d1a0, each run against the case that targets it, three times for concurrent-release:

Mutation Case Result
pe_map_release takes the shared lock instead of the exclusive one concurrent-release child crashes in 3 of 3 runs (0xC0000409, 0x80000003)
pe_map_release looks up and erases without the lock concurrent-release child crashes in 3 of 3 runs (0x80000003)
the registry entry is not erased concurrent-release 5 or 8 winners in round 0, or a crash, in 3 of 3 runs
pe_map_release calls finalize instead of dropping its reference release-during-notification-on-another-thread child crashes (0xC0000005)
pe_map_release reads one byte of any non-null argument first release-unowned-addresses access violation on an unreadable page
finalize skips RtlDeleteFunctionTable concurrent-release the child hangs and is killed after 60 s, in 3 of 3 runs

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068277597 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068277597). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T19:47:16Z. --- The branch is rebased on `7233cec`. The only conflict was the TLS paragraph in `docs/experiments.md`, where the thread-notification text and the `pe_map_export` readability sentence from main are both kept. `b90d1a0` adds three cases for the #164 contract to `cpu_native_lifetime`. Like the existing cases, each runs in its own child process. - **`release-unowned-addresses`.** Each of these releases returns 0: - null; - `base + 0x10` and `base + 1`; - an interior page of the image (`.rsrc`, which no notification touches) after it is made `PAGE_NOACCESS`; - a foreign `PAGE_NOACCESS` page; - a foreign read-write buffer. Because the two unreadable pages would fault on any read, they show that the argument is not dereferenced. The buffer keeps its bytes and its `MEM_COMMIT`/`PAGE_READWRITE` state, and no process detach is recorded. The base is then released with result 1. Before that call returns, the process detach is recorded, `RtlLookupFunctionEntry` stops finding the entry point's function, and the base is no longer committed. A second release returns 0. - **`concurrent-release`.** `cpu_tls_sink` gains `sink_race_release`, which starts eight native threads that spin on one flag and then release the same image together. It returns only after every thread has exited, thread detach included. In 50 rounds, every round has seven 0 results, one 1, one process detach and no unwind entry left. Addresses are the only identity, as the registry comment and the docs now state. After the rounds, the test maps a new copy, asserts that it took the freed address, and releases it through the stale pointer. - **`release-during-notification-on-another-thread`.** A worker's TLS callback blocks inside its thread attach, and the main thread releases the image. The first release returns 1 at once and a second returns 0. At that point the unwind entry is still present and no process detach has run. Once the callback is unblocked: - the entry point receives the admitted attach; - the worker performs the process detach and the table removal exactly once; - the thread detach is not delivered. Admission is defined as taking the reference under the registry lock. An admitted notification skips an image already marked released, but a callback that has already started finishes. Results on Windows 11 build 26300.9974, MSVC 14.44.35207, at `b90d1a0`: ```text cpu_native_lifetime ... Passed (7 cases, including the 3 above) cpu_native_tls ........ Passed cpu_native_seh ........ Passed ``` The full suite passes 122 of 122 tests. Three hardware or WARP capability checks are skipped. Mutations of `tools/pe_map.cpp` at `b90d1a0`, each run against the case that targets it, three times for `concurrent-release`: | Mutation | Case | Result | |---|---|---| | `pe_map_release` takes the shared lock instead of the exclusive one | `concurrent-release` | child crashes in 3 of 3 runs (0xC0000409, 0x80000003) | | `pe_map_release` looks up and erases without the lock | `concurrent-release` | child crashes in 3 of 3 runs (0x80000003) | | the registry entry is not erased | `concurrent-release` | 5 or 8 winners in round 0, or a crash, in 3 of 3 runs | | `pe_map_release` calls `finalize` instead of dropping its reference | `release-during-notification-on-another-thread` | child crashes (0xC0000005) | | `pe_map_release` reads one byte of any non-null argument first | `release-unowned-addresses` | access violation on an unreadable page | | `finalize` skips `RtlDeleteFunctionTable` | `concurrent-release` | the child hangs and is killed after 60 s, in 3 of 3 runs | _AI-assisted._
R0Y00 commented 2026-11-24 06:47:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:56:12Z.


The registry, concurrent release, deferred teardown and unwind checks now cover the agreed contract. One fixture assertion still depends on Windows allocation placement: expect("reused address", reused, previous_base) in concurrent-release. The mapper calls VirtualAlloc(nullptr, ...), so the next allocation can legitimately land elsewhere. Please condition the stale-pointer case on actual reuse; when the address differs, require release of the old address to return 0 and release the new mapping by its own base. Keep the one-winner and unwind checks unconditional.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068384876 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068384876). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T19:56:12Z. --- The registry, concurrent release, deferred teardown and unwind checks now cover the agreed contract. One fixture assertion still depends on Windows allocation placement: `expect("reused address", reused, previous_base)` in `concurrent-release`. The mapper calls `VirtualAlloc(nullptr, ...)`, so the next allocation can legitimately land elsewhere. Please condition the stale-pointer case on actual reuse; when the address differs, require release of the old address to return 0 and release the new mapping by its own base. Keep the one-winner and unwind checks unconditional.
Leyukaka commented 2026-11-24 06:47:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T20:06:52Z.


Done in 34f9eea: the stale-pointer case now depends on actual reuse. If the new mapping lands at the released address, releasing the stale pointer returns 1 and records that mapping's process detach. Otherwise the stale release returns 0 with no detach, and the new mapping is released by its own base. The one-winner and unwind checks are unchanged and unconditional.

On Windows 11 build 26300.9974, --run concurrent-release took the reuse branch. In a second run, the old base was held with a temporary VirtualAlloc(MEM_RESERVE) that is not part of the commit. The new mapping then landed elsewhere and the other branch passed. Both runs printed 50 rounds of 8 native concurrent releases: one winner each. The full suite passes 122 of 122 tests. This supersedes the sentence in my previous comment saying that the test asserts the new copy took the freed address.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068514198 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068514198). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-21T20:06:52Z. --- Done in `34f9eea`: the stale-pointer case now depends on actual reuse. If the new mapping lands at the released address, releasing the stale pointer returns 1 and records that mapping's process detach. Otherwise the stale release returns 0 with no detach, and the new mapping is released by its own base. The one-winner and unwind checks are unchanged and unconditional. On Windows 11 build 26300.9974, `--run concurrent-release` took the reuse branch. In a second run, the old base was held with a temporary `VirtualAlloc(MEM_RESERVE)` that is not part of the commit. The new mapping then landed elsewhere and the other branch passed. Both runs printed `50 rounds of 8 native concurrent releases: one winner each`. The full suite passes 122 of 122 tests. This supersedes the sentence in my previous comment saying that the test asserts the new copy took the freed address. _AI-assisted._
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!138
No description provided.