You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a0331c5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,9 @@ The Makefile targets are very simple:
98
98
99
99
`make library` - Builds a release version of the library without C++ support
100
100
101
-
`make library_less_strict` - Builds a release library with `ABORT_ON_UNOWNED_PTR=0`. Recommended when using IsoAlloc via `LD_PRELOAD`.
101
+
`make library_less_strict` - Builds a release library with `ABORT_ON_UNOWNED_PTR=0`. Recommended when using IsoAlloc via `LD_PRELOAD` or `DYLD_INSERT_LIBRARIES` with programs that hand pointers from other allocators to `free`.
102
+
103
+
`make preload_tests` - Builds the release library and runs programs that do not link it with the library preloaded, see [Using IsoAlloc As The System Allocator](#using-isoalloc-as-the-system-allocator).
102
104
103
105
`make library_debug` - Builds a debug version of the library
104
106
@@ -143,6 +145,22 @@ or
143
145
144
146
If you want to use IsoAlloc with a C++ program you can use the `c_library_objects` Makefile target. This will produce .o object files you can pass to your compiler. These targets are used internally to build the library with `new` and `delete` support.
145
147
148
+
## Using IsoAlloc As The System Allocator
149
+
150
+
The library built by `make library` (or `make cpp_library` for `new` and `delete` as well) takes over `malloc`, `calloc`, `realloc`, `reallocarray`, `free`, `posix_memalign`, `aligned_alloc`, `memalign`, `valloc`, `pvalloc` and `malloc_usable_size` in any program it is loaded into, so it can be used with existing and closed source programs without recompiling them.
151
+
152
+
On Linux use `LD_PRELOAD=/path/to/libisoalloc.so <program>`. The hooks are linker aliases for the `iso_` functions.
153
+
154
+
On macOS use `DYLD_INSERT_LIBRARIES=/path/to/libisoalloc.dylib <program>`. Every image on macOS is linked with a two level namespace, so a dylib that merely defines `malloc` is never called, and `DYLD_FORCE_FLAT_NAMESPACE` no longer changes that. Instead the library carries a `__DATA,__interpose` table that makes dyld rebind every image's references to the libSystem allocator (`malloc`, `calloc`, `realloc`, `reallocf`, `free`, `posix_memalign`, `aligned_alloc`, `valloc`, `malloc_size`, `malloc_good_size`, the typed `malloc_type_*` entry points and the C++ operators) to IsoAlloc. It also registers a `malloc_zone_t` and makes it the default zone, so `malloc_zone_malloc(malloc_default_zone(), ...)`, `malloc_zone_from_ptr`, `malloc_zone_free` and the rest of the zone API recognize IsoAlloc chunks, and libSystem drives IsoAlloc's `fork()` handlers through it. The same interpose table applies when a program is linked against the dylib directly. Some things to know on macOS:
155
+
156
+
* System Integrity Protection strips `DYLD_INSERT_LIBRARIES` from platform binaries such as `/usr/bin/python3`, silently. The program runs with the system allocator. Use a binary you built or installed yourself, for example from Homebrew.
157
+
* Applications with the hardened runtime need the `com.apple.security.cs.allow-dyld-environment-variables` entitlement, and ones with library validation only load dylibs signed by the same team.
158
+
* libSystem allocates before IsoAlloc's constructor runs and frameworks such as CoreFoundation allocate from their own zones, so pointers from the system allocator reach `free`, `realloc` and `malloc_size`. IsoAlloc hands those back to the zone that owns them, and `realloc` migrates them into IsoAlloc. Only a pointer that no allocator owns is treated as an error, which `ABORT_ON_UNOWNED_PTR` controls as usual.
159
+
160
+
On both platforms IsoAlloc is usually initialized by the first allocation rather than by its constructor, and `fork()` is safe while other threads allocate: on Linux through `pthread_atfork`, on macOS through the malloc zone callbacks. The library's destructor leaves all memory mapped unless `ISO_DTOR_CLEANUP` is set, because destructors of other libraries run after it and still use their allocations.
161
+
162
+
`make preload_tests` (or `make test_macos`, the same target) builds the library and a set of programs that do not link it, then runs them with the library inserted. They check every entry point is taken over, that pointers from the system allocator work, that threads and `fork()` are safe, that C++ operators are replaced, and that another library can allocate from its destructor. Run it with `ABORT_ON_UNOWNED_PTR=-DABORT_ON_UNOWNED_PTR=0` to cover the less strict configuration as well. A library built with `THREAD_SUPPORT=-DTHREAD_SUPPORT=0` only runs the single threaded programs.
163
+
146
164
## Debugging
147
165
148
166
If you try to use Isolation Alloc in an existing program then and you are getting crashes here are some tips to help you get started. If you aren't using `LD_PRELOAD` then first make sure you actually replaced all `malloc, calloc, realloc` and `free` calls to their `iso_alloc` equivalents. Don't forget things like `strdup` that return a pointer from `malloc`.
0 commit comments