Forward thread attach and detach to mapped images #139

Manually merged
github merged 3 commits from gh-pr/139/head into gh-pr/139/base 2026-11-26 21:29:43 +00:00
Owner

@⁠Leyukaka on GitHub · 2026-11-21 16:53 UTC · original
Leyukaka:thread-notify → main · +580 −27 · 7 files · 3 commits · merged 2026-11-21 20:25 UTC

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.

**@⁠Leyukaka** on GitHub · 2026-11-21 16:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139) `Leyukaka:thread-notify` → `main` · +580 −27 · 7 files · 3 commits · merged 2026-11-21 20:25 UTC ## 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._
pe_map.dll is loaded by Windows, so its DllMain receives DLL_THREAD_ATTACH
and DLL_THREAD_DETACH; it now forwards them to every image mapped by
pe_map_image, TLS callbacks first; attach in mapping order and detach in
reverse, as measured with two LoadLibraryW copies.

Guest callbacks run outside the registry lock. Each image holds one
reference for its registration and one per notification in flight;
pe_map_release unregisters the image, returns 1 and never waits, and the
image's process detach and unmapping run once, when its last reference
goes. No notification that starts after a release reaches the image.

cpu_native_tls compares one new thread's notifications between both
loaders. cpu_native_lifetime compares two mapped images with two native
loads, and releases another image and the image itself from inside a
thread-attach callback, through a one-shot hook in cpu_tls_sink armed for
that thread.

Refs #78
cpu_native_lifetime gains three cases for the #164 contract. Null,
interior and foreign addresses, including unreadable pages, return 0 and
change nothing. Eight native threads from cpu_tls_sink release one image
together in 50 rounds with exactly one 1. A release from another thread
while a TLS callback is blocked returns 1 at once, and teardown and .pdata
removal wait for the worker. RtlLookupFunctionEntry shows the unwind table
before and after each release. The registry comment now defines admission
as taking the reference and states that addresses are the only identity.

Refs #164
pe_map lets VirtualAlloc choose the base, so a new mapping may land
elsewhere. When it reuses the released address, the stale pointer
releases it; otherwise the stale release returns 0 and the new mapping is
released by its own base.

Refs #164
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:29:37 +00:00
github manually merged commit 34f9eea57b into gh-pr/139/base 2026-11-26 21:29:43 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 17:17 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 17:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066368012) 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.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 17:41 UTC · original

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.

**@⁠Leyukaka** on GitHub · 2026-11-21 17:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066676180) 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._
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 17:58 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 17:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066911617) 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.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 18:01 UTC · original

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.

**@⁠Leyukaka** on GitHub · 2026-11-21 18:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7066940038) 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._
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 18:09 UTC · original

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** on GitHub · 2026-11-21 18:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7067046014) 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 19:04 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 19:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7067743646) 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.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 19:47 UTC · original

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.

**@⁠Leyukaka** on GitHub · 2026-11-21 19:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068277597) 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._
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 19:56 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 19:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068384876) 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.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-21 20:06 UTC · original

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.

**@⁠Leyukaka** on GitHub · 2026-11-21 20:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/139#issuecomment-7068514198) 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._
This discussion has been locked. Commenting is limited to contributors.
No description provided.