Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Latest commit

 

History

History
104 lines (77 loc) · 2.84 KB

README.md

File metadata and controls

104 lines (77 loc) · 2.84 KB

malloc

Randomized implementation of standard C and C++ library dynamic memory management functions:

See usage examples in examples directory.

Build & Install

Requirements

Clone

$ git clone https://github.com/hse-malloc/malloc.git
$ cd malloc

Generate

$ cmake \
  -DCMAKE_CXX_COMPILER=clang++ \
  -DCMAKE_BUILD_TYPE=Release \
  -B build

Shared library

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>

Randomization

By default, address randomization is enabled.
You can disable it by passing following argument while generation:

-DHSE_MALLOC_NO_RANDOM=TRUE

Build

$ cmake --build build

Install

$ cmake --install build

Test

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

Docker

Available targets:

  • test: tests (default)
  • example-c: usage example in C using malloc
  • example-cpp: usage example in C++ using std::malloc
  • example-cpp-new: usage example in C++ using new and delete operators
$ docker build --target <TARGET> -t malloc_<TARGET> .

$ docker run --rm malloc_<TARGET>