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