Skip to content

Commit

Permalink
Rely on system loader for Android 7+
Browse files Browse the repository at this point in the history
Summary: See my previous explanation at D45354649. I believe the hack doees not work and is actually not needed for Android 7+ builds.

Reviewed By: danjin250

Differential Revision: D50320564

fbshipit-source-id: 008b8e6f6f9055cda2a83e5409fe2937502e3094
  • Loading branch information
adicatana authored and facebook-github-bot committed Mar 14, 2024
1 parent f5a31ef commit 5da8e80
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions java/com/facebook/soloader/SoFileLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.facebook.soloader;

import android.os.Build;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -30,12 +31,19 @@
public class SoFileLoaderImpl implements SoFileLoader {

private static final String TAG = "SoFileLoaderImpl";
private final Runtime mRuntime;
@Nullable private final Runtime mRuntime;
@Nullable private final Method mNativeLoadRuntimeMethod;
@Nullable private final String mLocalLdLibraryPath;
@Nullable private final String mLocalLdLibraryPathNoZips;

public SoFileLoaderImpl() {
if (Build.VERSION.SDK_INT >= 24) {
mRuntime = null;
mNativeLoadRuntimeMethod = null;
mLocalLdLibraryPath = null;
mLocalLdLibraryPathNoZips = null;
return;
}
mRuntime = Runtime.getRuntime();
mNativeLoadRuntimeMethod = SysUtil.getNativeLoadRuntimeMethod();
mLocalLdLibraryPath =
Expand All @@ -51,8 +59,8 @@ public void loadBytes(String pathName, ElfByteChannel bytes, int loadFlags) {
@Override
public void load(final String pathToSoFile, final int loadFlags) {
if (mNativeLoadRuntimeMethod == null) {
// nativeLoad() version with LD_LIBRARY_PATH override is not available, fallback to standard
// loader.
// nativeLoad() version with LD_LIBRARY_PATH override is not available,
// or not needed (Android 7+), fallback to standard loader.
System.load(pathToSoFile);
return;
}
Expand All @@ -63,7 +71,6 @@ public void load(final String pathToSoFile, final int loadFlags) {
try {
// nativeLoad should be synchronized so there's only one
// LD_LIBRARY_PATH in use regardless of how many ClassLoaders are in the system
// https://android.googlesource.com/platform/libcore/+/refs/tags/android-8.0.0_r45/ojluni/src/main/java/java/lang/Runtime.java#1103
synchronized (mRuntime) {
errorMessage =
(String)
Expand All @@ -76,8 +83,7 @@ public void load(final String pathToSoFile, final int loadFlags) {
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// Throw an SoLoaderULError to try to recover from the state
errorMessage =
"nativeLoad() error during invocation for " + pathToSoFile + ": " + errorMessage;
errorMessage = "nativeLoad() error during invocation for " + pathToSoFile + ": " + e;
throw new RuntimeException(errorMessage);
} finally {
if (errorMessage != null) {
Expand Down

0 comments on commit 5da8e80

Please sign in to comment.