Skip to content

Commit

Permalink
Improve logging of loading adapters on Windows
Browse files Browse the repository at this point in the history
This primarily improves the logging when loading an adapter fails on
Windows by printing out the result of `GetLastError()` when
`LoadLibrarExA()` returns null for cross-reference with
https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes.
  • Loading branch information
kbenzie committed Nov 22, 2024
1 parent b5294ee commit da5befe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions source/common/windows/ur_lib_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {
BOOL res = FreeLibrary(handle);
if (!res) {
logger::error(
"Failed to unload the library with the handle at address {}",
"Failed to unload the library with the handle at address 0x{}",
handle);
} else {
logger::info("unloaded adapter 0x{}", handle);
Expand All @@ -27,10 +27,14 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {

std::unique_ptr<HMODULE, LibLoader::lib_dtor>
LibLoader::loadAdapterLibrary(const char *name) {
auto handle = std::unique_ptr<HMODULE, LibLoader::lib_dtor>(
LoadLibraryExA(name, nullptr, 0));
logger::info("loaded adapter 0x{} ({})", handle, name);
return handle;
if (HMODULE handle = LoadLibraryExA(name, nullptr, 0)) {
logger::info("loaded adapter 0x{}: {}", handle, name);
return std::unique_ptr<HMODULE, LibLoader::lib_dtor>{handle};
} else {
logger::debug("loading adapter failed with error {}: {}",
GetLastError(), name);
}
return nullptr;
}

void *LibLoader::getFunctionPtr(HMODULE handle, const char *func_name) {
Expand Down

0 comments on commit da5befe

Please sign in to comment.