Engine robustness review fixes: crash-log repeats, teardown reserve, mutator gate, OOM dump safety
Native crash logger - Per-address slots keep hit counts and a last-write tick; a repeat relogs at powers of two, after 30 s, or for any non-AV code. The oldest noise slot is evicted when the table is full. - The logger checks its dedupe first, caches the module table, and opens the log handle once at install. Managed-noise bucket (coreclr, clrjit, System.Private.CoreLib). Main-thread queue - The action ring (ActionRing) rejects non-teardown work during a world transition and reserves its top 32 slots for teardown, so a stop is never lost behind held work. IsTeardownKind is shared by the enqueue and drain sides. ActionRing.TryPeekAt lets the cast drain's StopQueuedAtOrBefore walk the ring it no longer owns directly; the walk now checks every queued entry, since an entry's time is taken before the ring's lock. - MutatorGate: every AC-mutating helper opens with the same gate, AcMainThreadQueue.MustQueue(teardown: X); IsDraining and ShouldDefer added; teardown helpers are exempt from the hold. tools\check_offthread_mutators.py accepts MustQueue as the gate (it asks MainThreadGuard.IsOnMainThread itself). - MasteryFeed and VaultFeed pause during a transition. The heading slot drops a stale heading; the overlay select is kept. - RequestId never merges into an entry queued at or before the last transition hold; EnqueueRequestId returns false during a transition. - 0xF751 PlayerTeleport starts the 5 s settle window. - Cast slot: the queue time and Pending are published with Volatile.Write (a plain 64-bit store can tear on x86 and the drain reads both without the lock); the stop-wait flag is reset before the publishing store. Appraisals - Appraisal data survives a client release for 10 min (bounded at 4096); evicted on server delete (0xF747) and at session clear. 0xF747 is detected in SmartBox dispatch, independent of capture. Dumps - Dump start/end markers in the log; the launcher holds its wedge kill while a dump is in progress (DumpInProgressRule). The in-progress flag is cleared only when the writer thread exits. - The OOM dump triggers only on the main thread with AC's exact text, before stacks are built. Dumps are pruned only after a successful write, and other live clients' dumps are kept. CrashDump reads the file length before Delete. - ExitProcess/RtlExitUserProcess detours forward crash codes first. - The message box count is decremented first in a finally; 30 s safety reset when no box is visible on the main thread. - UsageStats counts the loader's CoreCLR fatal-error dumps (Logs\dumps\clr_*.dmp) as crashes alongside crash_*.dmp. Tests: EngineRobustnessTests, CrashLogFilterTests, UsageStatsTests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
55f7497065
commit
8c7201dc25
41 changed files with 1797 additions and 448 deletions
|
|
@ -1,8 +1,6 @@
|
|||
/*
|
||||
* CrashLogFilterTests.c - offline checks for CrashLogFilter.h (the native crash logger's
|
||||
* filter). Build and run (x86 or x64 cl, from a VS developer prompt):
|
||||
* cl /nologo /W4 /Fe:<scratch>\clf_tests.exe CrashLogFilterTests.c
|
||||
* <scratch>\clf_tests.exe (exit 0 = pass, 1 = fail)
|
||||
* filter). Build and run with Run-CrashLogFilterTests.ps1 (x86 MSVC). Exit 0 = pass.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
|
@ -18,73 +16,128 @@ static void check(int ok, const char* what)
|
|||
printf("[FAIL] %s\n", what);
|
||||
}
|
||||
|
||||
/* Seen in a real log: 24 handled .NET Framework AVs at ONE address spent the cap,
|
||||
* and the fatal AC fault later was never written. */
|
||||
static void netfx_noise_never_spends_the_cap(void)
|
||||
#define AV CLF_CODE_ACCESS_VIOLATION
|
||||
#define FC(s, code, addr, cls, now) clf_first_chance((s), (code), (addr), (cls), (now), &hits)
|
||||
|
||||
static int is_write(clf_decision d)
|
||||
{
|
||||
clf_state s = {0};
|
||||
int i, logged = 0;
|
||||
for (i = 0; i < 500; i++) {
|
||||
clf_decision d = clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x433620C8u, 1);
|
||||
if (d == CLF_LOG_NETFX) logged++;
|
||||
}
|
||||
check(logged == 1, "the repeating JIT-code AV is written once");
|
||||
check(s.counted == 0, "and never charged to the limit");
|
||||
check(s.netfxRepeats == 499, "repeats are counted");
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x0055FA24u, 0) == CLF_LOG_COUNTED,
|
||||
"a later AC fault is still written");
|
||||
return d == CLF_LOG_COUNTED || d == CLF_LOG_NOISE || d == CLF_LOG_REPEAT;
|
||||
}
|
||||
|
||||
static void other_faults_dedupe_per_address(void)
|
||||
/* Seen in a real log: handled .NET Framework AVs at ONE address spent the old cap,
|
||||
* and the fatal AC fault later was never written. */
|
||||
static void netfx_noise_never_spends_the_limit(void)
|
||||
{
|
||||
clf_state s = {0};
|
||||
unsigned int a;
|
||||
int i;
|
||||
for (i = 0; i < 50; i++)
|
||||
clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x00416C86u, 0);
|
||||
check(s.counted == 1 && s.otherRepeats == 49, "a repeating AC fault costs one entry");
|
||||
static clf_state s;
|
||||
unsigned int hits, i, written = 0;
|
||||
for (i = 0; i < 500; i++)
|
||||
if (is_write(FC(&s, AV, 0x433620C8u, CLF_CLASS_NETFX, 1000 + i * 10))) written++;
|
||||
/* first + the power-of-two repeats 2,4,8,16,32,64,128,256 = 9 entries for 500 hits */
|
||||
check(written == 9, "500 hits of one JIT-code AV: 9 entries (first + powers of two)");
|
||||
check(s.counted == 0, "and never charged to the limit");
|
||||
check(s.noiseRepeats == 491, "skipped repeats are counted as noise");
|
||||
check(FC(&s, AV, 0x0055FA24u, CLF_CLASS_AC, 7000) == CLF_LOG_COUNTED, "a later AC fault is still written");
|
||||
}
|
||||
|
||||
/* A contained AV at a known address that later goes fatal. */
|
||||
static void known_address_going_fatal_is_written(void)
|
||||
{
|
||||
static clf_state s;
|
||||
unsigned int hits, i;
|
||||
clf_decision d;
|
||||
for (i = 0; i < 3; i++) FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, 1000 + i);
|
||||
d = FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, 1010);
|
||||
check(d == CLF_LOG_REPEAT && hits == 4, "3 contained AVs, then a 4th (fatal) at the same address: written, repeat=4");
|
||||
|
||||
{
|
||||
static clf_state t;
|
||||
unsigned int now = 5000;
|
||||
for (i = 0; i < 1000; i++) FC(&t, AV, 0x00416C86u, CLF_CLASS_AC, now + i); /* within 1 s */
|
||||
d = FC(&t, AV, 0x00416C86u, CLF_CLASS_AC, now + 1000 + 31000);
|
||||
check(d == CLF_LOG_REPEAT && hits == 1001, "1000 repeats, then the same address 31 s later: written");
|
||||
d = FC(&t, AV, 0x00416C86u, CLF_CLASS_AC, now + 1000 + 31001);
|
||||
check(d == CLF_SKIP_REPEAT, "and the next one right after is not");
|
||||
}
|
||||
{
|
||||
static clf_state u;
|
||||
FC(&u, AV, 0x00500000u, CLF_CLASS_AC, 100);
|
||||
FC(&u, AV, 0x00500000u, CLF_CLASS_AC, 101);
|
||||
FC(&u, AV, 0x00500000u, CLF_CLASS_AC, 102); /* hits 3: skipped */
|
||||
d = FC(&u, CLF_CODE_HEAP_CORRUPTION, 0x00500000u, CLF_CLASS_AC, 103);
|
||||
check(d == CLF_LOG_REPEAT, "a non-AV code at a known address is always written");
|
||||
}
|
||||
{
|
||||
static clf_state w; /* the 32-bit tick wrap */
|
||||
FC(&w, AV, 0x00600000u, CLF_CLASS_AC, 0xFFFFF000u);
|
||||
FC(&w, AV, 0x00600000u, CLF_CLASS_AC, 0xFFFFF001u);
|
||||
FC(&w, AV, 0x00600000u, CLF_CLASS_AC, 0xFFFFF002u);
|
||||
d = FC(&w, AV, 0x00600000u, CLF_CLASS_AC, 0x00007000u); /* ~32 s later, past the wrap */
|
||||
check(d == CLF_LOG_REPEAT, "the 30 s relog survives the GetTickCount wrap");
|
||||
}
|
||||
}
|
||||
|
||||
static void ac_faults_limited_per_distinct_address(void)
|
||||
{
|
||||
static clf_state s;
|
||||
unsigned int hits, a;
|
||||
for (a = 0; a < 50; a++) FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, 1000);
|
||||
check(s.counted == 1, "a repeating AC fault is charged once");
|
||||
for (a = 1; a < CLF_MAX_COUNTED; a++)
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x00500000u + a * 16, 0) == CLF_LOG_COUNTED,
|
||||
check(FC(&s, AV, 0x00500000u + a * 16, CLF_CLASS_AC, 1000) == CLF_LOG_COUNTED,
|
||||
"distinct addresses written up to the limit");
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x00600000u, 0) == CLF_SKIP_CAP,
|
||||
"past the limit: skipped");
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x00416C86u, 0) == CLF_SKIP_REPEAT,
|
||||
"a known address is a repeat, not a cap hit");
|
||||
check(FC(&s, AV, 0x00700000u, CLF_CLASS_AC, 1000) == CLF_SKIP_CAP, "past the limit: skipped");
|
||||
check(FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, 1000) != CLF_SKIP_CAP,
|
||||
"a known address is decided as a repeat, never by the limit");
|
||||
}
|
||||
|
||||
static void codes(void)
|
||||
{
|
||||
clf_state s = {0};
|
||||
check(clf_first_chance(&s, 0xC00000FDu, 0x1000u, 0) == CLF_LOG_COUNTED, "stack overflow is logged");
|
||||
check(clf_first_chance(&s, 0xC0000374u, 0x2000u, 0) == CLF_LOG_COUNTED, "heap corruption is logged");
|
||||
check(clf_first_chance(&s, 0xC0000409u, 0x3000u, 0) == CLF_LOG_COUNTED, "stack buffer overrun is logged");
|
||||
check(clf_first_chance(&s, 0xC0000602u, 0x4000u, 0) == CLF_LOG_COUNTED, "fail-fast is logged");
|
||||
check(clf_first_chance(&s, 0xE06D7363u, 0x5000u, 0) == CLF_SKIP_CODE, "a C++ exception is not");
|
||||
check(clf_first_chance(&s, 0x80000003u, 0x6000u, 0) == CLF_SKIP_CODE, "a breakpoint is not");
|
||||
static clf_state s;
|
||||
unsigned int hits;
|
||||
check(FC(&s, 0xC00000FDu, 0x1000u, CLF_CLASS_AC, 1) == CLF_LOG_COUNTED, "stack overflow is logged");
|
||||
check(FC(&s, 0xC0000374u, 0x2000u, CLF_CLASS_AC, 1) == CLF_LOG_COUNTED, "heap corruption is logged");
|
||||
check(FC(&s, 0xC0000409u, 0x3000u, CLF_CLASS_AC, 1) == CLF_LOG_COUNTED, "stack buffer overrun is logged");
|
||||
check(FC(&s, 0xC0000602u, 0x4000u, CLF_CLASS_AC, 1) == CLF_LOG_COUNTED, "fail-fast is logged");
|
||||
check(FC(&s, 0xE06D7363u, 0x5000u, CLF_CLASS_AC, 1) == CLF_SKIP_CODE, "a C++ exception is not");
|
||||
check(FC(&s, 0x80000003u, 0x6000u, CLF_CLASS_AC, 1) == CLF_SKIP_CODE, "a breakpoint is not");
|
||||
}
|
||||
|
||||
static void netfx_classification(void)
|
||||
static void classification(void)
|
||||
{
|
||||
check(clf_is_netfx_module(L"clr.dll") && clf_is_netfx_module(L"MSCORLIB.NI.DLL")
|
||||
&& clf_is_netfx_module(L"mscorwks.dll") && clf_is_netfx_module(L"mscorlib.dll"),
|
||||
"the .NET Framework modules match, any case");
|
||||
check(!clf_is_netfx_module(L"coreclr.dll") && !clf_is_netfx_module(L"acclient.exe")
|
||||
&& !clf_is_netfx_module(L"clr.dllx") && !clf_is_netfx_module(0),
|
||||
"CoreCLR, AC and near-misses do not");
|
||||
check(clf_is_netfx_fault(CLF_CODE_ACCESS_VIOLATION, 1, 0, 0), "an AV in clr.dll is noise");
|
||||
check(clf_is_netfx_fault(CLF_CODE_ACCESS_VIOLATION, 0, 1, 1), "an AV in JIT code under clr frames is noise");
|
||||
check(!clf_is_netfx_fault(CLF_CODE_ACCESS_VIOLATION, 0, 1, 0), "an AV in no module under AC frames is not");
|
||||
check(!clf_is_netfx_fault(CLF_CODE_STACK_OVERFLOW, 1, 0, 0), "a stack overflow is never noise");
|
||||
check(!clf_is_netfx_fault(CLF_CODE_HEAP_CORRUPTION, 1, 0, 0), "heap corruption is never noise");
|
||||
check(clf_module_class(L"clr.dll") == CLF_CLASS_NETFX && clf_module_class(L"MSCORLIB.NI.DLL") == CLF_CLASS_NETFX
|
||||
&& clf_module_class(L"mscorwks.dll") == CLF_CLASS_NETFX && clf_module_class(L"mscorlib.dll") == CLF_CLASS_NETFX,
|
||||
"the .NET Framework modules, any case");
|
||||
check(clf_module_class(L"coreclr.dll") == CLF_CLASS_MANAGED && clf_module_class(L"clrjit.dll") == CLF_CLASS_MANAGED
|
||||
&& clf_module_class(L"System.Private.CoreLib.dll") == CLF_CLASS_MANAGED,
|
||||
"the engine's CoreCLR modules are managed noise");
|
||||
check(clf_module_class(L"acclient.exe") == CLF_CLASS_AC && clf_module_class(L"clr.dllx") == CLF_CLASS_AC
|
||||
&& clf_module_class(0) == CLF_CLASS_AC, "AC and near-misses are not noise");
|
||||
check(clf_classify(AV, CLF_CLASS_NETFX, 0, CLF_CLASS_AC) == CLF_CLASS_NETFX, "an AV in clr.dll is .NET Framework noise");
|
||||
check(clf_classify(AV, CLF_CLASS_AC, 1, CLF_CLASS_NETFX) == CLF_CLASS_NETFX, "JIT code under clr frames: .NET Framework noise");
|
||||
check(clf_classify(AV, CLF_CLASS_AC, 1, CLF_CLASS_MANAGED) == CLF_CLASS_MANAGED, "JIT code under CoreCLR frames: managed noise");
|
||||
check(clf_classify(AV, CLF_CLASS_MANAGED, 0, CLF_CLASS_AC) == CLF_CLASS_MANAGED, "an AV in coreclr.dll: managed noise");
|
||||
check(clf_classify(AV, CLF_CLASS_AC, 1, CLF_CLASS_AC) == CLF_CLASS_AC, "no module under AC frames: AC");
|
||||
check(clf_classify(AV, CLF_CLASS_AC, 0, CLF_CLASS_NETFX) == CLF_CLASS_AC, "an AV in an AC module is AC whatever is below it");
|
||||
check(clf_classify(CLF_CODE_STACK_OVERFLOW, CLF_CLASS_NETFX, 0, CLF_CLASS_AC) == CLF_CLASS_AC, "a stack overflow is never noise");
|
||||
check(clf_classify(CLF_CODE_HEAP_CORRUPTION, CLF_CLASS_MANAGED, 0, CLF_CLASS_AC) == CLF_CLASS_AC, "heap corruption is never noise");
|
||||
}
|
||||
|
||||
static void managed_noise_is_its_own_bucket(void)
|
||||
{
|
||||
static clf_state s;
|
||||
unsigned int hits, a;
|
||||
for (a = 0; a < 40; a++)
|
||||
check(FC(&s, AV, 0x70000000u + a * 16, CLF_CLASS_MANAGED, 1) == CLF_LOG_NOISE, "managed noise written once per address");
|
||||
check(s.counted == 0, "and never charged to the AC limit");
|
||||
}
|
||||
|
||||
static void last_chance_is_separate(void)
|
||||
{
|
||||
clf_state s = {0};
|
||||
unsigned int a;
|
||||
static clf_state s;
|
||||
unsigned int hits, a;
|
||||
int i, logged = 0;
|
||||
for (a = 0; a < CLF_MAX_COUNTED + 5; a++)
|
||||
clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x00700000u + a * 16, 0);
|
||||
FC(&s, AV, 0x00700000u + a * 16, CLF_CLASS_AC, 1);
|
||||
check(s.counted == CLF_MAX_COUNTED, "first-chance limit reached");
|
||||
check(clf_last_chance(&s) == CLF_LOG_LAST_CHANCE, "the unhandled one is still written");
|
||||
for (i = 0; i < 20; i++)
|
||||
|
|
@ -92,27 +145,35 @@ static void last_chance_is_separate(void)
|
|||
check(logged == CLF_MAX_LAST_CHANCE - 1, "last-chance has its own small limit");
|
||||
}
|
||||
|
||||
static void full_table_never_silences_ac_faults(void)
|
||||
static void full_table_evicts_oldest_noise(void)
|
||||
{
|
||||
clf_state s = {0};
|
||||
unsigned int a;
|
||||
static clf_state s;
|
||||
unsigned int hits, a;
|
||||
clf_decision d;
|
||||
for (a = 0; a < CLF_ADDR_SLOTS; a++)
|
||||
clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x40000000u + a * 16, 1); /* netfx fills it */
|
||||
check(s.addrCount == CLF_ADDR_SLOTS && s.counted == 0, "table full of .NET Framework addresses");
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x41000000u, 1) == CLF_SKIP_REPEAT,
|
||||
"a new .NET Framework address is no longer written");
|
||||
check(clf_first_chance(&s, CLF_CODE_ACCESS_VIOLATION, 0x0055FA24u, 0) == CLF_LOG_COUNTED,
|
||||
"an AC fault still is");
|
||||
FC(&s, AV, 0x40000000u + a * 16, CLF_CLASS_NETFX, 1000 + a); /* noise fills it, 0x40000000 oldest */
|
||||
check(s.counted == 0, "table full of .NET Framework addresses");
|
||||
d = FC(&s, AV, 0x0055FA24u, CLF_CLASS_AC, 5000);
|
||||
check(d == CLF_LOG_COUNTED, "an AC fault is written");
|
||||
check(clf_find(&s, 0x0055FA24u) != 0, "and tracked, in the evicted slot");
|
||||
check(clf_find(&s, 0x40000000u) == 0, "the least recently written noise slot was evicted");
|
||||
check(clf_find(&s, 0x40000010u) != 0, "the next one was not");
|
||||
check(FC(&s, AV, 0x0055FA24u, CLF_CLASS_AC, 5001) == CLF_LOG_REPEAT && hits == 2, "so its repeat is deduped");
|
||||
d = FC(&s, AV, 0x41000000u, CLF_CLASS_NETFX, 6000);
|
||||
check(d == CLF_LOG_NOISE, "a new .NET Framework address is written, evicting an older one");
|
||||
check(clf_find(&s, 0x0055FA24u) != 0, "AC slots are never evicted");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
netfx_noise_never_spends_the_cap();
|
||||
other_faults_dedupe_per_address();
|
||||
netfx_noise_never_spends_the_limit();
|
||||
known_address_going_fatal_is_written();
|
||||
ac_faults_limited_per_distinct_address();
|
||||
codes();
|
||||
netfx_classification();
|
||||
classification();
|
||||
managed_noise_is_its_own_bucket();
|
||||
last_chance_is_separate();
|
||||
full_table_never_silences_ac_faults();
|
||||
full_table_evicts_oldest_noise();
|
||||
printf("%d check(s), %d failed.\n", g_checks, g_failed);
|
||||
return g_failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue