Randomized implementation of standard C and C++ library dynamic memory management functions:
See usage examples in examples directory.
$ git clone https://github.com/hse-malloc/malloc.git
$ cd malloc
$ cmake \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE=Release \
-B build
Cmake builds libraries as static by default. To build shared libraries pass while generation:
-DBUILD_SHARED_LIBS=On
Then after build you can use LD_PRELOAD
to make other program to use malloc:
LD_PRELOAD="/path/to/libmalloc.so:/path/to/libhse_malloc.so" <program>
By default, address randomization is enabled.
You can disable it by passing following argument while generation:
-DHSE_MALLOC_NO_RANDOM=TRUE
$ cmake --build build
$ cmake --install build
Regenerate with following:
- Enable
Debug
build mode:-DCMAKE_BUILD_TYPE=Debug- Pass
libc++ >= 11.0.0
headers and library location:-DCMAKE_CXX_FLAGS="-I<libcxx-install-prefix>/include/c++/v1" \ -DCMAKE_EXE_LINKER_FLAGS="-L<libcxx-install-prefix>/lib -Wl,-rpath,<libcxx-install-prefix>/lib"
$ cd build
$ ctest --output-on-failure
Available targets:
test
: tests (default)example-c
: usage example in C usingmalloc
example-cpp
: usage example in C++ usingstd::malloc
example-cpp-new
: usage example in C++ usingnew
anddelete
operators
$ docker build --target <TARGET> -t malloc_<TARGET> .
$ docker run --rm malloc_<TARGET>