OSDN Git Service

Remove @KnownFailure tags for tests that pass.
[android-x86/dalvik.git] / libcore / dalvik / src / main / java / dalvik / system / Zygote.java
1 /*
2  * Copyright (C) 2006 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 package dalvik.system;
18
19 /**
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
22  * state.
23  * 
24  * @since Android 1.0
25  */
26 public class Zygote {
27     /*
28      * Bit values for "debugFlags" argument.  The definitions are duplicated
29      * in the native code.
30      */
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;
37
38     private Zygote() {}
39
40     /**
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()
44      *
45      * @return 0 if this is the child, pid of the child
46      * if this is the parent, or -1 on error
47      */
48     native public static int fork();
49
50     /**
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>.
54      *
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
65      * setrlimit(2) call.
66      *
67      * @return 0 if this is the child, pid of the child
68      * if this is the parent, or -1 on error.
69      */
70     native public static int forkAndSpecialize(int uid, int gid, int[] gids,
71             int debugFlags, int[][] rlimits);
72
73     /**
74      * Forks a new VM instance.
75      * @deprecated use {@link Zygote#forkAndSpecialize(int, int, int[], int, int[][])}
76      */
77     @Deprecated
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);
82     }
83
84     /**
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 
88      * zygote to exit.
89      *
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
100      * setrlimit(2) call.
101      *
102      * @return 0 if this is the child, pid of the child
103      * if this is the parent, or -1 on error.
104      */
105     native public static int forkSystemServer(int uid, int gid, 
106             int[] gids, int debugFlags, int[][] rlimits);
107
108     /**
109      * Special method to start the system server process.
110      * @deprecated use {@link Zygote#forkSystemServer(int, int, int[], int, int[][])}
111      */
112     @Deprecated
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);
117     }
118 }
119