14 #define SYSTEM_MODULEINFO_CPP
28 # define strcasecmp _stricmp
29 # define strncasecmp _strnicmp
33 static PsApiFunctions _psApi;
34 #define getpid _getpid
38 # define PATH_MAX 1024
40 #else // UNIX...: first the EGCS stuff, then the OS dependent includes
43 #include "sys/times.h"
44 #include "sys/param.h"
52 static std::vector<std::string> s_linkedModules;
56 static std::string module(
"");
62 if ( _psApi.isValid() ) {
66 #elif defined(__linux) || defined(__APPLE__)
71 module = mod.substr(0, mod.rfind(
'.'));
79 static std::string module(
"");
82 char name[PATH_MAX] = {
"Unknown.module"};
85 if ( _psApi.isValid() ) {
91 # if defined(__linux) || defined(__APPLE__)
96 if (::realpath(path, name))
109 int loc = module.rfind(
'.')+1;
112 else if ( module[loc] ==
'e' || module[loc] ==
'E' )
115 else if ( module[loc] ==
'd' || module[loc] ==
'D' )
117 else if ( module[loc] ==
's' && module[loc+1] ==
'o' )
128 static long pid = ::getpid();
130 static HANDLE hP = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
FALSE,pid);
132 static void* hP = (
void*)pid;
138 ModuleHandle = handle;
142 if ( 0 == ModuleHandle ) {
145 static HINSTANCE handle = 0;
147 if ( 0 == handle && _psApi.isValid() ) {
148 if ( _psApi.EnumProcessModules(
processHandle(), &handle,
sizeof(ModuleHandle), &cbNeeded) ) {
152 #elif defined(__linux) || defined(__APPLE__)
175 static HINSTANCE handle = 0;
177 if ( 0 == handle && _psApi.isValid() ) {
178 if ( _psApi.EnumProcessModules(
processHandle(), &handle,
sizeof(ModuleHandle), &cbNeeded) ) {
184 #elif defined(__linux) || defined(__APPLE__)
186 static Dl_info infoBuf, *info = &infoBuf;
188 void* handle = ::dlopen(0, RTLD_LAZY);
191 void*
func = ::dlsym(handle,
"main");
194 if ( 0 != ::dladdr(func, &infoBuf) ) {
209 static std::string module(
"");
210 if ( module.length() == 0 ) {
211 char name[PATH_MAX] = {
"Unknown.module"};
218 #elif defined(__linux) || defined(__APPLE__)
220 ::sprintf(cmd,
"/proc/%d/exe", ::getpid());
222 if (::readlink(cmd, name,
sizeof(name)) >= 0)
225 if (::realpath(((HMODULE*)
exeHandle())->dsc.filename, name))
233 if ( s_linkedModules.size() == 0 ) {
237 HINSTANCE handle[1024];
238 if ( _psApi.isValid() ) {
239 if ( _psApi.EnumProcessModules(
processHandle(),handle,
sizeof(handle),&cbNeeded) ) {
240 for (
size_t i = 0;
i < cbNeeded/
sizeof(HANDLE);
i++ ) {
241 if ( 0 < _psApi.GetModuleFileNameExA(
processHandle(), handle[
i], name,
sizeof(name)) ) {
242 s_linkedModules.push_back(name);
247 #elif defined(__linux) || defined(__APPLE__)
248 char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64];
249 ::sprintf(ff,
"/proc/%d/maps", ::getpid());
250 FILE*
maps = ::fopen(ff,
"r");
251 while( ::fgets(cmd,
sizeof(cmd), maps) ) {
253 sscanf(cmd,
"%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname);
254 if ( len > 0 && strncmp(buf2,
"r-xp",strlen(
"r-xp")) == 0 ) {
255 s_linkedModules.push_back(fname);
261 return s_linkedModules;
GAUDI_API ModuleType moduleType()
Get type of the module.
GAUDI_API void setModuleHandle(ImageHandle handle)
Attach module handle.
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
GAUDI_API ProcessHandle processHandle()
Handle to running process.
void * ImageHandle
Definition of an image handle.
GAUDI_API const std::string & exeName()
Name of the executable file running.
GAUDI_API ImageHandle moduleHandle()
Handle to currently executed module.
GAUDI_API ImageHandle exeHandle()
Handle to the executable file running.
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
GAUDI_API const std::vector< std::string > linkedModules()
Vector of names of linked modules.
GAUDI_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.