2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package dalvik.system;
20 * Provides access to the Dalvik "zygote" feature, which allows a VM instance to
21 * be partially initialized and then fork()'d from the partially initialized
28 * Bit values for "debugFlags" argument. The definitions are duplicated
31 /** enable debugging over JDWP */
32 public static final int DEBUG_ENABLE_DEBUGGER = 1;
33 /** enable JNI checks */
34 public static final int DEBUG_ENABLE_CHECKJNI = 1 << 1;
35 /** enable Java programming language "assert" statements */
36 public static final int DEBUG_ENABLE_ASSERT = 1 << 2;
41 * Forks a new Zygote instance, but does not leave the zygote mode.
42 * The current VM must have been started with the -Xzygote flag. The
43 * new child is expected to eventually call forkAndSpecialize()
45 * @return 0 if this is the child, pid of the child
46 * if this is the parent, or -1 on error
48 native public static int fork();
51 * Forks a new VM instance. The current VM must have been started
52 * with the -Xzygote flag. <b>NOTE: new instance keeps all
53 * root capabilities. The new process is expected to call capset()</b>.
55 * @param uid the UNIX uid that the new process should setuid() to after
56 * fork()ing and and before spawning any threads.
57 * @param gid the UNIX gid that the new process should setgid() to after
58 * fork()ing and and before spawning any threads.
59 * @param gids null-ok; a list of UNIX gids that the new process should
60 * setgroups() to after fork and before spawning any threads.
61 * @param debugFlags bit flags that enable debugging features.
62 * @param rlimits null-ok an array of rlimit tuples, with the second
63 * dimension having a length of 3 and representing
64 * (resource, rlim_cur, rlim_max). These are set via the posix
67 * @return 0 if this is the child, pid of the child
68 * if this is the parent, or -1 on error.
70 native public static int forkAndSpecialize(int uid, int gid, int[] gids,
71 int debugFlags, int[][] rlimits);
74 * Forks a new VM instance.
75 * @deprecated use {@link Zygote#forkAndSpecialize(int, int, int[], int, int[][])}
78 public static int forkAndSpecialize(int uid, int gid, int[] gids,
79 boolean enableDebugger, int[][] rlimits) {
80 int debugFlags = enableDebugger ? DEBUG_ENABLE_DEBUGGER : 0;
81 return forkAndSpecialize(uid, gid, gids, debugFlags, rlimits);
85 * Special method to start the system server process. In addition to the
86 * common actions performed in forkAndSpecialize, the pid of the child
87 * process is recorded such that the death of the child process will cause
90 * @param uid the UNIX uid that the new process should setuid() to after
91 * fork()ing and and before spawning any threads.
92 * @param gid the UNIX gid that the new process should setgid() to after
93 * fork()ing and and before spawning any threads.
94 * @param gids null-ok; a list of UNIX gids that the new process should
95 * setgroups() to after fork and before spawning any threads.
96 * @param debugFlags bit flags that enable debugging features.
97 * @param rlimits null-ok an array of rlimit tuples, with the second
98 * dimension having a length of 3 and representing
99 * (resource, rlim_cur, rlim_max). These are set via the posix
102 * @return 0 if this is the child, pid of the child
103 * if this is the parent, or -1 on error.
105 native public static int forkSystemServer(int uid, int gid,
106 int[] gids, int debugFlags, int[][] rlimits);
109 * Special method to start the system server process.
110 * @deprecated use {@link Zygote#forkSystemServer(int, int, int[], int, int[][])}
113 public static int forkSystemServer(int uid, int gid, int[] gids,
114 boolean enableDebugger, int[][] rlimits) {
115 int debugFlags = enableDebugger ? DEBUG_ENABLE_DEBUGGER : 0;
116 return forkAndSpecialize(uid, gid, gids, debugFlags, rlimits);