51
51
52
52
#if defined(__linux__)
53
53
#include < dlfcn.h>
54
+ #include < sys/stat.h>
55
+ #include < unistd.h>
54
56
#elif defined(__APPLE__)
55
57
#include < dlfcn.h>
56
58
#include < pthread.h>
59
+ #include < sys/stat.h>
60
+ #include < unistd.h>
57
61
#include < Cocoa/Cocoa.h>
58
62
#include < objc/objc-runtime.h>
59
63
#include < objc/objc-auto.h>
60
64
#elif defined(_WIN32)
65
+ #include < io.h>
61
66
#include < windows.h>
62
67
#include < libloaderapi.h>
63
68
#include < process.h>
@@ -105,6 +110,20 @@ static CreateJavaVM loadIsolateLibrary(const std::string library_path) {
105
110
const char * err = dlerror ();
106
111
std::stringstream builder {};
107
112
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
+ }
108
127
if (err) {
109
128
builder << " due to: " << err;
110
129
}
@@ -115,8 +134,39 @@ static CreateJavaVM loadIsolateLibrary(const std::string library_path) {
115
134
if (handle) {
116
135
return reinterpret_cast <CreateJavaVM>(GetProcAddress (handle, " JNI_CreateJavaVM" ));
117
136
} 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
+ };
118
151
std::stringstream builder {};
119
152
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
+ }
120
170
ABORT (builder.str ().c_str ())
121
171
}
122
172
#else
0 commit comments