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