Skip to content

Commit

Permalink
windows logging
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Mar 21, 2024
1 parent bb1f45e commit 031c9ea
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,33 @@ void os::dll_unload(void *lib) {
}
}

static size_t format_message_fixup(char* buf, size_t end) {
if (end > 3) {
if (buf[end - 1] == '\n') end--;
if (buf[end - 1] == '\r') end--;
if (buf[end - 1] == '.') end--;
buf[end] = '\0';
}
return end;
}

void* os::dll_lookup(void *lib, const char *name) {
return (void*)::GetProcAddress((HMODULE)lib, name);
void* ret = ::GetProcAddress((HMODULE)lib, name);
DWORD errval;
if ((errval = GetLastError()) != 0) {
char* buf[512];
size_t n = (size_t)FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
errval,
0,
buf,
(DWORD)sizeof(buf),
nullptr);
format_message_fixup(buf, n);
log_debug(os)("Symbol %s not found in dll: %s", name, buf);
}
return ret;
}

// Directory routines copied from src/win32/native/java/io/dirent_md.c
Expand Down Expand Up @@ -2165,14 +2190,7 @@ size_t os::lasterror(char* buf, size_t len) {
buf,
(DWORD)len,
nullptr);
if (n > 3) {
// Drop final '.', CR, LF
if (buf[n - 1] == '\n') n--;
if (buf[n - 1] == '\r') n--;
if (buf[n - 1] == '.') n--;
buf[n] = '\0';
}
return n;
return format_message_fixup(buf, n);
}

if (errno != 0) {
Expand Down

0 comments on commit 031c9ea

Please sign in to comment.