From 698158075b965214d37da55ca7e9cd77ef6ee515 Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 24 Apr 2023 11:31:11 -0700 Subject: [PATCH] update readme --- bin/readme.md | 16 +++++++++------- readme.md | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/readme.md b/bin/readme.md index 23b94e81..c7ec0814 100644 --- a/bin/readme.md +++ b/bin/readme.md @@ -1,7 +1,7 @@ # Windows Override -Dynamically overriding mimalloc on Windows is robust and has the -particular advantage to be able to redirect all malloc/free calls that go through +Dynamically overriding on mimalloc on Windows +is robust and has the particular advantage to be able to redirect all malloc/free calls that go through the (dynamic) C runtime allocator, including those from other DLL's or libraries. As it intercepts all allocation calls on a low level, it can be used reliably on large programs that include other 3rd party components. @@ -15,7 +15,7 @@ There are four requirements to make the overriding work robustly: (or use the `/INCLUDE:mi_version` switch on the linker). See the `mimalloc-override-test` project for an example on how to use this. -3. The `mimalloc-redirect.dll` (or `mimalloc-redirect32.dll`) must be put +3. The [`mimalloc-redirect.dll`](bin) (or `mimalloc-redirect32.dll`) must be put in the same folder as the main `mimalloc-override.dll` at runtime (as it is a dependency of that DLL). The redirection DLL ensures that all calls to the C runtime malloc API get redirected to mimalloc functions (which reside in `mimalloc-override.dll`). @@ -25,18 +25,20 @@ There are four requirements to make the overriding work robustly: For best performance on Windows with C++, it is also recommended to also override the `new`/`delete` operations (by including -[`mimalloc-new-delete.h`](https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-new-delete.h) a single(!) source file in your project). +[`mimalloc-new-delete.h`](include/mimalloc-new-delete.h) +a single(!) source file in your project). The environment variable `MIMALLOC_DISABLE_REDIRECT=1` can be used to disable dynamic overriding at run-time. Use `MIMALLOC_VERBOSE=1` to check if mimalloc was successfully redirected. -# Minject +## Minject We cannot always re-link an executable with `mimalloc-override.dll`, and similarly, we cannot always ensure the the DLL comes first in the import table of the final executable. -We can in many cases though patch existing executables without any recompilation +In many cases though we can patch existing executables without any recompilation if they are linked with the dynamic C runtime (`ucrtbase.dll`) -- just put the `mimalloc-override.dll` into the import table (and put `mimalloc-redirect.dll` in the same folder) -Such patching can be done for example with [CFF Explorer](https://ntcore.com/?page_id=388). +Such patching can be done for example with [CFF Explorer](https://ntcore.com/?page_id=388) or +the [`minject`](bin) program. The `minject` program can also do this from the command line, use `minject --help` for options. diff --git a/readme.md b/readme.md index 6f908ab9..f545fb9e 100644 --- a/readme.md +++ b/readme.md @@ -407,7 +407,7 @@ There are four requirements to make the overriding work robustly: call to the mimalloc API in the `main` function, like `mi_version()` (or use the `/INCLUDE:mi_version` switch on the linker). See the `mimalloc-override-test` project for an example on how to use this. -3. The `mimalloc-redirect.dll` (or `mimalloc-redirect32.dll`) must be put +3. The [`mimalloc-redirect.dll`](bin) (or `mimalloc-redirect32.dll`) must be put in the same folder as the main `mimalloc-override.dll` at runtime (as it is a dependency of that DLL). The redirection DLL ensures that all calls to the C runtime malloc API get redirected to mimalloc functions (which reside in `mimalloc-override.dll`).