25static std::vector<std::string> s_linkedModules;
29 static std::string module(
"" );
32#if defined( __linux ) || defined( __APPLE__ )
33 std::string mod = ::basename( (
char*)( (Dl_info*)
moduleHandle() )->dli_fname );
35 std::string mod = ::basename( ( (HMODULE*)
moduleHandle() )->dsc.filename );
37 module = mod.substr( 0, mod.rfind( '.' ) );
45 static std::string module(
"" );
48 char name[PATH_MAX] = {
"Unknown.module" };
50#if defined( __linux ) || defined( __APPLE__ )
51 const char* path = ( (Dl_info*)
moduleHandle() )->dli_fname;
53 const char* path = ( (HMODULE*)
moduleHandle() )->dsc.filename;
55 if ( ::realpath( path, name ) )
module = name;
66 size_t loc =
module.rfind( '.' ) + 1;
69 else if ( module[loc] ==
'e' || module[loc] ==
'E' )
71 else if ( module[loc] ==
's' && module[loc + 1] ==
'o' )
81 static long pid = ::getpid();
82 static void* hP = (
void*)pid;
89 if ( !ModuleHandle ) {
91#if defined( __linux ) || defined( __APPLE__ )
103#if defined( __linux ) || defined( __APPLE__ )
105 static Dl_info infoBuf, *info = &infoBuf;
107 void* handle = ::dlopen(
nullptr, RTLD_LAZY );
110 void* func = ::dlsym( handle,
"main" );
113 if ( 0 != ::dladdr( func, &infoBuf ) ) {
129 static std::string module(
"" );
130 if ( module.length() == 0 ) {
131 char name[PATH_MAX] = {
"Unknown.module" };
133#if defined( __linux ) || defined( __APPLE__ )
135 ::sprintf( cmd,
"/proc/%d/exe", ::getpid() );
137 if ( ::readlink( cmd, name,
sizeof( name ) ) >= 0 )
module = name;
139 if ( ::realpath( ( (HMODULE*)
exeHandle() )->dsc.filename, name ) )
module = name;
146 if ( s_linkedModules.size() == 0 ) {
147#if defined( __linux ) || defined( __APPLE__ )
148 char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64];
149 ::sprintf( ff,
"/proc/%d/maps", ::getpid() );
150 FILE* maps = ::fopen( ff,
"r" );
151 while ( ::fgets( cmd,
sizeof( cmd ), maps ) ) {
153 sscanf( cmd,
"%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname );
154 if ( len > 0 && strncmp( buf2,
"r-xp", strlen(
"r-xp" ) ) == 0 ) { s_linkedModules.push_back( fname ); }
159 return s_linkedModules;
GAUDI_API ProcessHandle processHandle()
Handle to running process.
void * ImageHandle
Definition of an image handle.
GAUDI_API ImageHandle exeHandle()
Handle to the executable file running.
GAUDI_API ModuleType moduleType()
Get type of the module.
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
GAUDI_API const std::vector< std::string > linkedModules()
Vector of names of linked modules.
GAUDI_API void setModuleHandle(ImageHandle handle)
Attach module handle.
GAUDI_API const std::string & exeName()
Name of the executable file running.