Merge "Lose some unnecessary JNI from the zygote."
This commit is contained in:
@@ -62,7 +62,8 @@ public class WrapperInit {
|
|||||||
// wrapper that it directly forked).
|
// wrapper that it directly forked).
|
||||||
if (fdNum != 0) {
|
if (fdNum != 0) {
|
||||||
try {
|
try {
|
||||||
FileDescriptor fd = ZygoteInit.createFileDescriptor(fdNum);
|
FileDescriptor fd = new FileDescriptor();
|
||||||
|
fd.setInt$(fdNum);
|
||||||
DataOutputStream os = new DataOutputStream(new FileOutputStream(fd));
|
DataOutputStream os = new DataOutputStream(new FileOutputStream(fd));
|
||||||
os.writeInt(Process.myPid());
|
os.writeInt(Process.myPid());
|
||||||
os.close();
|
os.close();
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
|
import static android.system.OsConstants.O_CLOEXEC;
|
||||||
|
|
||||||
import android.net.Credentials;
|
import android.net.Credentials;
|
||||||
import android.net.LocalSocket;
|
import android.net.LocalSocket;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
@@ -186,10 +188,9 @@ class ZygoteConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) {
|
if (parsedArgs.runtimeInit && parsedArgs.invokeWith != null) {
|
||||||
FileDescriptor[] pipeFds = Os.pipe();
|
FileDescriptor[] pipeFds = Os.pipe2(O_CLOEXEC);
|
||||||
childPipeFd = pipeFds[1];
|
childPipeFd = pipeFds[1];
|
||||||
serverPipeFd = pipeFds[0];
|
serverPipeFd = pipeFds[0];
|
||||||
ZygoteInit.setCloseOnExec(serverPipeFd, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,8 +225,6 @@ class ZygoteConnection {
|
|||||||
parsedArgs.debugFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
|
parsedArgs.debugFlags, rlimits, parsedArgs.mountExternal, parsedArgs.seInfo,
|
||||||
parsedArgs.niceName, fdsToClose, parsedArgs.instructionSet,
|
parsedArgs.niceName, fdsToClose, parsedArgs.instructionSet,
|
||||||
parsedArgs.appDataDir);
|
parsedArgs.appDataDir);
|
||||||
} catch (IOException ex) {
|
|
||||||
logAndPrintError(newStderr, "Exception creating pipe", ex);
|
|
||||||
} catch (ErrnoException ex) {
|
} catch (ErrnoException ex) {
|
||||||
logAndPrintError(newStderr, "Exception creating pipe", ex);
|
logAndPrintError(newStderr, "Exception creating pipe", ex);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
|
|||||||
@@ -165,8 +165,9 @@ public class ZygoteInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sServerSocket = new LocalServerSocket(
|
FileDescriptor fd = new FileDescriptor();
|
||||||
createFileDescriptor(fileDesc));
|
fd.setInt$(fileDesc);
|
||||||
|
sServerSocket = new LocalServerSocket(fd);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Error binding to local socket '" + fileDesc + "'", ex);
|
"Error binding to local socket '" + fileDesc + "'", ex);
|
||||||
@@ -780,16 +781,6 @@ public class ZygoteInit {
|
|||||||
static native void reopenStdio(FileDescriptor in,
|
static native void reopenStdio(FileDescriptor in,
|
||||||
FileDescriptor out, FileDescriptor err) throws IOException;
|
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
|
* Invokes select() on the provider array of file descriptors (selecting
|
||||||
* for readability only). Array elements of null are ignored.
|
* for readability only). Array elements of null are ignored.
|
||||||
@@ -800,16 +791,6 @@ public class ZygoteInit {
|
|||||||
*/
|
*/
|
||||||
static native int selectReadable(FileDescriptor[] fds) throws IOException;
|
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.
|
* Class not instantiable.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -125,40 +125,6 @@ static void com_android_internal_os_ZygoteInit_reopenStdio(JNIEnv* env,
|
|||||||
} while (err < 0 && errno == EINTR);
|
} 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 (
|
static jint com_android_internal_os_ZygoteInit_selectReadable (
|
||||||
JNIEnv *env, jobject clazz, jobjectArray fds)
|
JNIEnv *env, jobject clazz, jobjectArray fds)
|
||||||
{
|
{
|
||||||
@@ -226,12 +192,6 @@ static jint com_android_internal_os_ZygoteInit_selectReadable (
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject com_android_internal_os_ZygoteInit_createFileDescriptor (
|
|
||||||
JNIEnv *env, jobject clazz, jint fd)
|
|
||||||
{
|
|
||||||
return jniCreateFileDescriptor(env, fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNI registration.
|
* JNI registration.
|
||||||
*/
|
*/
|
||||||
@@ -249,12 +209,8 @@ static JNINativeMethod gMethods[] = {
|
|||||||
"(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
|
"(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;"
|
||||||
"Ljava/io/FileDescriptor;)V",
|
"Ljava/io/FileDescriptor;)V",
|
||||||
(void *) com_android_internal_os_ZygoteInit_reopenStdio},
|
(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",
|
{ "selectReadable", "([Ljava/io/FileDescriptor;)I",
|
||||||
(void *) com_android_internal_os_ZygoteInit_selectReadable },
|
(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)
|
int register_com_android_internal_os_ZygoteInit(JNIEnv* env)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user