Elements  6.0.1
A C++ base framework for the Euclid Software.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ThisModule.cpp
Go to the documentation of this file.
1 
23 
24 #include <cstddef>
25 #include <dlfcn.h>
26 
27 #include "ElementsKernel/FuncPtrCast.h" // for FuncPtrCast
28 #include "ElementsKernel/ModuleInfo.h" // for ModuleInfo
29 
30 namespace Elements {
31 namespace System {
32 
34  static ModuleInfo this_module;
35  if (this_module.isEmpty()) {
36  void* handle = ::dlopen(nullptr, RTLD_LAZY);
37  if (nullptr != handle) {
38  void* func = ::dlsym(handle, "main");
39  if (nullptr != func) {
40  this_module = ModuleInfo(FuncPtrCast<void*>(func));
41  }
42  }
43  }
44 
45  return this_module;
46 }
47 
48 } // namespace System
49 } // namespace Elements
OS specific details to access at run-time the module configuration of the process.
ELEMENTS_API const ModuleInfo & getThisExecutableInfo()
Definition: ThisModule.cpp:33
defines a Small helper function that allows the cast from void * to function pointer ...
header to get the module info statically