Elements 6.3.1
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
ThisModule.cpp
Go to the documentation of this file.
1
23
24#include <dlfcn.h> // for dlopen, dlsym
25
26#include "ElementsKernel/FuncPtrCast.h" // for FuncPtrCast
27#include "ElementsKernel/ModuleInfo.h" // for ModuleInfo
28
29namespace Elements::System {
30
32 static ModuleInfo this_module;
33 if (this_module.isEmpty()) {
34 void* handle = ::dlopen(nullptr, RTLD_LAZY);
35 if (nullptr != handle) {
36 void* func = ::dlsym(handle, "main");
37 if (nullptr != func) {
38 this_module = ModuleInfo(FuncPtrCast<void*>(func));
39 }
40 }
41 }
42
43 return this_module;
44}
45
46} // namespace Elements::System
defines a Small helper function that allows the cast from void * to function pointer
OS specific details to access at run-time the module configuration of the process.
header to get the module info statically
constexpr DESTPTR FuncPtrCast(SRC *const src_p) noexcept
Cast from void * to function pointer.
ELEMENTS_API const ModuleInfo & getThisExecutableInfo()