]>
Commit | Line | Data |
---|---|---|
1815bff5 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6d658acd A |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
1815bff5 A |
14 | * |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6d658acd A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1815bff5 A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * bootstrap -- fundamental service initiator and port server | |
27 | * Mike DeMoney, NeXT, Inc. | |
28 | * Copyright, 1990. All rights reserved. | |
29 | * | |
30 | * bootstrap.defs -- Mig interface definition | |
31 | */ | |
32 | ||
33 | subsystem bootstrap 400; | |
34 | ||
35 | /* | |
36 | * Interface: Bootstrap server | |
37 | * | |
38 | * The bootstrap server is the first user-mode task initiated by the Mach | |
39 | * kernel at system boot time. The bootstrap server provides two services, | |
40 | * it initiates other system tasks, and manages a table of name-port bindings | |
b51d5b5f | 41 | * for fundamental system services (e.g. lookupd, Window Manager, etc...). |
1815bff5 A |
42 | * |
43 | * Name-port bindings can be established with the bootstrap server by either | |
44 | * of two mechanisms: | |
45 | * | |
b51d5b5f A |
46 | * 1. The binding can be indicated, in advance of the service that backs it |
47 | * being available, via a "service create" request. In this case, bootstrap | |
48 | * will immediately create a port and bind the indicated name with that port. | |
49 | * At a later time, a service may "checkin" for the name-port | |
1815bff5 A |
50 | * binding and will be returned receive rights for the bound port. Lookup's |
51 | * on bindings created by this mechanism will return send rights to the port, | |
52 | * even if no service has "checked-in". In this case, requests sent to the | |
53 | * bound port will be queued until a server has checked-in and can satisfy the | |
54 | * request. | |
55 | * | |
56 | * 2. Bindings can be established dynamically via a "register" request. In | |
57 | * this case, the register request provides bootstrap with a name and send | |
58 | * rights for a port. Bootstrap will provide send rights for the bound port | |
59 | * to any requestor via the lookup request. | |
60 | * | |
61 | * Bootstrap provides its service port to descendant tasks via the Mach | |
62 | * "bootstrap" special task port. All direct descendants of bootstrap receive | |
63 | * a "privileged" bootstrap service port. System services that initiate | |
64 | * untrusted tasks should replace the Mach bootstrap task special port with | |
65 | * a subset bootstrap port to prevent them from infecting the namespace. | |
66 | * | |
67 | * The bootstrap server creates a "backup" port for each service that it | |
68 | * creates. This is used to detect when a checked out service is no longer | |
69 | * being served. The bootstrap server regains all rights to the port and | |
70 | * it is marked available for check-out again. This allows crashed servers to | |
71 | * resume service to previous clients. Lookup's on this named port will | |
72 | * continue to be serviced by bootstrap while holding receive rights for the | |
b51d5b5f A |
73 | * bound port. A client may detect that the service is inactive via the |
74 | * bootstrap status request. If an inactive service re-registers rather | |
75 | * than "checking-in" the original bound port is destroyed. | |
1815bff5 A |
76 | * |
77 | * The status of a named service may be obtained via the "status" request. | |
78 | * A service is "active" if a name-port binding exists and receive rights | |
79 | * to the bound port are held by a task other than bootstrap. | |
80 | * | |
b51d5b5f A |
81 | * The bootstrap server may also (re)start server processes associated with |
82 | * with a set of services. The definition of the server process is done | |
83 | * through the "create server" request. The server will be launched in the | |
84 | * same bootstrap context in which it was registered. | |
1815bff5 A |
85 | */ |
86 | ||
87 | #include <mach/std_types.defs> | |
b51d5b5f | 88 | #include <mach/mach_types.defs> |
1815bff5 A |
89 | import <servers/bootstrap_defs.h>; |
90 | ||
b51d5b5f A |
91 | type cmd_t = c_string[512]; |
92 | type name_t = c_string[128]; | |
93 | type cmd_array_t = ^array [] of cmd_t; | |
94 | type name_array_t = ^array [] of name_t; | |
95 | type bootstrap_status_t = integer_t; | |
96 | type bootstrap_status_array_t = ^array [] of bootstrap_status_t; | |
1815bff5 A |
97 | |
98 | serverprefix x_; | |
99 | ||
b51d5b5f A |
100 | /* |
101 | * kern_return_t | |
102 | * bootstrap_create_server(mach_port_t bootstrap_port, | |
103 | * cmd_t server_command, | |
104 | * integer_t server_uid, | |
105 | * boolean_t on_demand, | |
106 | * mach_port_t *server_port) | |
107 | * | |
108 | * Declares a server that mach_init will re-spawn within the specified | |
109 | * bootstrap context. The server is considered already "active" | |
110 | * (i.e. will not be re-spawned) until the returned server_port is | |
111 | * deallocated. | |
112 | * | |
113 | * In the meantime, services can be declared against the server, | |
114 | * by using the server_port as the privileged bootstrap target of | |
115 | * subsequent bootstrap_create_service() calls. | |
116 | * | |
117 | * When mach_init re-spawns the server, its task bootstrap port | |
118 | * is set to the privileged sever_port. Through this special | |
119 | * bootstrap port, it can access all of parent bootstrap's context | |
120 | * (and all services are created in the parent's namespace). But | |
121 | * all additional service declarations (and declaration removals) | |
122 | * will be associated with this particular server. | |
123 | * | |
124 | * Only a holder of the server_port privilege bootstrap port can | |
125 | * check in or register over those services. | |
126 | * | |
127 | * When all services associated with a server are deleted, and the server | |
128 | * exits, it will automatically be deleted itself. | |
129 | * | |
130 | * If the server is declared "on_demand," then a non-running server | |
131 | * will be re-launched on first use of one of the service ports | |
132 | * registered against it. Otherwise, it will be re-launched | |
133 | * immediately upon exiting (whether any client is actively using | |
134 | * any of the service ports or not). | |
135 | * | |
136 | * Errors: Returns appropriate kernel errors on rpc failure. | |
137 | * Returns BOOTSTRAP_NOT_PRIVILEGED, bootstrap or uid invalid. | |
138 | */ | |
139 | routine bootstrap_create_server( | |
140 | bootstrap_port : mach_port_t; | |
141 | server_cmd : cmd_t; | |
142 | server_uid : integer_t; | |
143 | on_demand : boolean_t; | |
144 | ServerSecToken token : security_token_t; | |
145 | out server_port : mach_port_make_send_t); | |
146 | ||
147 | /* | |
148 | * kern_return_t | |
149 | * bootstrap_unprivileged(mach_port_t bootstrap_port, | |
150 | * mach_port_t *unpriv_port) | |
151 | * | |
152 | * Given a bootstrap port, return its unprivileged equivalent. If | |
153 | * the port is already unprivileged, another reference to the same | |
154 | * port is returned. | |
155 | * | |
156 | * This is most often used by servers, which are launched with their | |
157 | * bootstrap port set to the privileged port for the server, to get | |
158 | * an unprivileged version of the same port for use by its unprivileged | |
159 | * children (or any offspring that it does not want to count as part | |
160 | * of the "server" for mach_init registration and re-launch purposes). | |
161 | */ | |
162 | routine bootstrap_unprivileged( | |
163 | bootstrap_port : mach_port_t; | |
164 | out unpriv_port : mach_port_t); | |
1815bff5 A |
165 | |
166 | /* | |
167 | * kern_return_t | |
168 | * bootstrap_check_in(mach_port_t bootstrap_port, | |
169 | * name_t service_name, | |
b51d5b5f | 170 | * mach_port_t *service_port) |
1815bff5 | 171 | * |
b51d5b5f A |
172 | * Returns the receive right for the service named by service_name. The |
173 | * service must have previously been declared in this bootstrap context via | |
174 | * a call to bootstrap_create_service(). Attempts to check_in a service | |
175 | * which is already active are not allowed. | |
176 | * | |
177 | * If the service was declared as being associated with a server, the | |
178 | * check_in must come from the server's privileged port (server_port). | |
1815bff5 A |
179 | * |
180 | * Errors: Returns appropriate kernel errors on rpc failure. | |
181 | * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. | |
182 | * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to | |
183 | * bootstrap port without privilege. | |
184 | * Returns BOOTSTRAP_SERVICE_ACTIVE, if service has already been | |
185 | * registered or checked-in. | |
186 | */ | |
187 | routine bootstrap_check_in( | |
188 | bootstrap_port : mach_port_t; | |
189 | service_name : name_t; | |
190 | out service_port : mach_port_move_receive_t); | |
191 | ||
192 | /* | |
193 | * kern_return_t | |
194 | * bootstrap_register(mach_port_t bootstrap_port, | |
195 | * name_t service_name, | |
196 | * mach_port_t service_port) | |
197 | * | |
b51d5b5f A |
198 | * Registers a send right for service_port with the service identified by |
199 | * service_name. Attempts to register a service where an active binding | |
200 | * already exists are rejected. | |
201 | * | |
202 | * If the service was previously declared with bootstrap_create_service(), | |
203 | * but is not currently active, this call can be used to undeclare the | |
204 | * service. The bootstrap port used must have sufficient privilege to | |
205 | * do so. (Registering MACH_PORT_NULL is especially useful for shutting | |
206 | * down declared services). | |
1815bff5 A |
207 | * |
208 | * Errors: Returns appropriate kernel errors on rpc failure. | |
209 | * Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to | |
210 | * bootstrap port without privilege. | |
211 | * Returns BOOTSTRAP_NAME_IN_USE, if service has already been | |
212 | * register or checked-in. | |
213 | */ | |
214 | routine bootstrap_register( | |
215 | bootstrap_port : mach_port_t; | |
216 | service_name : name_t; | |
217 | service_port : mach_port_t); | |
218 | ||
219 | /* | |
220 | * kern_return_t | |
221 | * bootstrap_look_up(mach_port_t bootstrap_port, | |
222 | * name_t service_name, | |
223 | * mach_port_t *service_port) | |
224 | * | |
b51d5b5f A |
225 | * Returns a send right for the service port declared/registered under the |
226 | * name service_name. The service is not guaranteed to be active. Use the | |
227 | * bootstrap_status call to determine the status of the service. | |
1815bff5 A |
228 | * |
229 | * Errors: Returns appropriate kernel errors on rpc failure. | |
230 | * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. | |
231 | */ | |
232 | routine bootstrap_look_up( | |
233 | bootstrap_port : mach_port_t; | |
234 | service_name : name_t; | |
235 | out service_port : mach_port_t); | |
236 | ||
237 | /* | |
238 | * kern_return_t | |
239 | * bootstrap_look_up_array(mach_port_t bootstrap_port, | |
240 | * name_array_t service_names, | |
241 | * int service_names_cnt, | |
242 | * port_array_t *service_port, | |
243 | * int *service_ports_cnt, | |
244 | * boolean_t *all_services_known) | |
245 | * | |
246 | * Returns port send rights in corresponding entries of the array service_ports | |
247 | * for all services named in the array service_names. Service_ports_cnt is | |
248 | * returned and will always equal service_names_cnt (assuming service_names_cnt | |
249 | * is greater than or equal to zero). | |
250 | * | |
251 | * Errors: Returns appropriate kernel errors on rpc failure. | |
252 | * Returns BOOTSTRAP_NO_MEMORY, if server couldn't obtain memory | |
253 | * for response. | |
254 | * Unknown service names have the corresponding service port set | |
255 | * to PORT_NULL. | |
256 | * If all services are known, all_services_known is true on | |
257 | * return, if any service is unknown, it's false. | |
258 | */ | |
259 | routine bootstrap_look_up_array( | |
260 | bootstrap_port : mach_port_t; | |
261 | service_names : name_array_t; | |
262 | out service_ports : mach_port_array_t; | |
263 | out all_services_known: boolean_t); | |
264 | ||
b51d5b5f A |
265 | /* |
266 | * kern_return_t | |
267 | * bootstrap_parent(mach_port_t bootstrap_port, | |
268 | * mach_port_t *parent_port); | |
269 | * | |
270 | * Given a bootstrap subset port, return the parent bootstrap port. | |
271 | * If the specified bootstrap port is already the root subset, | |
272 | * MACH_PORT_NULL will be returned. | |
273 | * | |
274 | * Errors: | |
275 | * Returns BOOTSTRAP_NOT_PRIVILEGED if the caller is not running | |
276 | * with an effective user id of root (as determined by the security | |
277 | * token in the message trailer). | |
278 | */ | |
279 | routine bootstrap_parent( | |
280 | bootstrap_port : mach_port_t; | |
281 | ServerSecToken token : security_token_t; | |
282 | out parent_port : mach_port_t); | |
1815bff5 A |
283 | |
284 | /* | |
285 | * kern_return_t | |
286 | * bootstrap_status(mach_port_t bootstrap_port, | |
287 | * name_t service_name, | |
b51d5b5f | 288 | * bootstrap_status_t *service_active); |
1815bff5 | 289 | * |
b51d5b5f A |
290 | * Returns: service_active indicates if service is active, inactive, or |
291 | * associated with a launch-on-demand server. | |
1815bff5 A |
292 | * |
293 | * Errors: Returns appropriate kernel errors on rpc failure. | |
294 | * Returns BOOTSTRAP_UNKNOWN_SERVICE, if service does not exist. | |
295 | */ | |
296 | routine bootstrap_status( | |
297 | bootstrap_port : mach_port_t; | |
298 | service_name : name_t; | |
b51d5b5f | 299 | out service_active : bootstrap_status_t); |
1815bff5 A |
300 | |
301 | /* | |
302 | * kern_return_t | |
303 | * bootstrap_info(port_t bootstrap_port, | |
304 | * name_array_t *service_names, | |
305 | * int *service_names_cnt, | |
306 | * name_array_t *server_names, | |
307 | * int *server_names_cnt, | |
308 | * bool_array_t *service_active, | |
309 | * int *service_active_cnt); | |
310 | * | |
311 | * Errors: Returns appropriate kernel errors on rpc failure. | |
312 | */ | |
313 | routine bootstrap_info( | |
314 | bootstrap_port : mach_port_t; | |
315 | out service_names : name_array_t, dealloc; | |
316 | out server_names : name_array_t, dealloc; | |
b51d5b5f | 317 | out service_active : bootstrap_status_array_t, dealloc); |
1815bff5 A |
318 | |
319 | /* | |
320 | * kern_return_t | |
321 | * bootstrap_subset(mach_port_t bootstrap_port, | |
322 | * mach_port_t requestor_port, | |
323 | * mach_port_t *subset_port); | |
324 | * | |
325 | * Returns a new port to use as a bootstrap port. This port behaves | |
326 | * exactly like the previous bootstrap_port, except that ports dynamically | |
327 | * registered via bootstrap_register() are available only to users of this | |
328 | * specific subset_port. Lookups on the subset_port will return ports | |
329 | * registered with this port specifically, and ports registered with | |
330 | * ancestors of this subset_port. Duplications of services already | |
331 | * registered with an ancestor port may be registered with the subset port | |
332 | * are allowed. Services already advertised may then be effectively removed | |
333 | * by registering PORT_NULL for the service. | |
b51d5b5f | 334 | * When it is detected that the requestor_port is destroyed the subset |
1815bff5 A |
335 | * port and all services advertized by it are destroied as well. |
336 | * | |
337 | * Errors: Returns appropriate kernel errors on rpc failure. | |
338 | */ | |
339 | routine bootstrap_subset( | |
340 | bootstrap_port : mach_port_t; | |
341 | requestor_port : mach_port_t; | |
342 | out subset_port : mach_port_t); | |
343 | ||
344 | /* | |
345 | * kern_return_t | |
346 | * bootstrap_create_service(mach_port_t bootstrap_port, | |
347 | * name_t service_name, | |
348 | * mach_port_t *service_port) | |
349 | * | |
350 | * Creates a service named "service_name" and returns send rights to that | |
351 | * port in "service_port." The port may later be checked in as if this | |
352 | * port were configured in the bootstrap configuration file. | |
353 | * | |
354 | * Errors: Returns appropriate kernel errors on rpc failure. | |
355 | * Returns BOOTSTRAP_SERVICE_ACTIVE, if service already exists. | |
356 | */ | |
357 | routine bootstrap_create_service( | |
358 | bootstrap_port : mach_port_t; | |
359 | service_name : name_t; | |
360 | out service_port : mach_port_t); | |
b51d5b5f | 361 |