fix(elc): add el_mem_check() memory guard — abort before OS OOM-kill
Add el_mem_check() to el_runtime.c: reads ELC_MAX_MEM_MB (default 512), checks RSS via getrusage (macOS bytes / Linux KB normalised to MB), prints a clear diagnostic to stderr and exits(1) if exceeded. Wire it into two places: - compiler.el: upfront check at --emit-header entry point - codegen.el: per-function check in the streaming loop after each el_arena_pop, so runaway growth is caught at the earliest function boundary rather than after the machine is already dying.
This commit is contained in:
@@ -531,6 +531,12 @@ el_val_t parse_int(el_val_t s, el_val_t default_val);
|
||||
el_val_t exit_program(el_val_t code);
|
||||
el_val_t getpid_now(void);
|
||||
|
||||
/* Self-terminating memory guard. Reads ELC_MAX_MEM_MB (default 512) and
|
||||
* exits with code 1 if resident memory exceeds the limit. Call periodically
|
||||
* during long compilation loops (e.g. after each function is compiled).
|
||||
* Returns 0 when memory is within bounds. */
|
||||
el_val_t el_mem_check(void);
|
||||
|
||||
/* ── CGI identity ─────────────────────────────────────────────────────────────
|
||||
* Called at the start of main() in CGI programs (those with a `cgi {}` block).
|
||||
* Records the program's DHARMA identity before any other code executes. */
|
||||
|
||||
Reference in New Issue
Block a user