Skip to content

Commit

Permalink
Add support for shared object name mapping in SoLoader
Browse files Browse the repository at this point in the history
Summary:
The class MergedSoMapping is responsible for mapping library names and
invoking the proper JNI_OnLoad.  The default implementation simply reports
that no libraries are merged, so there is no change in behavior.

Differential Revision: D3845378

fbshipit-source-id: 9f31b3419255568361a8dcbcb31b36e34d3a7177
  • Loading branch information
dreiss authored and Pascal Hartig committed Jan 9, 2018
1 parent 279ec70 commit fd90840
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion java/com/facebook/soloader/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include_defs("//oss_defs/SOLOADER_DEFS")

android_library(
name = 'soloader',
srcs = glob(['*.java']),
srcs = glob(['*.java'], excludes = ['MergedSoMapping.java']),
tests = [
'//javatests/com/facebook/soloader:soloader',
],
Expand All @@ -12,12 +12,18 @@ android_library(
# has to run very early in the app startup process.
# Definitely do *not* depend on guava.
'//deps:jsr-305',
':mapping-stub',
],
visibility = [
'PUBLIC',
],
)

java_library(
name = 'mapping-stub',
srcs = ['MergedSoMapping.java'],
)

project_config(
src_target = ':soloader',
)
14 changes: 14 additions & 0 deletions java/com/facebook/soloader/MergedSoMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.soloader;

class MergedSoMapping {
static String mapLibName(String preMergedLibName) {
return null;
}

static void invokeJniOnload(String preMergedLibName) {
throw new IllegalArgumentException(
"Unknown library: " + preMergedLibName);
}
}
9 changes: 8 additions & 1 deletion java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ public static synchronized void loadLibrary(String shortName, int loadFlags)
}
}

String mergedLibName = MergedSoMapping.mapLibName(shortName);
String nameToLoad = mergedLibName != null ? mergedLibName : shortName;

try {
loadLibraryBySoName(System.mapLibraryName(shortName), loadFlags);
loadLibraryBySoName(System.mapLibraryName(nameToLoad), loadFlags);
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (UnsatisfiedLinkError ex) {
Expand All @@ -302,6 +305,10 @@ public static synchronized void loadLibrary(String shortName, int loadFlags)
}
throw ex;
}

if (mergedLibName != null) {
MergedSoMapping.invokeJniOnload(shortName);
}
}

/**
Expand Down

0 comments on commit fd90840

Please sign in to comment.