Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a75d2baac8 | ||
|
|
26287ea45d |
No files matched your search
@@ -37,6 +37,16 @@ numeric core and does not move; the heading is the full version — corrected 20
|
||||
|
||||
### Changed
|
||||
|
||||
- **Hooks go into a game together, and come out together** (owner decision D134). Putting a hook in or taking it
|
||||
out stops every thread of the game for a moment, and until now that happened once for every hook: the thirteen
|
||||
Streamline hooks took 0.7 to 2.8 seconds of a game's start in real sessions (2026-11-13), and stopping a session
|
||||
took about a sixth of a second for each hook — two to three seconds, sometimes on the thread that draws. The
|
||||
hooks a moment finds are now put in under **one** stop of the threads, and a stop takes all of them out under
|
||||
one. On FrameLedger's own test program: nine hooks in 78–90 ms where they took 0.6–0.7 s; eighteen out in
|
||||
76–90 ms where they took 1.4–1.6 s. What a hook reads and when it is installed are unchanged, and no hook's own
|
||||
code changed. The log of the part inside the game has a new line for each such moment (`PATCH_BATCH`, with the
|
||||
time it took and the number of hooks). **Not run in a real game yet.**
|
||||
|
||||
- **The limitations, the accuracy statement and the user guide say what the first real sessions on 0.1.0-beta.45
|
||||
showed** (2026-11-13, six games): five of its six new readings were read in real games — every Streamline game
|
||||
asked whether its features are supported — and no game allocated a feature's resources after FrameLedger was in
|
||||
|
||||
@@ -158,6 +158,13 @@ own work item on the STA thread and puts back — and with the keys a parameter,
|
||||
> Until the run happens, the honest state of this line is *unmeasured*, not *passing*.
|
||||
3. Results recorded in the release notes ("measured overhead this release: …").
|
||||
|
||||
**What a patch costs when it goes in and comes out (since 0.1.0-beta.46) is not the per-present number above**, and
|
||||
is measured where it happens: `fl_guard`'s Streamline `[advanced]` case prints the microseconds of each install
|
||||
batch and of the stop's one restore (the Overlay's `PATCH_BATCH` lines), and the time from the unhook request to
|
||||
`UNHOOKED`; it asserts that every lazily installed patch is under a batch line, that the stop is one, and that the
|
||||
restore stays under a second — the bound the one-patch-at-a-time stop did not meet on the development PC. In a real
|
||||
game the same lines are in `logs\overlay-<pid>-….log`.
|
||||
|
||||
## Tier cross-validation (accuracy regression net) — **GONE, 2026-08-28, and this is the entry to read before planning P5**
|
||||
|
||||
~~Run the same game session with Tier 1 and Tier 2 simultaneously where possible (ETW does not conflict with hooking) and compare frametime distributions: Avg/1% Low must agree within **1%**. Divergence beyond that means one of the two paths is wrong and blocks the release. This is also the check that would have caught the original detection-accuracy problem.~~
|
||||
|
||||
+61
-5
@@ -196,8 +196,8 @@ Every hook must be listed here with a purpose. Anything not on this list is not
|
||||
| NGX parameter accessors (`NVSDK_NGX_Parameter_SetI/GetI/SetUI`) — **exported by `sl.common.dll` only; see below** | `Width`/`Height` (render) vs `OutWidth`/`OutHeight` (output), `PerfQualityValue` (quality preset), sharpness |
|
||||
| ✅ Streamline: `slEvaluateFeature` · ~~⏳ `slInit`~~ *(not hooked, and not to be: owner decision D129, 2026-11-12 — its row below says why)*, ~~`slSetFeatureLoaded`~~ *(its own row below since beta.45)*, ~~`slSetConstants`~~ *(its own row below since beta.43)*, ~~`slGetFeatureRequirements`~~ *(its own row below since beta.44, with `slGetFeatureVersion`)* | Feature set actually active when the game goes through SL rather than NGX directly (`kFeatureDLSS`, `DLSS_G`, `DLSS_RR`, `Reflex`, `NIS`; since beta.34 `kFeatureDLSS_NR` — DLSS 5's neural rendering, its own fact bit and family `FL_HOOK_SL_NEURAL_RENDERING`, D84; rule 4: the `feature` argument of the API hooked, nothing else). **Built 2026-08-09**, identity only: one MinHook detour on `sl.interposer.dll!slEvaluateFeature`, resolved **module-scoped** and installed lazily by the watchdog. Sets `FL_MEASURED_UPSCALER` + `FL_HOOK_UPSCALER_IDENTITY`; decodes `kFeatureDLSS`/`kFeatureNIS` and reports `FL_UPSCALER_UNKNOWN` for anything else. **Never `FL_UPSCALER_NONE`** — a Streamline-only writer cannot see FFX, XeSS or NGX-direct, and `NONE` is the only one of the three states that may be aggregated as a negative. **Since 0.1.0-beta.40 (Advanced metrics train B, D111), and only while the Agent asks** (`FlControlBlock.advancedRequested`): the `sl::DLSSOptions` a title chains into `inputs` — the struct the quality mode is read from — is read further: `outputWidth`/`outputHeight`, `preExposure`, `exposureScale`, `colorBuffersHDR`, the five presets of version 1, and where the struct's own `structVersion` proves them present `ultraQualityPreset` and `useAutoExposure` (≥ 2) and `alphaUpscalingEnabled` (≥ 3) — §Which struct version carries which field. Rule 4: more members of the same argument of the same call; `fl_adv_fields.h` is the one place, `tools/overlay-fields-check.ps1` holds it. No new patch site. **Measured** (the header's own functions, `/O2 /guard:cf /Qspectre /MT`, 20 M calls × 3): +9.5–11.7 ns per evaluation that chains the options while asked; with the word at 0, one relaxed load and a branch not taken — below what the bench resolves. Most titles set these through `slDLSSSetOptions`, which is not an export, and read N/A (train D) |
|
||||
| ✅ Streamline: `slSetConstants` (0.1.0-beta.43, Advanced metrics train B; owner decisions D111–D116, D122) | **What the game tells Streamline about a frame**, once per frame and viewport, read from the `sl::Constants` it passes — rule 4: an argument of the call hooked, and of it only the members named here. **Read:** `jitterOffset`, `mvecScale`, `cameraNear`, `cameraFar`, `cameraFOV`, `cameraAspectRatio` and the seven `Boolean`s (`depthInverted`, `cameraMotionIncluded`, `motionVectors3D`, `reset`, `orthographicProjection`, `motionVectorsDilated`, `motionVectorsJittered`). **Never read:** the five matrices (bytes 32..351 of the struct), `cameraPinholeOffset`, and the camera's position and three axes (bytes 368..423) — `tools/overlay-fields-check.ps1` refuses their names anywhere in code loaded into a game, and ctest `fl_adv_fields` publishes two structs that differ in every one of those bytes and gets the same bytes out. **The one row that is not installed unless asked for** (D111): `InstallByFamily` returns before it resolves the symbol in a process the Agent has never asked for Advanced metrics — resolving takes a reference on the module — so with the option off the export's first bytes are the file's (`fl_guard` `[advanced]` reads them from the target). Once asked, the patch goes in on that watchdog tick and stays for the life of the process; the detour forwards without looking while the request is off, and after a stop (`MayObserve`). **Every call** checks the struct's GUID and a `structVersion` of at least 1 before any member is read, and the viewport handle's the same way; every member read is one version 1 carries, so a version-1 struct laid against unreadable memory is read whole without a fault (the same ctest). **Summaries are the first viewport's**: a title with two viewports sets constants for each every frame, and "the last value" across them would flip twice a frame; the call count is of every viewport. `FLT_MAX` is Streamline's "not set" here and is kept nowhere (D119's plane at infinity is FidelityFX's). Family `FL_HOOK_SL_CONSTANTS` (bit 13), published with the patch: it entitles no field of a frame record, and tells "hooked, never called" from "not hooked". **Measured overhead** (the detour's body on the headers, the Overlay's flags, 20 million calls a run, three runs): not asked **+0.57 / +0.60 / +0.58 ns**; asked, the summarised viewport **+19.61 / +19.54 / +19.79 ns**; asked, another viewport +5.83 / +6.01 / +5.62 ns. |
|
||||
| ✅ Streamline: `slGetFeatureVersion` and `slGetFeatureRequirements` (0.1.0-beta.44, Advanced metrics train B's third step; owner decisions D111–D116, D122) | **What Streamline answers when the game asks about a feature** — which version it is, and what it requires. Two rows, two patches, two detours of one shape: **the original runs first, exactly once, on every path, with both arguments forwarded untouched**, and the struct the game passed is read only when the original said `eOk` — a refusal leaves the struct as the game made it, which is not an answer. Rule 4: an argument of the call hooked, read after the call, and of it only the members named here. **Read from `sl::FeatureVersion`:** `versionSL`, `versionNGX`. **Read from `sl::FeatureRequirements`:** `flags`, `maxNumCPUThreads`, `maxNumViewports`, `numRequiredTags`, `osVersionDetected`, `osVersionRequired`, `driverVersionDetected`, `driverVersionRequired`. **Never read:** `requiredTags` — the pointer the count belongs to — and everything after `driverVersionRequired`: the Vulkan queue counts and the pointers to the names of extensions and features. **No pointer of the game's is followed** (`tools/overlay-fields-check.ps1`, parameters `fv` and `fr`; ctest `fl_adv_fields`: two answers that differ only in those bytes publish the same region, and an answer cut off where the Vulkan members begin, laid against unreadable memory, is read without a fault; the injected `fl_guard` case's stub hands back wild pointers and no fault is counted). **Installed only where asked for** (D111), as `slSetConstants` is: `InstallByFamily` returns before it resolves either symbol in a process the Agent has never asked for Advanced metrics; once in, a patch stays for the life of the process and its detour forwards without looking while the request is off. **They are the first two rows of the table**: a game asks these while it starts, the watchdog patches rows in the table's order, and each patch stops the game's threads for a moment (0.1–0.25 s apart in the owner's logs of 2026-11-12, where `slSetConstants` was the fifth Streamline patch in, 1.9–7.8 s after the attach). In a process never asked they are passed over and the order changes nothing. ~~**Most sessions will still have missed the calls** — an attach after the game's start-up is the usual case — and the session then says the call was hooked and the game did not ask again.~~ *(Measured 2026-11-12, the owner's eight sessions on beta.44: both calls were read in six of six Streamline sessions on five games — Unreal's Streamline plugin asks again after the attach, Cyberpunk 2077 asks again for requirements and not for versions. A game that asks only while starting still reads "hooked, not asked again".)* Three conditions before a read, as for `slSetConstants`: the Agent is asking, observing has not stopped, and the struct carries its own GUID and a version of at least 1 on this call (a struct with another GUID is not kept: the injected case sends one). Every member read is version 1's (§Which struct version carries which field). **Twelve slots** in region 5 (`FlAdvancedState.features`, layout 5 as it was), one per feature in the order first asked about; the last answer about a feature is the one kept; a thirteenth feature is not kept. **A new request does not empty them**: what version a feature is and what it requires are facts about the process, and a second session of a game that kept running would otherwise have nothing where the first had the answer — the one group `Reset` leaves, with its bit of the mask. Streamline 1.x is refused before anything is resolved (`SpeaksStreamline2`). Families `FL_HOOK_SL_FEATURE_VERSION` (bit 15) and `FL_HOOK_SL_FEATURE_REQUIREMENTS` (bit 16), each published with its patch; neither entitles a field of a frame record. **Measured overhead** (the detours' bodies on the headers, the Overlay's flags, 20 million calls a run, three runs, eight features asked about in turn): the version — not asked **+0.58 / +0.61 / +0.58 ns**, asked **+14.82 / +14.54 / +14.47 ns**; the requirements — not asked **+0.58 / +0.63 / +0.61 ns**, asked **+20.88 / +21.01 / +20.96 ns**. A game makes these calls a handful of times. |
|
||||
| ✅ Streamline: `slIsFeatureSupported`, `slIsFeatureLoaded`, `slSetFeatureLoaded` (0.1.0-beta.45; owner decisions D129–D131) | **Whether a feature is supported, whether it is loaded, and the game switching it on and off.** Three rows, three patches. Rule 4: bare arguments and results of the calls hooked, and no vendor struct at all — the feature's id; the `sl::Result` `slIsFeatureSupported` returned, **every result**, since a refusal is the answer to that question (the original runs first, both arguments forwarded untouched); the `bool` `slIsFeatureLoaded` wrote, read only when it returned `eOk`; the `bool` the game passed to `slSetFeatureLoaded`, noted before the call. **The adapter `slIsFeatureSupported` is asked about is never read** (D131): `sl::AdapterInfo` holds the adapter's LUID or a Vulkan physical device; the detour forwards the reference and `tools/overlay-fields-check.ps1` refuses the names of its members (`deviceLUID`, `deviceLUIDSizeInBytes`, `vkPhysicalDevice`) anywhere in the Overlay and the Vulkan layer — the fixture's adapter carries a wild pointer. **Installed only where asked for** (D111), as the four rows before them. `slIsFeatureSupported` and `slIsFeatureLoaded` follow the two rows of beta.44 at the head of the table; `slSetFeatureLoaded` follows `slSetConstants`. **Kept in word 1 of the feature's slot** (region 5, layout 5 as it was): bit 2 and the result in bits 8..15, bits 3 and 4, bits 5 and 6 — the last two a session's, cleared by a new request; the rest the process's, kept (`fl_adv_fields.h` `kFeatureSessionBits`). A refused feature therefore has a slot now, with nothing in it but that word. The declarations of the three functions are the same from Streamline v2.0.0 to v2.14.16, and `sl::Result` is the same forty codes in the same order at all sixteen tags (`include/sl_result.h`, `05a3c7e3889c` … `8a844b68ff55`), so a code means the same whatever interposer answered. Families `FL_HOOK_SL_FEATURE_SUPPORTED` (bit 17), `FL_HOOK_SL_FEATURE_LOADED` (18), `FL_HOOK_SL_SET_FEATURE_LOADED` (19), each published with its patch. **Measured overhead** (the detours' bodies on the headers, the Overlay's flags, 20 million calls a run, three runs, eight features in turn): `slIsFeatureSupported` — not asked **+1.50 / +1.48 / +1.50 ns**, asked **+11.97 / +11.98 / +12.08 ns**; `slIsFeatureLoaded` — **+1.79 / +1.77 / +1.89 ns**, **+12.35 / +12.31 / +12.33 ns**; `slSetFeatureLoaded` — **+1.44 / +1.47 / +1.80 ns**, **+11.28 / +11.54 / +11.45 ns**. **`slInit` is not a row and will not be** (D129): a game calls it once, before the Overlay is in the process or before a patch can land — launch mode waits for the presentation runtime before it injects, nothing is ever patched on a game's thread (§H2), and a row that exists only for Advanced metrics waits for the Agent's request. **A stop takes about 160 ms for every patch it restores** (measured on the fixture, 0.1.0-beta.45: each `MH_DisableHook` snapshots the system's threads): twelve patches took 1.9 s, fifteen 2.4 s, and the watchdog's wait for the stop's log lines, 2 s until then, is now a quarter of a second for every patch the registry can hold. |
|
||||
| ✅ Streamline: `slGetFeatureVersion` and `slGetFeatureRequirements` (0.1.0-beta.44, Advanced metrics train B's third step; owner decisions D111–D116, D122) | **What Streamline answers when the game asks about a feature** — which version it is, and what it requires. Two rows, two patches, two detours of one shape: **the original runs first, exactly once, on every path, with both arguments forwarded untouched**, and the struct the game passed is read only when the original said `eOk` — a refusal leaves the struct as the game made it, which is not an answer. Rule 4: an argument of the call hooked, read after the call, and of it only the members named here. **Read from `sl::FeatureVersion`:** `versionSL`, `versionNGX`. **Read from `sl::FeatureRequirements`:** `flags`, `maxNumCPUThreads`, `maxNumViewports`, `numRequiredTags`, `osVersionDetected`, `osVersionRequired`, `driverVersionDetected`, `driverVersionRequired`. **Never read:** `requiredTags` — the pointer the count belongs to — and everything after `driverVersionRequired`: the Vulkan queue counts and the pointers to the names of extensions and features. **No pointer of the game's is followed** (`tools/overlay-fields-check.ps1`, parameters `fv` and `fr`; ctest `fl_adv_fields`: two answers that differ only in those bytes publish the same region, and an answer cut off where the Vulkan members begin, laid against unreadable memory, is read without a fault; the injected `fl_guard` case's stub hands back wild pointers and no fault is counted). **Installed only where asked for** (D111), as `slSetConstants` is: `InstallByFamily` returns before it resolves either symbol in a process the Agent has never asked for Advanced metrics; once in, a patch stays for the life of the process and its detour forwards without looking while the request is off. **They are the first two rows of the table**: a game asks these while it starts, the watchdog patches rows in the table's order, and each patch stops the game's threads for a moment (0.1–0.25 s apart in the owner's logs of 2026-11-12, where `slSetConstants` was the fifth Streamline patch in, 1.9–7.8 s after the attach). *(Since 0.1.0-beta.46 the rows a tick finds go in together, under one stop of the threads — §Unhooking, Batches — so the order no longer decides which row waits behind which; it is still the order of their log lines.)* In a process never asked they are passed over and the order changes nothing. ~~**Most sessions will still have missed the calls** — an attach after the game's start-up is the usual case — and the session then says the call was hooked and the game did not ask again.~~ *(Measured 2026-11-12, the owner's eight sessions on beta.44: both calls were read in six of six Streamline sessions on five games — Unreal's Streamline plugin asks again after the attach, Cyberpunk 2077 asks again for requirements and not for versions. A game that asks only while starting still reads "hooked, not asked again".)* Three conditions before a read, as for `slSetConstants`: the Agent is asking, observing has not stopped, and the struct carries its own GUID and a version of at least 1 on this call (a struct with another GUID is not kept: the injected case sends one). Every member read is version 1's (§Which struct version carries which field). **Twelve slots** in region 5 (`FlAdvancedState.features`, layout 5 as it was), one per feature in the order first asked about; the last answer about a feature is the one kept; a thirteenth feature is not kept. **A new request does not empty them**: what version a feature is and what it requires are facts about the process, and a second session of a game that kept running would otherwise have nothing where the first had the answer — the one group `Reset` leaves, with its bit of the mask. Streamline 1.x is refused before anything is resolved (`SpeaksStreamline2`). Families `FL_HOOK_SL_FEATURE_VERSION` (bit 15) and `FL_HOOK_SL_FEATURE_REQUIREMENTS` (bit 16), each published with its patch; neither entitles a field of a frame record. **Measured overhead** (the detours' bodies on the headers, the Overlay's flags, 20 million calls a run, three runs, eight features asked about in turn): the version — not asked **+0.58 / +0.61 / +0.58 ns**, asked **+14.82 / +14.54 / +14.47 ns**; the requirements — not asked **+0.58 / +0.63 / +0.61 ns**, asked **+20.88 / +21.01 / +20.96 ns**. A game makes these calls a handful of times. |
|
||||
| ✅ Streamline: `slIsFeatureSupported`, `slIsFeatureLoaded`, `slSetFeatureLoaded` (0.1.0-beta.45; owner decisions D129–D131) | **Whether a feature is supported, whether it is loaded, and the game switching it on and off.** Three rows, three patches. Rule 4: bare arguments and results of the calls hooked, and no vendor struct at all — the feature's id; the `sl::Result` `slIsFeatureSupported` returned, **every result**, since a refusal is the answer to that question (the original runs first, both arguments forwarded untouched); the `bool` `slIsFeatureLoaded` wrote, read only when it returned `eOk`; the `bool` the game passed to `slSetFeatureLoaded`, noted before the call. **The adapter `slIsFeatureSupported` is asked about is never read** (D131): `sl::AdapterInfo` holds the adapter's LUID or a Vulkan physical device; the detour forwards the reference and `tools/overlay-fields-check.ps1` refuses the names of its members (`deviceLUID`, `deviceLUIDSizeInBytes`, `vkPhysicalDevice`) anywhere in the Overlay and the Vulkan layer — the fixture's adapter carries a wild pointer. **Installed only where asked for** (D111), as the four rows before them. `slIsFeatureSupported` and `slIsFeatureLoaded` follow the two rows of beta.44 at the head of the table; `slSetFeatureLoaded` follows `slSetConstants`. **Kept in word 1 of the feature's slot** (region 5, layout 5 as it was): bit 2 and the result in bits 8..15, bits 3 and 4, bits 5 and 6 — the last two a session's, cleared by a new request; the rest the process's, kept (`fl_adv_fields.h` `kFeatureSessionBits`). A refused feature therefore has a slot now, with nothing in it but that word. The declarations of the three functions are the same from Streamline v2.0.0 to v2.14.16, and `sl::Result` is the same forty codes in the same order at all sixteen tags (`include/sl_result.h`, `05a3c7e3889c` … `8a844b68ff55`), so a code means the same whatever interposer answered. Families `FL_HOOK_SL_FEATURE_SUPPORTED` (bit 17), `FL_HOOK_SL_FEATURE_LOADED` (18), `FL_HOOK_SL_SET_FEATURE_LOADED` (19), each published with its patch. **Measured overhead** (the detours' bodies on the headers, the Overlay's flags, 20 million calls a run, three runs, eight features in turn): `slIsFeatureSupported` — not asked **+1.50 / +1.48 / +1.50 ns**, asked **+11.97 / +11.98 / +12.08 ns**; `slIsFeatureLoaded` — **+1.79 / +1.77 / +1.89 ns**, **+12.35 / +12.31 / +12.33 ns**; `slSetFeatureLoaded` — **+1.44 / +1.47 / +1.80 ns**, **+11.28 / +11.54 / +11.45 ns**. **`slInit` is not a row and will not be** (D129): a game calls it once, before the Overlay is in the process or before a patch can land — launch mode waits for the presentation runtime before it injects, nothing is ever patched on a game's thread (§H2), and a row that exists only for Advanced metrics waits for the Agent's request. **A stop takes about 160 ms for every patch it restores** (measured on the fixture, 0.1.0-beta.45: each `MH_DisableHook` snapshots the system's threads): twelve patches took 1.9 s, fifteen 2.4 s, and the watchdog's wait for the stop's log lines, 2 s until then, is now a quarter of a second for every patch the registry can hold. **Since 0.1.0-beta.46 (D134) a stop restores its patches under one stop of the threads**: eighteen in 76–90 ms on the fixture, where one by one they took 1.37–1.56 s (§Unhooking, Batches). |
|
||||
| ✅ Streamline: `slAllocateResources`, `slFreeResources`, `slShutdown` (0.1.0-beta.45; owner decision D130) | **The game allocating and freeing a feature's resources, and shutting Streamline down — counted, and nothing else.** Three rows, three patches. Rule 4: the feature's id is the only argument looked at; the command buffer and the viewport of the two resource calls are forwarded and never read (the fixture's command buffer is a wild pointer), and `slShutdown` has no argument. **`slFreeResources` and `slShutdown` are on a game's way out**: each detour notes the call first and then calls the original, exactly once, and runs nothing of ours after it returns; the fixture goes on calling the stub after `slShutdown`, through every detour. **Installed only where asked for** (D111); the last three Streamline rows of the table. **Kept** in word 1 of the feature's slot as two four-bit counts — allocations in bits 16..19, frees in 20..23, each stopping at 15 and never carrying into its neighbour — and, for `slShutdown`, in `FlAdvancedState.slShutdowns` (@308, the first of three reserved words; layout 5 as it was) with `FL_ADV_VALID_SL_SHUTDOWN` (bit 6 of the mask). All three are a session's: a new request clears them. Families `FL_HOOK_SL_ALLOCATE_RESOURCES` (bit 20), `FL_HOOK_SL_FREE_RESOURCES` (21), `FL_HOOK_SL_SHUTDOWN` (22). The three declarations are the same from Streamline v2.0.0 to v2.14.16. **Measured overhead** (the detours' bodies on the headers, the Overlay's flags, 20 million calls a run, three runs): `slAllocateResources` — not asked **+0.70 / +0.72 / +0.80 ns**, asked **+10.43 / +10.53 / +10.74 ns**; `slFreeResources` — **+0.61 / +0.84 / +0.58 ns**, **+10.33 / +10.57 / +10.44 ns**; `slShutdown` — not asked within the bench's noise (+0.06 / −0.12 / +0.04 ns), asked **+3.39 / +3.37 / +3.52 ns**. Inventory 23 → 26 rows; a Streamline title with Advanced metrics asked for now carries thirteen patches on the interposer, and a stop restores each in about 160 ms (the row above). **In real games (2026-11-13: six sessions, five games)** `slAllocateResources` was not called once after the attach, `slFreeResources` once in one game (Phantom Blade Zero, frame generation's) and `slShutdown` once in one (Dying Light: The Beast); no session counted a fault, and the two games that fault while closing did so at the offsets they had before these hooks. Installing the thirteen interposer patches took 0.7 s to 2.8 s of a game's start, 57 to 215 ms a patch. The owner's word on both (2026-11-13): `slAllocateResources` keeps its patch and is looked at again with more sessions (D135); installs and restores are to be batched, one stop of the threads for a batch (D134, 0.1.0-beta.46). |
|
||||
| ✅ Streamline: `slSetTag` — **and, since 2026-09-05, every tag's TYPE** (`slTagCensus`; a HUD-less / UI tag marks the present `FL_FG_DLSS_G`, rule 4: the same argument) | The **global** resource tags, where a title states the size of the buffer it is upscaling *from*: `kBufferTypeScalingInputColor`'s extent → `renderW/H` — **or, since 2026-09-05, the size the tagged `sl::Resource` declares when the extent is zero** (`TagSize` in `fl_sl_inputs.h`, shared by all three tag routes; GUID-checked; a Resource declaring no size is still the honest unknown). **Built 2026-08-15** (`FL_HOOK_UPSCALER_PARAMS`), and it is an ALTERNATIVE to the local tags in `slEvaluateFeature`'s `inputs`, not a layer over them — `sl_core_api.h:258` says global and local tags "do NOT interact", so a title using one yields nothing from the other and both are read. Published only on a frame where an evaluation was also seen, because a tag is viewport state that outlives any one frame. This row was MISSING from this table while the hook shipped, which is the gap the banner above now names |
|
||||
| ✅ Streamline: `slSetTagForFrame` — **and every tag's TYPE, as above** | The same global tags through **Streamline 2.8's frame-based entry point**, which deprecates `slSetTag`: `(const FrameToken&, const ViewportHandle&, const ResourceTag*, uint32_t, CommandBuffer*)` — the token first, then exactly `slSetTag`'s list, handed to the same tag walk. **Built 2026-09-04** (`FL_HOOK_UPSCALER_PARAMS`, its own trampoline; the family is now **published when whole** — once every tag export the loaded interposer has is patched — because publishing on the first row entitled records the second was not yet producing, 38 of 41 on the fixture: the ffx leaves' #110 defect again, fixed the same way). Measured need: Dying Light: The Beast (SL 2.8.0) published `Dlss` identity on every batch and the params bit on none across three captures, because a 2.8 title that tags per frame never calls the deprecated export. The token is not read; the frame count stays with `slGetNewFrameToken`. The installer picks this detour by SYMBOL (`kSymbolSlSetTagForFrame`, bound to the row by `static_assert`), not by family, since the two rows share a family bit and differ in signature |
|
||||
@@ -714,7 +714,7 @@ Every hook body is wrapped:
|
||||
```
|
||||
|
||||
- Any SEH exception inside our code ⇒ increment `faultCount`, record which hook, **return control to the original function** so the game continues.
|
||||
- 3 faults total ⇒ set `status = self_disabled`, ~~uninstall all hooks (`MH_DisableHook(MH_ALL_HOOKS)`)~~ restore each patch's prologue only while its bytes are still our jump (compare-and-restore per patch through `StopObserving`, §Unhooking, §H7 — `MH_ALL_HOOKS` would have removed an overlay chained after us; corrected 2026-09-27), stop writing, stay dormant. The Agent sees the flag and finalizes the session as `degraded`.
|
||||
- 3 faults total ⇒ set `status = self_disabled`, ~~uninstall all hooks (`MH_DisableHook(MH_ALL_HOOKS)`)~~ restore each patch's prologue only while its bytes are still our jump (compare-and-restore per patch through `StopObserving`, §Unhooking, §H7 — `MH_ALL_HOOKS` would have removed an overlay chained after us; corrected 2026-09-27; since 0.1.0-beta.46 the patches that are still ours come out together, under one stop of the threads — §Unhooking, Batches), stop writing, stay dormant. The Agent sees the flag and finalizes the session as `degraded`.
|
||||
- Never `__try` around the call to the original function — only around *our* code, so we never mask a game bug as ours or vice versa.
|
||||
- The trampoline call to the original is always executed exactly once, on every path, including error paths.
|
||||
|
||||
@@ -761,6 +761,55 @@ Every hook body is wrapped:
|
||||
> the shipped sequence against real MinHook patches: a full registry leaves the target's bytes untouched and
|
||||
> MinHook unasked; a stop arranged between the enable and the re-read ends with the function unpatched; a failed
|
||||
> patch gives its slot back; a slot is invisible to the walk until committed.
|
||||
>
|
||||
> **Batches, 0.1.0-beta.46 (owner decision D134): one stop of the game's threads for a group of patches.** MinHook
|
||||
> writes a jump with every other thread of the process stopped — a snapshot of the system's threads, then a
|
||||
> suspend, a context read and a resume for each of the process's — and `MH_EnableHook` / `MH_DisableHook` for one
|
||||
> target do all of that for one jump. The owner's logs of 2026-11-13 put a number on it: the thirteen Streamline
|
||||
> patches took 0.74 s to 2.8 s of a game's start, 57 to 215 ms each, and a stop restored its patches the same way.
|
||||
> MinHook 1.3.4 can queue — `MH_QueueEnableHook` / `MH_QueueDisableHook` mark a hook, `MH_ApplyQueued` executes
|
||||
> every mark under one stop — and `fl_patch_registry.h` now has the two sequences that use it:
|
||||
> `fl::patch::Batch` (`Add`: slot and create, nothing marked; `Commit`: enable them all) and
|
||||
> `fl::patch::RestoreAll`, which is the stop's walk. `InstallUpscalerHooks` queues every row a tick finds
|
||||
> something for and commits once, before the families that are published "when whole"; `InstallRtHooks` batches
|
||||
> its two; `StopObserving` calls `RestoreAll`. A patch's `HOOK_INSTALLED` line, family bit and latch still come in
|
||||
> that order and only once it is in. The loader detour, OpenGL and the three DXGI patches of init are as they were.
|
||||
>
|
||||
> **What the queue makes dangerous, and what the code therefore never does** (the plan was reviewed against
|
||||
> `hook.c` before a line was written, and its first form was refused). `MH_ApplyQueued` applies **every** hook
|
||||
> whose mark differs from its state — the process has one table, not one per caller. So (1) **no mark is ever left
|
||||
> standing**: a hook that failed to enable has its mark removed, or the next apply — the stop's own — would enable
|
||||
> it; (2) **only a patch that is still ours is ever marked for a restore** (`StillOurs`, as before; §H7), and
|
||||
> nothing is marked "all" — the refused draft marked everything and then un-marked what it must not restore, and
|
||||
> un-marking a hook that is already out marks it for *enabling*: the stop would have put a patch back in after the
|
||||
> stop; (3) **mark, apply and commit happen inside a gate** (`MinHookEngine::BeginQueue`, a slim lock taken
|
||||
> exclusively) so the watchdog's apply cannot execute the stop's marks nor the stop's the watchdog's. The gate is
|
||||
> held for one apply and never across a symbol lookup, which takes the loader's lock. It is the one lock in the
|
||||
> Overlay, and it is on no hook body's path: the only way from a hook to it is the stop itself, which already
|
||||
> waited for MinHook's own lock and a stop of the threads for every patch. Its owner re-enters it without
|
||||
> waiting. **The verdict on an install is the engine's, not the bytes'**: a foreign overlay patching over us a
|
||||
> moment after the apply would read as "not in", and treating that as a failure would mark a restore nobody had
|
||||
> compared. `MH_ApplyQueued` stops at the first hook that fails and says only that one did; the ones after it
|
||||
> are then enabled — or, in the stop, restored — one at a time, so one bad patch still costs one patch.
|
||||
> The write-then-read pair is unchanged: the stop clears the flag and then walks; `Commit` commits its slots and
|
||||
> then re-reads the flag, and takes out — compared first — what it put in when the flag is clear. A stop that
|
||||
> lands before the commit enables nothing.
|
||||
>
|
||||
> **Measured** on `hook-harness`'s Streamline target, the development PC, three runs before and after (`fl_guard`
|
||||
> `[advanced]` prints them): the nine Advanced-only patches went in one by one over 0.60 s / 0.70 s / 0.60 s
|
||||
> from the first log line to the ninth, 76–88 ms each; as one batch they take **81 / 90 / 78 ms**. The stop restored
|
||||
> eighteen patches in 1.37 s / 1.56 s / 1.37 s; under one apply, **77 / 90 / 76 ms** — and from the Agent's request
|
||||
> to `UNHOOKED`, 1.27–1.48 s became 94–110 ms. One stop of the threads costs what it cost for one patch, whether it
|
||||
> covers four, nine or eighteen. A new log line says so in the field: `PATCH_BATCH install` / `restore`, `a` the
|
||||
> microseconds, `b` the patches. **Not measured:** a real game — how long one stop of the threads is with a few
|
||||
> hundred of them, and whether any title minds patches arriving together (owner-only item 44). One more thing the
|
||||
> queue changes for the better: MinHook's single-target disable does not move a thread that is suspended inside
|
||||
> the patched bytes (`hook.c` passes the enable action to its thread fix-up in both directions); the queued apply
|
||||
> does. ctest `fl_unhook_inline` drives `Batch` and `RestoreAll` against real MinHook (three in under one apply,
|
||||
> a duplicate target refused without holding the others up, a foreign patch left byte for byte) and against a
|
||||
> model of MinHook's table for what real MinHook cannot be made to do on demand: an apply that fails halfway or
|
||||
> not at all, a stop inside the apply, a committed patch that is already out — the refused draft's failure — and
|
||||
> that no mark is ever standing or made outside the gate.
|
||||
|
||||
~~`FlRequestUnhook()` (or the control flag) ⇒ `MH_DisableHook(MH_ALL_HOOKS)`, restore vtable entries **only where they are still ours**, flush the ring, set status.~~ *(Corrected 2026-10-04: both reach `StopObserving` — compare-and-restore per patch as the note above says, then the status; there is no `MH_ALL_HOOKS`, no vtable entry and no ring flush. The watchdog flushes the native log on its way out.)* **The DLL is not `FreeLibrary`'d from the live process** — a thread could still be inside a trampoline. It goes dormant and unloads with the process. This is deliberate and documented.
|
||||
|
||||
@@ -789,6 +838,12 @@ before it. And when the slot has changed, going dormant costs nothing: we stay
|
||||
loaded anyway, and our detour remains in someone else's chain doing nothing
|
||||
harmful.
|
||||
|
||||
> **Said plainly, 2026-11-13: for the inline patches that re-check has never been made.** MinHook owns the write
|
||||
> window — it stops the threads, changes the protection and writes — and `StillOurs` is asked before it is called,
|
||||
> not inside. Between the two a foreign overlay could patch over us, on a thread MinHook has not stopped yet. The
|
||||
> batches of 0.1.0-beta.46 neither close that window nor widen it: the comparison and the write are apart by one
|
||||
> stop of the threads, as they were for each patch, once instead of once a patch.
|
||||
|
||||
Verified by `hook-harness --probe-unhook` (ctest `fl_unhook_preserves_foreign`),
|
||||
which simulates the foreign hooker rather than depending on RTSS being
|
||||
installed, so it is deterministic and runs on CI. Both halves are asserted: we
|
||||
@@ -810,7 +865,8 @@ No logging in hook bodies. A small fixed-size in-memory ring of structured event
|
||||
> writing), and since beta.42 `PATCH_FAILED` (a patch that did not go in, once per target and reason — §Unhooking)
|
||||
> and `FFX_DISPATCH`, `FFX_QUERY`, `UPSCALE_ROUTE`, `RUNTIME_CENSUS` (the note at the end of this section), and
|
||||
> since beta.43 `FFX_CONFIGURE` — each configure type a hooked ffx module was handed, in a process where
|
||||
> `ffxConfigure` is hooked at all (one asked for Advanced metrics).
|
||||
> `ffxConfigure` is hooked at all (one asked for Advanced metrics) — and since beta.46 `PATCH_BATCH`: one line an
|
||||
> apply, `install` or `restore`, `a` the microseconds it took and `b` the patches it covered (§Unhooking, Batches).
|
||||
> **Three flush points — four since beta.42, the same note —, none on a present path:** the end of `InitThread` (so the
|
||||
> file exists from the start of the session and a crash mid-session still leaves it), the watchdog when
|
||||
> `FlControlBlock.logFlushRequested` changes (a counter the Agent bumps at session end; nothing clears it),
|
||||
@@ -822,7 +878,7 @@ No logging in hook bodies. A small fixed-size in-memory ring of structured event
|
||||
> it reads 0. When the stop ran on a presenting thread — `MayObserve`'s one-frame safety stop — the watchdog's one
|
||||
> final flush could run while that thread was still writing, and the lines after it (the kernelbase loader detour is
|
||||
> the last patch) reached the ring after the last flush ever made. The stop now says when its last line is in, and
|
||||
> wakes the watchdog; the final flush waits for that, bounded at 2 s, then writes `STOP_FLUSHED`. And each slot has a
|
||||
> wakes the watchdog; the final flush waits for that, bounded at 2 s *(a quarter of a second for every patch the registry can hold since beta.45; the stop is one apply since beta.46 and the bound is for its fallback)*, then writes `STOP_FLUSHED`. And each slot has a
|
||||
> commit word written after its fields: `LogNote` claims a slot with one `fetch_add` and fills it afterwards, so a
|
||||
> flush on another thread could print a slot still being filled. A flush now prints only slots whose writer has
|
||||
> finished — an ordinary flush stops at the first that is not, for the next one; the final flush names it in a `#`
|
||||
|
||||
@@ -1549,6 +1549,13 @@ probe never showed a deadlock.
|
||||
> real-game leg — a title that pulls Streamline or D3D12 in lazily, hooked through the wake — which the
|
||||
> `loader detour:` report line will show as a non-zero wake count with the family present from the first
|
||||
> bucket.
|
||||
>
|
||||
> **0.1.0-beta.46 (owner decision D134): one suspension for a batch, and the rule is as it was.** The rows a
|
||||
> watchdog tick finds are enabled under one `MH_ApplyQueued` — one stop of the threads where there was one a row
|
||||
> (`17_HOOK_ENGINE` §Unhooking, Batches). Still only on the watchdog, never from the detour and never on a game's
|
||||
> thread; the gate around the queue is not held across a symbol lookup, so it is never held with the loader's lock
|
||||
> wanted. What a stop of the threads costs in a real game was read from the owner's logs of 2026-11-13: 57 to
|
||||
> 215 ms, thirteen times over for a Streamline title until this release.
|
||||
|
||||
### H11 ◐ · XeFG and FSR3-FG identity — **AMD built 2026-09-04 through the ffx-api leaves, complete 2026-09-06; Intel closed by licence; FSR 3.0 host route built 2026-09-05**
|
||||
|
||||
|
||||
@@ -323,9 +323,11 @@ static_assert(kFamilySlConstants != kFamilyEvaluateFeature && kFamilySlConstants
|
||||
// Vulkan extensions and features -- are never followed (fl_adv_fields.h; tools/overlay-fields-check.ps1).
|
||||
//
|
||||
// INSTALLED ONLY WHERE ASKED FOR, as slSetConstants is (D111), a row and a bit each. THEY ARE THE FIRST ROWS OF THE
|
||||
// TABLE because a game asks while it starts: the watchdog patches the rows in the table's order, each patch stops
|
||||
// the game's threads for a moment, and in a process that was asked these two are the ones that cannot wait. In a
|
||||
// process never asked they are passed over before anything is resolved, and the order changes nothing.
|
||||
// TABLE because a game asks while it starts: until 0.1.0-beta.46 the watchdog patched the rows one by one in the
|
||||
// table's order, each patch stopped the game's threads for a moment, and in a process that was asked these two were
|
||||
// the ones that could not wait. The rows a tick finds now go in together, under one stop of the threads (D134), and
|
||||
// the table's order is the order of their log lines. In a process never asked they are passed over before anything
|
||||
// is resolved.
|
||||
inline constexpr uint32_t kFamilySlFeatureVersion = static_cast<uint32_t>(fl::FL_HOOK_SL_FEATURE_VERSION);
|
||||
inline constexpr uint32_t kFamilySlFeatureRequirements = static_cast<uint32_t>(fl::FL_HOOK_SL_FEATURE_REQUIREMENTS);
|
||||
static_assert(kFamilySlFeatureVersion != kFamilySlFeatureRequirements &&
|
||||
|
||||
@@ -57,7 +57,8 @@ enum class InstallResult : std::uint32_t {
|
||||
CreateFailed =
|
||||
4, // the hooker could not create the hook (MinHook: already created, unsupported prologue, memory)
|
||||
EnableFailed = 5, // created, not enabled: no patch at the target
|
||||
StoppedDuring = 6, // the stop ran while this patch went in; the installer took it out again
|
||||
StoppedDuring = 6, // the stop ran while this patch went in; the installer took it out again, or never put it in
|
||||
Pending = 7, // in a Batch, created and waiting for its Commit; never logged
|
||||
};
|
||||
|
||||
template <std::uint32_t Capacity>
|
||||
@@ -176,6 +177,222 @@ InstallResult Install(Registry<Capacity>& registry, const std::atomic<std::uint3
|
||||
return InstallResult::Installed;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// BATCHES (0.1.0-beta.46, owner decision D134): several patches in, or every patch out, for ONE stop of the process's
|
||||
// threads instead of one a patch.
|
||||
//
|
||||
// WHY. MinHook stops every thread of the process to write a jump: a snapshot of the system's threads, then a suspend,
|
||||
// a context read and a resume for each of this process's. Enabling or disabling ONE hook does all of that for one
|
||||
// jump. In the owner's games of 2026-11-13 the thirteen Streamline patches took 0.7 s to 2.8 s of a game's start that
|
||||
// way, 57 to 215 ms each, and a stop restored its patches at about 160 ms each. MinHook can queue: mark hooks to be
|
||||
// enabled or disabled, then apply every mark under one stop of the threads.
|
||||
//
|
||||
// WHAT THE QUEUE IS, AND THE TWO THINGS IT MAKES DANGEROUS (hook.c, MH_ApplyQueued). The queue is ONE table for the
|
||||
// process: applying it applies every hook whose mark differs from its state -- not the caller's marks, everybody's.
|
||||
// So:
|
||||
// 1. A mark may never be left standing. A hook marked "enable" that failed, left marked, would be enabled by the
|
||||
// next apply -- the stop's own, if that came next. And a hook marked "disable" for a target that a foreign overlay
|
||||
// has patched over would have OUR saved bytes written over THEIR jump by whoever applied next (§H7).
|
||||
// 2. Two threads may not interleave their marks and applies: the installer's apply would execute the stop's marks
|
||||
// and the other way round.
|
||||
// Hence the GATE (`BeginQueue` / `EndQueue` on the engine): mark, apply and commit happen inside it, and when it is
|
||||
// free no hook has a mark that differs from its state. The gate is held for one apply and never across anything that
|
||||
// can take the loader's lock (resolving a symbol is done before, by the caller).
|
||||
//
|
||||
// A draft of this marked EVERYTHING for disabling and then un-marked the targets it must not restore. It was refused
|
||||
// on review against hook.c: un-marking a hook that is already disabled marks it for ENABLING, and the stop's own apply
|
||||
// would have put a patch back in after the stop. Nothing here marks "all", and nothing un-marks by marking the
|
||||
// opposite except where the hook's state is known.
|
||||
//
|
||||
// THE ENGINE, beside Create: QueueEnable(target) / QueueDisable(target) -> bool (mark only); Apply() -> bool (every
|
||||
// mark, one stop of the threads; false when any failed -- it stops at the first failure and does not say which);
|
||||
// EnsureEnabled(target) / EnsureDisabled(target) -> bool (one hook, true when it is in that state afterwards);
|
||||
// BeginQueue() / EndQueue().
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// The stop's walk: every committed patch that is still OURS is restored, under one apply; a patch a foreign overlay
|
||||
// has patched over is left exactly as it is (17_HOOK_ENGINE §Unhooking, §H7). The caller has already cleared the
|
||||
// observing flag -- this is the read half of the pair described at the top of this file.
|
||||
//
|
||||
// `ours(target, detour)` -> bool: the bytes at the target are still the jump made for us (fl_patch_check.h).
|
||||
// `report(name, target, wasOurs, restored)` is called once per committed patch, after the gate is released.
|
||||
template <std::uint32_t Capacity, class Hooker, class Ours, class Report>
|
||||
void RestoreAll(const Registry<Capacity>& registry, Hooker&& hooker, Ours&& ours, Report&& report) noexcept {
|
||||
struct Entry {
|
||||
void* target;
|
||||
const char* name;
|
||||
bool wasOurs;
|
||||
bool marked;
|
||||
bool restored;
|
||||
};
|
||||
Entry entries[Capacity];
|
||||
std::uint32_t count = 0;
|
||||
bool anyMarked = false;
|
||||
|
||||
hooker.BeginQueue();
|
||||
registry.ForEachLive(
|
||||
[&entries, &count, &anyMarked, &hooker, &ours](void* target, void* detour, const char* name) noexcept {
|
||||
if (count >= Capacity) {
|
||||
return;
|
||||
}
|
||||
// Only a patch that is still ours is ever marked. One that is not is not touched -- not marked, and not
|
||||
// un-marked either: it has no mark to remove.
|
||||
const bool mine = ours(target, detour);
|
||||
const bool marked = mine && hooker.QueueDisable(target);
|
||||
anyMarked = anyMarked || marked;
|
||||
entries[count++] = Entry{target, name, mine, marked, false};
|
||||
});
|
||||
const bool applied = !anyMarked || hooker.Apply();
|
||||
for (std::uint32_t i = 0; i < count; ++i) {
|
||||
Entry& e = entries[i];
|
||||
if (!e.marked) {
|
||||
continue;
|
||||
}
|
||||
// The apply stops at the first hook it cannot restore: the ones after it are taken out one at a time, as
|
||||
// every patch was until 0.1.0-beta.46. One that will not come out at all has its mark removed -- it is
|
||||
// enabled, so marking it "enable" leaves nothing to apply.
|
||||
e.restored = applied || hooker.EnsureDisabled(e.target);
|
||||
if (!e.restored) {
|
||||
hooker.QueueEnable(e.target);
|
||||
}
|
||||
}
|
||||
hooker.EndQueue();
|
||||
|
||||
for (std::uint32_t i = 0; i < count; ++i) {
|
||||
report(entries[i].name, entries[i].target, entries[i].wasOurs, entries[i].restored);
|
||||
}
|
||||
}
|
||||
|
||||
// Several patches, registered before any can run, enabled under ONE stop of the threads, and none left in after a
|
||||
// stop -- the sequence of Install, for a group. One thread fills and commits a batch (the Overlay's watchdog).
|
||||
//
|
||||
// Add: claim a slot and create the hook; nothing is at the target yet and nothing is marked. Commit: enable them all.
|
||||
// After Commit every item carries its InstallResult, and the caller does what follows a patch (its log line, its
|
||||
// family bit) for the ones that read Installed, in the order they were added.
|
||||
template <std::uint32_t Capacity>
|
||||
class Batch {
|
||||
public:
|
||||
struct Item {
|
||||
void* target = nullptr;
|
||||
void* detour = nullptr;
|
||||
const char* name = nullptr;
|
||||
void* context = nullptr; // the caller's: what to do once the patch is in
|
||||
std::uint32_t word = 0; // the caller's
|
||||
int slot = -1;
|
||||
InstallResult result = InstallResult::NoTarget;
|
||||
};
|
||||
|
||||
// Pending: the hook is created and waits for Commit. Anything else is final and nothing was added.
|
||||
template <class Hooker>
|
||||
InstallResult Add(Registry<Capacity>& registry, const std::atomic<std::uint32_t>& observing, Hooker&& hooker,
|
||||
void* target, void* detour, void** original, const char* name, void* context,
|
||||
std::uint32_t word) noexcept {
|
||||
if (target == nullptr) {
|
||||
return InstallResult::NoTarget;
|
||||
}
|
||||
if (observing.load(std::memory_order_seq_cst) == 0u) {
|
||||
return InstallResult::Stopped;
|
||||
}
|
||||
if (count_ >= Capacity) {
|
||||
return InstallResult::Full; // not reachable before the registry itself is full: one slot an item
|
||||
}
|
||||
const int slot = registry.Claim(target, detour, name);
|
||||
if (slot < 0) {
|
||||
return InstallResult::Full;
|
||||
}
|
||||
if (!hooker.Create(target, detour, original)) {
|
||||
registry.Release(slot);
|
||||
return InstallResult::CreateFailed;
|
||||
}
|
||||
items_[count_++] = Item{target, detour, name, context, word, slot, InstallResult::Pending};
|
||||
return InstallResult::Pending;
|
||||
}
|
||||
|
||||
template <class Hooker, class Ours>
|
||||
void Commit(Registry<Capacity>& registry, const std::atomic<std::uint32_t>& observing, Hooker&& hooker,
|
||||
Ours&& ours) noexcept {
|
||||
if (count_ == 0u) {
|
||||
return;
|
||||
}
|
||||
hooker.BeginQueue();
|
||||
if (observing.load(std::memory_order_seq_cst) == 0u) {
|
||||
// The stop ran between Add and here. Nothing was marked and nothing is at any target: the slots go back,
|
||||
// and the hooks stay created and disabled in the engine, as a hook that failed to enable always has.
|
||||
for (std::uint32_t i = 0; i < count_; ++i) {
|
||||
registry.Release(items_[i].slot);
|
||||
items_[i].result = InstallResult::StoppedDuring;
|
||||
}
|
||||
hooker.EndQueue();
|
||||
return;
|
||||
}
|
||||
for (std::uint32_t i = 0; i < count_; ++i) {
|
||||
if (!hooker.QueueEnable(items_[i].target)) {
|
||||
registry.Release(items_[i].slot);
|
||||
items_[i].result = InstallResult::EnableFailed;
|
||||
}
|
||||
}
|
||||
const bool applied = hooker.Apply();
|
||||
for (std::uint32_t i = 0; i < count_; ++i) {
|
||||
Item& item = items_[i];
|
||||
if (item.result != InstallResult::Pending) {
|
||||
continue;
|
||||
}
|
||||
// The ENGINE says whether the hook is enabled, not the bytes at the target: a foreign overlay that
|
||||
// patched over us a moment after the apply would read as "not in", and taking that for a failure would
|
||||
// mark a restore nobody had compared (§H7). The apply stops at the first hook that fails, so the ones
|
||||
// after it are enabled one at a time -- one bad patch costs one patch, as it always has.
|
||||
if (applied || hooker.EnsureEnabled(item.target)) {
|
||||
registry.Commit(item.slot);
|
||||
item.result = InstallResult::Installed;
|
||||
} else {
|
||||
hooker.QueueDisable(item.target); // it is disabled: this removes the mark, and marks nothing
|
||||
registry.Release(item.slot);
|
||||
item.result = InstallResult::EnableFailed;
|
||||
}
|
||||
}
|
||||
hooker.EndQueue();
|
||||
|
||||
if (observing.load(std::memory_order_seq_cst) != 0u) {
|
||||
return;
|
||||
}
|
||||
// The stop ran while the batch went in -- the re-read of Install, for the group. Its walk either saw the
|
||||
// committed slots and restored the patches, and then they are no longer ours and nothing is marked, or it had
|
||||
// passed them, and this takes them out. Compared first, as the stop compares: a patch something else has
|
||||
// patched over in the meantime is left to it.
|
||||
bool takeOut[Capacity]{};
|
||||
bool anyMarked = false;
|
||||
hooker.BeginQueue();
|
||||
for (std::uint32_t i = 0; i < count_; ++i) {
|
||||
const Item& item = items_[i];
|
||||
if (item.result == InstallResult::Installed) {
|
||||
takeOut[i] = ours(item.target, item.detour) && hooker.QueueDisable(item.target);
|
||||
anyMarked = anyMarked || takeOut[i];
|
||||
}
|
||||
}
|
||||
const bool out = !anyMarked || hooker.Apply();
|
||||
for (std::uint32_t i = 0; i < count_; ++i) {
|
||||
Item& item = items_[i];
|
||||
if (item.result != InstallResult::Installed) {
|
||||
continue;
|
||||
}
|
||||
if (takeOut[i] && !out && !hooker.EnsureDisabled(item.target)) {
|
||||
hooker.QueueEnable(item.target); // enabled and staying so: no mark may be left standing
|
||||
}
|
||||
registry.Retire(item.slot);
|
||||
item.result = InstallResult::StoppedDuring;
|
||||
}
|
||||
hooker.EndQueue();
|
||||
}
|
||||
|
||||
std::uint32_t Count() const noexcept { return count_; }
|
||||
const Item& At(std::uint32_t i) const noexcept { return items_[i]; }
|
||||
void Clear() noexcept { count_ = 0u; }
|
||||
|
||||
private:
|
||||
Item items_[Capacity]{};
|
||||
std::uint32_t count_ = 0u;
|
||||
};
|
||||
|
||||
} // namespace fl::patch
|
||||
|
||||
#endif // FRAMELEDGER_FL_PATCH_REGISTRY_H
|
||||
@@ -164,6 +164,7 @@ enum FlLogCode : uint32_t {
|
||||
kLogUpscaleRoute,
|
||||
kLogRuntimeCensus,
|
||||
kLogFfxConfigureType,
|
||||
kLogPatchBatch,
|
||||
};
|
||||
|
||||
const char* LogCodeName(uint32_t code) noexcept {
|
||||
@@ -204,6 +205,8 @@ const char* LogCodeName(uint32_t code) noexcept {
|
||||
return "RUNTIME_CENSUS";
|
||||
case kLogFfxConfigureType:
|
||||
return "FFX_CONFIGURE";
|
||||
case kLogPatchBatch:
|
||||
return "PATCH_BATCH";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
@@ -395,15 +398,77 @@ static_assert(fl::inventory::kRowCount + kPatchSitesOutsideTheInventory <= kMaxP
|
||||
"the patch registry cannot hold every patch this DLL may install -- raise kMaxPatches with the table");
|
||||
fl::patch::Registry<kMaxPatches> g_patches;
|
||||
|
||||
// MinHook, as the engine fl::patch::Install drives.
|
||||
// THE GATE around MinHook's queue (fl_patch_registry.h, BATCHES; 0.1.0-beta.46). MH_ApplyQueued applies every mark
|
||||
// in the process's one table, so the watchdog's "mark, apply, commit" and the stop's "mark, apply" must not
|
||||
// interleave. A slim reader/writer lock, taken exclusively: no allocation, no handle, nothing to initialise or tear
|
||||
// down. Held for one apply -- one stop of the threads -- and never across a symbol lookup (the loader's lock).
|
||||
//
|
||||
// NOT IN ANY HOOK BODY. The one path from a hook to here is the stop itself -- MayObserve reading the Agent's request,
|
||||
// or the third fault -- which already blocked for MinHook's own lock and a stop of the threads for every patch it
|
||||
// restored. It waits here for at most the watchdog's one apply, once in a process's life.
|
||||
//
|
||||
// RE-ENTERED BY ITS OWNER WITHOUT WAITING: a slim lock taken twice by one thread never returns. The only way there is
|
||||
// a stop that begins on the thread that is inside a batch -- a third fault in the LoadLibrary detour, if the engine
|
||||
// loaded a module under the gate. That stop then runs with the marks the batch has made; the batch's own re-read of
|
||||
// the flag takes out what it put in (fl_patch_registry.h, Batch::Commit).
|
||||
SRWLOCK g_patchGate = SRWLOCK_INIT;
|
||||
std::atomic<DWORD> g_patchGateOwner{0};
|
||||
uint32_t g_patchGateDepth = 0; // the owner's alone
|
||||
|
||||
// MinHook, as the engine fl::patch::Install, Batch and RestoreAll drive.
|
||||
struct MinHookEngine {
|
||||
static bool Create(void* target, void* detour, void** original) noexcept {
|
||||
return MH_CreateHook(target, detour, original) == MH_OK;
|
||||
}
|
||||
static bool Enable(void* target) noexcept { return MH_EnableHook(target) == MH_OK; }
|
||||
static void Disable(void* target) noexcept { MH_DisableHook(target); }
|
||||
|
||||
static bool QueueEnable(void* target) noexcept { return MH_QueueEnableHook(target) == MH_OK; }
|
||||
static bool QueueDisable(void* target) noexcept { return MH_QueueDisableHook(target) == MH_OK; }
|
||||
static bool Apply() noexcept { return MH_ApplyQueued() == MH_OK; }
|
||||
static bool EnsureEnabled(void* target) noexcept {
|
||||
const MH_STATUS status = MH_EnableHook(target);
|
||||
return status == MH_OK || status == MH_ERROR_ENABLED;
|
||||
}
|
||||
static bool EnsureDisabled(void* target) noexcept {
|
||||
const MH_STATUS status = MH_DisableHook(target);
|
||||
return status == MH_OK || status == MH_ERROR_DISABLED;
|
||||
}
|
||||
static void BeginQueue() noexcept {
|
||||
const DWORD self = GetCurrentThreadId();
|
||||
if (g_patchGateOwner.load(std::memory_order_acquire) == self) {
|
||||
++g_patchGateDepth;
|
||||
return;
|
||||
}
|
||||
AcquireSRWLockExclusive(&g_patchGate);
|
||||
g_patchGateOwner.store(self, std::memory_order_release);
|
||||
}
|
||||
static void EndQueue() noexcept {
|
||||
if (g_patchGateDepth != 0u) {
|
||||
--g_patchGateDepth;
|
||||
return;
|
||||
}
|
||||
g_patchGateOwner.store(0, std::memory_order_release);
|
||||
ReleaseSRWLockExclusive(&g_patchGate);
|
||||
}
|
||||
};
|
||||
|
||||
// The performance counter, as a number. QuadPart is named in the initialiser so that it is the member the union
|
||||
// holds when it is read back (SonarCloud's cpp:S6232 on a `{}` that initialises the other half).
|
||||
int64_t QpcNow() noexcept {
|
||||
LARGE_INTEGER now{.QuadPart = 0};
|
||||
QueryPerformanceCounter(&now);
|
||||
return now.QuadPart;
|
||||
}
|
||||
|
||||
// Microseconds since `fromTicks` (QpcNow), for a PATCH_BATCH line; saturating, because the line's field is 32 bits.
|
||||
uint32_t MicrosSince(int64_t fromTicks) noexcept {
|
||||
const int64_t now = QpcNow();
|
||||
const uint64_t ticks = now > fromTicks ? static_cast<uint64_t>(now - fromTicks) : 0u;
|
||||
const uint64_t micros = g_logQpcFreq != 0u ? ticks * 1000000ull / g_logQpcFreq : 0u;
|
||||
return micros > 0xFFFFFFFFull ? 0xFFFFFFFFu : static_cast<uint32_t>(micros);
|
||||
}
|
||||
|
||||
// A patch that did not go in, said ONCE per target and reason: the lazy installers retry every second, and a line a
|
||||
// second would push everything else out of a 256-event ring. Init and watchdog threads only, which never install at
|
||||
// the same time (the watchdog starts after the init thread's last install), so a plain table.
|
||||
@@ -919,7 +984,7 @@ void WakeWatchdog() noexcept;
|
||||
|
||||
void StopObserving(uint32_t reason) noexcept {
|
||||
// Compare-exchange, not a plain check-then-set: the watchdog and a game
|
||||
// thread inside a hook body can both arrive here, and MH_DisableHook must run
|
||||
// thread inside a hook body can both arrive here, and the restore must run
|
||||
// exactly once. The loser returns without touching status, so the FIRST
|
||||
// reason wins -- a self-disable already in flight is not overwritten by a
|
||||
// safety stop that arrives a millisecond later, or the record of WHY we
|
||||
@@ -939,14 +1004,27 @@ void StopObserving(uint32_t reason) noexcept {
|
||||
// is restored only while the bytes at its target are still the jump MinHook
|
||||
// wrote for us; otherwise it is left in place and our detour stays in the
|
||||
// other overlay's chain doing nothing -- g_observing is 0, every body forwards.
|
||||
g_patches.ForEachLive([](void* target, void* detour, const char* name) noexcept {
|
||||
if (fl::patch::StillOurs(target, detour)) {
|
||||
const bool ok = MH_DisableHook(target) == MH_OK;
|
||||
LogNote(kLogUnhookRestored, name, ok ? 1u : 0u, reinterpret_cast<uint64_t>(target));
|
||||
} else {
|
||||
LogNote(kLogUnhookDeclined, name, 0u, reinterpret_cast<uint64_t>(target));
|
||||
}
|
||||
});
|
||||
//
|
||||
// ONE STOP OF THE GAME'S THREADS FOR ALL OF THEM (0.1.0-beta.46, owner decision D134). Each patch was restored by
|
||||
// its own MH_DisableHook -- a snapshot of the system's threads and a suspend of every one of this process's, per
|
||||
// patch: about 160 ms each, two to three seconds for a Streamline title, possibly on the thread that presents.
|
||||
// RestoreAll marks the patches that are still ours and applies the marks together (fl_patch_registry.h says what
|
||||
// may and may not be marked, and why). The lines below are written after the gate is released.
|
||||
const int64_t began = QpcNow();
|
||||
uint32_t restored = 0;
|
||||
fl::patch::RestoreAll(
|
||||
g_patches, MinHookEngine{},
|
||||
[](const void* target, const void* detour) noexcept { return fl::patch::StillOurs(target, detour); },
|
||||
[&restored](const char* name, void* target, bool wasOurs, bool ok) noexcept {
|
||||
if (wasOurs) {
|
||||
LogNote(kLogUnhookRestored, name, ok ? 1u : 0u, reinterpret_cast<uint64_t>(target));
|
||||
restored += ok ? 1u : 0u;
|
||||
} else {
|
||||
LogNote(kLogUnhookDeclined, name, 0u, reinterpret_cast<uint64_t>(target));
|
||||
}
|
||||
});
|
||||
// a = the microseconds the walk and its one apply took, b = how many patches it restored.
|
||||
LogNote(kLogPatchBatch, "restore", MicrosSince(began), restored);
|
||||
if (g_state != nullptr) {
|
||||
std::atomic_ref<uint32_t> status{g_state->status};
|
||||
status.store(reason, std::memory_order_release);
|
||||
@@ -986,6 +1064,63 @@ bool PatchTarget(void* target, void* detour, void** original, const char* name)
|
||||
return false;
|
||||
}
|
||||
|
||||
// SEVERAL PATCHES FOR ONE STOP OF THE GAME'S THREADS (0.1.0-beta.46, owner decision D134). The lazy installers put a
|
||||
// row's patch into the watchdog's batch instead of making it at once, and the batch goes in when the walk is done:
|
||||
// thirteen Streamline rows were thirteen stops of every thread of the game, 0.7 s to 2.8 s of its start in the
|
||||
// owner's logs of 2026-11-13. fl_patch_registry.h holds the sequence and what it must never do.
|
||||
//
|
||||
// WATCHDOG THREAD ONLY, and empty between two installers: each commits what it queued before it returns.
|
||||
fl::patch::Batch<kMaxPatches> g_batch;
|
||||
|
||||
// What PatchTarget does, deferred: the slot is claimed and the hook created now; the patch, its HOOK_INSTALLED line,
|
||||
// its family bit and its latch come at CommitPatchBatch -- in that order, and only if the patch went in. `family` is
|
||||
// 0 for a row whose family is published elsewhere, once every row of it is in; `latch` is the row's "patched" word.
|
||||
bool QueuePatch(void* target, void* detour, void** original, const char* name, uint32_t family,
|
||||
std::atomic<uint32_t>* latch) noexcept {
|
||||
const fl::patch::InstallResult result =
|
||||
g_batch.Add(g_patches, g_observing, MinHookEngine{}, target, detour, original, name, latch, family);
|
||||
if (result == fl::patch::InstallResult::Pending) {
|
||||
return true;
|
||||
}
|
||||
if (result != fl::patch::InstallResult::NoTarget) {
|
||||
NotePatchFailedOnce(target, result, name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CommitPatchBatch() noexcept {
|
||||
const uint32_t count = g_batch.Count();
|
||||
if (count == 0u) {
|
||||
return;
|
||||
}
|
||||
const int64_t began = QpcNow();
|
||||
g_batch.Commit(g_patches, g_observing, MinHookEngine{}, [](const void* target, const void* detour) noexcept {
|
||||
return fl::patch::StillOurs(target, detour);
|
||||
});
|
||||
const uint32_t micros = MicrosSince(began);
|
||||
uint32_t installed = 0;
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
const auto& item = g_batch.At(i);
|
||||
if (item.result != fl::patch::InstallResult::Installed) {
|
||||
NotePatchFailedOnce(item.target, item.result, item.name);
|
||||
continue;
|
||||
}
|
||||
LogNote(kLogHookInstalled, item.name, 0, reinterpret_cast<uint64_t>(item.target));
|
||||
// The family, then the latch: PublishHookFamily's order, for a row that has both.
|
||||
if (item.word != 0u && g_state != nullptr) {
|
||||
std::atomic_ref<uint32_t> hooks{g_state->hooksInstalledMask};
|
||||
hooks.fetch_or(item.word, std::memory_order_relaxed);
|
||||
}
|
||||
if (item.context != nullptr) {
|
||||
static_cast<std::atomic<uint32_t>*>(item.context)->store(1u, std::memory_order_release);
|
||||
}
|
||||
++installed;
|
||||
}
|
||||
// a = the microseconds the one apply took, b = how many patches it put in.
|
||||
LogNote(kLogPatchBatch, "install", micros, installed);
|
||||
g_batch.Clear();
|
||||
}
|
||||
|
||||
// Returns false when we must not record this present.
|
||||
//
|
||||
// The supervision deadline is NOT here any more -- it is the watchdog's, which
|
||||
@@ -2611,12 +2746,8 @@ bool InstallRow(const wchar_t* moduleName, const char* symbol, uint32_t family,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PatchTarget(target, detour, original, name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PublishHookFamily(family, live);
|
||||
return true;
|
||||
// Queued, not patched: the family is published and the latch set when the batch commits (CommitPatchBatch).
|
||||
return QueuePatch(target, detour, original, name, family, &live);
|
||||
}
|
||||
|
||||
// Bind a row's family bit to the detour that implements it.
|
||||
@@ -2720,11 +2851,8 @@ bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t fam
|
||||
if (target == nullptr) {
|
||||
return false; // not loaded, or a module of the name that does not speak ffx-api
|
||||
}
|
||||
if (!PatchTarget(target, FfxConfigureDetour(slot), reinterpret_cast<void**>(&g_origFfxConfigure[slot]), name)) {
|
||||
return false;
|
||||
}
|
||||
g_ffxConfigurePatched[slot].store(1, std::memory_order_release);
|
||||
return true;
|
||||
return QueuePatch(target, FfxConfigureDetour(slot), reinterpret_cast<void**>(&g_origFfxConfigure[slot]), name,
|
||||
0u, &g_ffxConfigurePatched[slot]);
|
||||
}
|
||||
if (family == fl::inventory::kFamilyEvaluateFeature) {
|
||||
return InstallRow(moduleName, symbol, family, reinterpret_cast<void*>(&Hook_SlEvaluateFeature),
|
||||
@@ -2753,11 +2881,7 @@ bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t fam
|
||||
frameRow ? reinterpret_cast<void*>(&Hook_SlSetTagForFrame) : reinterpret_cast<void*>(&Hook_SlSetTag);
|
||||
void** original =
|
||||
frameRow ? reinterpret_cast<void**>(&g_origSlSetTagForFrame) : reinterpret_cast<void**>(&g_origSlSetTag);
|
||||
if (!PatchTarget(target, detour, original, name)) {
|
||||
return false;
|
||||
}
|
||||
patched.store(1, std::memory_order_release);
|
||||
return true;
|
||||
return QueuePatch(target, detour, original, name, 0u, &patched);
|
||||
}
|
||||
if (family == static_cast<uint32_t>(fl::FL_HOOK_FG_EVALUATIONS)) {
|
||||
return InstallRow(moduleName, symbol, family, reinterpret_cast<void*>(&Hook_SlGetNewFrameToken),
|
||||
@@ -2793,12 +2917,8 @@ bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t fam
|
||||
if (target == nullptr) {
|
||||
return false; // not loaded, or a module of the name that does not speak the 3.0 host ABI
|
||||
}
|
||||
if (!PatchTarget(target, reinterpret_cast<void*>(&Hook_FfxFsr3ContextDispatchUpscale),
|
||||
reinterpret_cast<void**>(&g_origFfxFsr3DispatchUpscale), name)) {
|
||||
return false;
|
||||
}
|
||||
g_fsr3HostPatched.store(1, std::memory_order_release);
|
||||
return true;
|
||||
return QueuePatch(target, reinterpret_cast<void*>(&Hook_FfxFsr3ContextDispatchUpscale),
|
||||
reinterpret_cast<void**>(&g_origFfxFsr3DispatchUpscale), name, 0u, &g_fsr3HostPatched);
|
||||
}
|
||||
const auto slot = static_cast<uint32_t>(leaf);
|
||||
if (g_ffxPatched[slot].load(std::memory_order_acquire) != 0) {
|
||||
@@ -2808,11 +2928,8 @@ bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t fam
|
||||
if (target == nullptr) {
|
||||
return false; // not loaded, or a module of the name that does not speak ffx-api
|
||||
}
|
||||
if (!PatchTarget(target, FfxDispatchDetour(slot), reinterpret_cast<void**>(&g_origFfxDispatch[slot]), name)) {
|
||||
return false;
|
||||
}
|
||||
g_ffxPatched[slot].store(1, std::memory_order_release);
|
||||
return true;
|
||||
return QueuePatch(target, FfxDispatchDetour(slot), reinterpret_cast<void**>(&g_origFfxDispatch[slot]), name, 0u,
|
||||
&g_ffxPatched[slot]);
|
||||
}
|
||||
if (family == fl::inventory::kFamilyFfxQuery) {
|
||||
// FOUR ROWS, ONE ARM, the dispatch arm's shape: the row's MODULE picks the trampoline and the latch slot.
|
||||
@@ -2829,11 +2946,8 @@ bool InstallByFamily(const wchar_t* moduleName, const char* symbol, uint32_t fam
|
||||
if (target == nullptr) {
|
||||
return false; // not loaded, or a module of the name that does not speak ffx-api
|
||||
}
|
||||
if (!PatchTarget(target, FfxQueryDetour(slot), reinterpret_cast<void**>(&g_origFfxQuery[slot]), name)) {
|
||||
return false;
|
||||
}
|
||||
g_ffxQueryPatched[slot].store(1, std::memory_order_release);
|
||||
return true;
|
||||
return QueuePatch(target, FfxQueryDetour(slot), reinterpret_cast<void**>(&g_origFfxQuery[slot]), name, 0u,
|
||||
&g_ffxQueryPatched[slot]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2957,6 +3071,9 @@ bool InstallUpscalerHooks() noexcept {
|
||||
}
|
||||
FL_HOOK_INVENTORY(FL_INSTALL_ROW)
|
||||
#undef FL_INSTALL_ROW
|
||||
// Every row this tick found something to patch for goes in now, together -- and before the families that are
|
||||
// published "when whole", which read the latches the commit sets.
|
||||
CommitPatchBatch();
|
||||
PublishParamsFamilyIfWhole();
|
||||
PublishFfxFamilyIfWhole();
|
||||
PublishFfxQueryFamilyIfWhole();
|
||||
@@ -3088,20 +3205,21 @@ bool InstallRtHooks() noexcept {
|
||||
const bool buildAgrees = directVtbl[fl::d3d12::kBuildRaytracingAccelerationStructureIndex] ==
|
||||
computeVtbl[fl::d3d12::kBuildRaytracingAccelerationStructureIndex];
|
||||
|
||||
// The two go in together (0.1.0-beta.46): one stop of the game's threads, not two.
|
||||
if (dispatchAgrees && g_rtDispatchLive.load(std::memory_order_acquire) == 0 &&
|
||||
PatchTarget(directVtbl[fl::d3d12::kDispatchRaysIndex], reinterpret_cast<void*>(&Hook_DispatchRays),
|
||||
reinterpret_cast<void**>(&g_origDispatchRays),
|
||||
"d3d12!ID3D12GraphicsCommandList4::DispatchRays")) {
|
||||
PublishHookFamily(static_cast<uint32_t>(fl::FL_HOOK_RT_DISPATCH), g_rtDispatchLive);
|
||||
QueuePatch(directVtbl[fl::d3d12::kDispatchRaysIndex], reinterpret_cast<void*>(&Hook_DispatchRays),
|
||||
reinterpret_cast<void**>(&g_origDispatchRays), "d3d12!ID3D12GraphicsCommandList4::DispatchRays",
|
||||
static_cast<uint32_t>(fl::FL_HOOK_RT_DISPATCH), &g_rtDispatchLive)) {
|
||||
installed = true;
|
||||
}
|
||||
if (buildAgrees && g_rtAsBuildLive.load(std::memory_order_acquire) == 0 &&
|
||||
PatchTarget(directVtbl[fl::d3d12::kBuildRaytracingAccelerationStructureIndex],
|
||||
reinterpret_cast<void*>(&Hook_BuildRtAs), reinterpret_cast<void**>(&g_origBuildRtAs),
|
||||
"d3d12!ID3D12GraphicsCommandList4::BuildRaytracingAccelerationStructure")) {
|
||||
PublishHookFamily(static_cast<uint32_t>(fl::FL_HOOK_RT_AS_BUILD), g_rtAsBuildLive);
|
||||
QueuePatch(directVtbl[fl::d3d12::kBuildRaytracingAccelerationStructureIndex],
|
||||
reinterpret_cast<void*>(&Hook_BuildRtAs), reinterpret_cast<void**>(&g_origBuildRtAs),
|
||||
"d3d12!ID3D12GraphicsCommandList4::BuildRaytracingAccelerationStructure",
|
||||
static_cast<uint32_t>(fl::FL_HOOK_RT_AS_BUILD), &g_rtAsBuildLive)) {
|
||||
installed = true;
|
||||
}
|
||||
CommitPatchBatch();
|
||||
}
|
||||
|
||||
// Closed before release: a command list left recording holds its allocator.
|
||||
@@ -3267,7 +3385,9 @@ DWORD WatchdogLoop() noexcept {
|
||||
// Twelve patches (the Streamline fixture until then) took 1.9 s and fitted; with three more rows the stop took 2.4 s,
|
||||
// the flush gave up first, and the log ended "the stop was still writing" with the last three UNHOOK_RESTORED lines
|
||||
// missing -- the patches were restored, the log did not say so. The wait ends the moment the stop is logged, so the
|
||||
// longer bound costs nothing where the stop is quick.
|
||||
// longer bound costs nothing where the stop is quick. Since 0.1.0-beta.46 the stop restores its patches under one
|
||||
// stop of the threads and is quick; the bound stays for the case it was sized for -- an apply that fails and falls
|
||||
// back to one restore a patch.
|
||||
constexpr ULONGLONG kStopLogWaitMs = 250ull * kMaxPatches;
|
||||
|
||||
DWORD WINAPI WatchdogThread(LPVOID) noexcept {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -7416,6 +7417,7 @@ TEST_CASE("region 5 carries what a Streamline title chains into its evaluation,
|
||||
}
|
||||
|
||||
// ---- 2. ASKED: the patches go in on the tick that sees the request, and the next publications carry the groups.
|
||||
const ULONGLONG askedAt = GetTickCount64();
|
||||
SetAdvancedRequest(r, 1u);
|
||||
REQUIRE(WaitForHookFamily(r.st, slConstants));
|
||||
REQUIRE(WaitForHookFamily(r.st, static_cast<uint32_t>(fl::FL_HOOK_SL_FEATURE_VERSION)));
|
||||
@@ -7426,6 +7428,9 @@ TEST_CASE("region 5 carries what a Streamline title chains into its evaluation,
|
||||
REQUIRE(WaitForHookFamily(r.st, static_cast<uint32_t>(fl::FL_HOOK_SL_ALLOCATE_RESOURCES)));
|
||||
REQUIRE(WaitForHookFamily(r.st, static_cast<uint32_t>(fl::FL_HOOK_SL_FREE_RESOURCES)));
|
||||
REQUIRE(WaitForHookFamily(r.st, static_cast<uint32_t>(fl::FL_HOOK_SL_SHUTDOWN)));
|
||||
// Measured, not asserted: a tick's wait (up to a second) and then the nine patches. Printed so that a pull request
|
||||
// which changes how patches go in can say what it did to this (0.1.0-beta.46).
|
||||
WARN("asked -> the nine Advanced-only families published: " << (GetTickCount64() - askedAt) << " ms");
|
||||
REQUIRE(ReadTargetExportBytes(child.pi.dwProcessId, FL_STUB_SL_INTERPOSER, "slSetConstants", now));
|
||||
CHECK(std::memcmp(pristine, now, sizeof(now)) != 0); // patched now
|
||||
for (int i = 0; i < kFeatureExports; ++i) {
|
||||
@@ -7557,12 +7562,15 @@ TEST_CASE("region 5 carries what a Streamline title chains into its evaluation,
|
||||
// ---- 4. STOPPED: the export's first bytes are the file's again, and the log says which patch was restored.
|
||||
// The status is written after the last patch is restored, and a restore is some 160 ms: fifteen patches in this
|
||||
// target since 0.1.0-beta.45, so the wait is ten seconds where three were enough for twelve.
|
||||
const ULONGLONG stopAt = GetTickCount64();
|
||||
r.ctl->unhookRequested = 1;
|
||||
for (int i = 0; i < 200 && r.st->status != fl::FL_STATUS_UNHOOKED; ++i) {
|
||||
for (int i = 0; i < 1000 && r.st->status != fl::FL_STATUS_UNHOOKED; ++i) {
|
||||
++r.ctl->guardTicks;
|
||||
Sleep(50);
|
||||
Sleep(10);
|
||||
}
|
||||
REQUIRE(r.st->status == fl::FL_STATUS_UNHOOKED);
|
||||
// Measured, not asserted: the request is read within a frame, then every patch is restored.
|
||||
WARN("unhook requested -> UNHOOKED: " << (GetTickCount64() - stopAt) << " ms");
|
||||
std::wstring log;
|
||||
std::string text;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
@@ -7587,4 +7595,56 @@ TEST_CASE("region 5 carries what a Streamline title chains into its evaluation,
|
||||
}
|
||||
CHECK(text.find("UNHOOK_DECLINED") == std::string::npos);
|
||||
CHECK(text.find("PATCH_FAILED") == std::string::npos);
|
||||
|
||||
// 0.1.0-beta.46 (owner decision D134): the rows go in by the batch -- one stop of the target's threads for the rows
|
||||
// a tick found, not one a row -- and the stop takes every patch out under one. The log says so: a PATCH_BATCH line
|
||||
// an apply, `b` the number of patches it covered. Counted from the log, not written here as numbers: the rows
|
||||
// that install unasked go in on an earlier tick than the nine that wait for the request, so there are at least two
|
||||
// install lines, and every HOOK_INSTALLED that is not one of init's own (DXGI, the loader, OpenGL) is under one.
|
||||
const auto eachLine = [&text](const char* needle, const auto& visit) {
|
||||
std::size_t at = 0;
|
||||
while ((at = text.find(needle, at)) != std::string::npos) {
|
||||
const std::size_t end = text.find('\n', at);
|
||||
visit(text.substr(at, end == std::string::npos ? std::string::npos : end - at));
|
||||
at = end == std::string::npos ? text.size() : end;
|
||||
}
|
||||
};
|
||||
const auto field = [](const std::string& line, std::string_view key, int base) {
|
||||
const std::size_t at = line.find(key);
|
||||
return at == std::string::npos ? 0ull : std::strtoull(line.c_str() + at + key.size(), nullptr, base);
|
||||
};
|
||||
unsigned long long installBatches = 0;
|
||||
unsigned long long installedByBatch = 0;
|
||||
unsigned long long restoreBatches = 0;
|
||||
unsigned long long restoredByBatch = 0;
|
||||
unsigned long long restoreMicros = 0;
|
||||
unsigned long long installedLazily = 0;
|
||||
unsigned long long restoredLines = 0;
|
||||
eachLine("PATCH_BATCH install", [&](const std::string& line) {
|
||||
++installBatches;
|
||||
installedByBatch += field(line, " b=0x", 16);
|
||||
WARN("an install batch put " << field(line, " b=0x", 16) << " patches in, in " << field(line, " a=", 10)
|
||||
<< " us");
|
||||
});
|
||||
eachLine("PATCH_BATCH restore", [&](const std::string& line) {
|
||||
++restoreBatches;
|
||||
restoredByBatch += field(line, " b=0x", 16);
|
||||
restoreMicros += field(line, " a=", 10);
|
||||
});
|
||||
eachLine("HOOK_INSTALLED ", [&](const std::string& line) {
|
||||
if (line.find("dxgi!") == std::string::npos && line.find("kernelbase!") == std::string::npos &&
|
||||
line.find("opengl32!") == std::string::npos) {
|
||||
++installedLazily;
|
||||
}
|
||||
});
|
||||
eachLine("UNHOOK_RESTORED ", [&](const std::string&) { ++restoredLines; });
|
||||
CHECK(installBatches >= 2u);
|
||||
CHECK(installedByBatch == installedLazily);
|
||||
CHECK(installedLazily >= 10u); // slSetConstants and the eight feature exports among them
|
||||
CHECK(restoreBatches == 1u);
|
||||
CHECK(restoredByBatch == restoredLines);
|
||||
// One stop of the threads, not one a patch: restoring these one by one took 1.3 s to 1.5 s on the development PC
|
||||
// (0.1.0-beta.45, eighteen patches). A bound a slow runner still meets, and the old way did not.
|
||||
WARN("the stop's one apply restored " << restoredByBatch << " patches in " << restoreMicros << " us");
|
||||
CHECK(restoreMicros < 1000000ull);
|
||||
}
|
||||
@@ -367,3 +367,452 @@ TEST_CASE("a patch that failed gives its slot back, and a slot is not seen by th
|
||||
registry.Retire(-3);
|
||||
CHECK(registry.LiveCount() == 0u);
|
||||
}
|
||||
|
||||
// --- batches (0.1.0-beta.46, owner decision D134) --------------------------------------------------------------------
|
||||
// Several patches for ONE stop of the process's threads, and every patch out the same way. Driven twice: against real
|
||||
// MinHook, for what is at the target, and against a MODEL of MinHook's table (hook.c: each hook has a state and a
|
||||
// mark, and an apply executes every hook whose two differ, stopping at the first that fails), for the things real
|
||||
// MinHook cannot be made to do on demand -- an apply that fails halfway, a stop that lands inside one.
|
||||
namespace {
|
||||
|
||||
// MinHook with its queue, as dllmain.cpp's MinHookEngine hands it to Batch and RestoreAll. The gate is the Overlay's;
|
||||
// one thread patches here.
|
||||
struct RealQueue {
|
||||
static bool Create(void* target, void* detour, void** original) noexcept {
|
||||
return MH_CreateHook(target, detour, original) == MH_OK;
|
||||
}
|
||||
static bool QueueEnable(void* target) noexcept { return MH_QueueEnableHook(target) == MH_OK; }
|
||||
static bool QueueDisable(void* target) noexcept { return MH_QueueDisableHook(target) == MH_OK; }
|
||||
static bool Apply() noexcept { return MH_ApplyQueued() == MH_OK; }
|
||||
static bool EnsureEnabled(void* target) noexcept {
|
||||
const MH_STATUS status = MH_EnableHook(target);
|
||||
return status == MH_OK || status == MH_ERROR_ENABLED;
|
||||
}
|
||||
static bool EnsureDisabled(void* target) noexcept {
|
||||
const MH_STATUS status = MH_DisableHook(target);
|
||||
return status == MH_OK || status == MH_ERROR_DISABLED;
|
||||
}
|
||||
static void BeginQueue() noexcept {}
|
||||
static void EndQueue() noexcept {}
|
||||
};
|
||||
|
||||
bool RealOurs(const void* target, const void* detour) noexcept {
|
||||
return fl::patch::StillOurs(target, detour);
|
||||
}
|
||||
|
||||
struct Model {
|
||||
static constexpr int kMax = 8;
|
||||
void* target[kMax]{};
|
||||
bool enabled[kMax]{};
|
||||
bool marked[kMax]{}; // MinHook's queueEnable: the state the next apply gives the hook
|
||||
bool foreign[kMax]{}; // somebody else patched over this one
|
||||
int count = 0;
|
||||
|
||||
void* neverEnables = nullptr; // the hook at this target cannot be enabled
|
||||
bool applyFails = false; // the apply does nothing and says so
|
||||
std::atomic<std::uint32_t>* stopsDuringApply = nullptr;
|
||||
|
||||
int applies = 0;
|
||||
int gate = 0;
|
||||
bool touchedOutsideTheGate = false;
|
||||
bool wroteOverAForeignPatch = false;
|
||||
|
||||
int Find(const void* t) const noexcept {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (target[i] == t) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
bool AMarkIsStanding() const noexcept {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (enabled[i] != marked[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Enabled(const void* t) const noexcept {
|
||||
const int i = Find(t);
|
||||
return i >= 0 && enabled[i];
|
||||
}
|
||||
void Set(int i, bool on) noexcept {
|
||||
if (i < 0 || i >= count) {
|
||||
return;
|
||||
}
|
||||
if (!on && enabled[i] && foreign[i]) {
|
||||
wroteOverAForeignPatch = true; // our saved bytes over their jump: what §H7 forbids
|
||||
}
|
||||
enabled[i] = on;
|
||||
marked[i] = on;
|
||||
}
|
||||
// Somebody else patched over the hook at `t`.
|
||||
void PatchOver(const void* t) noexcept {
|
||||
const int i = Find(t);
|
||||
if (i >= 0) {
|
||||
foreign[i] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelEngine {
|
||||
Model* m;
|
||||
bool Create(void* target, void*, void**) const noexcept {
|
||||
if (m->Find(target) >= 0 || m->count == Model::kMax) {
|
||||
return false;
|
||||
}
|
||||
m->target[m->count++] = target;
|
||||
return true;
|
||||
}
|
||||
bool Mark(void* target, bool on) const noexcept {
|
||||
const int i = m->Find(target);
|
||||
if (i < 0) {
|
||||
return false;
|
||||
}
|
||||
m->touchedOutsideTheGate = m->touchedOutsideTheGate || m->gate == 0;
|
||||
m->marked[i] = on;
|
||||
return true;
|
||||
}
|
||||
bool QueueEnable(void* target) const noexcept { return Mark(target, true); }
|
||||
bool QueueDisable(void* target) const noexcept { return Mark(target, false); }
|
||||
bool Apply() const noexcept {
|
||||
++m->applies;
|
||||
m->touchedOutsideTheGate = m->touchedOutsideTheGate || m->gate == 0;
|
||||
if (m->stopsDuringApply != nullptr) {
|
||||
m->stopsDuringApply->store(0u);
|
||||
}
|
||||
if (m->applyFails) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m->count; ++i) {
|
||||
if (m->enabled[i] == m->marked[i]) {
|
||||
continue;
|
||||
}
|
||||
if (m->marked[i] && m->target[i] == m->neverEnables) {
|
||||
return false; // hook.c: the first failure ends the apply, the rest keep their marks
|
||||
}
|
||||
m->Set(i, m->marked[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool EnsureEnabled(void* target) const noexcept {
|
||||
const int i = m->Find(target);
|
||||
if (i < 0 || target == m->neverEnables) {
|
||||
return false;
|
||||
}
|
||||
m->Set(i, true);
|
||||
return true;
|
||||
}
|
||||
bool EnsureDisabled(void* target) const noexcept {
|
||||
const int i = m->Find(target);
|
||||
if (i < 0) {
|
||||
return false;
|
||||
}
|
||||
m->Set(i, false);
|
||||
return true;
|
||||
}
|
||||
void BeginQueue() const noexcept { ++m->gate; }
|
||||
void EndQueue() const noexcept { --m->gate; }
|
||||
};
|
||||
|
||||
// "Still ours", for the model: in, and nobody patched over it.
|
||||
struct ModelOurs {
|
||||
const Model* m;
|
||||
bool operator()(const void* target, const void*) const noexcept {
|
||||
const int i = m->Find(target);
|
||||
return i >= 0 && m->enabled[i] && !m->foreign[i];
|
||||
}
|
||||
};
|
||||
|
||||
int g_a = 0;
|
||||
int g_b = 0;
|
||||
int g_c = 0;
|
||||
int g_detour = 0;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("a batch puts three patches in under one apply, and the stop takes them out under one",
|
||||
"[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
fl::patch::Registry<3> registry;
|
||||
fl::patch::Batch<3> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
void* first = reinterpret_cast<void*>(&First);
|
||||
void* second = reinterpret_cast<void*>(&Second);
|
||||
void* third = reinterpret_cast<void*>(&Third);
|
||||
const int firstPlain = First(3);
|
||||
const int secondPlain = Second(3);
|
||||
const int thirdPlain = Third(3);
|
||||
|
||||
REQUIRE(MH_Initialize() == MH_OK);
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, first, reinterpret_cast<void*>(&DetourFirst),
|
||||
reinterpret_cast<void**>(&g_origFirst), "first", nullptr, 0u) == InstallResult::Pending);
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, second, reinterpret_cast<void*>(&DetourSecond),
|
||||
reinterpret_cast<void**>(&g_origSecond), "second", nullptr, 0u) == InstallResult::Pending);
|
||||
// The same target a second time: the engine refuses it, its slot goes back, and the others are not held up.
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, second, reinterpret_cast<void*>(&DetourSecond),
|
||||
reinterpret_cast<void**>(&g_origSecond), "second again", nullptr,
|
||||
0u) == InstallResult::CreateFailed);
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, third, reinterpret_cast<void*>(&DetourThird),
|
||||
reinterpret_cast<void**>(&g_origThird), "third", nullptr, 7u) == InstallResult::Pending);
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, nullptr, first, nullptr, "nothing", nullptr, 0u) ==
|
||||
InstallResult::NoTarget);
|
||||
REQUIRE(batch.Count() == 3u);
|
||||
|
||||
// Added is not patched: nothing is at any target, and the stop's walk has nothing to see.
|
||||
CHECK(First(3) == firstPlain);
|
||||
CHECK(Third(3) == thirdPlain);
|
||||
CHECK(registry.LiveCount() == 0u);
|
||||
|
||||
batch.Commit(registry, observing, RealQueue{}, RealOurs);
|
||||
for (std::uint32_t i = 0; i < batch.Count(); ++i) {
|
||||
CHECK(batch.At(i).result == InstallResult::Installed);
|
||||
}
|
||||
CHECK(batch.At(2).word == 7u); // what the caller attached comes back with the item
|
||||
CHECK(First(3) == firstPlain + 1000000);
|
||||
CHECK(Second(3) == secondPlain + 2000000);
|
||||
CHECK(Third(3) == thirdPlain + 3000000);
|
||||
CHECK(registry.LiveCount() == 3u);
|
||||
batch.Clear();
|
||||
CHECK(batch.Count() == 0u);
|
||||
|
||||
// The stop: one walk, one apply, every patch reported as ours and restored.
|
||||
observing.store(0u);
|
||||
int restored = 0;
|
||||
int declined = 0;
|
||||
fl::patch::RestoreAll(registry, RealQueue{}, RealOurs,
|
||||
[&restored, &declined](const char*, void*, bool wasOurs, bool ok) noexcept {
|
||||
restored += (wasOurs && ok) ? 1 : 0;
|
||||
declined += wasOurs ? 0 : 1;
|
||||
});
|
||||
CHECK(restored == 3);
|
||||
CHECK(declined == 0);
|
||||
CHECK(First(3) == firstPlain);
|
||||
CHECK(Second(3) == secondPlain);
|
||||
CHECK(Third(3) == thirdPlain);
|
||||
|
||||
// Stopping is one-way for a batch as for a single patch: nothing is created after it.
|
||||
CHECK(batch.Add(registry, observing, RealQueue{}, first, reinterpret_cast<void*>(&DetourFirst),
|
||||
reinterpret_cast<void**>(&g_origFirst), "first", nullptr, 0u) == InstallResult::Stopped);
|
||||
MH_Uninitialize();
|
||||
}
|
||||
|
||||
TEST_CASE("the stop's batch leaves a patch a foreign overlay patched over exactly as it is, and restores the others",
|
||||
"[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
fl::patch::Registry<2> registry;
|
||||
fl::patch::Batch<2> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
void* first = reinterpret_cast<void*>(&First);
|
||||
void* second = reinterpret_cast<void*>(&Second);
|
||||
const int secondPlain = Second(3);
|
||||
|
||||
REQUIRE(MH_Initialize() == MH_OK);
|
||||
REQUIRE(batch.Add(registry, observing, RealQueue{}, first, reinterpret_cast<void*>(&DetourFirst),
|
||||
reinterpret_cast<void**>(&g_origFirst), "first", nullptr, 0u) == InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, RealQueue{}, second, reinterpret_cast<void*>(&DetourSecond),
|
||||
reinterpret_cast<void**>(&g_origSecond), "second", nullptr, 0u) == InstallResult::Pending);
|
||||
batch.Commit(registry, observing, RealQueue{}, RealOurs);
|
||||
REQUIRE(registry.LiveCount() == 2u);
|
||||
|
||||
// A foreign overlay patches First after us.
|
||||
std::uint8_t* foreignRelay = MakeRelay(reinterpret_cast<void*>(&ForeignDetour), first);
|
||||
std::int32_t savedRel = 0;
|
||||
RepointJump(first, foreignRelay, &savedRel);
|
||||
std::uint8_t theirs[5]{};
|
||||
std::memcpy(theirs, first, sizeof(theirs));
|
||||
REQUIRE(First(5) == 4); // their hook is what runs
|
||||
|
||||
observing.store(0u);
|
||||
int restored = 0;
|
||||
int declined = 0;
|
||||
fl::patch::RestoreAll(registry, RealQueue{}, RealOurs,
|
||||
[&restored, &declined](const char*, void*, bool wasOurs, bool ok) noexcept {
|
||||
restored += (wasOurs && ok) ? 1 : 0;
|
||||
declined += wasOurs ? 0 : 1;
|
||||
});
|
||||
CHECK(restored == 1);
|
||||
CHECK(declined == 1);
|
||||
CHECK(std::memcmp(theirs, first, sizeof(theirs)) == 0); // not one byte of theirs was written
|
||||
CHECK(First(5) == 4);
|
||||
CHECK(Second(3) == secondPlain);
|
||||
|
||||
// ...and no mark was left on the declined one: an apply by anybody afterwards still does not touch it.
|
||||
CHECK(MH_ApplyQueued() == MH_OK);
|
||||
CHECK(std::memcmp(theirs, first, sizeof(theirs)) == 0);
|
||||
|
||||
RestoreJump(first, savedRel); // the foreign overlay goes away before MinHook is torn down
|
||||
MH_Uninitialize();
|
||||
VirtualFree(foreignRelay, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
TEST_CASE("an apply that fails halfway costs one patch, and leaves no mark for a later apply to act on",
|
||||
"[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
fl::patch::Registry<3> registry;
|
||||
fl::patch::Batch<3> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
Model model;
|
||||
model.neverEnables = &g_b;
|
||||
const ModelEngine engine{&model};
|
||||
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_a, &g_detour, nullptr, "a", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_b, &g_detour, nullptr, "b", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_c, &g_detour, nullptr, "c", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
CHECK_FALSE(model.AMarkIsStanding()); // adding marks nothing
|
||||
batch.Commit(registry, observing, engine, ModelOurs{&model});
|
||||
|
||||
CHECK(batch.At(0).result == InstallResult::Installed);
|
||||
CHECK(batch.At(1).result == InstallResult::EnableFailed);
|
||||
CHECK(batch.At(2).result == InstallResult::Installed); // the apply stopped at b; c went in by itself
|
||||
CHECK(model.Enabled(&g_a));
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
CHECK(model.Enabled(&g_c));
|
||||
CHECK(registry.LiveCount() == 2u);
|
||||
CHECK(model.applies == 1);
|
||||
CHECK_FALSE(model.AMarkIsStanding());
|
||||
CHECK_FALSE(model.touchedOutsideTheGate);
|
||||
CHECK(model.gate == 0);
|
||||
|
||||
// The stop's apply -- anybody's apply -- must not be what puts b in.
|
||||
model.neverEnables = nullptr;
|
||||
CHECK(engine.Apply());
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
|
||||
// b's slot went back: the third slot can be claimed again.
|
||||
CHECK(registry.Claim(&g_b, &g_detour, "b again") >= 0);
|
||||
}
|
||||
|
||||
TEST_CASE("an apply that does nothing at all still gets every patch in, one at a time", "[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
fl::patch::Registry<2> registry;
|
||||
fl::patch::Batch<2> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
Model model;
|
||||
model.applyFails = true; // MinHook could not stop the threads: nothing applied, one status for all
|
||||
const ModelEngine engine{&model};
|
||||
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_a, &g_detour, nullptr, "a", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_b, &g_detour, nullptr, "b", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
batch.Commit(registry, observing, engine, ModelOurs{&model});
|
||||
CHECK(batch.At(0).result == InstallResult::Installed);
|
||||
CHECK(batch.At(1).result == InstallResult::Installed);
|
||||
CHECK(registry.LiveCount() == 2u);
|
||||
CHECK_FALSE(model.AMarkIsStanding());
|
||||
|
||||
// And the stop, with the same failing apply, still takes both out.
|
||||
observing.store(0u);
|
||||
int restored = 0;
|
||||
fl::patch::RestoreAll(
|
||||
registry, engine, ModelOurs{&model},
|
||||
[&restored](const char*, void*, bool wasOurs, bool ok) noexcept { restored += (wasOurs && ok) ? 1 : 0; });
|
||||
CHECK(restored == 2);
|
||||
CHECK_FALSE(model.Enabled(&g_a));
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
CHECK_FALSE(model.AMarkIsStanding());
|
||||
CHECK_FALSE(model.touchedOutsideTheGate);
|
||||
}
|
||||
|
||||
TEST_CASE("a stop before the batch commits enables nothing; a stop inside its apply is undone by the batch itself",
|
||||
"[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
Model model;
|
||||
const ModelEngine engine{&model};
|
||||
|
||||
SECTION("the stop ran between the adds and the commit") {
|
||||
fl::patch::Registry<2> registry;
|
||||
fl::patch::Batch<2> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_a, &g_detour, nullptr, "a", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_b, &g_detour, nullptr, "b", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
observing.store(0u);
|
||||
batch.Commit(registry, observing, engine, ModelOurs{&model});
|
||||
CHECK(batch.At(0).result == InstallResult::StoppedDuring);
|
||||
CHECK(batch.At(1).result == InstallResult::StoppedDuring);
|
||||
CHECK(model.applies == 0); // nothing was marked, nothing applied
|
||||
CHECK_FALSE(model.Enabled(&g_a));
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
CHECK(registry.LiveCount() == 0u);
|
||||
CHECK(registry.Claim(&g_a, &g_detour, "free again") >= 0); // never live, so not retired
|
||||
}
|
||||
|
||||
SECTION("the stop ran while the apply was putting them in") {
|
||||
fl::patch::Registry<2> registry;
|
||||
fl::patch::Batch<2> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
model.stopsDuringApply = &observing;
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_a, &g_detour, nullptr, "a", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_b, &g_detour, nullptr, "b", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
batch.Commit(registry, observing, engine, ModelOurs{&model});
|
||||
CHECK(batch.At(0).result == InstallResult::StoppedDuring);
|
||||
CHECK(batch.At(1).result == InstallResult::StoppedDuring);
|
||||
CHECK_FALSE(model.Enabled(&g_a)); // put in, and taken out again by the installer
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
CHECK(model.applies == 2); // one in, one out
|
||||
CHECK(registry.LiveCount() == 0u);
|
||||
CHECK(registry.Claim(&g_a, &g_detour, "again") == -1); // they were live: the slots are never reused
|
||||
CHECK_FALSE(model.AMarkIsStanding());
|
||||
CHECK_FALSE(model.touchedOutsideTheGate);
|
||||
CHECK(model.gate == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("the stop marks only what is still ours: a foreign patch is not written, a restored patch is not put back",
|
||||
"[unhook][registry][batch]") {
|
||||
using fl::patch::InstallResult;
|
||||
fl::patch::Registry<3> registry;
|
||||
fl::patch::Batch<3> batch;
|
||||
std::atomic<std::uint32_t> observing{1u};
|
||||
Model model;
|
||||
const ModelEngine engine{&model};
|
||||
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_a, &g_detour, nullptr, "a", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_b, &g_detour, nullptr, "b", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
REQUIRE(batch.Add(registry, observing, engine, &g_c, &g_detour, nullptr, "c", nullptr, 0u) ==
|
||||
InstallResult::Pending);
|
||||
batch.Commit(registry, observing, engine, ModelOurs{&model});
|
||||
REQUIRE(registry.LiveCount() == 3u);
|
||||
|
||||
model.PatchOver(&g_a); // a: somebody patched over us
|
||||
// c: committed, and already taken out -- an installer between its own disable and its Retire. The draft that
|
||||
// marked everything and then un-marked what it must not restore marked THIS one for enabling, and the stop's own
|
||||
// apply put the patch back in after the stop.
|
||||
model.Set(model.Find(&g_c), false);
|
||||
model.applies = 0;
|
||||
|
||||
observing.store(0u);
|
||||
int ours = 0;
|
||||
int notOurs = 0;
|
||||
fl::patch::RestoreAll(registry, engine, ModelOurs{&model},
|
||||
[&ours, ¬Ours](const char*, void*, bool wasOurs, bool ok) noexcept {
|
||||
ours += (wasOurs && ok) ? 1 : 0;
|
||||
notOurs += wasOurs ? 0 : 1;
|
||||
});
|
||||
CHECK(ours == 1); // b
|
||||
CHECK(notOurs == 2); // a and c
|
||||
CHECK(model.applies == 1);
|
||||
CHECK(model.Enabled(&g_a)); // theirs: still in
|
||||
CHECK_FALSE(model.wroteOverAForeignPatch);
|
||||
CHECK_FALSE(model.Enabled(&g_b));
|
||||
CHECK_FALSE(model.Enabled(&g_c)); // stayed out
|
||||
CHECK_FALSE(model.AMarkIsStanding());
|
||||
CHECK_FALSE(model.touchedOutsideTheGate);
|
||||
CHECK(model.gate == 0);
|
||||
|
||||
// Nothing of ours left: a second stop's walk marks nothing and applies nothing.
|
||||
model.applies = 0;
|
||||
fl::patch::RestoreAll(registry, engine, ModelOurs{&model}, [](const char*, void*, bool, bool) noexcept {});
|
||||
CHECK(model.applies == 0);
|
||||
}
|
||||
Reference in new issue
Block a user