aboutsummaryrefslogtreecommitdiff
path: root/src/actual.h
blob: cb08d420cda0f252611d0a8a09dfc68504945dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#ifndef CHANGE_SRC_ACTUAL_FUNCTION_H_
#define CHANGE_SRC_ACTUAL_FUNCTION_H_

#include <dlfcn.h>
#include <sys/mman.h>
#include <sys/uio.h>

#include <memory>
#include <cstring>

namespace actual {

template <class Result, typename... Arguments>
using ptr = Result(*)(Arguments...);

template <typename FunctionPtr>
FunctionPtr get_ptr(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;
}

}

#endif  // CHANGE_SRC_ACTUAL_FUNCTION_H_