shared lock - part of #188 - #189
Closed
doomedraven wants to merge 1 commit into
Closed
doomedraven wants to merge 1 commit into
doomedraven wants to merge 1 commit into
Conversation
**`CAPE/CAPE.h`** — added `extern CRITICAL_SECTION g_dotnet_jit_lock;` (the lock defined in `hook_clr.c`, init'd in `DllMain`) so `CAPE.c` can share it. **`CAPE/CAPE.c` `DumpInterestingRegions`** — wrapped both .NET blocks (the `IsDotNetImage` image dump and the `g_dotnet_jit` native-cache dump) in `EnterCriticalSection(&g_dotnet_jit_lock)` / `LeaveCriticalSection`. This serializes the teardown scan against the `compileMethod` hook (still running on JIT worker threads during teardown), so they no longer race on: - `CapeMetaData` scratch fields → dumps can't get cross-written metadata - `DotNetCacheDumpCount` check-then-increment → count stays exact vs. `jit_dumps` - `g_dotnet_jit` reads vs. concurrent `lookup_add` No early returns between Enter/Leave, so the lock can't leak. Lock ordering (`g_dotnet_jit_lock` → dump/log/heap) matches what `hook_clr.c` already established, so no AB‑BA deadlock. `DotNetCacheDumpCount` stays `unsigned int` — with both writers now under the same CS (grep confirms there are only two), atomics aren't needed. Left as-is on purpose: the two other `lookup_get(&g_dotnet_jit, …)` reads at `CAPE.c:1094` / `1287` — pure reads of a prepend-only/never-deleted list, safe on x86/x64 without the lock.
doomedraven
marked this pull request as draft
August 30, 2026 19:31
Owner
|
It is preferred to use internal lookup functions rather than critical section apis, I have attempted to harden and complete the lookup functions in #190. I will attempt to replace all critical section and TLS apis with the internal lookup functions using thread id as key. |
Contributor
Author
|
ok, it was also pushed to 188, so i will update it in 188 once i test it tomorrow and 190 is merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CAPE/CAPE.h— addedextern CRITICAL_SECTION g_dotnet_jit_lock;(the lock defined inhook_clr.c, init'd inDllMain) soCAPE.ccan share it.CAPE/CAPE.cDumpInterestingRegions— wrapped both .NET blocks (theIsDotNetImageimage dump and theg_dotnet_jitnative-cache dump) inEnterCriticalSection(&g_dotnet_jit_lock)/LeaveCriticalSection. This serializes the teardown scan against thecompileMethodhook (still running on JIT worker threads during teardown), so they no longer race on:CapeMetaDatascratch fields → dumps can't get cross-written metadataDotNetCacheDumpCountcheck-then-increment → count stays exact vs.jit_dumpsg_dotnet_jitreads vs. concurrentlookup_addNo early returns between Enter/Leave, so the lock can't leak. Lock ordering (
g_dotnet_jit_lock→ dump/log/heap) matches whathook_clr.calready established, so no AB‑BA deadlock.DotNetCacheDumpCountstaysunsigned int— with both writers now under the same CS (grep confirms there are only two), atomics aren't needed.Left as-is on purpose: the two other
lookup_get(&g_dotnet_jit, …)reads atCAPE.c:1094/1287— pure reads of a prepend-only/never-deleted list, safe on x86/x64 without the lock.