diff options
author | Adrian Kummerlaender | 2016-02-17 21:58:38 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-02-17 21:58:38 +0100 |
commit | 3294bfe789ff354ca372f7c32275316bf4491ca5 (patch) | |
tree | 0ee3f580402b87edb57129d2ca56460657d5d609 /src/bootstrap.cc | |
parent | af756d78ac042a2eed2417c5250d4b675d43bf93 (diff) | |
download | change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar.gz change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar.bz2 change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar.lz change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar.xz change-3294bfe789ff354ca372f7c32275316bf4491ca5.tar.zst change-3294bfe789ff354ca372f7c32275316bf4491ca5.zip |
Separate static allocator from payload function interpositions
Diffstat (limited to 'src/bootstrap.cc')
-rw-r--r-- | src/bootstrap.cc | 43 |
1 files changed, 43 insertions, 0 deletions
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<void, void*> actual_free{}; + + if ( !actual_free ) { + actual_free = actual::get_ptr<decltype(actual_free)>("free"); + } + + if ( !init::from_static_buffer(ptr) ) { + actual_free(ptr); + } +} + +void* malloc(size_t size) { + static actual::ptr<void*, size_t> actual_malloc{}; + + if ( init::dlsymContext::is_active() ) { + return init::static_malloc(size); + } else { + if ( !actual_malloc ) { + actual_malloc = actual::get_ptr<decltype(actual_malloc)>("malloc"); + } + + return actual_malloc(size); + } +} + +void* calloc(size_t block, size_t size) { + static actual::ptr<void*, size_t, size_t> actual_calloc{}; + + if ( init::dlsymContext::is_active() ) { + return init::static_calloc(block, size); + } else { + if ( !actual_calloc ) { + actual_calloc = actual::get_ptr<decltype(actual_calloc)>("calloc"); + } + + return actual_calloc(block, size); + } +} |