Commit dd713ed
fix(sys): vendor Apple THREAD_LOCAL patch in napi-rs/mimalloc fork
Apple targets in mimalloc v3 default to MI_TLS_MODEL_FIXED_SLOT, which
stores the per-thread heap pointer in TCB[108]/[109] — a hardcoded slot
shared by every image in the process. Two napi addons statically linking
mimalloc into the same Node.js process collide on that slot, crashing
the second one on load. The earlier -DMI_HAS_TLS_SLOT=0 workaround
(routing Apple to MI_TLS_MODEL_DYNAMIC_PTHREADS) leaks a pthread key on
process exit, which causes background threads (e.g. rayon workers from
oxc) to abort when they next allocate.
Switch to THREAD_LOCAL + RECURSE_GUARD by carrying the patch directly
in our mimalloc fork (napi-rs/mimalloc, branch dev3) instead of rewriting
prim.h at build time. Per-image __thread storage gives addons their own
heap pointer; no pthread key means nothing for the destructor to break.
- Repoint mimalloc3 submodule URL → https://github.com/napi-rs/mimalloc
branch dev3 (currently v3.3.2 + the prim.h patch on top).
- Drop the build.rs -DMI_HAS_TLS_SLOT=0 workaround.
Supersedes #67.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent ec2fc80 commit dd713ed
3 files changed
Lines changed: 7 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
107 | 83 | | |
108 | 84 | | |
109 | 85 | | |
| |||
0 commit comments