Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
url = https://github.com/microsoft/mimalloc.git
[submodule "libmimalloc-sys/c_src/mimalloc3"]
path = libmimalloc-sys/c_src/mimalloc3
url = https://github.com/napi-rs/mimalloc.git
url = https://github.com/microsoft/mimalloc.git
branch = dev3
16 changes: 12 additions & 4 deletions libmimalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ fn main() {
cmake_config.define("MI_LOCAL_DYNAMIC_TLS", "ON");
}

// Note: the previous `-DMI_HAS_TLS_SLOT=0` workaround for Apple has been
// replaced by a vendored source patch in our mimalloc fork (napi-rs/mimalloc
// dev3) that routes Apple to `MI_TLS_MODEL_THREAD_LOCAL + MI_TLS_RECURSE_GUARD`
// directly in `include/mimalloc/prim.h`. See that patch for the full rationale.
// On macOS, mimalloc v3 defaults to 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 per-thread heap and crashes. Force the thread-local model
// so each image gets its own `__thread` storage (a v3-only cmake option from
// microsoft/mimalloc b83dee64, issue #1301).
if env::var_os("CARGO_FEATURE_V3").is_some() && target_os == "macos" {
cmake_config
.define("MI_TLS_MODEL_LOCAL", "ON")
// macOS may allocate on a thread-local's first access; guard against
// re-entering malloc until the process is initialized.
.define("MI_TLS_RECURSE_GUARD", "ON");
}

if (target_os == "linux" || target_os == "android")
&& env::var_os("CARGO_FEATURE_NO_THP").is_some()
Expand Down
2 changes: 1 addition & 1 deletion libmimalloc-sys/c_src/mimalloc
Loading