From 3294bfe789ff354ca372f7c32275316bf4491ca5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 17 Feb 2016 21:58:38 +0100 Subject: Separate static allocator from payload function interpositions --- src/bootstrap.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bootstrap.cc (limited to 'src/bootstrap.cc') diff --git a/src/bootstrap.cc b/src/bootstrap.cc new file mode 100644 index 0000000..309ff20 --- /dev/null +++ b/src/bootstrap.cc @@ -0,0 +1,43 @@ +#include "actual.h" + +#include "init/alloc.h" + +void free(void* ptr) { + static actual::ptr actual_free{}; + + if ( !actual_free ) { + actual_free = actual::get_ptr("free"); + } + + if ( !init::from_static_buffer(ptr) ) { + actual_free(ptr); + } +} + +void* malloc(size_t size) { + static actual::ptr actual_malloc{}; + + if ( init::dlsymContext::is_active() ) { + return init::static_malloc(size); + } else { + if ( !actual_malloc ) { + actual_malloc = actual::get_ptr("malloc"); + } + + return actual_malloc(size); + } +} + +void* calloc(size_t block, size_t size) { + static actual::ptr actual_calloc{}; + + if ( init::dlsymContext::is_active() ) { + return init::static_calloc(block, size); + } else { + if ( !actual_calloc ) { + actual_calloc = actual::get_ptr("calloc"); + } + + return actual_calloc(block, size); + } +} -- cgit v1.2.3