]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/mach_notify.c
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / mach_notify.c
1 /*
2 * Copyright (c) 2001-2002,2004,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
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,
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * IDENTIFICATION:
25 * stub generated Fri Mar 1 18:02:22 2002
26 * with a MiG generated Thu Feb 21 15:16:47 PST 2002 by root@blur
27 * OPTIONS:
28 */
29
30 /* Module notify */
31
32 #include <string.h>
33 #include <mach/ndr.h>
34 #include <mach/boolean.h>
35 #include <mach/kern_return.h>
36 #include <mach/notify.h>
37 #include <mach/mach_types.h>
38 #include <mach/message.h>
39 #include <mach/mig_errors.h>
40 #include <mach/port.h>
41
42 #include <mach/std_types.h>
43 #include <mach/mig.h>
44
45 #ifndef mig_internal
46 #define mig_internal static
47 #endif /* mig_internal */
48
49 #ifndef mig_external
50 #define mig_external
51 #endif /* mig_external */
52
53 #ifndef TypeCheck
54 #define TypeCheck 0
55 #endif /* TypeCheck */
56
57 #ifndef LimitCheck
58 #define LimitCheck 0
59 #endif /* LimitCheck */
60
61 #ifndef min
62 #define min(a,b) ( ((a) < (b))? (a): (b) )
63 #endif /* min */
64
65 #ifndef UseStaticTemplates
66 #define UseStaticTemplates 1
67 #endif /* UseStaticTemplates */
68
69 #define _WALIGN_(x) (((x) + 3) & ~3)
70 #define _WALIGNSZ_(x) _WALIGN_(sizeof(x))
71 #ifndef __DeclareRcvRpc
72 #define __DeclareRcvRpc(_NUM_, _NAME_)
73 #endif /* __DeclareRcvRpc */
74
75 #ifndef __BeforeRcvRpc
76 #define __BeforeRcvRpc(_NUM_, _NAME_)
77 #endif /* __BeforeRcvRpc */
78
79 #ifndef __AfterRcvRpc
80 #define __AfterRcvRpc(_NUM_, _NAME_)
81 #endif /* __AfterRcvRpc */
82
83 #ifndef __DeclareRcvSimple
84 #define __DeclareRcvSimple(_NUM_, _NAME_)
85 #endif /* __DeclareRcvSimple */
86
87 #ifndef __BeforeRcvSimple
88 #define __BeforeRcvSimple(_NUM_, _NAME_)
89 #endif /* __BeforeRcvSimple */
90
91 #ifndef __AfterRcvSimple
92 #define __AfterRcvSimple(_NUM_, _NAME_)
93 #endif /* __AfterRcvSimple */
94
95 #define novalue void
96
97 #define msgh_request_port msgh_local_port
98 #define MACH_MSGH_BITS_REQUEST(bits) MACH_MSGH_BITS_LOCAL(bits)
99 #define msgh_reply_port msgh_remote_port
100 #define MACH_MSGH_BITS_REPLY(bits) MACH_MSGH_BITS_REMOTE(bits)
101
102 #define MIG_RETURN_ERROR(X, code) {\
103 ((mig_reply_error_t *)X)->RetCode = code;\
104 ((mig_reply_error_t *)X)->NDR = NDR_record;\
105 return;\
106 }
107
108 /* typedefs for all requests */
109
110 typedef struct {
111 mach_msg_header_t Head;
112 NDR_record_t NDR;
113 mach_port_name_t name;
114 } __Request__mach_notify_port_deleted_t;
115
116 typedef struct {
117 mach_msg_header_t Head;
118 /* start of the kernel processed data */
119 mach_msg_body_t msgh_body;
120 mach_msg_port_descriptor_t rights;
121 /* end of the kernel processed data */
122 } __Request__mach_notify_port_destroyed_t;
123
124 typedef struct {
125 mach_msg_header_t Head;
126 NDR_record_t NDR;
127 mach_port_mscount_t mscount;
128 } __Request__mach_notify_no_senders_t;
129
130 typedef struct {
131 mach_msg_header_t Head;
132 } __Request__mach_notify_send_once_t;
133
134 typedef struct {
135 mach_msg_header_t Head;
136 NDR_record_t NDR;
137 mach_port_name_t name;
138 } __Request__mach_notify_dead_name_t;
139
140
141 /* typedefs for all replies */
142
143 typedef struct {
144 mach_msg_header_t Head;
145 NDR_record_t NDR;
146 kern_return_t RetCode;
147 } __Reply__mach_notify_port_deleted_t;
148
149 typedef struct {
150 mach_msg_header_t Head;
151 NDR_record_t NDR;
152 kern_return_t RetCode;
153 } __Reply__mach_notify_port_destroyed_t;
154
155 typedef struct {
156 mach_msg_header_t Head;
157 NDR_record_t NDR;
158 kern_return_t RetCode;
159 } __Reply__mach_notify_no_senders_t;
160
161 typedef struct {
162 mach_msg_header_t Head;
163 NDR_record_t NDR;
164 kern_return_t RetCode;
165 } __Reply__mach_notify_send_once_t;
166
167 typedef struct {
168 mach_msg_header_t Head;
169 NDR_record_t NDR;
170 kern_return_t RetCode;
171 } __Reply__mach_notify_dead_name_t;
172
173
174 /* Forward Declarations */
175
176
177 mig_internal novalue _Xmach_notify_port_deleted
178 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP);
179
180 mig_internal novalue _Xmach_notify_port_destroyed
181 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP);
182
183 mig_internal novalue _Xmach_notify_no_senders
184 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP);
185
186 mig_internal novalue _Xmach_notify_send_once
187 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP);
188
189 mig_internal novalue _Xmach_notify_dead_name
190 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP);
191
192
193 /* SimpleRoutine mach_notify_port_deleted */
194 #ifdef mig_external
195 mig_external
196 #else
197 extern
198 #endif /* mig_external */
199 kern_return_t cdsa_mach_notify_port_deleted
200 (
201 mach_port_t notify,
202 mach_port_name_t name
203 );
204
205 /* SimpleRoutine mach_notify_port_deleted */
206 mig_internal novalue _Xmach_notify_port_deleted
207 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
208 {
209 typedef struct {
210 mach_msg_header_t Head;
211 NDR_record_t NDR;
212 mach_port_name_t name;
213 mach_msg_trailer_t trailer;
214 } Request;
215
216 #if TypeCheck
217 typedef __Request__mach_notify_port_deleted_t __Request;
218 #endif
219
220 typedef __Reply__mach_notify_port_deleted_t Reply;
221 /*
222 * typedef struct {
223 * mach_msg_header_t Head;
224 * NDR_record_t NDR;
225 * kern_return_t RetCode;
226 * } mig_reply_error_t;
227 */
228
229 register Request *In0P = (Request *) InHeadP;
230 register Reply *OutP = (Reply *) OutHeadP;
231 __DeclareRcvSimple(65, "mach_notify_port_deleted")
232 __BeforeRcvSimple(65, "mach_notify_port_deleted")
233 #if TypeCheck
234 if ((In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) ||
235 (In0P->Head.msgh_size != sizeof(__Request)))
236 { MIG_RETURN_ERROR(OutP, MIG_BAD_ARGUMENTS); }
237 #endif /* TypeCheck */
238
239 OutP->RetCode = cdsa_mach_notify_port_deleted(In0P->Head.msgh_request_port, In0P->name);
240 __AfterRcvSimple(65, "mach_notify_port_deleted")
241 }
242
243 /* SimpleRoutine mach_notify_port_destroyed */
244 #ifdef mig_external
245 mig_external
246 #else
247 extern
248 #endif /* mig_external */
249 kern_return_t cdsa_mach_notify_port_destroyed
250 (
251 mach_port_t notify,
252 mach_port_t rights
253 );
254
255 /* SimpleRoutine mach_notify_port_destroyed */
256 mig_internal novalue _Xmach_notify_port_destroyed
257 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
258 {
259 typedef struct {
260 mach_msg_header_t Head;
261 /* start of the kernel processed data */
262 mach_msg_body_t msgh_body;
263 mach_msg_port_descriptor_t rights;
264 /* end of the kernel processed data */
265 mach_msg_trailer_t trailer;
266 } Request;
267
268 #if TypeCheck
269 typedef __Request__mach_notify_port_destroyed_t __Request;
270 #endif
271
272 typedef __Reply__mach_notify_port_destroyed_t Reply;
273 /*
274 * typedef struct {
275 * mach_msg_header_t Head;
276 * NDR_record_t NDR;
277 * kern_return_t RetCode;
278 * } mig_reply_error_t;
279 */
280
281 register Request *In0P = (Request *) InHeadP;
282 register Reply *OutP = (Reply *) OutHeadP;
283 __DeclareRcvSimple(69, "mach_notify_port_destroyed")
284 __BeforeRcvSimple(69, "mach_notify_port_destroyed")
285 #if TypeCheck
286 if (!(In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) ||
287 (In0P->msgh_body.msgh_descriptor_count != 1) ||
288 (In0P->Head.msgh_size != sizeof(__Request)))
289 { MIG_RETURN_ERROR(OutP, MIG_BAD_ARGUMENTS); }
290 #endif /* TypeCheck */
291
292 #if TypeCheck
293 if (In0P->rights.type != MACH_MSG_PORT_DESCRIPTOR ||
294 In0P->rights.disposition != MACH_MSG_TYPE_MOVE_RECEIVE)
295 { MIG_RETURN_ERROR(OutP, MIG_TYPE_ERROR); }
296 #endif /* TypeCheck */
297
298 OutP->RetCode = cdsa_mach_notify_port_destroyed(In0P->Head.msgh_request_port, In0P->rights.name);
299 __AfterRcvSimple(69, "mach_notify_port_destroyed")
300 }
301
302 /* SimpleRoutine mach_notify_no_senders */
303 #ifdef mig_external
304 mig_external
305 #else
306 extern
307 #endif /* mig_external */
308 kern_return_t cdsa_mach_notify_no_senders
309 (
310 mach_port_t notify,
311 mach_port_mscount_t mscount
312 );
313
314 /* SimpleRoutine mach_notify_no_senders */
315 mig_internal novalue _Xmach_notify_no_senders
316 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
317 {
318 typedef struct {
319 mach_msg_header_t Head;
320 NDR_record_t NDR;
321 mach_port_mscount_t mscount;
322 mach_msg_trailer_t trailer;
323 } Request;
324
325 #if TypeCheck
326 typedef __Request__mach_notify_no_senders_t __Request;
327 #endif
328
329 typedef __Reply__mach_notify_no_senders_t Reply;
330 /*
331 * typedef struct {
332 * mach_msg_header_t Head;
333 * NDR_record_t NDR;
334 * kern_return_t RetCode;
335 * } mig_reply_error_t;
336 */
337
338 register Request *In0P = (Request *) InHeadP;
339 register Reply *OutP = (Reply *) OutHeadP;
340 __DeclareRcvSimple(70, "mach_notify_no_senders")
341 __BeforeRcvSimple(70, "mach_notify_no_senders")
342 #if TypeCheck
343 if ((In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) ||
344 (In0P->Head.msgh_size != sizeof(__Request)))
345 { MIG_RETURN_ERROR(OutP, MIG_BAD_ARGUMENTS); }
346 #endif /* TypeCheck */
347
348 OutP->RetCode = cdsa_mach_notify_no_senders(In0P->Head.msgh_request_port, In0P->mscount);
349 __AfterRcvSimple(70, "mach_notify_no_senders")
350 }
351
352 /* SimpleRoutine mach_notify_send_once */
353 #ifdef mig_external
354 mig_external
355 #else
356 extern
357 #endif /* mig_external */
358 kern_return_t cdsa_mach_notify_send_once
359 (
360 mach_port_t notify
361 );
362
363 /* SimpleRoutine mach_notify_send_once */
364 mig_internal novalue _Xmach_notify_send_once
365 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
366 {
367 typedef struct {
368 mach_msg_header_t Head;
369 mach_msg_trailer_t trailer;
370 } Request;
371
372 #if TypeCheck
373 typedef __Request__mach_notify_send_once_t __Request;
374 #endif
375
376 typedef __Reply__mach_notify_send_once_t Reply;
377 /*
378 * typedef struct {
379 * mach_msg_header_t Head;
380 * NDR_record_t NDR;
381 * kern_return_t RetCode;
382 * } mig_reply_error_t;
383 */
384
385 register Request *In0P = (Request *) InHeadP;
386 register Reply *OutP = (Reply *) OutHeadP;
387 __DeclareRcvSimple(71, "mach_notify_send_once")
388 __BeforeRcvSimple(71, "mach_notify_send_once")
389 #if TypeCheck
390 if ((In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) ||
391 (In0P->Head.msgh_size != sizeof(__Request)))
392 { MIG_RETURN_ERROR(OutP, MIG_BAD_ARGUMENTS); }
393 #endif /* TypeCheck */
394
395 OutP->RetCode = cdsa_mach_notify_send_once(In0P->Head.msgh_request_port);
396 __AfterRcvSimple(71, "mach_notify_send_once")
397 }
398
399 /* SimpleRoutine mach_notify_dead_name */
400 #ifdef mig_external
401 mig_external
402 #else
403 extern
404 #endif /* mig_external */
405 kern_return_t cdsa_mach_notify_dead_name
406 (
407 mach_port_t notify,
408 mach_port_name_t name
409 );
410
411 /* SimpleRoutine mach_notify_dead_name */
412 mig_internal novalue _Xmach_notify_dead_name
413 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
414 {
415 typedef struct {
416 mach_msg_header_t Head;
417 NDR_record_t NDR;
418 mach_port_name_t name;
419 mach_msg_trailer_t trailer;
420 } Request;
421
422 #if TypeCheck
423 typedef __Request__mach_notify_dead_name_t __Request;
424 #endif
425
426 typedef __Reply__mach_notify_dead_name_t Reply;
427 /*
428 * typedef struct {
429 * mach_msg_header_t Head;
430 * NDR_record_t NDR;
431 * kern_return_t RetCode;
432 * } mig_reply_error_t;
433 */
434
435 register Request *In0P = (Request *) InHeadP;
436 register Reply *OutP = (Reply *) OutHeadP;
437 __DeclareRcvSimple(72, "mach_notify_dead_name")
438 __BeforeRcvSimple(72, "mach_notify_dead_name")
439 #if TypeCheck
440 if ((In0P->Head.msgh_bits & MACH_MSGH_BITS_COMPLEX) ||
441 (In0P->Head.msgh_size != sizeof(__Request)))
442 { MIG_RETURN_ERROR(OutP, MIG_BAD_ARGUMENTS); }
443 #endif /* TypeCheck */
444
445 OutP->RetCode = cdsa_mach_notify_dead_name(In0P->Head.msgh_request_port, In0P->name);
446 __AfterRcvSimple(72, "mach_notify_dead_name")
447 }
448
449 /* union of all requests */
450
451 union __RequestUnion__cdsa_notify_subsystem {
452 __Request__mach_notify_port_deleted_t Request_mach_notify_port_deleted;
453 __Request__mach_notify_port_destroyed_t Request_mach_notify_port_destroyed;
454 __Request__mach_notify_no_senders_t Request_mach_notify_no_senders;
455 __Request__mach_notify_send_once_t Request_mach_notify_send_once;
456 __Request__mach_notify_dead_name_t Request_mach_notify_dead_name;
457 };
458
459 /* union of all replies */
460
461 union __ReplyUnion__cdsa_notify_subsystem {
462 __Reply__mach_notify_port_deleted_t Reply_mach_notify_port_deleted;
463 __Reply__mach_notify_port_destroyed_t Reply_mach_notify_port_destroyed;
464 __Reply__mach_notify_no_senders_t Reply_mach_notify_no_senders;
465 __Reply__mach_notify_send_once_t Reply_mach_notify_send_once;
466 __Reply__mach_notify_dead_name_t Reply_mach_notify_dead_name;
467 };
468
469
470 extern boolean_t cdsa_notify_server(
471 mach_msg_header_t *InHeadP,
472 mach_msg_header_t *OutHeadP);
473
474 extern mig_routine_t notify_server_routine(
475 mach_msg_header_t *InHeadP);
476
477
478 /* Description of this subsystem, for use in direct RPC */
479 const struct cdsa_notify_subsystem {
480 mig_server_routine_t server; /* Server routine */
481 mach_msg_id_t start; /* Min routine number */
482 mach_msg_id_t end; /* Max routine number + 1 */
483 unsigned int maxsize; /* Max msg size */
484 vm_address_t reserved; /* Reserved */
485 struct routine_descriptor /*Array of routine descriptors */
486 routine[9];
487 } cdsa_notify_subsystem = {
488 notify_server_routine,
489 64,
490 73,
491 sizeof(union __ReplyUnion__cdsa_notify_subsystem),
492 (vm_address_t)0,
493 {
494 {0, 0, 0, 0, 0, 0},
495 { (mig_impl_routine_t) 0,
496 (mig_stub_routine_t) _Xmach_notify_port_deleted, 2, 0, (routine_arg_descriptor_t)0, sizeof(__Reply__mach_notify_port_deleted_t)},
497 {0, 0, 0, 0, 0, 0},
498 {0, 0, 0, 0, 0, 0},
499 {0, 0, 0, 0, 0, 0},
500 { (mig_impl_routine_t) 0,
501 (mig_stub_routine_t) _Xmach_notify_port_destroyed, 2, 0, (routine_arg_descriptor_t)0, sizeof(__Reply__mach_notify_port_destroyed_t)},
502 { (mig_impl_routine_t) 0,
503 (mig_stub_routine_t) _Xmach_notify_no_senders, 2, 0, (routine_arg_descriptor_t)0, sizeof(__Reply__mach_notify_no_senders_t)},
504 { (mig_impl_routine_t) 0,
505 (mig_stub_routine_t) _Xmach_notify_send_once, 1, 0, (routine_arg_descriptor_t)0, sizeof(__Reply__mach_notify_send_once_t)},
506 { (mig_impl_routine_t) 0,
507 (mig_stub_routine_t) _Xmach_notify_dead_name, 2, 0, (routine_arg_descriptor_t)0, sizeof(__Reply__mach_notify_dead_name_t)},
508 }
509 };
510
511 mig_external boolean_t cdsa_notify_server
512 (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
513 {
514 /*
515 * typedef struct {
516 * mach_msg_header_t Head;
517 * NDR_record_t NDR;
518 * kern_return_t RetCode;
519 * } mig_reply_error_t;
520 */
521
522 register mig_routine_t routine;
523
524 OutHeadP->msgh_bits = MACH_MSGH_BITS(MACH_MSGH_BITS_REPLY(InHeadP->msgh_bits), 0);
525 OutHeadP->msgh_remote_port = InHeadP->msgh_reply_port;
526 /* Minimal size: routine() will update it if different */
527 OutHeadP->msgh_size = sizeof(mig_reply_error_t);
528 OutHeadP->msgh_local_port = MACH_PORT_NULL;
529 OutHeadP->msgh_id = InHeadP->msgh_id + 100;
530
531 if ((InHeadP->msgh_id > 72) || (InHeadP->msgh_id < 64) ||
532 ((routine = cdsa_notify_subsystem.routine[InHeadP->msgh_id - 64].stub_routine) == 0)) {
533 ((mig_reply_error_t *)OutHeadP)->NDR = NDR_record;
534 ((mig_reply_error_t *)OutHeadP)->RetCode = MIG_BAD_ID;
535 return FALSE;
536 }
537 (*routine) (InHeadP, OutHeadP);
538 return TRUE;
539 }
540
541 mig_external mig_routine_t notify_server_routine
542 (mach_msg_header_t *InHeadP)
543 {
544 register int msgh_id;
545
546 msgh_id = InHeadP->msgh_id - 64;
547
548 if ((msgh_id > 8) || (msgh_id < 0))
549 return 0;
550
551 return cdsa_notify_subsystem.routine[msgh_id].stub_routine;
552 }