From 98f68dd9bb0318acfaaf7f2e7ad571a19729a8bb Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 16 Feb 2016 23:55:40 +0100 Subject: Move actual function pointers to function local static variables The previous approach of storing them in static variables of the `actual` namespace and initializing them statically did not work out as it is not guaranteed that they are initialized before any interposed function is called. --- src/actual.h | 46 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) (limited to 'src/actual.h') diff --git a/src/actual.h b/src/actual.h index af64ec3..cb08d42 100644 --- a/src/actual.h +++ b/src/actual.h @@ -12,49 +12,21 @@ #include #include -namespace { - template - using function_ptr = Result(*)(Arguments...); - - template - FunctionPtr get_actual_function(const std::string& symbol_name) { - const void* symbol_address{ dlsym(RTLD_NEXT, symbol_name.c_str()) }; - - FunctionPtr actual_function{}; - std::memcpy(&actual_function, &symbol_address, sizeof(symbol_address)); - - return actual_function; - } -} - namespace actual { - static auto write = get_actual_function< - function_ptr - >("write"); - - static auto writev = get_actual_function< - function_ptr - >("writev"); - static auto rename = get_actual_function< - function_ptr - >("rename"); +template +using ptr = Result(*)(Arguments...); - static auto rmdir = get_actual_function< - function_ptr - >("rmdir"); +template +FunctionPtr get_ptr(const std::string& symbol_name) { + const void* symbol_address{ dlsym(RTLD_NEXT, symbol_name.c_str()) }; - static auto unlink = get_actual_function< - function_ptr - >("unlink"); + FunctionPtr actual_function{}; + std::memcpy(&actual_function, &symbol_address, sizeof(symbol_address)); - static auto unlinkat = get_actual_function< - function_ptr - >("unlinkat"); + return actual_function; +} - static auto mmap = get_actual_function< - function_ptr - >("mmap"); } #endif // CHANGE_SRC_ACTUAL_FUNCTION_H_ -- cgit v1.2.3