Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f2118d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[WebView] Only pass one path to relro creation/loading at a time."

parents 88a41923 ae498f27
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -454,13 +454,13 @@ public final class WebViewFactory {
        // waiting on relro creation.
        if (Build.SUPPORTED_32_BIT_ABIS.length > 0) {
            if (DEBUG) Log.v(LOGTAG, "Create 32 bit relro");
            WebViewLibraryLoader.createRelroFile(false /* is64Bit */, nativeLibraryPaths);
            WebViewLibraryLoader.createRelroFile(false /* is64Bit */, nativeLibraryPaths[0]);
            numRelros++;
        }

        if (Build.SUPPORTED_64_BIT_ABIS.length > 0) {
            if (DEBUG) Log.v(LOGTAG, "Create 64 bit relro");
            WebViewLibraryLoader.createRelroFile(true /* is64Bit */, nativeLibraryPaths);
            WebViewLibraryLoader.createRelroFile(true /* is64Bit */, nativeLibraryPaths[1]);
            numRelros++;
        }
        return numRelros;
+13 −17
Original line number Diff line number Diff line
@@ -62,20 +62,18 @@ class WebViewLibraryLoader {
            boolean result = false;
            boolean is64Bit = VMRuntime.getRuntime().is64Bit();
            try {
                if (args.length != 2 || args[0] == null || args[1] == null) {
                if (args.length != 1 || args[0] == null) {
                    Log.e(LOGTAG, "Invalid RelroFileCreator args: " + Arrays.toString(args));
                    return;
                }
                Log.v(LOGTAG, "RelroFileCreator (64bit = " + is64Bit + "), "
                        + " 32-bit lib: " + args[0] + ", 64-bit lib: " + args[1]);
                Log.v(LOGTAG, "RelroFileCreator (64bit = " + is64Bit + "), lib: " + args[0]);
                if (!sAddressSpaceReserved) {
                    Log.e(LOGTAG, "can't create relro file; address space not reserved");
                    return;
                }
                result = nativeCreateRelroFile(args[0] /* path32 */,
                                               args[1] /* path64 */,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
                                               CHROMIUM_WEBVIEW_NATIVE_RELRO_64);
                result = nativeCreateRelroFile(args[0] /* path */,
                                               is64Bit ? CHROMIUM_WEBVIEW_NATIVE_RELRO_64 :
                                                         CHROMIUM_WEBVIEW_NATIVE_RELRO_32);
                if (result && DEBUG) Log.v(LOGTAG, "created relro file");
            } finally {
                // We must do our best to always notify the update service, even if something fails.
@@ -96,7 +94,7 @@ class WebViewLibraryLoader {
    /**
     * Create a single relro file by invoking an isolated process that to do the actual work.
     */
    static void createRelroFile(final boolean is64Bit, String[] nativeLibraryPaths) {
    static void createRelroFile(final boolean is64Bit, String nativeLibraryPath) {
        final String abi =
                is64Bit ? Build.SUPPORTED_64_BIT_ABIS[0] : Build.SUPPORTED_32_BIT_ABIS[0];

@@ -114,13 +112,12 @@ class WebViewLibraryLoader {
        };

        try {
            if (nativeLibraryPaths == null
                    || nativeLibraryPaths[0] == null || nativeLibraryPaths[1] == null) {
            if (nativeLibraryPath == null) {
                throw new IllegalArgumentException(
                        "Native library paths to the WebView RelRo process must not be null!");
            }
            int pid = LocalServices.getService(ActivityManagerInternal.class).startIsolatedProcess(
                    RelroFileCreator.class.getName(), nativeLibraryPaths,
                    RelroFileCreator.class.getName(), new String[] { nativeLibraryPath },
                    "WebViewLoader-" + abi, abi, Process.SHARED_RELRO_UID, crashHandler);
            if (pid <= 0) throw new Exception("Failed to start the relro file creator process");
        } catch (Throwable t) {
@@ -217,8 +214,9 @@ class WebViewLibraryLoader {

        final String libraryFileName =
                WebViewFactory.getWebViewLibrary(packageInfo.applicationInfo);
        int result = nativeLoadWithRelroFile(libraryFileName, CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
                                             CHROMIUM_WEBVIEW_NATIVE_RELRO_64, clazzLoader);
        String relroPath = VMRuntime.getRuntime().is64Bit() ? CHROMIUM_WEBVIEW_NATIVE_RELRO_64 :
                                                              CHROMIUM_WEBVIEW_NATIVE_RELRO_32;
        int result = nativeLoadWithRelroFile(libraryFileName, relroPath, clazzLoader);
        if (result != WebViewFactory.LIBLOAD_SUCCESS) {
            Log.w(LOGTAG, "failed to load with relro file, proceeding without");
        } else if (DEBUG) {
@@ -313,8 +311,6 @@ class WebViewLibraryLoader {
    }

    static native boolean nativeReserveAddressSpace(long addressSpaceToReserve);
    static native boolean nativeCreateRelroFile(String lib32, String lib64,
                                                        String relro32, String relro64);
    static native int nativeLoadWithRelroFile(String lib, String relro32, String relro64,
                                                      ClassLoader clazzLoader);
    static native boolean nativeCreateRelroFile(String lib, String relro);
    static native int nativeLoadWithRelroFile(String lib, String relro, ClassLoader clazzLoader);
}
+5 −22
Original line number Diff line number Diff line
@@ -143,17 +143,7 @@ jboolean ReserveAddressSpace(JNIEnv*, jclass, jlong size) {
  return DoReserveAddressSpace(size);
}

jboolean CreateRelroFile(JNIEnv* env, jclass, jstring lib32, jstring lib64,
                         jstring relro32, jstring relro64) {
#ifdef __LP64__
  jstring lib = lib64;
  jstring relro = relro64;
  (void)lib32; (void)relro32;
#else
  jstring lib = lib32;
  jstring relro = relro32;
  (void)lib64; (void)relro64;
#endif
jboolean CreateRelroFile(JNIEnv* env, jclass, jstring lib, jstring relro) {
  jboolean ret = JNI_FALSE;
  const char* lib_utf8 = env->GetStringUTFChars(lib, NULL);
  if (lib_utf8 != NULL) {
@@ -167,15 +157,8 @@ jboolean CreateRelroFile(JNIEnv* env, jclass, jstring lib32, jstring lib64,
  return ret;
}

jint LoadWithRelroFile(JNIEnv* env, jclass, jstring lib, jstring relro32,
                       jstring relro64, jobject clazzLoader) {
#ifdef __LP64__
  jstring relro = relro64;
  (void)relro32;
#else
  jstring relro = relro32;
  (void)relro64;
#endif
jint LoadWithRelroFile(JNIEnv* env, jclass, jstring lib, jstring relro,
                       jobject clazzLoader) {
  jint ret = LIBLOAD_FAILED_JNI_CALL;
  const char* lib_utf8 = env->GetStringUTFChars(lib, NULL);
  if (lib_utf8 != NULL) {
@@ -196,10 +179,10 @@ const JNINativeMethod kJniMethods[] = {
  { "nativeReserveAddressSpace", "(J)Z",
      reinterpret_cast<void*>(ReserveAddressSpace) },
  { "nativeCreateRelroFile",
      "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z",
      "(Ljava/lang/String;Ljava/lang/String;)Z",
      reinterpret_cast<void*>(CreateRelroFile) },
  { "nativeLoadWithRelroFile",
      "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)I",
      "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)I",
      reinterpret_cast<void*>(LoadWithRelroFile) },
};