Skip to content

Commit dc35644

Browse files
committed
[GR-69799] Abort: Failed to load isolate library.
PullRequest: graal/22196
2 parents 86e86c3 + 08a647a commit dc35644

File tree

1 file changed

+50
-0
lines changed
  • sdk/src/org.graalvm.nativebridge.launcher/src

1 file changed

+50
-0
lines changed

sdk/src/org.graalvm.nativebridge.launcher/src/launcher.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@
5151

5252
#if defined(__linux__)
5353
#include<dlfcn.h>
54+
#include<sys/stat.h>
55+
#include<unistd.h>
5456
#elif defined(__APPLE__)
5557
#include<dlfcn.h>
5658
#include<pthread.h>
59+
#include<sys/stat.h>
60+
#include<unistd.h>
5761
#include<Cocoa/Cocoa.h>
5862
#include<objc/objc-runtime.h>
5963
#include<objc/objc-auto.h>
6064
#elif defined(_WIN32)
65+
#include <io.h>
6166
#include<windows.h>
6267
#include<libloaderapi.h>
6368
#include<process.h>
@@ -105,6 +110,20 @@ static CreateJavaVM loadIsolateLibrary(const std::string library_path) {
105110
const char* err = dlerror();
106111
std::stringstream builder {};
107112
builder << "Failed to load isolate library " << library_path;
113+
struct stat sb;
114+
if (stat(library_path.c_str(), &sb) == -1) {
115+
builder << " (file does not exist)";
116+
} else {
117+
if (!S_ISREG(sb.st_mode)) {
118+
builder << " (not a regular file)";
119+
} else {
120+
bool readable = (access(library_path.c_str(), R_OK) == 0);
121+
bool executable = (access(library_path.c_str(), X_OK) == 0);
122+
builder << " (regular file, "
123+
<< (readable ? "readable" : "not readable") << ", "
124+
<< (executable ? "executable" : "not executable") << ")";
125+
}
126+
}
108127
if (err) {
109128
builder << " due to: " << err;
110129
}
@@ -115,8 +134,39 @@ static CreateJavaVM loadIsolateLibrary(const std::string library_path) {
115134
if (handle) {
116135
return reinterpret_cast<CreateJavaVM>(GetProcAddress(handle, "JNI_CreateJavaVM"));
117136
} else {
137+
DWORD errorMessageID = GetLastError();
138+
std::string err;
139+
if (errorMessageID != 0) {
140+
LPSTR messageBuffer = nullptr;
141+
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
142+
nullptr,
143+
errorMessageID,
144+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
145+
(LPSTR)&messageBuffer,
146+
0,
147+
nullptr);
148+
err = std::string {messageBuffer, size};
149+
LocalFree(messageBuffer);
150+
};
118151
std::stringstream builder {};
119152
builder << "Failed to load isolate library " << library_path;
153+
DWORD attrs = GetFileAttributesA(library_path.c_str());
154+
if (attrs == INVALID_FILE_ATTRIBUTES) {
155+
builder << " (file does not exist)";
156+
} else {
157+
if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
158+
builder << " (is a directory)";
159+
} else {
160+
bool readable = (_access(library_path.c_str(), 4) == 0);
161+
bool executable = (_access(library_path.c_str(), 1) == 0);
162+
builder << " (regular file, "
163+
<< (readable ? "readable" : "not readable") << ", "
164+
<< (executable ? "executable" : "not executable") << ")";
165+
}
166+
}
167+
if (!err.empty()) {
168+
builder << " due to: " << err;
169+
}
120170
ABORT(builder.str().c_str())
121171
}
122172
#else

0 commit comments

Comments
 (0)