Snapshot for release 2026.10.19.1 (internal fa7a8f6)

This commit is contained in:
Tom Bohar 2026-10-19 09:11:20 -04:00
commit 44074df011
110 changed files with 8017 additions and 291 deletions

View file

@ -17,10 +17,20 @@
* heap corruption.
* - Each faulting address has a slot with its hit count and the time it was last
* written. The first sighting is written. A repeat is written again (with its count)
* when the count is a power of two, when 30 s have passed since that address was
* last written, or when the code is not an AV. So a contained AV that later recurs
* as the fatal one is not swallowed as "seen before": a fatal fault is usually a
* terminate from some handler, and then no last-chance filter ever runs.
* when the count is a power of two (any class), or, for an AC-class address only,
* when 30 s have passed since it was last written, or when the code is not an AV.
* So a contained AV that later recurs as the fatal one is not swallowed as "seen
* before": a fatal fault is usually a terminate from some handler, and then no
* last-chance filter ever runs.
* Review fix (2026-10-18): the 30 s relog used to apply to noise too, so Decal's
* handled null-ref AV (about once a minute, one address) was written on EVERY hit:
* ~1,440 entries (~5-6 KB each with the stack sweep) per day per client. Noise now
* repeats only at powers of two (about 11 entries a day for that address), and the
* 30 s / non-AV relogs are capped per address (CLF_MAX_RELOGS); what a cap or the
* dedupe skips is still in the flush ring, so a fatal hit is recovered at exit.
* - A total byte budget (CLF_MAX_LOG_BYTES, counted from the file's size at install plus
* what this process writes): past it ordinary entries are dropped after ONE marker
* line; fatal entries (last-chance, crash-exit flush) get CLF_LOG_RESERVE_BYTES more.
* - Noise is classified, written once per address like the rest, and never charged to
* the AC limit:
* .NET Framework (Decal plugins): faulting module clr.dll, mscorwks.dll, mscorlib;
@ -50,6 +60,9 @@
#define CLF_MAX_LAST_CHANCE 8
#define CLF_ADDR_SLOTS 128
#define CLF_RELOG_MS 30000u
#define CLF_MAX_RELOGS 16 /* non-power-of-two rewrites per address */
#define CLF_MAX_LOG_BYTES (3u * 1024u * 1024u) /* ordinary entries stop here */
#define CLF_LOG_RESERVE_BYTES (256u * 1024u) /* extra room for fatal entries */
#define CLF_CODE_ACCESS_VIOLATION 0xC0000005u
#define CLF_CODE_FAIL_FAST 0xC0000602u
@ -80,6 +93,7 @@ typedef struct {
unsigned int lastWriteMs;
unsigned char cls; /* clf_class */
unsigned char used;
unsigned char relogs; /* writes that were not first / power-of-two (time, non-AV) */
} clf_slot;
typedef struct {
@ -90,6 +104,10 @@ typedef struct {
unsigned int otherRepeats; /* other repeats not written */
unsigned int overCap; /* not written: limit reached */
unsigned int untracked; /* AC addresses written but not tracked (table full of AC) */
unsigned int relogCapped; /* relogs skipped: the address used its CLF_MAX_RELOGS */
unsigned int logBytes; /* bytes in the log file: size at install + written since */
unsigned int byteDenied; /* entries dropped by the byte budget */
unsigned char capMarked; /* the budget marker line has been written */
} clf_state;
static int clf_is_logged_code(unsigned int code)
@ -152,10 +170,22 @@ static clf_decision clf_repeat(clf_state* s, clf_slot* slot, unsigned int code,
{
slot->hits++;
if (hits) *hits = slot->hits;
if (clf_is_pow2(slot->hits) || nowMs - slot->lastWriteMs >= CLF_RELOG_MS || code != CLF_CODE_ACCESS_VIOLATION) {
if (clf_is_pow2(slot->hits)) {
slot->lastWriteMs = nowMs;
return CLF_LOG_REPEAT;
}
/* The 30 s relog is for genuine (AC-class) faults only: noise at one address (Decal's
* handled null-ref, about once a minute) would otherwise be written on every hit. A
* non-AV code is always written, within the per-address cap. */
if ((slot->cls == CLF_CLASS_AC && nowMs - slot->lastWriteMs >= CLF_RELOG_MS)
|| code != CLF_CODE_ACCESS_VIOLATION) {
if (slot->relogs < CLF_MAX_RELOGS) {
slot->relogs++;
slot->lastWriteMs = nowMs;
return CLF_LOG_REPEAT;
}
s->relogCapped++;
}
if (slot->cls != CLF_CLASS_AC) s->noiseRepeats++; else s->otherRepeats++;
return CLF_SKIP_REPEAT;
}
@ -189,6 +219,7 @@ static clf_decision clf_new(clf_state* s, unsigned int code, unsigned int addr,
slot->hits = 1;
slot->lastWriteMs = nowMs;
slot->cls = (unsigned char)cls;
slot->relogs = 0;
slot->used = 1;
} else {
s->untracked++;
@ -266,6 +297,26 @@ static int clf_ring_take(clf_ring* g, clf_rec* out, unsigned int* older)
return n;
}
typedef enum {
CLF_BYTES_OK = 0, /* write the entry */
CLF_BYTES_MARK, /* over the budget: write the one marker line, then no entry */
CLF_BYTES_DENY, /* over the budget: write nothing */
} clf_bytes;
/*
* The byte budget, asked before each entry. fatal: a last-chance / crash-exit entry,
* which may use CLF_LOG_RESERVE_BYTES beyond CLF_MAX_LOG_BYTES. The caller adds what it
* writes to s->logBytes (the marker included).
*/
static clf_bytes clf_bytes_gate(clf_state* s, int fatal)
{
unsigned int limit = CLF_MAX_LOG_BYTES + (fatal ? CLF_LOG_RESERVE_BYTES : 0u);
if (s->logBytes < limit) return CLF_BYTES_OK;
s->byteDenied++;
if (!fatal && !s->capMarked) { s->capMarked = 1; return CLF_BYTES_MARK; }
return CLF_BYTES_DENY;
}
/* The last-chance (unhandled) filter. Any code: whatever reaches it is fatal. */
static clf_decision clf_last_chance(clf_state* s)
{

View file

@ -27,7 +27,9 @@
#include <windows.h>
/* File version of this native module (bump with every behavioural change). */
#define RC_SEH_TRAMPOLINE_VERSION 7 /* v7: stack sweeps bounded by this thread's stack (TEB), never
#define RC_SEH_TRAMPOLINE_VERSION 8 /* v8: noise repeats only at powers of two, capped relogs per address,
a total byte budget for native-crash.log (CrashLogFilter.h);
v7: stack sweeps bounded by this thread's stack (TEB), never
reading at or past StackBase;
v6: AwfulWaffle's crash logger (per-address dedupe, pid/date,
flush ring, RC_FlushCrashLog, module cache) merged with v3-v5;
@ -546,7 +548,21 @@ static clf_class cl_first_frame_class(unsigned int esp)
static void cl_write(const char* p, DWORD n)
{
DWORD wr;
if (g_logHandle != INVALID_HANDLE_VALUE) WriteFile(g_logHandle, p, n, &wr, NULL);
if (g_logHandle != INVALID_HANDLE_VALUE && WriteFile(g_logHandle, p, n, &wr, NULL))
g_filter.logBytes += wr; /* under g_logOwner, like every writer */
}
/* The byte budget (CrashLogFilter.h). Under the lock, before an entry. Returns 1 when the
* entry may be written. The first refusal of an ordinary entry writes one marker line. */
static int cl_budget(int fatal)
{
clf_bytes b = clf_bytes_gate(&g_filter, fatal);
if (b == CLF_BYTES_MARK) {
const char* m = "\r\n==== NATIVE CRASH LOGGER: log size budget reached, further ordinary entries are dropped "
"(fatal entries still get a reserve; restart the client or trim the file to resume) ====\r\n";
cl_write(m, (DWORD)lstrlenA(m));
}
return b == CLF_BYTES_OK;
}
/* Append " pid=N tid=N date=YYYY-MM-DD time=HH:MM:SS" (local time). */
@ -569,7 +585,7 @@ static char* cl_stamp(char* p)
return p;
}
static void cl_write_entry(PEXCEPTION_POINTERS ep, const char* kind, unsigned int hits)
static void cl_write_entry(PEXCEPTION_POINTERS ep, const char* kind, unsigned int hits, int fatal)
{
char* p = g_buf;
CONTEXT* c = ep->ContextRecord;
@ -577,6 +593,7 @@ static void cl_write_entry(PEXCEPTION_POINTERS ep, const char* kind, unsigned in
unsigned int exAddr = (unsigned int)(UINT_PTR)ep->ExceptionRecord->ExceptionAddress;
unsigned int words;
if (g_logHandle == INVALID_HANDLE_VALUE) return;
if (!cl_budget(fatal)) return;
p = cl_str(p, "\r\n==== NATIVE CRASH LOGGER (");
p = cl_str(p, kind);
@ -604,6 +621,10 @@ static void cl_write_entry(PEXCEPTION_POINTERS ep, const char* kind, unsigned in
p = cl_u(p, g_filter.otherRepeats);
p = cl_str(p, " overCap=");
p = cl_u(p, g_filter.overCap);
p = cl_str(p, " relogCapped=");
p = cl_u(p, g_filter.relogCapped);
p = cl_str(p, " logBytes=");
p = cl_u(p, g_filter.logBytes);
p = cl_str(p, "\r\n eip="); p = cl_sym(p, c->Eip, 1);
p = cl_str(p, " esp="); p = cl_hex(p, c->Esp);
p = cl_str(p, " ebp="); p = cl_hex(p, c->Ebp);
@ -670,6 +691,7 @@ static void cl_flush_locked(const char* reason, unsigned int code, unsigned int
n = k;
}
if (n == 0 || g_logHandle == INVALID_HANDLE_VALUE) return;
if (!cl_budget(maxAgeMs == 0)) return; /* last chance / crash exit are fatal: they get the reserve */
p = g_buf;
p = cl_str(p, "\r\n==== NATIVE CRASH LOGGER (flush: ");
p = cl_str(p, reason);
@ -731,7 +753,7 @@ static LONG CALLBACK CrashVeh(PEXCEPTION_POINTERS ep)
if (slot) {
/* A repeat: decided without touching any module. */
if (clf_repeat(&g_filter, slot, code, now, &hits) == CLF_LOG_REPEAT) {
cl_write_entry(ep, slot->cls != CLF_CLASS_AC ? "first-chance, repeat, noise" : "first-chance, repeat", hits);
cl_write_entry(ep, slot->cls != CLF_CLASS_AC ? "first-chance, repeat, noise" : "first-chance, repeat", hits, 0);
written = 1;
}
} else {
@ -742,11 +764,11 @@ static LONG CALLBACK CrashVeh(PEXCEPTION_POINTERS ep)
leaf == NULL && code == CLF_CODE_ACCESS_VIOLATION ? cl_first_frame_class(ep->ContextRecord->Esp) : CLF_CLASS_AC);
clf_decision d = clf_new(&g_filter, code, exAddr, cls, now);
if (d == CLF_LOG_COUNTED)
cl_write_entry(ep, "first-chance", 1);
cl_write_entry(ep, "first-chance", 1, 0);
else if (d == CLF_LOG_NOISE)
cl_write_entry(ep, cls == CLF_CLASS_NETFX
? "first-chance, .NET Framework noise, not counted"
: "first-chance, managed (CoreCLR) noise, not counted", 1);
: "first-chance, managed (CoreCLR) noise, not counted", 1, 0);
written = d == CLF_LOG_COUNTED || d == CLF_LOG_NOISE;
}
/* Kept for a flush (memory only): the fatal hit is often one not written here. */
@ -766,7 +788,7 @@ static LONG WINAPI CrashLastChance(PEXCEPTION_POINTERS ep)
if (cl_lock()) {
cl_flush_locked("last chance", ep->ExceptionRecord->ExceptionCode, 0);
if (clf_last_chance(&g_filter) == CLF_LOG_LAST_CHANCE)
cl_write_entry(ep, "LAST-CHANCE, unhandled", 1);
cl_write_entry(ep, "LAST-CHANCE, unhandled", 1, 1);
cl_unlock();
}
if (g_prevFilter && g_prevFilter != CrashLastChance) {
@ -830,6 +852,9 @@ RC_InstallCrashLogger(const wchar_t* logPath)
FILE_ATTRIBUTE_NORMAL, NULL);
if (h != INVALID_HANDLE_VALUE) {
HANDLE old = g_logHandle;
DWORD size = GetFileSize(h, NULL); /* the budget counts what is already there */
g_filter.logBytes = size == INVALID_FILE_SIZE ? 0u : (unsigned int)size;
g_filter.capMarked = 0;
g_logHandle = h;
if (old != INVALID_HANDLE_VALUE) { CloseHandle(old); }
}
@ -949,7 +974,7 @@ static int gt_filter(PEXCEPTION_POINTERS ep, GT_FAULT* f)
f->module[k] = 0;
}
if (InterlockedIncrement(&g_gameTickRecords) <= CL_MAX_GAMETICK) {
cl_write_entry(ep, "AV CAUGHT IN GAME TICK (Client::UseTime guard; tick dropped, client kept running)", 1);
cl_write_entry(ep, "AV CAUGHT IN GAME TICK (Client::UseTime guard; tick dropped, client kept running)", 1, 0);
}
cl_unlock();
if (leaf && f->module && f->module[0]) {

View file

@ -222,8 +222,87 @@ static void ring_order_overflow_and_written(void)
check(got == 1 && out[0].addr == 0x9999 && older == 0, "after a flush, only what came since");
}
/* Review fix: Decal's handled null-ref AV at one JIT-code address about once a minute was
* written on EVERY hit (the 30 s relog applied to noise). A day of it: 1,440 hits. */
static void noise_once_a_minute_is_not_written_every_hit(void)
{
static clf_state s;
unsigned int hits, i, written = 0, now = 100000u;
for (i = 0; i < 1440; i++, now += 60000u)
if (is_write(FC(&s, AV, 0x433620C8u, CLF_CLASS_NETFX, now))) written++;
/* first + powers of two 2..1024 = 1 + 10 */
check(written == 11, "1,440 once-a-minute hits of one noise address: 11 entries, not 1,440");
check(s.counted == 0, "and none charged to the limit");
check(s.noiseRepeats == 1440 - 11, "skipped noise repeats are counted");
{
static clf_state m;
written = 0;
for (i = 0; i < 1440; i++) if (is_write(FC(&m, AV, 0x70001000u, CLF_CLASS_MANAGED, 5000u + i * 60000u))) written++;
check(written == 11, "managed noise is the same");
}
}
/* A genuine (AC) address keeps its 30 s relog, but only CLF_MAX_RELOGS times. */
static void ac_relog_is_capped_per_address(void)
{
static clf_state s;
unsigned int hits, i, written = 0, now = 1000u;
check(FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, now) == CLF_LOG_COUNTED, "first sighting written");
for (i = 2; i <= 1500; i++) {
now += 31000u;
if (is_write(FC(&s, AV, 0x00416C86u, CLF_CLASS_AC, now))) written++;
}
{
unsigned int pow2 = 0, v;
for (v = 2; v <= 1500; v <<= 1) pow2++; /* 2..1024 = 10 */
check(written == pow2 + CLF_MAX_RELOGS, "1,500 hits 31 s apart: the power-of-two ones + CLF_MAX_RELOGS time relogs");
}
check(s.relogCapped > 0, "the skipped relogs are counted");
check(clf_find(&s, 0x00416C86u)->relogs == CLF_MAX_RELOGS, "the slot used its relog budget");
}
/* A non-AV code at a known address is written, within the same per-address cap. */
static void non_av_relog_is_capped(void)
{
static clf_state s;
unsigned int hits, i, written = 0;
FC(&s, AV, 0x00500000u, CLF_CLASS_AC, 100);
for (i = 0; i < 200; i++)
if (is_write(FC(&s, CLF_CODE_HEAP_CORRUPTION, 0x00500000u, CLF_CLASS_AC, 200 + i))) written++;
/* hits 2..201: powers of two 2,4,..,128 = 7, plus the capped relogs */
check(written == 7 + CLF_MAX_RELOGS, "non-AV repeats: powers of two + CLF_MAX_RELOGS, not every hit");
}
/* The byte budget: ordinary entries stop after one marker; fatal ones get a reserve. */
static void byte_budget(void)
{
static clf_state s;
int i;
check(clf_bytes_gate(&s, 0) == CLF_BYTES_OK, "an empty log accepts an entry");
s.logBytes = CLF_MAX_LOG_BYTES - 1;
check(clf_bytes_gate(&s, 0) == CLF_BYTES_OK, "one byte under the budget still accepts");
s.logBytes = CLF_MAX_LOG_BYTES;
check(clf_bytes_gate(&s, 0) == CLF_BYTES_MARK, "at the budget: the marker, once");
for (i = 0; i < 5; i++)
check(clf_bytes_gate(&s, 0) == CLF_BYTES_DENY, "then ordinary entries are dropped");
check(s.byteDenied == 6, "and counted");
check(clf_bytes_gate(&s, 1) == CLF_BYTES_OK, "a fatal entry still fits in the reserve");
s.logBytes = CLF_MAX_LOG_BYTES + CLF_LOG_RESERVE_BYTES;
check(clf_bytes_gate(&s, 1) == CLF_BYTES_DENY, "and not past the reserve");
{
static clf_state t; /* a log that starts over the budget (shared file already big) */
t.logBytes = CLF_MAX_LOG_BYTES + 10;
check(clf_bytes_gate(&t, 1) == CLF_BYTES_OK, "a fatal entry fits in the reserve of a log that opened over budget");
check(clf_bytes_gate(&t, 0) == CLF_BYTES_MARK, "its first ordinary entry gets the marker");
}
}
int main(void)
{
noise_once_a_minute_is_not_written_every_hit();
ac_relog_is_capped_per_address();
non_av_relog_is_capped();
byte_budget();
fatal_repeat_recovered_by_flush(5);
fatal_repeat_recovered_by_flush(100);
fatal_repeat_recovered_by_flush(1000);