1#ifndef _mach_exc_server_
2#define _mach_exc_server_
3
4/* Module mach_exc */
5
6#include <string.h>
7#include <mach/ndr.h>
8#include <mach/boolean.h>
9#include <mach/kern_return.h>
10#include <mach/notify.h>
11#include <mach/mach_types.h>
12#include <mach/message.h>
13#include <mach/mig_errors.h>
14#include <mach/port.h>
15
16/* BEGIN MIG_STRNCPY_ZEROFILL CODE */
17
18#if defined(__has_include)
19#if __has_include(<mach/mig_strncpy_zerofill_support.h>)
20#ifndef USING_MIG_STRNCPY_ZEROFILL
21#define USING_MIG_STRNCPY_ZEROFILL
22#endif
23#ifndef __MIG_STRNCPY_ZEROFILL_FORWARD_TYPE_DECLS__
24#define __MIG_STRNCPY_ZEROFILL_FORWARD_TYPE_DECLS__
25#ifdef __cplusplus
26extern "C" {
27#endif
28#ifndef __MIG_STRNCPY_ZEROFILL_FORWARD_TYPE_DECLS_CSTRING_ATTR
29#define __MIG_STRNCPY_ZEROFILL_FORWARD_TYPE_DECLS_CSTRING_COUNTEDBY_ATTR(C) __unsafe_indexable
30#endif
31 extern int mig_strncpy_zerofill(char * dest, const char * src, int len) __attribute__((weak_import));
32#ifdef __cplusplus
33}
34#endif
35#endif /* __MIG_STRNCPY_ZEROFILL_FORWARD_TYPE_DECLS__ */
36#endif /* __has_include(<mach/mig_strncpy_zerofill_support.h>) */
37#endif /* __has_include */
38
39/* END MIG_STRNCPY_ZEROFILL CODE */
40
41
42#ifdef AUTOTEST
43#ifndef FUNCTION_PTR_T
44#define FUNCTION_PTR_T
45typedef void (*function_ptr_t)(mach_port_t, char *, mach_msg_type_number_t);
46typedef struct {
47 char * name;
48 function_ptr_t function;
49} function_table_entry;
50typedef function_table_entry *function_table_t;
51#endif /* FUNCTION_PTR_T */
52#endif /* AUTOTEST */
53
54#ifndef mach_exc_MSG_COUNT
55#define mach_exc_MSG_COUNT 5
56#endif /* mach_exc_MSG_COUNT */
57
58#include <Availability.h>
59#include <mach/std_types.h>
60#include <mach/mig.h>
61#include <ipc/ipc_voucher.h>
62#include <kern/ipc_kobject.h>
63#include <kern/ipc_tt.h>
64#include <kern/ipc_host.h>
65#include <kern/ledger.h>
66#include <kern/processor.h>
67#include <kern/sync_sema.h>
68#include <ipc/ipc_eventlink.h>
69#include <vm/memory_object.h>
70#include <vm/vm_map.h>
71#include <kern/arcade.h>
72#include <kern/ipc_mig.h>
73#include <kern/task_ident.h>
74#include <kern/kern_cdata.h>
75#include <mach/mig.h>
76#include <mach/mach_types.h>
77
78#ifdef __BeforeMigServerHeader
79__BeforeMigServerHeader
80#endif /* __BeforeMigServerHeader */
81
82#ifndef MIG_SERVER_ROUTINE
83#define MIG_SERVER_ROUTINE
84#endif
85
86
87/* Routine mach_exception_raise */
88#ifdef mig_external
89mig_external
90#else
91extern
92#endif /* mig_external */
93MIG_SERVER_ROUTINE
94kern_return_t catch_mach_exception_raise
95(
96 mach_port_t exception_port,
97 mach_port_t thread,
98 mach_port_t task,
99 exception_type_t exception,
100 mach_exception_data_t code,
101 mach_msg_type_number_t codeCnt
102);
103
104/* Routine mach_exception_raise_state */
105#ifdef mig_external
106mig_external
107#else
108extern
109#endif /* mig_external */
110MIG_SERVER_ROUTINE
111kern_return_t catch_mach_exception_raise_state
112(
113 mach_port_t exception_port,
114 exception_type_t exception,
115 const mach_exception_data_t code,
116 mach_msg_type_number_t codeCnt,
117 int *flavor,
118 const thread_state_t old_state,
119 mach_msg_type_number_t old_stateCnt,
120 thread_state_t new_state,
121 mach_msg_type_number_t *new_stateCnt
122);
123
124/* Routine mach_exception_raise_state_identity */
125#ifdef mig_external
126mig_external
127#else
128extern
129#endif /* mig_external */
130MIG_SERVER_ROUTINE
131kern_return_t catch_mach_exception_raise_state_identity
132(
133 mach_port_t exception_port,
134 mach_port_t thread,
135 mach_port_t task,
136 exception_type_t exception,
137 mach_exception_data_t code,
138 mach_msg_type_number_t codeCnt,
139 int *flavor,
140 thread_state_t old_state,
141 mach_msg_type_number_t old_stateCnt,
142 thread_state_t new_state,
143 mach_msg_type_number_t *new_stateCnt
144);
145
146/* Routine mach_exception_raise_identity_protected */
147#ifdef mig_external
148mig_external
149#else
150extern
151#endif /* mig_external */
152MIG_SERVER_ROUTINE
153kern_return_t catch_mach_exception_raise_identity_protected
154(
155 mach_port_t exception_port,
156 uint64_t thread_id,
157 mach_port_t task_id_token_t,
158 exception_type_t exception,
159 mach_exception_data_t code,
160 mach_msg_type_number_t codeCnt
161);
162
163/* Routine mach_exception_raise_backtrace */
164#ifdef mig_external
165mig_external
166#else
167extern
168#endif /* mig_external */
169MIG_SERVER_ROUTINE
170kern_return_t catch_mach_exception_raise_backtrace
171(
172 mach_port_t exception_port,
173 mach_port_t kcdata_object_t,
174 exception_type_t exception,
175 mach_exception_data_t code,
176 mach_msg_type_number_t codeCnt
177);
178
179#ifdef mig_external
180mig_external
181#else
182extern
183#endif /* mig_external */
184boolean_t mach_exc_server(
185 mach_msg_header_t *InHeadP,
186 void *InDataP,
187 mach_msg_max_trailer_t *InTrailerP,
188 mach_msg_header_t *OutHeadP,
189 void *OutDataP);
190
191#ifdef mig_external
192mig_external
193#else
194extern
195#endif /* mig_external */
196mig_kern_routine_t mach_exc_server_routine(
197 mach_msg_header_t *InHeadP);
198
199
200/* Description of this kernel subsystem, for use in direct RPC */
201extern const struct catch_mach_exc_subsystem {
202 mig_kern_server_routine_t kserver; /* Server routine */
203 mach_msg_id_t start; /* Min routine number */
204 mach_msg_id_t end; /* Max routine number + 1 */
205 unsigned int maxsize; /* Max msg size */
206 vm_address_t reserved; /* Reserved */
207 struct kern_routine_descriptor /* Array of routine descriptors */
208 kroutine[5];
209} catch_mach_exc_subsystem;
210
211/* typedefs for all requests */
212
213#ifndef __Request__mach_exc_subsystem__defined
214#define __Request__mach_exc_subsystem__defined
215
216#ifdef __MigPackStructs
217#pragma pack(push, 4)
218#endif
219 typedef struct {
220 mach_msg_header_t Head;
221 /* start of the kernel processed data */
222 mach_msg_body_t msgh_body;
223 mach_msg_port_descriptor_t thread;
224 mach_msg_port_descriptor_t task;
225 /* end of the kernel processed data */
226 NDR_record_t NDR;
227 exception_type_t exception;
228 mach_msg_type_number_t codeCnt;
229 int64_t code[2];
230 } __Request__mach_exception_raise_t __attribute__((unused));
231#ifdef __MigPackStructs
232#pragma pack(pop)
233#endif
234/* Struct for kernel processed data (Header + Descriptors) */
235#ifdef __MigPackStructs
236#pragma pack(push, 4)
237#endif
238 typedef struct {
239 mach_msg_header_t Head;
240 mach_msg_body_t msgh_body;
241 mach_msg_port_descriptor_t thread;
242 mach_msg_port_descriptor_t task;
243 } __RequestKData__mach_exception_raise_t __attribute__((unused));
244#ifdef __MigPackStructs
245#pragma pack(pop)
246#endif
247/* Struct for pure user data */
248#ifdef __MigPackStructs
249#pragma pack(push, 4)
250#endif
251 typedef struct {
252 NDR_record_t NDR;
253 exception_type_t exception;
254 mach_msg_type_number_t codeCnt;
255 int64_t code[2];
256 char padding[0]; /* Avoid generating empty UData structs */
257 } __RequestUData__mach_exception_raise_t __attribute__((unused));
258#ifdef __MigPackStructs
259#pragma pack(pop)
260#endif
261
262#ifdef __MigPackStructs
263#pragma pack(push, 4)
264#endif
265 typedef struct {
266 mach_msg_header_t Head;
267 NDR_record_t NDR;
268 exception_type_t exception;
269 mach_msg_type_number_t codeCnt;
270 int64_t code[2];
271 int flavor;
272 mach_msg_type_number_t old_stateCnt;
273 natural_t old_state[1296];
274 } __Request__mach_exception_raise_state_t __attribute__((unused));
275#ifdef __MigPackStructs
276#pragma pack(pop)
277#endif
278/* Struct for kernel processed data (Header + Descriptors) */
279#ifdef __MigPackStructs
280#pragma pack(push, 4)
281#endif
282 typedef struct {
283 mach_msg_header_t Head;
284 } __RequestKData__mach_exception_raise_state_t __attribute__((unused));
285#ifdef __MigPackStructs
286#pragma pack(pop)
287#endif
288/* Struct for pure user data */
289#ifdef __MigPackStructs
290#pragma pack(push, 4)
291#endif
292 typedef struct {
293 NDR_record_t NDR;
294 exception_type_t exception;
295 mach_msg_type_number_t codeCnt;
296 int64_t code[2];
297 int flavor;
298 mach_msg_type_number_t old_stateCnt;
299 natural_t old_state[1296];
300 char padding[0]; /* Avoid generating empty UData structs */
301 } __RequestUData__mach_exception_raise_state_t __attribute__((unused));
302#ifdef __MigPackStructs
303#pragma pack(pop)
304#endif
305
306#ifdef __MigPackStructs
307#pragma pack(push, 4)
308#endif
309 typedef struct {
310 mach_msg_header_t Head;
311 /* start of the kernel processed data */
312 mach_msg_body_t msgh_body;
313 mach_msg_port_descriptor_t thread;
314 mach_msg_port_descriptor_t task;
315 /* end of the kernel processed data */
316 NDR_record_t NDR;
317 exception_type_t exception;
318 mach_msg_type_number_t codeCnt;
319 int64_t code[2];
320 int flavor;
321 mach_msg_type_number_t old_stateCnt;
322 natural_t old_state[1296];
323 } __Request__mach_exception_raise_state_identity_t __attribute__((unused));
324#ifdef __MigPackStructs
325#pragma pack(pop)
326#endif
327/* Struct for kernel processed data (Header + Descriptors) */
328#ifdef __MigPackStructs
329#pragma pack(push, 4)
330#endif
331 typedef struct {
332 mach_msg_header_t Head;
333 mach_msg_body_t msgh_body;
334 mach_msg_port_descriptor_t thread;
335 mach_msg_port_descriptor_t task;
336 } __RequestKData__mach_exception_raise_state_identity_t __attribute__((unused));
337#ifdef __MigPackStructs
338#pragma pack(pop)
339#endif
340/* Struct for pure user data */
341#ifdef __MigPackStructs
342#pragma pack(push, 4)
343#endif
344 typedef struct {
345 NDR_record_t NDR;
346 exception_type_t exception;
347 mach_msg_type_number_t codeCnt;
348 int64_t code[2];
349 int flavor;
350 mach_msg_type_number_t old_stateCnt;
351 natural_t old_state[1296];
352 char padding[0]; /* Avoid generating empty UData structs */
353 } __RequestUData__mach_exception_raise_state_identity_t __attribute__((unused));
354#ifdef __MigPackStructs
355#pragma pack(pop)
356#endif
357
358#ifdef __MigPackStructs
359#pragma pack(push, 4)
360#endif
361 typedef struct {
362 mach_msg_header_t Head;
363 /* start of the kernel processed data */
364 mach_msg_body_t msgh_body;
365 mach_msg_port_descriptor_t task_id_token_t;
366 /* end of the kernel processed data */
367 NDR_record_t NDR;
368 uint64_t thread_id;
369 exception_type_t exception;
370 mach_msg_type_number_t codeCnt;
371 int64_t code[2];
372 } __Request__mach_exception_raise_identity_protected_t __attribute__((unused));
373#ifdef __MigPackStructs
374#pragma pack(pop)
375#endif
376/* Struct for kernel processed data (Header + Descriptors) */
377#ifdef __MigPackStructs
378#pragma pack(push, 4)
379#endif
380 typedef struct {
381 mach_msg_header_t Head;
382 mach_msg_body_t msgh_body;
383 mach_msg_port_descriptor_t task_id_token_t;
384 } __RequestKData__mach_exception_raise_identity_protected_t __attribute__((unused));
385#ifdef __MigPackStructs
386#pragma pack(pop)
387#endif
388/* Struct for pure user data */
389#ifdef __MigPackStructs
390#pragma pack(push, 4)
391#endif
392 typedef struct {
393 NDR_record_t NDR;
394 uint64_t thread_id;
395 exception_type_t exception;
396 mach_msg_type_number_t codeCnt;
397 int64_t code[2];
398 char padding[0]; /* Avoid generating empty UData structs */
399 } __RequestUData__mach_exception_raise_identity_protected_t __attribute__((unused));
400#ifdef __MigPackStructs
401#pragma pack(pop)
402#endif
403
404#ifdef __MigPackStructs
405#pragma pack(push, 4)
406#endif
407 typedef struct {
408 mach_msg_header_t Head;
409 /* start of the kernel processed data */
410 mach_msg_body_t msgh_body;
411 mach_msg_port_descriptor_t kcdata_object_t;
412 /* end of the kernel processed data */
413 NDR_record_t NDR;
414 exception_type_t exception;
415 mach_msg_type_number_t codeCnt;
416 int64_t code[2];
417 } __Request__mach_exception_raise_backtrace_t __attribute__((unused));
418#ifdef __MigPackStructs
419#pragma pack(pop)
420#endif
421/* Struct for kernel processed data (Header + Descriptors) */
422#ifdef __MigPackStructs
423#pragma pack(push, 4)
424#endif
425 typedef struct {
426 mach_msg_header_t Head;
427 mach_msg_body_t msgh_body;
428 mach_msg_port_descriptor_t kcdata_object_t;
429 } __RequestKData__mach_exception_raise_backtrace_t __attribute__((unused));
430#ifdef __MigPackStructs
431#pragma pack(pop)
432#endif
433/* Struct for pure user data */
434#ifdef __MigPackStructs
435#pragma pack(push, 4)
436#endif
437 typedef struct {
438 NDR_record_t NDR;
439 exception_type_t exception;
440 mach_msg_type_number_t codeCnt;
441 int64_t code[2];
442 char padding[0]; /* Avoid generating empty UData structs */
443 } __RequestUData__mach_exception_raise_backtrace_t __attribute__((unused));
444#ifdef __MigPackStructs
445#pragma pack(pop)
446#endif
447#endif /* !__Request__mach_exc_subsystem__defined */
448
449
450/* union of all requests */
451
452#ifndef __RequestUnion__catch_mach_exc_subsystem__defined
453#define __RequestUnion__catch_mach_exc_subsystem__defined
454union __RequestUnion__catch_mach_exc_subsystem {
455 __Request__mach_exception_raise_t Request_mach_exception_raise;
456 __Request__mach_exception_raise_state_t Request_mach_exception_raise_state;
457 __Request__mach_exception_raise_state_identity_t Request_mach_exception_raise_state_identity;
458 __Request__mach_exception_raise_identity_protected_t Request_mach_exception_raise_identity_protected;
459 __Request__mach_exception_raise_backtrace_t Request_mach_exception_raise_backtrace;
460};
461#endif /* __RequestUnion__catch_mach_exc_subsystem__defined */
462/* typedefs for all replies */
463
464#ifndef __Reply__mach_exc_subsystem__defined
465#define __Reply__mach_exc_subsystem__defined
466
467#ifdef __MigPackStructs
468#pragma pack(push, 4)
469#endif
470 typedef struct {
471 mach_msg_header_t Head;
472 NDR_record_t NDR;
473 kern_return_t RetCode;
474 } __Reply__mach_exception_raise_t __attribute__((unused));
475#ifdef __MigPackStructs
476#pragma pack(pop)
477#endif
478/* Struct for kernel processed data (Header + Descriptors) */
479#ifdef __MigPackStructs
480#pragma pack(push, 4)
481#endif
482 typedef struct {
483 mach_msg_header_t Head;
484 } __ReplyKData__mach_exception_raise_t __attribute__((unused));
485#ifdef __MigPackStructs
486#pragma pack(pop)
487#endif
488/* Struct for pure user data */
489#ifdef __MigPackStructs
490#pragma pack(push, 4)
491#endif
492 typedef struct {
493 NDR_record_t NDR;
494 kern_return_t RetCode;
495 char padding[0]; /* Avoid generating empty UData structs */
496 } __ReplyUData__mach_exception_raise_t __attribute__((unused));
497#ifdef __MigPackStructs
498#pragma pack(pop)
499#endif
500
501#ifdef __MigPackStructs
502#pragma pack(push, 4)
503#endif
504 typedef struct {
505 mach_msg_header_t Head;
506 NDR_record_t NDR;
507 kern_return_t RetCode;
508 int flavor;
509 mach_msg_type_number_t new_stateCnt;
510 natural_t new_state[1296];
511 } __Reply__mach_exception_raise_state_t __attribute__((unused));
512#ifdef __MigPackStructs
513#pragma pack(pop)
514#endif
515/* Struct for kernel processed data (Header + Descriptors) */
516#ifdef __MigPackStructs
517#pragma pack(push, 4)
518#endif
519 typedef struct {
520 mach_msg_header_t Head;
521 } __ReplyKData__mach_exception_raise_state_t __attribute__((unused));
522#ifdef __MigPackStructs
523#pragma pack(pop)
524#endif
525/* Struct for pure user data */
526#ifdef __MigPackStructs
527#pragma pack(push, 4)
528#endif
529 typedef struct {
530 NDR_record_t NDR;
531 kern_return_t RetCode;
532 int flavor;
533 mach_msg_type_number_t new_stateCnt;
534 natural_t new_state[1296];
535 char padding[0]; /* Avoid generating empty UData structs */
536 } __ReplyUData__mach_exception_raise_state_t __attribute__((unused));
537#ifdef __MigPackStructs
538#pragma pack(pop)
539#endif
540
541#ifdef __MigPackStructs
542#pragma pack(push, 4)
543#endif
544 typedef struct {
545 mach_msg_header_t Head;
546 NDR_record_t NDR;
547 kern_return_t RetCode;
548 int flavor;
549 mach_msg_type_number_t new_stateCnt;
550 natural_t new_state[1296];
551 } __Reply__mach_exception_raise_state_identity_t __attribute__((unused));
552#ifdef __MigPackStructs
553#pragma pack(pop)
554#endif
555/* Struct for kernel processed data (Header + Descriptors) */
556#ifdef __MigPackStructs
557#pragma pack(push, 4)
558#endif
559 typedef struct {
560 mach_msg_header_t Head;
561 } __ReplyKData__mach_exception_raise_state_identity_t __attribute__((unused));
562#ifdef __MigPackStructs
563#pragma pack(pop)
564#endif
565/* Struct for pure user data */
566#ifdef __MigPackStructs
567#pragma pack(push, 4)
568#endif
569 typedef struct {
570 NDR_record_t NDR;
571 kern_return_t RetCode;
572 int flavor;
573 mach_msg_type_number_t new_stateCnt;
574 natural_t new_state[1296];
575 char padding[0]; /* Avoid generating empty UData structs */
576 } __ReplyUData__mach_exception_raise_state_identity_t __attribute__((unused));
577#ifdef __MigPackStructs
578#pragma pack(pop)
579#endif
580
581#ifdef __MigPackStructs
582#pragma pack(push, 4)
583#endif
584 typedef struct {
585 mach_msg_header_t Head;
586 NDR_record_t NDR;
587 kern_return_t RetCode;
588 } __Reply__mach_exception_raise_identity_protected_t __attribute__((unused));
589#ifdef __MigPackStructs
590#pragma pack(pop)
591#endif
592/* Struct for kernel processed data (Header + Descriptors) */
593#ifdef __MigPackStructs
594#pragma pack(push, 4)
595#endif
596 typedef struct {
597 mach_msg_header_t Head;
598 } __ReplyKData__mach_exception_raise_identity_protected_t __attribute__((unused));
599#ifdef __MigPackStructs
600#pragma pack(pop)
601#endif
602/* Struct for pure user data */
603#ifdef __MigPackStructs
604#pragma pack(push, 4)
605#endif
606 typedef struct {
607 NDR_record_t NDR;
608 kern_return_t RetCode;
609 char padding[0]; /* Avoid generating empty UData structs */
610 } __ReplyUData__mach_exception_raise_identity_protected_t __attribute__((unused));
611#ifdef __MigPackStructs
612#pragma pack(pop)
613#endif
614
615#ifdef __MigPackStructs
616#pragma pack(push, 4)
617#endif
618 typedef struct {
619 mach_msg_header_t Head;
620 NDR_record_t NDR;
621 kern_return_t RetCode;
622 } __Reply__mach_exception_raise_backtrace_t __attribute__((unused));
623#ifdef __MigPackStructs
624#pragma pack(pop)
625#endif
626/* Struct for kernel processed data (Header + Descriptors) */
627#ifdef __MigPackStructs
628#pragma pack(push, 4)
629#endif
630 typedef struct {
631 mach_msg_header_t Head;
632 } __ReplyKData__mach_exception_raise_backtrace_t __attribute__((unused));
633#ifdef __MigPackStructs
634#pragma pack(pop)
635#endif
636/* Struct for pure user data */
637#ifdef __MigPackStructs
638#pragma pack(push, 4)
639#endif
640 typedef struct {
641 NDR_record_t NDR;
642 kern_return_t RetCode;
643 char padding[0]; /* Avoid generating empty UData structs */
644 } __ReplyUData__mach_exception_raise_backtrace_t __attribute__((unused));
645#ifdef __MigPackStructs
646#pragma pack(pop)
647#endif
648#endif /* !__Reply__mach_exc_subsystem__defined */
649
650
651/* union of all replies */
652
653#ifndef __ReplyUnion__catch_mach_exc_subsystem__defined
654#define __ReplyUnion__catch_mach_exc_subsystem__defined
655union __ReplyUnion__catch_mach_exc_subsystem {
656 __Reply__mach_exception_raise_t Reply_mach_exception_raise;
657 __Reply__mach_exception_raise_state_t Reply_mach_exception_raise_state;
658 __Reply__mach_exception_raise_state_identity_t Reply_mach_exception_raise_state_identity;
659 __Reply__mach_exception_raise_identity_protected_t Reply_mach_exception_raise_identity_protected;
660 __Reply__mach_exception_raise_backtrace_t Reply_mach_exception_raise_backtrace;
661};
662#endif /* __ReplyUnion__catch_mach_exc_subsystem__defined */
663
664#ifndef subsystem_to_name_map_mach_exc
665#define subsystem_to_name_map_mach_exc \
666 { "mach_exception_raise", 2405 },\
667 { "mach_exception_raise_state", 2406 },\
668 { "mach_exception_raise_state_identity", 2407 },\
669 { "mach_exception_raise_identity_protected", 2408 },\
670 { "mach_exception_raise_backtrace", 2409 }
671#endif
672
673#ifdef __AfterMigServerHeader
674__AfterMigServerHeader
675#endif /* __AfterMigServerHeader */
676
677#endif /* _mach_exc_server_ */
678