项目作者: hse-malloc

项目描述 :
Randomized malloc implementation
高级语言: C++
项目地址: git://github.com/hse-malloc/malloc.git
创建时间: 2020-09-15T11:05:50Z
项目社区:https://github.com/hse-malloc/malloc

开源协议:

下载


malloc

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

See usage examples in examples directory.

Build & Install

Requirements

Clone

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

Generate

  1. $ cmake \
  2. -DCMAKE_CXX_COMPILER=clang++ \
  3. -DCMAKE_BUILD_TYPE=Release \
  4. -B build

Shared library

Cmake builds libraries as static by default. To build shared libraries pass while generation:

  1. -DBUILD_SHARED_LIBS=On

Then after build you can use LD_PRELOAD to make other program to use malloc:

  1. 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:

  1. -DHSE_MALLOC_NO_RANDOM=TRUE

Build

  1. $ cmake --build build

Install

  1. $ cmake --install build

Test

Regenerate with following:

  • Enable Debug build mode:
    1. -DCMAKE_BUILD_TYPE=Debug
  • Pass libc++ >= 11.0.0 headers and library location:
    1. -DCMAKE_CXX_FLAGS="-I<libcxx-install-prefix>/include/c++/v1" \
    2. -DCMAKE_EXE_LINKER_FLAGS="-L<libcxx-install-prefix>/lib -Wl,-rpath,<libcxx-install-prefix>/lib"
  1. $ cd build
  2. $ 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
  1. $ docker build --target <TARGET> -t malloc_<TARGET> .
  2. $ docker run --rm malloc_<TARGET>