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

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

Merge changes I7ce670f5,I0bd2de38

* changes:
  Preload with RELRO sharing in the WebView zygote.
  Make WebViewLibraryLoader interface more flexible.
parents c709366f f4f647e2
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -493,11 +493,12 @@ public class ZygoteProcess {
     * Instructs the zygote to pre-load the classes and native libraries at the given paths
     * for the specified abi. Not all zygotes support this function.
     */
    public boolean preloadPackageForAbi(String packagePath, String libsPath, String cacheKey,
                                        String abi) throws ZygoteStartFailedEx, IOException {
    public boolean preloadPackageForAbi(String packagePath, String libsPath, String libFileName,
                                        String cacheKey, String abi) throws ZygoteStartFailedEx,
                                                                            IOException {
        synchronized(mLock) {
            ZygoteState state = openZygoteSocketIfNeeded(abi);
            state.writer.write("4");
            state.writer.write("5");
            state.writer.newLine();

            state.writer.write("--preload-package");
@@ -509,6 +510,9 @@ public class ZygoteProcess {
            state.writer.write(libsPath);
            state.writer.newLine();

            state.writer.write(libFileName);
            state.writer.newLine();

            state.writer.write(cacheKey);
            state.writer.newLine();

+10 −13
Original line number Diff line number Diff line
@@ -205,25 +205,21 @@ public final class WebViewFactory {
        }

        PackageManager packageManager = AppGlobals.getInitialApplication().getPackageManager();
        PackageInfo packageInfo;
        String libraryFileName;
        try {
            packageInfo = packageManager.getPackageInfo(packageName,
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName,
                    PackageManager.GET_META_DATA | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
            libraryFileName = getWebViewLibrary(packageInfo.applicationInfo);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(LOGTAG, "Couldn't find package " + packageName);
            return LIBLOAD_WRONG_PACKAGE_NAME;
        }

        try {
            int loadNativeRet = WebViewLibraryLoader.loadNativeLibrary(clazzLoader, packageInfo);
        int loadNativeRet = WebViewLibraryLoader.loadNativeLibrary(clazzLoader, libraryFileName);
        // If we failed waiting for relro we want to return that fact even if we successfully
        // load the relro file.
        if (loadNativeRet == LIBLOAD_SUCCESS) return response.status;
        return loadNativeRet;
        } catch (MissingWebViewPackageException e) {
            Log.e(LOGTAG, "Couldn't load native library: " + e);
            return LIBLOAD_FAILED_TO_LOAD_LIBRARY;
        }
    }

    static WebViewFactoryProvider getProvider() {
@@ -454,7 +450,8 @@ public final class WebViewFactory {
                ClassLoader clazzLoader = webViewContext.getClassLoader();

                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
                WebViewLibraryLoader.loadNativeLibrary(clazzLoader, sPackageInfo);
                WebViewLibraryLoader.loadNativeLibrary(clazzLoader,
                        getWebViewLibrary(sPackageInfo.applicationInfo));
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);

                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
+2 −5
Original line number Diff line number Diff line
@@ -234,17 +234,14 @@ public class WebViewLibraryLoader {
     * <p class="note"><b>Note:</b> Assumes that we have waited for relro creation.
     *
     * @param clazzLoader class loader used to find the linker namespace to load the library into.
     * @param packageInfo the package from which WebView is loaded.
     * @param libraryFileName the filename of the library to load.
     */
    static int loadNativeLibrary(ClassLoader clazzLoader, PackageInfo packageInfo)
            throws WebViewFactory.MissingWebViewPackageException {
    public static int loadNativeLibrary(ClassLoader clazzLoader, String libraryFileName) {
        if (!sAddressSpaceReserved) {
            Log.e(LOGTAG, "can't load with relro file; address space not reserved");
            return WebViewFactory.LIBLOAD_ADDRESS_SPACE_NOT_RESERVED;
        }

        final String libraryFileName =
                WebViewFactory.getWebViewLibrary(packageInfo.applicationInfo);
        String relroPath = VMRuntime.getRuntime().is64Bit() ? CHROMIUM_WEBVIEW_NATIVE_RELRO_64 :
                                                              CHROMIUM_WEBVIEW_NATIVE_RELRO_32;
        int result = nativeLoadWithRelroFile(libraryFileName, relroPath, clazzLoader);
+3 −1
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ public class WebViewZygote {
            final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) :
                    TextUtils.join(File.pathSeparator, zipPaths);

            String libFileName = WebViewFactory.getWebViewLibrary(sPackage.applicationInfo);

            // In the case where the ApplicationInfo has been modified by the stub WebView,
            // we need to use the original ApplicationInfo to determine what the original classpath
            // would have been to use as a cache key.
@@ -179,7 +181,7 @@ public class WebViewZygote {
            ZygoteProcess.waitForConnectionToZygote(sZygote.getPrimarySocketAddress());

            Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath);
            sZygote.preloadPackageForAbi(zip, librarySearchPath, cacheKey,
            sZygote.preloadPackageForAbi(zip, librarySearchPath, libFileName, cacheKey,
                                         Build.SUPPORTED_ABIS[0]);
        } catch (Exception e) {
            Log.e(LOGTAG, "Error connecting to webview zygote", e);
+7 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebViewFactory;
import android.webkit.WebViewFactoryProvider;
import android.webkit.WebViewLibraryLoader;

import java.io.DataOutputStream;
import java.io.File;
@@ -71,7 +72,8 @@ class WebViewZygoteInit {
        }

        @Override
        protected void handlePreloadPackage(String packagePath, String libsPath, String cacheKey) {
        protected void handlePreloadPackage(String packagePath, String libsPath, String libFileName,
                String cacheKey) {
            Log.i(TAG, "Beginning package preload");
            // Ask ApplicationLoaders to create and cache a classloader for the WebView APK so that
            // our children will reuse the same classloader instead of creating their own.
@@ -80,6 +82,10 @@ class WebViewZygoteInit {
            ClassLoader loader = ApplicationLoaders.getDefault().createAndCacheWebViewClassLoader(
                    packagePath, libsPath, cacheKey);

            // Load the native library using WebViewLibraryLoader to share the RELRO data with other
            // processes.
            WebViewLibraryLoader.loadNativeLibrary(loader, libFileName);

            // Add the APK to the Zygote's list of allowed files for children.
            String[] packageList = TextUtils.split(packagePath, File.pathSeparator);
            for (String packageEntry : packageList) {
Loading