• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <jni.h>
24 #include <vector>
25 #include <android-base/stringprintf.h>
26 
27 #define CREATE_ERROR(...) StringPrintf("%s:%d: ", __FILE__, __LINE__). \
28                               append(StringPrintf(__VA_ARGS__))
29 
30 namespace android {
31 namespace zygote {
32 
33 pid_t ForkCommon(JNIEnv* env,bool is_system_server,
34                  const std::vector<int>& fds_to_close,
35                  const std::vector<int>& fds_to_ignore,
36                  bool is_priority_fork,
37                  bool purge = true);
38 
39 /**
40  * Fork a process. The pipe fds are used for usap communication, or -1 in
41  * other cases. Session_socket_fds are FDs used for zygote communication that must be dealt
42  * with hygienically, but are not otherwise used here. Args_known indicates that the process
43  * will be immediately specialized with arguments that are already known, so no usap
44  * communication is required. Is_priority_fork should be true if this is on the app startup
45  * critical path. Purge specifies that unused pages should be purged before the fork.
46  */
47 int forkApp(JNIEnv* env,
48             int read_pipe_fd,
49             int write_pipe_fd,
50             const std::vector<int>& session_socket_fds,
51             bool args_known,
52             bool is_priority_fork,
53             bool purge);
54 
55 [[noreturn]]
56 void ZygoteFailure(JNIEnv* env,
57                    const char* process_name,
58                    jstring managed_process_name,
59                    const std::string& msg);
60 
61 }  // namespace zygote
62 }  // namespace android
63 
64 #endif // _COM_ANDROID_INTERNAL_OS_ZYGOTE_
65