blob: 3323a23a36b0658f928a72a15e224c2d7d9d4b2a [file] [log] [blame]
Elliott Hughes01158d72011-09-19 19:47:10 -07001/*
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
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070017#include <grp.h>
Elliott Hughes01158d72011-09-19 19:47:10 -070018#include <paths.h>
Elliott Hughesada2da92012-01-17 17:58:58 -080019#include <signal.h>
Elliott Hughes01158d72011-09-19 19:47:10 -070020#include <stdlib.h>
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070021#include <sys/types.h>
22#include <sys/wait.h>
Elliott Hughes01158d72011-09-19 19:47:10 -070023#include <unistd.h>
24
Elliott Hughesb6636b82012-04-24 10:41:16 -070025#include "cutils/sched_policy.h"
Elliott Hughes4ffd3132011-10-24 12:06:42 -070026#include "debugger.h"
27#include "jni_internal.h"
Elliott Hughes4ffd3132011-10-24 12:06:42 -070028#include "JNIHelp.h"
29#include "ScopedLocalRef.h"
30#include "ScopedPrimitiveArray.h"
31#include "ScopedUtfChars.h"
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070032#include "thread.h"
33
Elliott Hughesb4807ec2012-01-17 18:33:04 -080034#if defined(HAVE_PRCTL)
35#include <sys/prctl.h>
36#endif
37
Elliott Hughesc151f902012-06-21 20:33:21 -070038#if defined(HAVE_SELINUX)
39#include <selinux/android.h>
40#endif
41
Brian Carlstrom154cef62012-05-02 22:34:03 -070042#if defined(__linux__)
43#include <sys/personality.h>
44#endif
45
Elliott Hughes01158d72011-09-19 19:47:10 -070046namespace art {
47
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070048static pid_t gSystemServerPid = 0;
49
Elliott Hughes0512f022012-03-15 22:10:52 -070050static void Zygote_nativeExecShell(JNIEnv* env, jclass, jstring javaCommand) {
Elliott Hughes01158d72011-09-19 19:47:10 -070051 ScopedUtfChars command(env, javaCommand);
52 if (command.c_str() == NULL) {
53 return;
54 }
Elliott Hughesc1f143d2011-12-01 17:31:10 -080055 const char* argp[] = {_PATH_BSHELL, "-c", command.c_str(), NULL};
Elliott Hughes01158d72011-09-19 19:47:10 -070056 LOG(INFO) << "Exec: " << argp[0] << ' ' << argp[1] << ' ' << argp[2];
57
Elliott Hughesba8eee12012-01-24 20:25:24 -080058 execv(_PATH_BSHELL, const_cast<char**>(argp));
Elliott Hughes01158d72011-09-19 19:47:10 -070059 exit(127);
60}
61
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070062// This signal handler is for zygote mode, since the zygote must reap its children
Elliott Hughes1bac54f2012-03-16 12:48:31 -070063static void SigChldHandler(int /*signal_number*/) {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -070064 pid_t pid;
65 int status;
66
67 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
68 // Log process-death status that we care about. In general it is
69 // not safe to call LOG(...) from a signal handler because of
70 // possible reentrancy. However, we know a priori that the
71 // current implementation of LOG() is safe to call from a SIGCHLD
72 // handler in the zygote process. If the LOG() implementation
73 // changes its locking strategy or its use of syscalls within the
74 // lazy-init critical section, its use here may become unsafe.
75 if (WIFEXITED(status)) {
76 if (WEXITSTATUS(status)) {
77 LOG(INFO) << "Process " << pid << " exited cleanly (" << WEXITSTATUS(status) << ")";
78 } else if (false) {
79 LOG(INFO) << "Process " << pid << " exited cleanly (" << WEXITSTATUS(status) << ")";
80 }
81 } else if (WIFSIGNALED(status)) {
82 if (WTERMSIG(status) != SIGKILL) {
83 LOG(INFO) << "Process " << pid << " terminated by signal (" << WTERMSIG(status) << ")";
84 } else if (false) {
85 LOG(INFO) << "Process " << pid << " terminated by signal (" << WTERMSIG(status) << ")";
86 }
87#ifdef WCOREDUMP
88 if (WCOREDUMP(status)) {
89 LOG(INFO) << "Process " << pid << " dumped core";
90 }
91#endif /* ifdef WCOREDUMP */
92 }
93
94 // If the just-crashed process is the system_server, bring down zygote
95 // so that it is restarted by init and system server will be restarted
96 // from there.
97 if (pid == gSystemServerPid) {
Brian Carlstrom6a4be3a2011-10-20 16:34:03 -070098 LOG(ERROR) << "Exit zygote because system server (" << pid << ") has terminated";
99 kill(getpid(), SIGKILL);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700100 }
101 }
102
103 if (pid < 0) {
104 PLOG(WARNING) << "Zygote SIGCHLD error in waitpid";
105 }
106}
107
Elliott Hughes0512f022012-03-15 22:10:52 -0700108// Configures the SIGCHLD handler for the zygote process. This is configured
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700109// very late, because earlier in the runtime we may fork() and exec()
110// other processes, and we want to waitpid() for those rather than
111// have them be harvested immediately.
112//
113// This ends up being called repeatedly before each fork(), but there's
114// no real harm in that.
Elliott Hughes0512f022012-03-15 22:10:52 -0700115static void SetSigChldHandler() {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700116 struct sigaction sa;
117 memset(&sa, 0, sizeof(sa));
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700118 sa.sa_handler = SigChldHandler;
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700119
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700120 int err = sigaction(SIGCHLD, &sa, NULL);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700121 if (err < 0) {
122 PLOG(WARNING) << "Error setting SIGCHLD handler";
123 }
124}
125
Elliott Hughes0512f022012-03-15 22:10:52 -0700126// Sets the SIGCHLD handler back to default behavior in zygote children.
127static void UnsetSigChldHandler() {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700128 struct sigaction sa;
129 memset(&sa, 0, sizeof(sa));
130 sa.sa_handler = SIG_DFL;
131
Elliott Hughes362f9bc2011-10-17 18:56:41 -0700132 int err = sigaction(SIGCHLD, &sa, NULL);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700133 if (err < 0) {
134 PLOG(WARNING) << "Error unsetting SIGCHLD handler";
135 }
136}
137
138// Calls POSIX setgroups() using the int[] object as an argument.
139// A NULL argument is tolerated.
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700140static void SetGids(JNIEnv* env, jintArray javaGids) {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700141 if (javaGids == NULL) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700142 return;
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700143 }
144
145 COMPILE_ASSERT(sizeof(gid_t) == sizeof(jint), sizeof_gid_and_jint_are_differerent);
146 ScopedIntArrayRO gids(env, javaGids);
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700147 CHECK(gids.get() != NULL);
148 int rc = setgroups(gids.size(), reinterpret_cast<const gid_t*>(&gids[0]));
149 if (rc == -1) {
150 PLOG(FATAL) << "setgroups failed";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700151 }
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700152}
153
154// Sets the resource limits via setrlimit(2) for the values in the
155// two-dimensional array of integers that's passed in. The second dimension
156// contains a tuple of length 3: (resource, rlim_cur, rlim_max). NULL is
157// treated as an empty array.
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700158static void SetRLimits(JNIEnv* env, jobjectArray javaRlimits) {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700159 if (javaRlimits == NULL) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700160 return;
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700161 }
162
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700163 rlimit rlim;
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700164 memset(&rlim, 0, sizeof(rlim));
165
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700166 for (int i = 0; i < env->GetArrayLength(javaRlimits); ++i) {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700167 ScopedLocalRef<jobject> javaRlimitObject(env, env->GetObjectArrayElement(javaRlimits, i));
168 ScopedIntArrayRO javaRlimit(env, reinterpret_cast<jintArray>(javaRlimitObject.get()));
169 if (javaRlimit.size() != 3) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700170 LOG(FATAL) << "rlimits array must have a second dimension of size 3";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700171 }
172
173 rlim.rlim_cur = javaRlimit[1];
174 rlim.rlim_max = javaRlimit[2];
175
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700176 int rc = setrlimit(javaRlimit[0], &rlim);
177 if (rc == -1) {
178 PLOG(FATAL) << "setrlimit(" << javaRlimit[0] << ", "
179 << "{" << rlim.rlim_cur << ", " << rlim.rlim_max << "}) failed";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700180 }
181 }
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700182}
183
Elliott Hughes76e36942012-03-16 13:44:56 -0700184#if defined(HAVE_ANDROID_OS)
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700185
186// The debug malloc library needs to know whether it's the zygote or a child.
187extern "C" int gMallocLeakZygoteChild;
188
189static void EnableDebugger() {
190 // To let a non-privileged gdbserver attach to this
191 // process, we must set our dumpable flag.
192 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
193 PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
194 }
195 // We don't want core dumps, though, so set the core dump size to 0.
196 rlimit rl;
197 rl.rlim_cur = 0;
198 rl.rlim_max = RLIM_INFINITY;
199 if (setrlimit(RLIMIT_CORE, &rl) == -1) {
200 PLOG(ERROR) << "setrlimit(RLIMIT_CORE) failed for pid " << getpid();
201 }
202}
203
204static void EnableKeepCapabilities() {
205 int rc = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
206 if (rc == -1) {
207 PLOG(FATAL) << "prctl(PR_SET_KEEPCAPS) failed";
208 }
209}
210
Elliott Hughes76e36942012-03-16 13:44:56 -0700211static void SetCapabilities(int64_t permitted, int64_t effective) {
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700212 __user_cap_header_struct capheader;
213 __user_cap_data_struct capdata;
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700214
215 memset(&capheader, 0, sizeof(capheader));
216 memset(&capdata, 0, sizeof(capdata));
217
218 capheader.version = _LINUX_CAPABILITY_VERSION;
219 capheader.pid = 0;
220
221 capdata.effective = effective;
222 capdata.permitted = permitted;
223
224 if (capset(&capheader, &capdata) != 0) {
Elliott Hughes3d30d9b2011-12-07 17:35:48 -0800225 PLOG(FATAL) << "capset(" << permitted << ", " << effective << ") failed";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700226 }
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700227}
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700228
229static void SetSchedulerPolicy() {
230 errno = -set_sched_policy(0, SP_DEFAULT);
231 if (errno != 0) {
232 PLOG(FATAL) << "set_sched_policy(0, SP_DEFAULT) failed";
233 }
234}
235
Elliott Hughes76e36942012-03-16 13:44:56 -0700236#else
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700237
238static int gMallocLeakZygoteChild = 0;
239
240static void EnableDebugger() {}
241static void EnableKeepCapabilities() {}
Elliott Hughes76e36942012-03-16 13:44:56 -0700242static void SetCapabilities(int64_t, int64_t) {}
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700243static void SetSchedulerPolicy() {}
244
Elliott Hughes76e36942012-03-16 13:44:56 -0700245#endif
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700246
Elliott Hughes0512f022012-03-15 22:10:52 -0700247static void EnableDebugFeatures(uint32_t debug_flags) {
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700248 // Must match values in dalvik.system.Zygote.
249 enum {
250 DEBUG_ENABLE_DEBUGGER = 1,
251 DEBUG_ENABLE_CHECKJNI = 1 << 1,
252 DEBUG_ENABLE_ASSERT = 1 << 2,
253 DEBUG_ENABLE_SAFEMODE = 1 << 3,
254 DEBUG_ENABLE_JNI_LOGGING = 1 << 4,
255 };
256
257 if ((debug_flags & DEBUG_ENABLE_CHECKJNI) != 0) {
258 Runtime* runtime = Runtime::Current();
259 JavaVMExt* vm = runtime->GetJavaVM();
260 if (!vm->check_jni) {
261 LOG(DEBUG) << "Late-enabling -Xcheck:jni";
Elliott Hughes88c5c352012-03-15 18:49:48 -0700262 vm->SetCheckJniEnabled(true);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700263 // There's only one thread running at this point, so only one JNIEnv to fix up.
Elliott Hughes88c5c352012-03-15 18:49:48 -0700264 Thread::Current()->GetJniEnv()->SetCheckJniEnabled(true);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700265 } else {
266 LOG(DEBUG) << "Not late-enabling -Xcheck:jni (already on)";
267 }
268 debug_flags &= ~DEBUG_ENABLE_CHECKJNI;
269 }
270
271 if ((debug_flags & DEBUG_ENABLE_JNI_LOGGING) != 0) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800272 gLogVerbosity.third_party_jni = true;
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700273 debug_flags &= ~DEBUG_ENABLE_JNI_LOGGING;
274 }
275
276 Dbg::SetJdwpAllowed((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700277 if ((debug_flags & DEBUG_ENABLE_DEBUGGER) != 0) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700278 EnableDebugger();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700279 }
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700280 debug_flags &= ~DEBUG_ENABLE_DEBUGGER;
281
282 // These two are for backwards compatibility with Dalvik.
283 debug_flags &= ~DEBUG_ENABLE_ASSERT;
284 debug_flags &= ~DEBUG_ENABLE_SAFEMODE;
285
286 if (debug_flags != 0) {
287 LOG(ERROR) << StringPrintf("Unknown bits set in debug_flags: %#x", debug_flags);
288 }
289}
290
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700291// Utility routine to fork zygote and specialize the child process.
Elliott Hughes0512f022012-03-15 22:10:52 -0700292static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGids,
293 jint debug_flags, jobjectArray javaRlimits,
Elliott Hughesc151f902012-06-21 20:33:21 -0700294 jlong permittedCapabilities, jlong effectiveCapabilities,
295 jstring java_se_info, jstring java_se_name, bool is_system_server) {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700296 Runtime* runtime = Runtime::Current();
297 CHECK(runtime->IsZygote()) << "runtime instance not started with -Xzygote";
298 if (false) { // TODO: do we need do anything special like !dvmGcPreZygoteFork()?
299 LOG(FATAL) << "pre-fork heap failed";
300 }
301
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700302 SetSigChldHandler();
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700303
304 // Grab thread before fork potentially makes Thread::pthread_key_self_ unusable.
305 Thread* self = Thread::Current();
306
307 // dvmDumpLoaderStats("zygote"); // TODO: ?
308 pid_t pid = fork();
309
310 if (pid == 0) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700311 // The child process.
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700312 gMallocLeakZygoteChild = 1;
313
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700314 // Keep capabilities across UID change, unless we're staying root.
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700315 if (uid != 0) {
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700316 EnableKeepCapabilities();
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700317 }
318
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700319 SetGids(env, javaGids);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700320
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700321 SetRLimits(env, javaRlimits);
322
323 int rc = setgid(gid);
324 if (rc == -1) {
Elliott Hughes3d30d9b2011-12-07 17:35:48 -0800325 PLOG(FATAL) << "setgid(" << gid << ") failed";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700326 }
327
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700328 rc = setuid(uid);
329 if (rc == -1) {
Elliott Hughes3d30d9b2011-12-07 17:35:48 -0800330 PLOG(FATAL) << "setuid(" << uid << ") failed";
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700331 }
332
Brian Carlstrom154cef62012-05-02 22:34:03 -0700333#if defined(__linux__)
Elliott Hughes51e53862012-05-02 17:17:28 -0700334 // Work around ARM kernel ASLR lossage (http://b/5817320).
335 int old_personality = personality(0xffffffff);
336 int new_personality = personality(old_personality | ADDR_NO_RANDOMIZE);
337 if (new_personality == -1) {
338 PLOG(WARNING) << "personality(" << new_personality << ") failed";
339 }
Brian Carlstrom154cef62012-05-02 22:34:03 -0700340#endif
Elliott Hughes51e53862012-05-02 17:17:28 -0700341
Elliott Hughes3d30d9b2011-12-07 17:35:48 -0800342 SetCapabilities(permittedCapabilities, effectiveCapabilities);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700343
Elliott Hughes2abeb9b2012-05-11 23:42:02 -0700344 SetSchedulerPolicy();
Elliott Hughesb6636b82012-04-24 10:41:16 -0700345
Elliott Hughesc151f902012-06-21 20:33:21 -0700346#if defined(HAVE_SELINUX) && defined(HAVE_ANDROID_OS)
347 {
348 ScopedUtfChars se_info(env, java_se_info);
349 CHECK(se_info != NULL);
350 ScopedUtfChars se_name(env, java_se_name);
351 CHECK(se_name != NULL);
352 rc = selinux_android_setcontext(uid, is_system_server, se_info, se_name);
353 if (rc == -1) {
354 PLOG(FATAL) << "selinux_android_setcontext(" << uid << ", "
355 << (is_system_server ? "true" : "false") << ", "
356 << "\"" << se_info << "\", \"" << se_name << "\") failed";
357 }
358 }
359#else
360 UNUSED(is_system_server);
361 UNUSED(java_se_info);
362 UNUSED(java_se_name);
363#endif
364
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700365 // Our system thread ID, etc, has changed so reset Thread state.
366 self->InitAfterFork();
367
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700368 EnableDebugFeatures(debug_flags);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700369
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700370 UnsetSigChldHandler();
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700371 runtime->DidForkFromZygote();
372 } else if (pid > 0) {
373 // the parent process
374 }
375 return pid;
376}
377
Elliott Hughes0512f022012-03-15 22:10:52 -0700378static jint Zygote_nativeForkAndSpecialize(JNIEnv* env, jclass, jint uid, jint gid, jintArray gids,
Elliott Hughesc151f902012-06-21 20:33:21 -0700379 jint debug_flags, jobjectArray rlimits,
380 jstring se_info, jstring se_name) {
381 return ForkAndSpecializeCommon(env, uid, gid, gids, debug_flags, rlimits, 0, 0, se_info, se_name, false);
Brian Carlstroma9f19782011-10-13 00:14:47 -0700382}
383
Elliott Hughes0512f022012-03-15 22:10:52 -0700384static jint Zygote_nativeForkSystemServer(JNIEnv* env, jclass, uid_t uid, gid_t gid, jintArray gids,
385 jint debug_flags, jobjectArray rlimits,
386 jlong permittedCapabilities, jlong effectiveCapabilities) {
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700387 pid_t pid = ForkAndSpecializeCommon(env, uid, gid, gids,
388 debug_flags, rlimits,
Elliott Hughesc151f902012-06-21 20:33:21 -0700389 permittedCapabilities, effectiveCapabilities, NULL, NULL, true);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700390 if (pid > 0) {
391 // The zygote process checks whether the child process has died or not.
392 LOG(INFO) << "System server process " << pid << " has been created";
393 gSystemServerPid = pid;
394 // There is a slight window that the system server process has crashed
395 // but it went unnoticed because we haven't published its pid yet. So
396 // we recheck here just to make sure that all is well.
397 int status;
398 if (waitpid(pid, &status, WNOHANG) == pid) {
399 LOG(FATAL) << "System server process " << pid << " has died. Restarting Zygote!";
400 }
401 }
402 return pid;
403}
404
Elliott Hughes01158d72011-09-19 19:47:10 -0700405static JNINativeMethod gMethods[] = {
406 NATIVE_METHOD(Zygote, nativeExecShell, "(Ljava/lang/String;)V"),
407 //NATIVE_METHOD(Zygote, nativeFork, "()I"),
Elliott Hughesc151f902012-06-21 20:33:21 -0700408 NATIVE_METHOD(Zygote, nativeForkAndSpecialize, "(II[II[[ILjava/lang/String;Ljava/lang/String;)I"),
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700409 NATIVE_METHOD(Zygote, nativeForkSystemServer, "(II[II[[IJJ)I"),
Elliott Hughes01158d72011-09-19 19:47:10 -0700410};
411
Elliott Hughes01158d72011-09-19 19:47:10 -0700412void register_dalvik_system_Zygote(JNIEnv* env) {
Elliott Hughes7756d542012-05-24 21:56:51 -0700413 REGISTER_NATIVE_METHODS("dalvik/system/Zygote");
Elliott Hughes01158d72011-09-19 19:47:10 -0700414}
415
416} // namespace art