1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _COM_ANDROID_INTERNAL_OS_ZYGOTE_H 18 #define _COM_ANDROID_INTERNAL_OS_ZYGOTE_H 19 20 #define LOG_TAG "Zygote" 21 #define ATRACE_TAG ATRACE_TAG_DALVIK 22 23 /* 24 * All functions that lead to ForkCommon must be marked with the 25 * no_stack_protector attributed. Because ForkCommon changes the stack 26 * protector cookie, all of the guard checks on the frames above ForkCommon 27 * would fail when they are popped. 28 */ 29 #define NO_STACK_PROTECTOR __attribute__((no_stack_protector)) 30 31 #include <jni.h> 32 #include <vector> 33 #include <android-base/stringprintf.h> 34 35 #define CREATE_ERROR(...) StringPrintf("%s:%d: ", __FILE__, __LINE__). \ 36 append(StringPrintf(__VA_ARGS__)) 37 38 namespace android { 39 namespace zygote { 40 41 pid_t ForkCommon(JNIEnv* env,bool is_system_server, 42 const std::vector<int>& fds_to_close, 43 const std::vector<int>& fds_to_ignore, 44 bool is_priority_fork, 45 bool purge = true); 46 47 /** 48 * Fork a process. The pipe fds are used for usap communication, or -1 in 49 * other cases. Session_socket_fds are FDs used for zygote communication that must be dealt 50 * with hygienically, but are not otherwise used here. Args_known indicates that the process 51 * will be immediately specialized with arguments that are already known, so no usap 52 * communication is required. Is_priority_fork should be true if this is on the app startup 53 * critical path. Purge specifies that unused pages should be purged before the fork. 54 */ 55 int forkApp(JNIEnv* env, 56 int read_pipe_fd, 57 int write_pipe_fd, 58 const std::vector<int>& session_socket_fds, 59 bool args_known, 60 bool is_priority_fork, 61 bool purge); 62 63 [[noreturn]] 64 void ZygoteFailure(JNIEnv* env, 65 const char* process_name, 66 jstring managed_process_name, 67 const std::string& msg); 68 69 } // namespace zygote 70 } // namespace android 71 72 #endif // _COM_ANDROID_INTERNAL_OS_ZYGOTE_ 73