3737#include < sys/types.h>
3838#include < dirent.h>
3939
40- #include < algorithm>
4140#include < array>
4241#include < atomic>
4342#include < functional>
44- #include < iterator>
4543#include < list>
4644#include < optional>
4745#include < sstream>
@@ -1944,9 +1942,6 @@ void zygote::ZygoteFailure(JNIEnv* env,
19441942 __builtin_unreachable ();
19451943}
19461944
1947- static std::set<int >* gPreloadFds = nullptr ;
1948- static bool gPreloadFdsExtracted = false ;
1949-
19501945// Utility routine to fork a process from the zygote.
19511946pid_t zygote::ForkCommon (JNIEnv* env, bool is_system_server,
19521947 const std::vector<int >& fds_to_close,
@@ -1972,12 +1967,9 @@ pid_t zygote::ForkCommon(JNIEnv* env, bool is_system_server,
19721967 __android_log_close ();
19731968 AStatsSocket_close ();
19741969
1975- // If this is the first fork for this zygote, create the open FD table,
1976- // verifying that files are of supported type and allowlisted. Otherwise (not
1977- // the first fork), check that the open files have not changed. Newly open
1978- // files are not expected, and will be disallowed in the future. Currently
1979- // they are allowed if they pass the same checks as in the
1980- // FileDescriptorTable::Create() above.
1970+ // If this is the first fork for this zygote, create the open FD table. If
1971+ // it isn't, we just need to check whether the list of open files has changed
1972+ // (and it shouldn't in the normal case).
19811973 if (gOpenFdTable == nullptr ) {
19821974 gOpenFdTable = FileDescriptorTable::Create (fds_to_ignore, fail_fn);
19831975 } else {
@@ -2074,12 +2066,7 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
20742066 fds_to_ignore.push_back (gSystemServerSocketFd );
20752067 }
20762068
2077- if (gPreloadFds && gPreloadFdsExtracted ) {
2078- fds_to_ignore.insert (fds_to_ignore.end (), gPreloadFds ->begin (), gPreloadFds ->end ());
2079- }
2080-
2081- pid_t pid = zygote::ForkCommon (env, /* is_system_server= */ false , fds_to_close, fds_to_ignore,
2082- true );
2069+ pid_t pid = zygote::ForkCommon (env, false , fds_to_close, fds_to_ignore, true );
20832070
20842071 if (pid == 0 ) {
20852072 SpecializeCommon (env, uid, gid, gids, runtime_flags, rlimits,
@@ -2220,10 +2207,6 @@ int zygote::forkApp(JNIEnv* env,
22202207 }
22212208 fds_to_ignore.push_back (gSystemServerSocketFd );
22222209 }
2223- if (gPreloadFds && gPreloadFdsExtracted ) {
2224- fds_to_ignore.insert (fds_to_ignore.end (), gPreloadFds ->begin (), gPreloadFds ->end ());
2225- }
2226-
22272210 return zygote::ForkCommon (env, /* is_system_server= */ false , fds_to_close,
22282211 fds_to_ignore, is_priority_fork == JNI_TRUE, purge);
22292212}
@@ -2481,35 +2464,6 @@ static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIE
24812464#endif
24822465}
24832466
2484- static void com_android_internal_os_Zygote_nativeMarkOpenedFilesBeforePreload (JNIEnv* env, jclass) {
2485- // Ignore invocations when too early or too late.
2486- if (gPreloadFds ) {
2487- return ;
2488- }
2489-
2490- // App Zygote Preload starts soon. Save FDs remaining open. After the
2491- // preload finishes newly open files will be determined.
2492- auto fail_fn = std::bind (zygote::ZygoteFailure, env, " zygote" , nullptr , _1);
2493- gPreloadFds = GetOpenFds (fail_fn).release ();
2494- }
2495-
2496- static void com_android_internal_os_Zygote_nativeAllowFilesOpenedByPreload (JNIEnv* env, jclass) {
2497- // Ignore invocations when too early or too late.
2498- if (!gPreloadFds || gPreloadFdsExtracted ) {
2499- return ;
2500- }
2501-
2502- // Find the newly open FDs, if any.
2503- auto fail_fn = std::bind (zygote::ZygoteFailure, env, " zygote" , nullptr , _1);
2504- std::unique_ptr<std::set<int >> current_fds = GetOpenFds (fail_fn);
2505- auto difference = std::make_unique<std::set<int >>();
2506- std::set_difference (current_fds->begin (), current_fds->end (), gPreloadFds ->begin (),
2507- gPreloadFds ->end (), std::inserter (*difference, difference->end ()));
2508- delete gPreloadFds ;
2509- gPreloadFds = difference.release ();
2510- gPreloadFdsExtracted = true ;
2511- }
2512-
25132467static const JNINativeMethod gMethods [] = {
25142468 {" nativeForkAndSpecialize" ,
25152469 " (II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/"
@@ -2552,14 +2506,8 @@ static const JNINativeMethod gMethods[] = {
25522506 (void *)com_android_internal_os_Zygote_nativeBoostUsapPriority},
25532507 {" nativeParseSigChld" , " ([BI[I)I" ,
25542508 (void *)com_android_internal_os_Zygote_nativeParseSigChld},
2555-
25562509 {" nativeSupportsTaggedPointers" , " ()Z" ,
25572510 (void *)com_android_internal_os_Zygote_nativeSupportsTaggedPointers},
2558-
2559- {" nativeMarkOpenedFilesBeforePreload" , " ()V" ,
2560- (void *)com_android_internal_os_Zygote_nativeMarkOpenedFilesBeforePreload},
2561- {" nativeAllowFilesOpenedByPreload" , " ()V" ,
2562- (void *)com_android_internal_os_Zygote_nativeAllowFilesOpenedByPreload},
25632511};
25642512
25652513int register_com_android_internal_os_Zygote (JNIEnv* env) {
@@ -2572,4 +2520,4 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) {
25722520
25732521 return RegisterMethodsOrDie (env, " com/android/internal/os/Zygote" , gMethods , NELEM (gMethods ));
25742522}
2575- } // namespace android
2523+ } // namespace android
0 commit comments