Commit f8b6ea0
authored
chore(deps): switch mimalloc3 to upstream microsoft/mimalloc (#82)
### Background
On macOS, mimalloc v3 stores the per-thread heap pointer in a fixed TLS slot (TCB `[108]`/`[109]`) shared by every image, so a second statically-linked copy (e.g. another napi addon) adopts the first's heap and crashes. We worked around this with a vendored `prim.h` patch in the `napi-rs/mimalloc` fork. Upstream now fixes it in [microsoft/mimalloc#1301](microsoft/mimalloc#1301) ([b83dee64](microsoft/mimalloc@b83dee6)) by exposing cmake options, so we can drop the fork.
### Changes
- **`.gitmodules`** — `mimalloc3` url `napi-rs/mimalloc` → `microsoft/mimalloc`.
- **`mimalloc3`** — `5853e09` (fork) → `b83dee64` (official `dev3`); drops the vendored `prim.h` patch.
- **`build.rs`** — on v3 + macOS, enable the official options:
```rust
if env::var_os("CARGO_FEATURE_V3").is_some() && target_os == "macos" {
cmake_config
.define("MI_TLS_MODEL_LOCAL", "ON") // -> MI_TLS_MODEL_THREAD_LOCAL=1
.define("MI_TLS_RECURSE_GUARD", "ON"); // -> MI_TLS_RECURSE_GUARD=1
}
```
- **`mimalloc` (v2)** — routine bump `02a2f5d` → `fef6b0d`.
### Notes
- **Scope: v3 + macOS only.** Options exist only in v3; Linux already defaults to thread-local (no-op), Android/OpenBSD use pthreads, Windows uses its own TlsAlloc path. Add `target_os == "ios"` to cover iOS/tvOS.
- **`MI_TLS_RECURSE_GUARD` is belt-and-suspenders** — upstream `prim.h` already auto-enables it on Apple; we set it explicitly for clarity.
- **No regression of the dead-main-thread fix** (issue #1287 / rolldown#9722): the `MI_THREADID_INVALID` poison in `mi_tld_free` is present in `b83dee64`.
### Verification (macOS)
- v3 build: `CMakeCache` `MI_TLS_MODEL_LOCAL:BOOL=ON` / `MI_TLS_RECURSE_GUARD:BOOL=ON`; compiled with `MI_TLS_MODEL_THREAD_LOCAL=1` + `MI_TLS_RECURSE_GUARD=1`.
- Default (v2) build: options absent (gating works), builds clean.
- `cargo test --features v3`: `mimalloc-safe` 6/6 pass; `libmimalloc-sys-test` runs.1 parent 14128b9 commit f8b6ea0
4 files changed
Lines changed: 15 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
83 | 91 | | |
84 | 92 | | |
85 | 93 | | |
| |||
- CMakeLists.txt+47-3
- bin/bundle.sh+9-5
- ide/vs2022/mimalloc-lib.vcxproj+1-1
- include/mimalloc/internal.h+11-11
- include/mimalloc/prim.h+32-29
- include/mimalloc/types.h+24-10
- src/alloc.c+17-9
- src/arena.c+67-43
- src/free.c+13-7
- src/init.c+10-8
- src/libc.c+9-7
- src/options.c+15-14
- src/page.c+4-3
- src/prim/emscripten/prim.c+2-2
- src/prim/osx/alloc-override-zone.c+9
- src/prim/unix/prim.c+13-12
- src/prim/wasi/prim.c+4-4
- src/prim/windows/prim.c+4-4
- test/main-static-dep.cpp+4
- test/test-api.c+4
0 commit comments