mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-12-04 04:37:20 +08:00
Close the cross-platform sanitizer gaps that were leaving real concurrency and undefined-behavior bugs uncaught, and fix a data race the first widened run surfaced. - tsan: the data-race gate ran three suites (mem, slab_alloc, parallel) over no real threaded production code. It now covers every threaded surface that runs clean and stable under TSan: the parallel-extraction worker pool (parallel, worker_pool, pipeline), the filesystem watcher, the embedded HTTP server (httpd), diagnostics sampling, the MCP server and mutation guard, subprocess supervision, and the runnable daemon-coordination paths (daemon, daemon_application). daemon_runtime (deadlocks under TSan+fork), daemon_ipc and daemon_frontend (test-harness synchronization, not production) are excluded with the reasons recorded in the Makefile. - tsan: fixed a genuine data race the widened gate immediately found — cbm_lsp_max_walk_depth's lazy cache was read and written by parallel LSP-extraction workers without synchronization. A data race is undefined behavior even when every worker computes the same value, so the cache slot is now a relaxed atomic: a plain load on the hot path, and a first-touch double-compute simply stores the same value. - tsan(ci + local): the test-tsan job now runs on Linux amd64, Linux arm64, AND native ARM64 macOS (the threading code is shared, so a race is usually caught on all three, but scheduler differences let each surface one the others miss). The local ladder gained `run.sh tsan` and `tsan-amd64` plus the matching compose services. TSan's shadow memory aborts under modern high-entropy ASLR, so the containers run under `setarch -R` with an unconfined seccomp profile (the personality syscall is otherwise blocked) and the CI Linux legs lower vm.mmap_rnd_bits first; amd64 TSan cannot run under x86_64-on-ARM translation and is a real-hardware/CI gate only (documented in run.sh). - ubsan(win/arm64): native ARM64 Windows had no sanitizer at all — AddressSanitizer ships no aarch64-w64-windows-gnu runtime. UBSan in trap mode (-fsanitize-trap=undefined) needs no runtime library, so it instruments natively and turns undefined behavior into an illegal-instruction trap; -fstack-protector-strong adds stack-smash coverage the heap tools miss. The GitHub windows-11-arm leg switches from unsanitized to this, and vm/win.sh gains trap-ubsan-build / trap-ubsan-test for local iteration (reproduce under the emulated x86_64 UBSan to see which check fired). The whole codebase builds and runs clean under it. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
68 lines
2.7 KiB
C
68 lines
2.7 KiB
C
#ifndef CBM_LSP_SCOPE_H
|
|
#define CBM_LSP_SCOPE_H
|
|
|
|
#include "type_rep.h"
|
|
#include "../arena.h"
|
|
#include <stdatomic.h> /* relaxed cache for cbm_lsp_max_walk_depth */
|
|
#include <stdlib.h> /* getenv, atoi (cbm_lsp_max_walk_depth) */
|
|
|
|
typedef struct {
|
|
const char* name;
|
|
const CBMType* type;
|
|
} CBMVarBinding;
|
|
|
|
#define CBM_SCOPE_CHUNK_BINDINGS 16
|
|
|
|
typedef struct CBMScopeChunk {
|
|
CBMVarBinding bindings[CBM_SCOPE_CHUNK_BINDINGS];
|
|
int used;
|
|
struct CBMScopeChunk* next;
|
|
} CBMScopeChunk;
|
|
|
|
typedef struct CBMScope {
|
|
struct CBMScope* parent;
|
|
CBMScopeChunk* chunks;
|
|
CBMArena* arena; // owning arena, propagated to children at push time
|
|
} CBMScope;
|
|
|
|
// Bail-to-UNKNOWN depth for type-lookup chains: alias resolution, MRO walks,
|
|
// embedded-field/struct-traversal. Exceeding this collapses to cbm_type_unknown
|
|
// rather than recursing — guards against pathological hierarchies.
|
|
#define CBM_LSP_MAX_LOOKUP_DEPTH 16
|
|
|
|
// Recursion cap for the per-language "resolve calls in AST node" walkers. These
|
|
// recurse once per AST nesting level; a deeply-nested or cyclic file can drive
|
|
// them into a native stack overflow (SIGSEGV) that takes down the whole index.
|
|
// Past this cap the wrapper skips the subtree — those calls stay unresolved,
|
|
// which is graceful degradation, not a crash. 512 is far deeper than any
|
|
// hand-written source nests; override for pathological/generated repos via the
|
|
// CBM_LSP_MAX_WALK_DEPTH env var (positive integer).
|
|
#define CBM_LSP_MAX_WALK_DEPTH 512
|
|
|
|
// Resolved walk-depth cap: env override (CBM_LSP_MAX_WALK_DEPTH, if a positive
|
|
// integer) else CBM_LSP_MAX_WALK_DEPTH. Read once and cached — the walkers call
|
|
// this per node, so it must not hit getenv on the hot path. The cache is
|
|
// idempotent under multi-threaded indexing (every worker computes the same
|
|
// value), but a plain data race is undefined behavior even when the values
|
|
// agree, so the slot is a relaxed atomic: on the hot path this is a plain load
|
|
// with no fence, and a first-touch double-compute simply stores the same
|
|
// value. This keeps the parallel extractor TSan-clean.
|
|
static inline int cbm_lsp_max_walk_depth(void) {
|
|
static _Atomic int cached = -1;
|
|
int value = atomic_load_explicit(&cached, memory_order_relaxed);
|
|
if (value < 0) {
|
|
const char* e = getenv("CBM_LSP_MAX_WALK_DEPTH");
|
|
int v = (e && *e) ? atoi(e) : 0;
|
|
value = (v > 0) ? v : CBM_LSP_MAX_WALK_DEPTH;
|
|
atomic_store_explicit(&cached, value, memory_order_relaxed);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
CBMScope* cbm_scope_push(CBMArena* a, CBMScope* current);
|
|
CBMScope* cbm_scope_pop(CBMScope* scope);
|
|
void cbm_scope_bind(CBMScope* scope, const char* name, const CBMType* type);
|
|
const CBMType* cbm_scope_lookup(const CBMScope* scope, const char* name);
|
|
|
|
#endif // CBM_LSP_SCOPE_H
|