pe: install a main image's TLS block in slot 0 of every thread #981
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/988"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T20:03:25Z.
Refs #870, Refs #165
This is the focused main-image TLS slot and per-thread initialization PR that R0Y00 asked for on #870 (18:29Z). It was reworked after review in
2134f9d(explicit participants),419e859(retryable release refusal),685dce4(0/1 release convention, notification gating),440de93(explicit guest-thread enrollment instead of process termination) anddc7bd04(a failedResumeThreadrefuses the creation). R0Y00 added4af2ab0(reclaiming terminated suspended enrollments, with thecancelledcontrol). The rule and fixture shape are MoonYueya's (#870, 18:23Z and 19:17Z), and they offered to review. The code and fixtures here are this repository's own. It builds on #883 and #920 and is separate from #961 (ordinal-only imports).Problem
Code compiled with
/GAassumes its EXE owns TLS index 0. It reads thread-locals asmov rcx, gs:[58h]/mov rcx, [rcx], with no_tls_indexload.pe_mapserves the template through a carrier DLL with its own index, so a mapped/GAimage reads and writes whatever block the host keeps in slot 0.Change (
tools/pe_map.cpp)pe_map_run_mainispe_map_runfor the image the host treats as its main executable.pe_map_runis unchanged.Explicit participation, with an own-thread handshake. Only participating threads get the image's block in slot 0, and each thread swaps its own slot. No thread writes another thread's slot, and there is no sweep. The participants are:
pe_map_run_main, from before the process-attach callbacks untilpe_map_releaseon that thread;pe_map_main_create_thread(below), from theirDLL_THREAD_ATTACH(before any image is notified) to theirDLL_THREAD_DETACH(after every image was notified, and before ntdll frees the thread's blocks);pe_map_main_thread_enterandpe_map_main_thread_leave.Explicit guest-thread enrollment. No thread is classified by inspecting it, and no thread notification can end the process. The host binds the main image's
CreateThreadimports tope_map_main_create_thread, which hasCreateThread's signature. While an image is started as the main image, it does the following:SYNCHRONIZEhandle before it can run;CREATE_SUSPENDED.Only a thread found in that table installs the image's block at its
DLL_THREAD_ATTACH. Every other thread returns at once, untouched. The pe_map start routine calls the guest's start routine only if the installation succeeded. Failures are reported before guest code runs:pe_map_main_create_threadreturns null withERROR_NOT_ENOUGH_MEMORYand no thread exists.ResumeThreadreturnedDWORD(-1)):pe_map_main_create_threadreturns null withResumeThread's last error, never a suspended handle. The thread, still suspended at the pe_map start routine, is ended. Its entry and watch handle stay reserved until the handle is signaled, so release keeps refusing and the slot is not reused while the thread could exist.0xE0000201without calling the guest's routine. The main image's callbacks are not notified, because the thread does not participate.All three are counted in
pe_map_main_tls_stats. Entries whose thread ended before its start routine (for example a suspended worker the guest terminated) are reclaimed once their handle is signaled (4af2ab0).pe_map_main_tls_injectforces the enrollment (1), installation (2) or resume (3) failure, for tests.I chose enrollment over scoping the mode to a dedicated child process. Any rule that classifies a thread inside
DLL_THREAD_ATTACHcan fail at a point where the only choices are to run guest code with the wrong block or to kill the process. With enrollment the creator decides before the thread exists.Supported thread entries.
pe_map_run_main.CreateThreadimport bound tope_map_main_create_thread.Not supported, and running with the host's slot 0:
CreateThreadaddress it looked up itself,CreateRemoteThread(Ex),NtCreateThreadEx, thread-pool work, or a C runtime's_beginthreadexin another DLL;No allocation on attach. A participant keeps its previous slot 0 in pe_map TLS slots reserved at the start. They are below
TLS_MINIMUM_AVAILABLE, so setting them never allocates. Its thread handle goes into a fixed 64-entry table.Release is a retryable refusal.
pe_map_releasekeeps its published 0/1 convention. It returns 0 and changes nothing while any participant other than the calling thread may still run the image's code. That covers:pe_map_main_tls_statsthen reports last release 2. While refused, the image stays registered and mapped, its unwind data stays registered, its carrier stays loaded, and every participant keeps its slot. The caller retries.An accepted release is checked and committed under one lock, so no participant can join in between. It does the following:
Notifications. The main image's TLS callbacks receive
DLL_THREAD_ATTACHandDLL_THREAD_DETACHonly on participating threads, because a/GAcallback on another thread would read the host's block. Other images, and EXEs started withpe_map_run, are notified as before.On a participating thread the host's own index-0 code reads the image's block, so a host that owns slot 0 must not touch its thread-locals there. That rules out a Python host for this test: in Python 3.13,
python313.dllcarries static TLS.Tests
cpu_exe_tls_slot0is a CRT-free/GAEXE. Its template is an int (7) plus a0x1400-byte array of0xFF. Its TLS callback and each thread (the initial thread and two workers) check whether slot 0 equals the entry at_tls_index. Only when it does, a thread checks its template copy, writes the whole array, reads it back and callsHeapValidate. There are two variants:cpu_exe_tls_slot0_pauseadds worker c, which pauses inside the image's code on an event.cpu_exe_tls_slot0_enrollfirst starts probe worker p, whose start routine touches a global sentinel as its first statement, and records a failedCreateThreadinstead of exiting.Windows evidence and mapped evidence are in separate tests.
cpu_native_exe_tls_slot0_windows: the Windows launch only, where the EXE owns index 0:cpu_native_exe_tls_slot0andcpu_native_exe_tls_slot0_enroll:pe_maponly.cpu_exe_tls_slot0_hostis a CRT-free host with its own TLS directory and a thread-local sentinel, so its block owns slot 0. It binds onlykernel32.dlland runs each scenario as its own child process. Underpe_map_run_mainit binds the guest'sCreateThreadtope_map_main_create_thread. Underpe_map_runit binds kernel32's.Non-participating host threads. Each scenario has two:
Neither may ever see a change. The guest exports its TLS callback counts by reason (
exe_slot0_callback_counts). Underpe_map_run_main, the callback must not run during the late thread's life. Underpe_map_run, the late thread's attach and detach still reach the guest.A refused release returns 0 with the refusal reported, and the accepted release is the only one that returns 1. Every accepted release must leave the image no longer committed,
RtlLookupFunctionEntryfinding nothing for its entry point, and the carrier unloaded. A further release must return 0 (exactly one cleanup).Counters, in order: installed, restored, exited, refused releases, pending, active, last release, untracked, enrollments refused, enrolled threads failed.
main: a host thread enters and leaves2,2; 04,4,0,0,0,0,1,0,0,0alive: a host participant is still entered2,2; 04,4,0,1,0,0,1,0,0,0exited: a host participant is ended withTerminateThread2,2; 04,3,1,0,0,0,1,0,0,0untracked: 64 host participants, the last finds the table full2,2; 067,67,0,1,0,0,1,0,0,0paused: guest worker c paused inside the image's code3,3; 05,5,0,1,0,0,1,0,0,0plain:pe_map_run(negative control), every slot-0 checkn,X=83,3; 20,0,0,0,0,0,-1,0,0,0cpu_native_exe_tls_slot0_enrollcovers forced enrollment failures. Each scenario also has a host participant, and the reader, late-thread, release and cleanup checks apply:probe(control): p enrolled, log addsp2=yy p:yyyy p3=y-1,1,0,03,35,5,0,0,0,0,1,0,0,0enroll_refused: p's enrollment fails0,0,8,0:CreateThreadreturned null, no thread2,24,4,0,0,0,0,1,0,1,0install_failed: installation on p fails0,1,0,e0000201: p ended before its start routine2,24,4,0,0,0,0,1,0,0,1resume_failed: the resume of p fails0,0,5,0: null withResumeThread's error, p ended while suspended2,24,4,0,0,0,0,1,0,1,0cancelled(R0Y00): 65 suspended workers ended in turn, then p1,1,0,0, log addsp2=yy p:yyyy p3=y-3,35,5,0,0,0,0,1,0,0,65The probe worker is created without
CREATE_SUSPENDED, so the boundCreateThreadperforms the resume. In every failure scenario the sentinel stayed 0, the guest got no callback for p, workers a and b were enrolled normally afterwards, and the host process survived: it printed its report and exited 0.pausedis the paused-participant test R0Y00 asked for.aliveanduntrackedare the deterministic controls for a participant that is still running or cannot be inspected.alivefails, andpausedcrashes with0xC0000005.mainfails with guest totals4,4.install_failedfails with sentinel 1 andp:n---.__fastfailrestored:install_failedfails because the child host dies with0xC0000409.resume_failedfails: the guest waits on a thread that never runs, and the child exits with0xE0000003.Tested
Commit
dc7bd04. Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64,TMP/TEMPon a non-system drive.^cpu_native_exe_tls_slot0(_windows|_enroll)?$) with--repeat until-fail:5: 5/5 ondevand 5/5 onrelease.ctest -R '^cpu_native_(exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|exe_tls_slot0|exe_tls_slot0_windows|exe_tls_slot0_enroll|load_cookie)$': 11/11 ondevand 11/11 onrelease. This set includes the ordinary DLL notification tests and thepe_map_runEXE tests, which are unchanged.releaserun failedcpu_native_startup: its native Windows launch, which does not load pe_map, hit the 30 s timeout while a repository-wide scan was running alongside.mainbut merges cleanly.mainhas not changedpe_map.cppsince the base.Not covered
ExitProcess, so slot 0 must be returned from a hook on the image's ownExitProcessimport, and its CRT's thread-detach callback frees what it finds in slot 0 (MoonYueya's two pitfalls). R0Y00 suggested reviewing the exit path separately.This checks a loader stage. It makes no claim that the main executable runs.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:10:22Z.
The source-built /GA fixture and the independent host TLS checks are useful. This entry still cannot safely accept every live thread. During install, an unsuccessful enumeration or inspection is treated as an empty result. During release, a failed OpenThread or inspection is counted as a dead thread, even though its slot may remain installed. That path can report success and unload the carrier while an existing thread may still use the block. DLL_THREAD_ATTACH also continues after allocation failure with the host slot still in place.
Please start with a controlled host and explicit participation of threads allowed to execute the mapped image, with a safe install/restore handshake. If inspection or restore is uncertain, distinguish it from confirmed exit and preserve the backing state. Add a deterministic failure control and a host-TLS reader that proves no unowned thread is modified. Keep native and mapped startup evidence separate.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T20:19:49Z.
Independent run of
a472abaon Windows 11 (the PR was run on Windows 10): Windows 11 Pro 26100, Intel Core i7-6820HQ, MSVC 19.52,devpreset, host Python 3.12. The head merges cleanly withmainat2f2893f(git merge-tree).Result: passes. The guest log of the main-image run equals the native launch, and the plain
pe_map_runcontrol reports no on every slot-0 check:Not covered here: this host did not reuse the terminated thread's ID within the attempts (
reuse=n). The stale record was dropped at release instead, so the reuse path is not covered by this run.Wider selection:
tls|native_exe|pe_map|static_exepasses 12/12, with no skips. I did not run thereleasepreset here.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T20:29:51Z.
Thanks. Reworked in
2134f9d, a new commit on top with no force-push. The PR description above still describes the first version (sweep of all threads); the updated model is indocs/experiments.md, "Main-image TLS slot 0".pe_map_run_main(until release on that thread); threads the image starts (Windows start address inside the image), from their attach before any image is notified to their detach after every image was notified; and host threads between their ownpe_map_main_thread_enterandpe_map_main_thread_leave.OpenThread.pe_map_main_tls_statslast release 0) and keeps the carrier loaded. The participant's own later leave or detach still restores it, and a new main image is refused while it is pending.DLL_THREAD_ATTACH.TLS_MINIMUM_AVAILABLE, so setting them never allocates. Handles go in the fixed table.alive: a host participant is inside the image at release → uncertain, carrier kept. Counters4,4,0,1,0,0,0,0.untracked: 64 host participants, so the last finds the table full and cannot be inspected → uncertain, carrier kept. Counters67,67,0,1,0,0,0,0.exited: a participant is ended withTerminateThread→ exit confirmed from its handle, release complete. Counters4,3,1,0,0,0,1,0.main: complete release, carrier unloaded. Counters4,4,0,0,0,0,1,0.plain(control):pe_map_run, every slot-0 checkn.releaseand millions indev.cpu_native_exe_tls_slot0_windowscovers only the Windows launch.cpu_native_exe_tls_slot0covers only thepe_mapscenarios.Results: Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1.
ctest -R '^cpu_native_(exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|exe_tls_slot0|exe_tls_slot0_windows|load_cookie)$'passed 10/10 ondevand 10/10 onrelease.form_coverage_check,docs_links_checkandbidi_controls_checkpass.devrun faileduntrackedfrom a stalepe_map.dll: restoring the source after the mutation runs kept the file's old timestamp, so Ninja skipped the rebuild. After a rebuild it passed 10/10untrackedruns and the full set again.mainbut merges cleanly;mainhas not changedpe_map.cppsince the base.Still not covered: CRT EXEs and the
ExitProcessexit path, threads that start in host code and call into the image without entering, and more than one main image.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:46:04Z.
The own-thread handshake and nonparticipant check are useful improvements. There is still a lifetime gap in
2134f9d: if another participant is live at release,release_mainonly setskeep_carrier.finalizestill unregisters unwind data and frees the EXE, andpe_map_releasereturns 1. Thealivefixture leaves the worker in host test code, so its later TLS restoration cannot exercise that gap. Please either require all participants to leave or be confirmed exited before the API unregisters the mapping (with a retryable refusal), or hold a lifetime reference covering image code, unwind data and carrier until the last participant is done. A source-built test should pause a participant at a known point during image work, ask release from the host, then allow it to return and verify one final cleanup. The existing no-sweep and unrelated host TLS controls should stay.Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T21:05:14Z.
Thanks. Addressed in
419e859, a new commit on top with no force-push. I picked the first model: a retryable refusal.pe_map_releasenow returns 2 and changes nothing while any participant other than the calling thread may still run the image's code. That covers a handle that is not signaled or cannot be waited on, a participant without a handle, and an attaching thread whose start address could not be read.slot_lockhold, so no participant can join in between. It restores the calling thread, counts signaled participants as exited, ends the mode, and then unregisters and frees the image once through the existing path.keep_carrieris removed. There is no longer a path that frees the EXE while a participant may still run.cpu_exe_tls_slot0_pauseadds guest worker c, which runs its slot-0 check and then pauses inside the image's code on an event. The host does the following:2;RtlLookupFunctionEntrystill finds its entry point, that the carrier is loaded, and that the starting thread's slot 0 still holds the image's block;1. After that the image is no longer committed, the unwind lookup finds nothing, and the carrier is unloaded;0, so there was exactly one cleanup.aliveanduntrackednow expect the refusal, then an accepted release after the participant leaves.exitedis confirmed from its handle. Windows evidence stays in its own test.pe_map_releasethat never refuses,alivefails: there is no refusal, and the cleanup happens while the participant is live.pausedcrashes with0xC0000005, because c resumes in the freed image.Results: Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1.
ctest -R '^cpu_native_(exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|exe_tls_slot0|exe_tls_slot0_windows|load_cookie)$'passed 10/10 ondevand 10/10 onrelease.main4,4,0,0,0,0,1,0alive4,4,0,1,0,0,1,0exited4,3,1,0,0,0,1,0untracked67,67,0,1,0,0,1,0paused5,5,0,1,0,0,1,0plain0,0,0,0,0,0,-1,0mainbut merges cleanly, andmainhas not changedpe_map.cpp.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:17:33Z.
The paused guest worker now tests the lifetime gap from the previous review: the refused release keeps code, unwind data and carrier intact until the worker finishes. Two compatibility checks remain for
419e859.pe_map_release0/1 convention. A return of 2 is truthy, and existing callers treat nonzero as successful unregister. Return 0 for the opt-in mode's retryable refusal, before altering registration. A distinct reason can stay in the main-image status API; keep checking that the later release returns 1 exactly once.install_current_threadskips a thread that does not participate, butnotify_threadstill calls the main image's thread callbacks on it. A /GA callback then sees the host's slot 0. The current unrelated reader starts before the image is mapped, so it cannot exercise attach/detach after startup. Gate the opt-in image's notifications on the same slot ownership, preserve ordinary DLL and pe_map_run notifications, and add a host thread created after startup with a TLS sentinel and explicit callback-count checks. Also state how a failure to classify a new guest worker prevents it from entering guest code with the wrong block.Please keep the paused-worker/unwind checks and the existing host-sentinel checks.
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T21:32:05Z.
Thanks. Addressed in
685dce4, a new commit on top with no force-push. The paused-worker, unwind-data and host-sentinel checks are unchanged.pe_map_releasekeeps its 0/1 convention.pe_map_main_tls_stats(last release = 2).release == 0plus status 2. It checks that the later accepted release returns 1, that it is the only release that does, and that a further release returns 0.DLL_THREAD_ATTACHandDLL_THREAD_DETACHonly on threads that participate. The gate uses the same participation slot thatinstall_current_threadandrestore_current_threaduse.pe_map_runare notified exactly as before.cpu_native_tls,cpu_native_tls_value,cpu_native_tls_data,cpu_native_lifetime,cpu_native_exe_tlsandcpu_native_startuppass unchanged.exe_slot0_callback_counts), read before and after that thread's life:pe_map_run_main, the guest gets 0 callbacks for the late thread, and its thread attach/detach totals count only its own workers:2,2, or3,3with the paused worker.pe_map_run, the late thread's attach and detach still reach the guest (2, totals3,3). This is the preserved behaviour.mainfails because the guest receives 2 callbacks for the late thread and its totals become4,4.NtQueryInformationThreadwithThreadQuerySetWin32StartAddress), or an image thread whose block cannot be installed, cannot be run safely either way. As a guest thread it would reach guest code with the host's block, and treated as one, host code would read the image's block. pe_map therefore ends the process with__fastfail(FAST_FAIL_FATAL_APP_EXIT)insideDLL_THREAD_ATTACH, before the thread reaches its start routine. A misclassified worker can never enter guest code with the wrong block. The earlier "fault" counter that made release refuse is removed. This path is not exercised by a test: it would need fault injection in the query.Results: Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1.
ctest -R '^cpu_native_(exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|exe_tls_slot0|exe_tls_slot0_windows|load_cookie)$'passed 10/10 ondevand 10/10 onrelease.419e859.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:39:48Z.
I reproduced 2/2 slot-0 tests on Windows Release at
685dce48. The late host thread gets zero guest callbacks in the main-image mode and still gets two in plain mode. The paused worker also preserves the image, unwind data and carrier while release returns 0. The remaining issue is the newly added process termination inDLL_THREAD_ATTACHif classification or TLS installation fails. That can kill the whole host on an unrelated thread's notification. Scope this experiment to a dedicated child process and state which thread-entry patterns it supports, or give the host an explicit guest-thread enrollment path that can report failure before guest code runs. A child fixture that forces the query or installation to fail must show the outcome before the start routine touches a sentinel. Keep the present 0/1 and late-host checks.Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T22:58:42Z.
Thanks. Addressed in
440de93, a new commit on top with no force-push. I chose the explicit guest-thread enrollment path, not a dedicated child-process scope. The termination is gone: no thread notification can end the process any more.Why enrollment. A child-process scope would still need a rule for classifying threads, and any classification that can fail in
DLL_THREAD_ATTACHhas the same problem: at that point the thread can only run guest code with the wrong block, or be killed. With enrollment the creator decides, before the thread exists, that it is a guest thread. pe_map never has to guess about a thread it did not create, and every failure surfaces before the guest's start routine runs.No process termination. The
NtQueryInformationThreadstart-address classification and both__fastfailcalls are removed.DLL_THREAD_ATTACHinstalls slot 0 only on a thread found in pe_map's enrollment table. Every other thread, whatever its start address, returns at once and is never touched, so an unrelated thread's notification can no longer affect the host.Enrollment path. The host binds the main image's
CreateThreadimports to the new exportpe_map_main_create_thread, which hasCreateThread's signature. While an image is started as the main image, it does the following:SYNCHRONIZEhandle before the thread can run;CREATE_SUSPENDED.The thread installs the image's block at its own
DLL_THREAD_ATTACH, before any image is notified, as before. The pe_map start routine calls the guest's start routine only if that installation succeeded. Failures are reported before guest code runs:pe_map_main_create_threadreturns null withERROR_NOT_ENOUGH_MEMORYand no thread exists. The guest's caller sees an ordinaryCreateThreadfailure.0xE0000201without calling the guest's start routine. The main image's callbacks are not notified, because the thread does not participate.Both outcomes are counted in
pe_map_main_tls_stats, which now has 10 entries: enrollments refused and enrolled threads failed. An enrolled thread that has not yet passed its start routine counts as one that may run the image's code, so release refuses while it lives.Supported thread entries.
pe_map_run_main.CreateThreadimport that the host bound tope_map_main_create_thread.pe_map_main_thread_enter(returns 0 if it cannot install) andpe_map_main_thread_leave.Not supported, and running with the host's slot 0:
CreateThreadaddress it looked up itself,CreateRemoteThread(Ex),NtCreateThreadEx, thread-pool work, or a C runtime's_beginthreadexin another DLL;This is in
docs/experiments.mdand the PR description.Child fixture for forced failures.
cpu_native_exe_tls_slot0_enrollruns one child host process per scenario withcpu_exe_tls_slot0_enroll. Its probe worker p touches a global sentinel as the first statement of its start routine, and its entry records a failedCreateThreadinstead of exiting.pe_map_main_tls_inject(test-only, one shot) makes the next enrollment (1) or installation (2) fail. There is no query left to fail, so the enrollment refusal takes its place.probe(control)1,1,0,0, log addsp2=yy p:yyyy p3=y-3,35,5,0,0,0,0,1,0,0,0enroll_refused0,0,8,0: null, no thread2,24,4,0,0,0,0,1,0,1,0install_failed0,1,0,e0000201: ended before its start routine2,24,4,0,0,0,0,1,0,0,1In both failure scenarios the sentinel stays 0, the guest gets no callback for p, workers a and b are enrolled normally afterwards, and the host survives: it prints its report and exits 0. The reader, late-thread, release and cleanup checks all apply.
Mutations (not committed):
install_failedfails: sentinel 1, and p's check sees the host's block (p:n---,X=1).__fastfailrestored,install_failedfails because the child host dies with0xC0000409before printing.685dce4; their counters only gain the two new zero columns. That covers the 0/1 release convention with exactly one cleanup,aliveanduntrackedrefused and then accepted,exitedconfirmed from its handle, andpausedrefusing with image, unwind data and carrier intact. The late host thread gets 0 guest callbacks underpe_map_run_mainand 2 underpe_map_run. The non-participating reader and the late thread never see their slot 0 or sentinel change. The guest's workers are now enrolled through the boundCreateThread, and the native and mapped evidence stay in separate tests.Results: Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1,
TMP/TEMPon a non-system drive.ctest -R '^cpu_native_(exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|exe_tls_slot0|exe_tls_slot0_windows|exe_tls_slot0_enroll|load_cookie)$'passed 11/11 ondev(full build) and 11/11 onrelease, with no capability skips. This includes the ordinary DLL notification tests and thepe_map_runEXE tests, which are unchanged.form_coverage_check,docs_links_checkandbidi_controls_checkpass.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T23:07:44Z.
The explicit enrollment revision removed the process-kill path, and the original native/mapped/enrollment suites passed locally. I found one additional lifecycle case: after 64 suspended workers were cancelled before entry, creation 65 failed even though all 64 handles were signaled. I pushed a focused fix and a control that completes 65 cancellations without entry or callback and accounts for every exit. All three TLS suites passed five repeats in Windows Release.
One startup API failure path remains: the wrapper ignores ResumeThread returning DWORD(-1). Please preserve that error and refuse creation to the guest instead of returning a live suspended handle as success. Keep enrollment/watch state until the private failed thread is safely accounted for, and add a one-shot failure control verifying the guest start sentinel stays untouched and a later enrollment can still run. ResumeThread error contract
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T23:28:07Z.
Thanks for the review and for
4af2ab0. I built on top of it without rewriting it. The ResumeThread path is addressed indc7bd046, a new commit with no force-push.ResumeThread failure refuses creation. If
ResumeThreadreturnsDWORD(-1),pe_map_main_create_threaddoes the following:ResumeThread's last error;CANCELLEDunder the lock;The guest never gets a live suspended handle, and the thread-ID output is reset to 0.
Enrollment and watch state are kept until the thread is accounted for. The
CANCELLEDentry keeps its slot and itsSYNCHRONIZEhandle until that handle is signaled. While it is unsignaled, release refuses and the slot is not reused. Once it is signaled, yourreap_ended_enrollmentsfrees it, immediately in the wrapper or later at the next creation or the accepted release. A cancelled thread is counted once, as a refused enrollment (the guest saw null). Reaping does not count it again as a failed enrolled thread.One-shot failure control.
pe_map_main_tls_inject(3)makes the next resume in the wrapper fail withERROR_ACCESS_DENIED. The probe worker is now created withoutCREATE_SUSPENDED, so the wrapper itself performs the resume. The thread ID is written before the resume, so it is known before the thread can run. New scenarioresume_failed, in its own child host:0,0,5,0: sentinel untouched,CreateThreadreturned null, last error 5, no exit code;2,2(none for p);4,4,0,0,0,0,1,0,1,0, so the refusal is counted and nothing is pending;Mutation (not committed): with the old behaviour, ignoring the failure and returning the handle,
resume_failedfails. The guest waits on a thread that never runs, and the child exits with0xE0000003.Existing suites kept, including your
cancelledcontrol: 65 cancellations,5,5,0,0,0,0,1,0,0,65, no start routine and no callback.probe,enroll_refusedandinstall_failedare unchanged, and the six mapped scenarios and the Windows test are unchanged.Results: Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1, at
dc7bd046.^cpu_native_exe_tls_slot0(_windows|_enroll)?$) with--repeat until-fail:5: 5/5 ondevand 5/5 onrelease.exe_start|startup|tls|tls_value|tls_data|lifetime|exe_tls|load_cookieplus the three slot-0 suites): 11/11 ondevand 11/11 onrelease.releaserun had one failure: the native Windows launch ofcpu_startup_exe.exeincpu_native_startuphit its 30 s timeout while a repository-widebidi_controls_checkscan was running alongside. That leg does not load pe_map.cpu_native_startuppassed 5/5 at about 6 s each, and the full set passed 11/11.form_coverage_check,docs_links_checkandbidi_controls_checkpass. No capability skips.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T23:29:30Z.
Your
dc7bd046now returns the ResumeThread error and exercises the refused start and a later successful enrollment. I kept that revision and pushed969b7f72to wait on the creator-owned handle: a concurrent enrollment can reap and close the watch as soon as the worker exits. The three native/mapped TLS CTests passed eight repeats each on Windows Release (24/24), including the resume and cancelled-worker controls. The updated head is waiting on CI.