microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
9.74k stars 791 forks source link

Add dllhook mode #888

Closed Andarwinux closed 1 month ago

Andarwinux commented 1 month ago

Hi. Static override with dynamic UCRT is not feasible on Windows, and dynamic override requires explicit link to mimalloc, or patch exe, which is unacceptable in some use cases, so would it be possible to consider add a "dllhook" mode? Rename mimalloc to a standard library such as WINMM.DLL, and then that WINMM.DLL transparently replaces malloc. Thanks.

ref: https://github.com/ysc3839/FontMod

daanx commented 1 month ago

Interesting approach that you linked. However, since everything starts to allocate very early in the loading process, mimalloc_redirect must be one of the first to load in order to install the hooks before any allocation happens (or a later free will get pointers from the initial allocations from another allocator). I am not sure if WINMM is loaded early enough.. (this is the purpose of the minject program -- to ensure that mimalloc_redirect is loaded early)