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

Commit 4b988166 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Allow app zygote to keep APK / shared libs open across fork.

It appears that a recent change in ART causes the application APK to be
held open as a file descriptor as soon as the class loader for that
application is instantiated. This creates issues for the application
zygote, which pre-creates the class loader and forks later. For now,
allow the app APK and shared libs to be open as file descriptors when
forking.

Bug: 111434506
Test: atest CtsApptestCases:ServiceTest
Change-Id: I5f3f4fb41a037362b4f0999ddd20402cbe56f025
parent 6ab2e4a9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ class AppZygoteInit {
            Log.i(TAG, "Beginning application preload for " + appInfo.packageName);
            LoadedApk loadedApk = new LoadedApk(null, appInfo, null, null, false, true, false);
            ClassLoader loader = loadedApk.getClassLoader();

            Zygote.allowAppFilesAcrossFork(appInfo);

            Class<?> cl;
            Method m;
            try {
+1 −12
Original line number Diff line number Diff line
@@ -78,18 +78,7 @@ class WebViewZygoteInit {
            ClassLoader loader = loadedApk.getClassLoader();
            doPreload(loader, WebViewFactory.getWebViewLibrary(appInfo));

            // Add the APK to the Zygote's list of allowed files for children.
            Zygote.nativeAllowFileAcrossFork(appInfo.sourceDir);
            if (appInfo.splitSourceDirs != null) {
                for (String path : appInfo.splitSourceDirs) {
                    Zygote.nativeAllowFileAcrossFork(path);
                }
            }
            if (appInfo.sharedLibraryFiles != null) {
                for (String path : appInfo.sharedLibraryFiles) {
                    Zygote.nativeAllowFileAcrossFork(path);
                }
            }
            Zygote.allowAppFilesAcrossFork(appInfo);

            Log.i(TAG, "Application preload done");
        }
+22 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.system.OsConstants.O_CLOEXEC;

import static com.android.internal.os.ZygoteConnectionConstants.MAX_ZYGOTE_ARGC;

import android.content.pm.ApplicationInfo;
import android.net.Credentials;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
@@ -371,6 +372,27 @@ public final class Zygote {
     */
    protected static native void nativeAllowFileAcrossFork(String path);

    /**
     * Lets children of the zygote inherit open file descriptors that belong to the
     * ApplicationInfo that is passed in.
     *
     * @param appInfo ApplicationInfo of the application
     */
    protected static void allowAppFilesAcrossFork(ApplicationInfo appInfo) {
        Zygote.nativeAllowFileAcrossFork(appInfo.sourceDir);
        if (appInfo.splitSourceDirs != null) {
            for (String path : appInfo.splitSourceDirs) {
                Zygote.nativeAllowFileAcrossFork(path);
            }
        }
        // As well as its shared libs
        if (appInfo.sharedLibraryFiles != null) {
            for (String path : appInfo.sharedLibraryFiles) {
                Zygote.nativeAllowFileAcrossFork(path);
            }
        }
    }

    /**
     * Installs a seccomp filter that limits setresuid()/setresgid() to the passed-in range
     * @param uidGidMin The smallest allowed uid/gid