Skip to content

chore(deps): switch mimalloc3 to upstream microsoft/mimalloc#82

Draft
shulaoda wants to merge 1 commit into
mainfrom
06-23-chore_deps_switch_mimalloc3_to_upstream_microsoft_mimalloc
Draft

chore(deps): switch mimalloc3 to upstream microsoft/mimalloc#82
shulaoda wants to merge 1 commit into
mainfrom
06-23-chore_deps_switch_mimalloc3_to_upstream_microsoft_mimalloc

Conversation

@shulaoda

Copy link
Copy Markdown
Collaborator

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 (b83dee64) by exposing cmake options, so we can drop the fork.

Changes

  • .gitmodulesmimalloc3 url napi-rs/mimallocmicrosoft/mimalloc.
  • mimalloc35853e09 (fork) → b83dee64 (official dev3); drops the vendored prim.h patch.
  • build.rs — on v3 + macOS, enable the official options:
    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 02a2f5dfef6b0d.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant