1 | /* |
2 | * Copyright (c) 2012-2013, 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_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. The rights granted to you under the License |
10 | * may not be used to create, or enable the creation or redistribution of, |
11 | * unlawful or unlicensed copies of an Apple operating system, or to |
12 | * circumvent, violate, or enable the circumvention or violation of, any |
13 | * terms of an Apple operating system software license agreement. |
14 | * |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
17 | * |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and |
24 | * limitations under the License. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | |
29 | #ifndef _TASK_CORPSE_H_ |
30 | #define _TASK_CORPSE_H_ |
31 | |
32 | #include <stdint.h> |
33 | #include <mach/mach_types.h> |
34 | #include <kern/kern_cdata.h> |
35 | #include <kern/kcdata.h> |
36 | |
37 | typedef struct kcdata_item *task_crashinfo_item_t; |
38 | |
39 | /* Deprecated: use the KCDATA_* macros for all future use */ |
40 | #define CRASHINFO_ITEM_TYPE(item) KCDATA_ITEM_TYPE(item) |
41 | #define CRASHINFO_ITEM_SIZE(item) KCDATA_ITEM_SIZE(item) |
42 | #define CRASHINFO_ITEM_DATA_PTR(item) KCDATA_ITEM_DATA_PTR(item) |
43 | |
44 | #define (item) KCDATA_ITEM_NEXT_HEADER(item) |
45 | |
46 | #define CRASHINFO_ITEM_FOREACH(head) KCDATA_ITEM_FOREACH(head) |
47 | |
48 | |
49 | #ifndef KERNEL |
50 | #define task_crashinfo_get_data_with_desc kcdata_get_data_with_desc |
51 | |
52 | #endif /* KERNEL */ |
53 | |
54 | #ifdef XNU_KERNEL_PRIVATE |
55 | |
56 | #ifdef CONFIG_EXCLAVES |
57 | /* Larger buffer to accomodate exclave backtrace info */ |
58 | #define CORPSEINFO_ALLOCATION_SIZE (1024 * 48) |
59 | #else |
60 | #define CORPSEINFO_ALLOCATION_SIZE (1024 * 16) |
61 | #endif /* CONFIG_EXCLAVES */ |
62 | #define BTINFO_ALLOCATION_SIZE (1024 * 20) |
63 | |
64 | #if XNU_TARGET_OS_WATCH |
65 | #define TOTAL_CORPSES_ALLOWED 4 |
66 | #else /* XNU_TARGET_OS_WATCH */ |
67 | #define TOTAL_CORPSES_ALLOWED 5 |
68 | #endif /* XNU_TARGET_OS_WATCH */ |
69 | |
70 | #define TOTAL_USER_FAULTS_ALLOWED 1 |
71 | |
72 | #if DEBUG || DEVELOPMENT |
73 | extern bool corpse_threshold_system_limit; |
74 | #endif /* DEBUG || DEVELOPMENT */ |
75 | extern bool exc_via_corpse_forking; |
76 | extern bool corpse_for_fatal_memkill; |
77 | |
78 | extern kern_return_t task_mark_corpse(task_t task); |
79 | |
80 | extern kern_return_t task_deliver_crash_notification(task_t, thread_t, exception_type_t, mach_exception_subcode_t); |
81 | |
82 | /* In the corpseinfo kcd_user_flags */ |
83 | __options_closed_decl(corpse_flags_t, uint16_t, { |
84 | CORPSE_CRASHINFO_HAS_REF = 0x1, |
85 | CORPSE_CRASHINFO_USER_FAULT = 0x2 |
86 | }); |
87 | |
88 | extern kcdata_descriptor_t task_get_corpseinfo(task_t task); |
89 | |
90 | extern kcdata_descriptor_t task_crashinfo_alloc_init( |
91 | mach_vm_address_t crash_data_p, |
92 | unsigned size, corpse_flags_t kc_u_flags, unsigned kc_flags); |
93 | extern kcdata_descriptor_t task_btinfo_alloc_init( |
94 | mach_vm_address_t addr, unsigned size); |
95 | extern kern_return_t task_crashinfo_destroy(kcdata_descriptor_t data); |
96 | |
97 | extern unsigned long total_corpses_count(void) __attribute__((pure)); |
98 | extern boolean_t corpses_enabled(void); |
99 | |
100 | extern kern_return_t task_generate_corpse_internal( |
101 | task_t task, |
102 | task_t *corpse_task, |
103 | thread_t *thread, |
104 | exception_type_t etype, |
105 | mach_exception_data_type_t code, |
106 | mach_exception_data_type_t subcode, |
107 | void *reason); |
108 | |
109 | extern void task_clear_corpse(task_t task); |
110 | |
111 | extern kern_return_t task_duplicate_map_and_threads( |
112 | task_t task, |
113 | void *p, |
114 | task_t new_task, |
115 | thread_t *thread, |
116 | uint64_t **udata_buffer, |
117 | int *size, |
118 | int *num_udata, |
119 | bool for_exception); |
120 | |
121 | extern kern_return_t task_enqueue_exception_with_corpse( |
122 | task_t task, |
123 | exception_type_t etype, |
124 | mach_exception_data_t code, |
125 | mach_msg_type_number_t codeCnt, |
126 | void *reason, |
127 | boolean_t lightweight); |
128 | |
129 | extern kern_return_t current_thread_collect_backtrace_info( |
130 | kcdata_descriptor_t *new_desc, |
131 | exception_type_t etype, |
132 | mach_exception_data_t code, |
133 | mach_msg_type_number_t codeCnt, |
134 | void *reason); |
135 | |
136 | extern void task_add_to_corpse_task_list(task_t corpse_task); |
137 | void task_remove_from_corpse_task_list(task_t corpse_task); |
138 | void task_purge_all_corpses(void); |
139 | kern_return_t find_corpse_task_by_uniqueid_grp(uint64_t uid, task_t *target, task_grp_t grp); |
140 | extern uint64_t task_corpse_get_crashed_thread_id(task_t corpse_task); |
141 | |
142 | #endif /* XNU_KERNEL_PRIVATE */ |
143 | |
144 | #endif /* _TASK_CORPSE_H_ */ |
145 | |