mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
In worker executables scr_stack_guard is thread-local, and on Darwin every thread-local access calls the variable's TLV thunk. Every stack-checked function paid that call on entry; in tsc-ts the checks were about 12% of the instructions retired on macOS. The runtime now also keeps the running stack's guard in a pthread key's thread-specific-data slot, written wherever scr_stack_guard changes (thread start, fiber switches). libpthread stores a thread's values in an array at its thread pointer, indexed by key; scr_stack_guard_init probes that layout once and exports the slot's byte offset. Emitted checks in Darwin worker executables load the guard from TPIDRRO_EL0 (masked) plus the offset on arm64, or %gs plus the offset on x86-64: no call. If the probe fails the offset stays zero and the checks call scr_stack_guard_get from a cold block. Other targets are unchanged.