Skip to content

Commit

Permalink
[GR-37925] Remove throwException from JVM_LoadLibrary to work around …
Browse files Browse the repository at this point in the history
…Sulong issue

PullRequest: graal/11497
  • Loading branch information
lewurm committed Apr 1, 2022
2 parents 92e120f + dab80a4 commit 7c72b85
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ JNIEXPORT jboolean JNICALL
JVM_IsUseContainerSupport(void);

JNIEXPORT void * JNICALL
JVM_LoadLibrary(const char *name, jboolean throwException);
JVM_LoadLibrary(const char *name /*, jboolean throwException*/);

JNIEXPORT void JNICALL
JVM_UnloadLibrary(void * handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ jlong (*JVM_MaxMemory)(void);

jint (*JVM_ActiveProcessorCount)(void);

void * (*JVM_LoadLibrary)(const char *name, jboolean throwException);
void * (*JVM_LoadLibrary)(const char *name /*, jboolean throwException*/);

void (*JVM_UnloadLibrary)(void * handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ JNIEXPORT jint JNICALL JVM_ActiveProcessorCount(void) {
return (*getEnv())->JVM_ActiveProcessorCount();
}

JNIEXPORT void* JNICALL JVM_LoadLibrary(const char *name, jboolean throwException) {
// GR-37925: In some scenarios it can happen that the caller uses JVM_LoadLibrary(const char*) as signature. This is fine by the C ABI, but Sulong does not like it.
JNIEXPORT void* JNICALL JVM_LoadLibrary(const char *name /*, jboolean throwException*/) {
IMPLEMENTED(JVM_LoadLibrary);
return (*getEnv())->JVM_LoadLibrary(name, throwException);
return (*getEnv())->JVM_LoadLibrary(name /*, throwException*/);
}

JNIEXPORT void JNICALL JVM_UnloadLibrary(void *handle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,12 +2083,13 @@ private static boolean hasDynamicLoaderCache() {

@VmImpl
@TruffleBoundary
public @Pointer TruffleObject JVM_LoadLibrary(@Pointer TruffleObject namePtr, @SuppressWarnings("unused") boolean throwException_) {
public @Pointer TruffleObject JVM_LoadLibrary(@Pointer TruffleObject namePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
getLogger().fine(String.format("JVM_LoadLibrary: '%s'", name));

// don't trust the value coming from native code, it might be garbage if the used base lib
// doesn't have this signature.
// We don't pass `throwException` down due to GR-37925, but even if Sulong would
// be fixed, it might be garbage if the used base lib has a mismatching signature,
// so we recompute its value instead on our side.
boolean throwException = !hasDynamicLoaderCache();

TruffleObject lib = getNativeAccess().loadLibrary(Paths.get(name));
Expand Down

0 comments on commit 7c72b85

Please sign in to comment.