Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DsoUtils.h
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 // note: This, I believe, should be part of Reflex::SharedLibrary
7 
8 #ifndef GAUDIKERNEL_DSOUTILS_H
9 #define GAUDIKERNEL_DSOUTILS_H
10 
11 // STL includes
12 #include <string>
13 
14 #include "GaudiKernel/System.h"
15 
16 // Reflex includes
17 #include "Reflex/Reflex.h"
18 
19 namespace DsoUtils {
20 
21 inline std::string libNativeName( const std::string& libName )
22 {
23 #if defined(_WIN32)
24  return libName+".dll";
25 #elif defined(__linux) || defined(__APPLE__)
26  return "lib"+libName+".so";
27 #else
28  // variant of the GIGO design pattern
29  return libName;
30 #endif
31 }
32 
33 #ifdef _GNU_SOURCE
34 #include <dlfcn.h>
35 static std::string dsoName( const ROOT::Reflex::Member& mem )
36 {
37  Dl_info info;
38  if (dladdr (
39 #if __GNUC__ < 4
40  (void*)mem.Stubfunction()
41 #else
42  System::FuncPtrCast<void*>(mem.Stubfunction())
43 #endif
44  , &info) == 0)
45  return "";
46 
47  const char* pos = strrchr (info.dli_fname, '/');
48  if (pos)
49  ++pos;
50  else
51  pos = info.dli_fname;
52  return pos;
53 }
54 #elif defined(_WIN32)
55 #include <windows.h>
56 
57 static std::string dsoName( const ROOT::Reflex::Member& mem )
58 {
59  void* addr = (void*)(mem.Stubfunction());
60  if (addr) {
61  MEMORY_BASIC_INFORMATION mbi;
62  if ( VirtualQuery(addr, &mbi, sizeof(mbi)) ) {
63  HMODULE h_module = (HMODULE)mbi.AllocationBase;
64  char mod[1024];
65  if( GetModuleFileName(h_module, mod, sizeof(mod)) ) {
66  const char* pos = strrchr (mod, '\\');
67  if (pos)
68  ++pos;
69  else
70  pos = mod;
71  return pos;
72  }
73  }
74  }
75  return "";
76 }
77 
78 #else // dummy implementation for unknown platforms
79 static std::string dsoName( const ROOT::Reflex::Member& )
80 {
81  return "";
82 }
83 
84 #endif
85 
86 static bool inDso( const ROOT::Reflex::Member& mem,
87  const std::string& dsoname )
88 {
89 #ifdef _WIN32
90  char sep = '\\';
91 #else
92  char sep = '/';
93 #endif
94 
95  std::string srcname = dsoName(mem);
96  if (srcname.empty()) {
97  // we do not know the name of the library, let's guess it's OK
98  return true;
99  }
100 
101  std::string::size_type pos = dsoname.find_last_of(sep);
102  std::string curname;
103  if (std::string::npos == pos) {
104  curname = dsoname;
105  } else {
106  curname = dsoname.substr(pos+1);
107  }
108 
109  return srcname == curname;
110 }
111 
112 } // end namespace DsoUtils
113 
114 #endif // not GAUDIKERNEL_DSOUTILS_H
115 

Generated at Wed Dec 4 2013 14:33:10 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004