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

Commit a101befb authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Lose some unnecessary JNI from the zygote."

parents 012de64e 3fe59510
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ public class WrapperInit {
            // wrapper that it directly forked).
            if (fdNum != 0) {
                try {
                    FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum);
                    FileDescriptor fd = new FileDescriptor();
                    fd.setInt$(fdNum);
                    DataOutputStream os = new DataOutputStream(new FileOutputStream(fd));
                    os.writeInt(Process.myPid());
                    os.close();
+3 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.os;

import static android.system.OsConstants.O_CLOEXEC;

import android.net.Credentials;
import android.net.LocalSocket;
import android.os.Process;
@@ -186,10 +188,9 @@ class ZygoteConnection {
            }

            if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) {
                FileDescriptor[] pipeFds = Os.pipe();
                FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC);
                childPipeFd = pipeFds[1];
                serverPipeFd = pipeFds[0];
                ZygoteInit.setCloseOnExec(serverPipeFd, true);
            }

            /**
@@ -224,8 +225,6 @@ class ZygoteConnection {
                    parsedArgs.debugFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
                    parsedArgs.niceName, fdsToClose, parsedArgs.instructionSet,
                    parsedArgs.appDataDir);
        } catch (IOException ex) {
            logAndPrintError(newStderr, "Exception creating pipe", ex);
        } catch (ErrnoException ex) {
            logAndPrintError(newStderr, "Exception creating pipe", ex);
        } catch (IllegalArgumentException ex) {
+3 −22
Original line number Diff line number Diff line
@@ -165,8 +165,9 @@ public class ZygoteInit {
            }

            try {
                sServerSocket = new LocalServerSocket(
                        createFileDescriptor(fileDesc));
                FileDescriptor fd = new FileDescriptor();
                fd.setInt$(fileDesc);
                sServerSocket = new LocalServerSocket(fd);
            } catch (IOException ex) {
                throw new RuntimeException(
                        "Error binding to local socket '" + fileDesc + "'", ex);
@@ -780,16 +781,6 @@ public class ZygoteInit {
    static native void reopenStdio(FileDescriptor in,
            FileDescriptor out, FileDescriptor err) throws IOException;

    /**
     * Toggles the close-on-exec flag for the specified file descriptor.
     *
     * @param fd non-null; file descriptor
     * @param flag desired close-on-exec flag state
     * @throws IOException
     */
    static native void setCloseOnExec(FileDescriptor fd, boolean flag)
            throws IOException;

    /**
     * Invokes select() on the provider array of file descriptors (selecting
     * for readability only). Array elements of null are ignored.
@@ -800,16 +791,6 @@ public class ZygoteInit {
     */
    static native int selectReadable(FileDescriptor[] fds) throws IOException;

    /**
     * Creates a file descriptor from an int fd.
     *
     * @param fd integer OS file descriptor
     * @return non-null; FileDescriptor instance
     * @throws IOException if fd is invalid
     */
    static native FileDescriptor createFileDescriptor(int fd)
            throws IOException;

    /**
     * Class not instantiable.
     */
+0 −44
Original line number Diff line number Diff line
@@ -125,40 +125,6 @@ static void com_android_internal_os_ZygoteInit_reopenStdio(JNIEnv* env,
    } while (err < 0 && errno == EINTR);
}

static void com_android_internal_os_ZygoteInit_setCloseOnExec (JNIEnv *env,
    jobject clazz, jobject descriptor, jboolean flag)
{
    int fd;
    int err;
    int fdFlags;

    fd = jniGetFDFromFileDescriptor(env, descriptor);

    if  (env->ExceptionCheck()) {
        return;
    }

    fdFlags = fcntl(fd, F_GETFD);

    if (fdFlags < 0) {
        jniThrowIOException(env, errno);
        return;
    }

    if (flag) {
        fdFlags |= FD_CLOEXEC;
    } else {
        fdFlags &= ~FD_CLOEXEC;
    }

    err = fcntl(fd, F_SETFD, fdFlags);

    if (err < 0) {
        jniThrowIOException(env, errno);
        return;
    }
}

static jint com_android_internal_os_ZygoteInit_selectReadable (
        JNIEnv *env, jobject clazz, jobjectArray fds)
{
@@ -226,12 +192,6 @@ static jint com_android_internal_os_ZygoteInit_selectReadable (
    return -1;
}

static jobject com_android_internal_os_ZygoteInit_createFileDescriptor (
        JNIEnv *env, jobject clazz, jint fd)
{
    return jniCreateFileDescriptor(env, fd);
}

/*
 * JNI registration.
 */
@@ -249,12 +209,8 @@ static JNINativeMethod gMethods[] = {
        "(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
        "Ljava/io/FileDescriptor;)V",
            (void *) com_android_internal_os_ZygoteInit_reopenStdio},
    { "setCloseOnExec", "(Ljava/io/FileDescriptor;Z)V",
        (void *)  com_android_internal_os_ZygoteInit_setCloseOnExec},
    { "selectReadable", "([Ljava/io/FileDescriptor;)I",
        (void *) com_android_internal_os_ZygoteInit_selectReadable },
    { "createFileDescriptor", "(I)Ljava/io/FileDescriptor;",
        (void *) com_android_internal_os_ZygoteInit_createFileDescriptor }
};
int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
{