@@ -22,11 +22,20 @@ void* ModuleHandle::open(pcstr moduleName)
2222 close ();
2323
2424 Log (" Loading DLL:" , moduleName);
25- #if defined(WINDOWS)
26- handle = ::LoadLibrary (moduleName);
25+
26+ #ifdef WINDOWS
27+ handle = LoadLibraryA (moduleName);
28+ #elif defined(LINUX)
29+ handle = dlopen (name, RTLD_LAZY);
2730#endif
2831 if (handle == nullptr )
29- Msg (" ! Failed to load DLL: %d" , GetLastError ());
32+ {
33+ #ifdef WINDOWS
34+ Msg (" ! Failed to load DLL: 0x%d" , GetLastError ());
35+ #elif defined(LINUX)
36+ Msg (" ! Failed to load DLL: 0x%d" , dlerror ());
37+ #endif
38+ }
3039
3140 return handle;
3241}
@@ -35,9 +44,24 @@ void ModuleHandle::close()
3544{
3645 if (dontUnload)
3746 return ;
38- #if defined(WINDOWS)
39- FreeLibrary (static_cast <HMODULE>(handle));
47+
48+ bool closed = false ;
49+
50+ #ifdef WINDOWS
51+ closed = FreeLibrary (static_cast <HMODULE>(handle)) != 0 ;
52+ #else
53+ closed = dlclose (handle) == 0 ;
54+ #endif
55+
56+ if (closed == false )
57+ {
58+ #ifdef WINDOWS
59+ Msg (" ! Failed to close DLL: 0x%d" , GetLastError ());
60+ #elif LINUX
61+ Msg (" ! Failed to close DLL: 0x%d" , dlerror ());
4062#endif
63+ }
64+
4165 handle = nullptr ;
4266}
4367
@@ -53,8 +77,23 @@ void* ModuleHandle::operator()() const
5377
5478void * ModuleHandle::getProcAddress (pcstr procName) const
5579{
56- #if defined(WINDOWS)
57- return GetProcAddress (static_cast <HMODULE>(handle), procName);
80+ void * proc = nullptr ;
81+
82+ #ifdef WINDOWS
83+ proc = ::GetProcAddress (static_cast <HMODULE>(handle), procName);
84+ #elif defined(LINUX)
85+ proc = dlsym (handle, procedure);
5886#endif
87+
88+ if (proc == nullptr )
89+ {
90+ #ifdef WINDOWS
91+ Msg (" ! Failed to load procedure [%s] from DLL: 0x%d" , procName, GetLastError ());
92+ #elif LINUX
93+ Msg (" ! Failed to load procedure [%s] from DLL: 0x%d" , procName, dlerror ());
94+ #endif
95+ }
96+
97+ return proc;
5998}
60- }
99+ } // namespace XRay
0 commit comments