Skip to content

Commit

Permalink
xrCore/ModuleLookup.cpp: Linux implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 27, 2018
1 parent 8855679 commit 65559cd
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions src/xrCore/ModuleLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ void* ModuleHandle::open(pcstr moduleName)
close();

Log("Loading DLL:", moduleName);
#if defined(WINDOWS)
handle = ::LoadLibrary(moduleName);

#ifdef WINDOWS
handle = LoadLibraryA(moduleName);
#elif defined(LINUX)
handle = dlopen(name, RTLD_LAZY);
#endif
if (handle == nullptr)
Msg("! Failed to load DLL: %d", GetLastError());
{
#ifdef WINDOWS
Msg("! Failed to load DLL: 0x%d", GetLastError());
#elif defined(LINUX)
Msg("! Failed to load DLL: 0x%d", dlerror());
#endif
}

return handle;
}
Expand All @@ -35,9 +44,24 @@ void ModuleHandle::close()
{
if (dontUnload)
return;
#if defined(WINDOWS)
FreeLibrary(static_cast<HMODULE>(handle));

bool closed = false;

#ifdef WINDOWS
closed = FreeLibrary(static_cast<HMODULE>(handle)) != 0;
#else
closed = dlclose(handle) == 0;
#endif

if (closed == false)
{
#ifdef WINDOWS
Msg("! Failed to close DLL: 0x%d", GetLastError());
#elif LINUX
Msg("! Failed to close DLL: 0x%d", dlerror());
#endif
}

handle = nullptr;
}

Expand All @@ -53,8 +77,23 @@ void* ModuleHandle::operator()() const

void* ModuleHandle::getProcAddress(pcstr procName) const
{
#if defined(WINDOWS)
return GetProcAddress(static_cast<HMODULE>(handle), procName);
void* proc = nullptr;

#ifdef WINDOWS
proc = ::GetProcAddress(static_cast<HMODULE>(handle), procName);
#elif defined(LINUX)
proc = dlsym(handle, procedure);
#endif

if (proc == nullptr)
{
#ifdef WINDOWS
Msg("! Failed to load procedure [%s] from DLL: 0x%d", procName, GetLastError());
#elif LINUX
Msg("! Failed to load procedure [%s] from DLL: 0x%d", procName, dlerror());
#endif
}

return proc;
}
}
} // namespace XRay

0 comments on commit 65559cd

Please sign in to comment.