]> git.saurik.com Git - apple/system_cmds.git/blob - lsmp.tproj/common.h
ea07dc22cdee60e3ee4bb18c98b2961bbf44beb8
[apple/system_cmds.git] / lsmp.tproj / common.h
1 /*
2 * Copyright (c) 2002-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23
24 #ifndef system_cmds_common_h
25 #define system_cmds_common_h
26
27 #include <mach/mach.h>
28
29 #define PROC_NAME_LEN 100
30 #define BUFSTR_LEN 30
31 #define VOUCHER_DETAIL_MAXLEN 1024
32
33 /* common struct to hold all configurations, static and args based */
34 struct prog_configs {
35 boolean_t show_all_tasks;
36 boolean_t show_voucher_details;
37 boolean_t verbose;
38 int voucher_detail_length;
39 pid_t pid; /* if user focusing only one pid */
40 };
41
42 extern struct prog_configs lsmp_config;
43
44 /* exception port information */
45 struct exc_port_info {
46 mach_msg_type_number_t count;
47 mach_port_t ports[EXC_TYPES_COUNT];
48 exception_mask_t masks[EXC_TYPES_COUNT];
49 exception_behavior_t behaviors[EXC_TYPES_COUNT];
50 thread_state_flavor_t flavors[EXC_TYPES_COUNT];
51 };
52
53 /* private structure to hold thread specific information */
54 struct my_per_thread_info {
55 mach_port_t thread;
56 uint32_t th_kobject;
57 uint64_t th_id;
58 char * voucher_detail;
59 };
60
61 /* kobject to name hash table declarations */
62 #define K2N_TABLE_SIZE 256
63
64 struct k2n_table_node {
65 natural_t kobject; /* kobject referred to by the name -- the key into the table */
66 ipc_info_name_t *info_name; /* info about the name that refers to the key kobject -- value of the table */
67 struct k2n_table_node *next;
68 };
69
70 struct k2n_table_node *k2n_table_lookup_next(struct k2n_table_node *node, natural_t kobject);
71 struct k2n_table_node *k2n_table_lookup(struct k2n_table_node **table, natural_t kobject);
72
73 /* private structure to wrap up per-task info */
74 typedef struct my_per_task_info {
75 task_t task;
76 pid_t pid;
77 vm_address_t task_kobject;
78 ipc_info_space_t info;
79 ipc_info_name_array_t table;
80 mach_msg_type_number_t tableCount;
81 ipc_info_tree_name_array_t tree;
82 mach_msg_type_number_t treeCount;
83 boolean_t valid; /* TRUE if all data is accurately collected */
84 struct k2n_table_node *k2ntable[K2N_TABLE_SIZE];
85 char processName[PROC_NAME_LEN];
86 struct exc_port_info exceptionInfo;
87 struct my_per_thread_info * threadInfos; /* dynamically allocated in collect_per_task_info */
88 unsigned int threadCount;
89 struct exc_port_info *threadExceptionInfos; /* this is 2 dimensional array with threadCount X struct exc_port_info of ports */
90 } my_per_task_info_t;
91
92
93 /*
94 * WARNING - these types are copied from xnu/osfmk/kern/ipc_kobject.h
95 * Need to stay in sync to print accurate results.
96 */
97 #define IKOT_NONE 0
98 #define IKOT_THREAD 1
99 #define IKOT_TASK 2
100 #define IKOT_HOST 3
101 #define IKOT_HOST_PRIV 4
102 #define IKOT_PROCESSOR 5
103 #define IKOT_PSET 6
104 #define IKOT_PSET_NAME 7
105 #define IKOT_TIMER 8
106 #define IKOT_PAGING_REQUEST 9
107 #define IKOT_MIG 10
108 #define IKOT_MEMORY_OBJECT 11
109 #define IKOT_XMM_PAGER 12
110 #define IKOT_XMM_KERNEL 13
111 #define IKOT_XMM_REPLY 14
112 #define IKOT_UND_REPLY 15
113 #define IKOT_HOST_NOTIFY 16
114 #define IKOT_HOST_SECURITY 17
115 #define IKOT_LEDGER 18
116 #define IKOT_MASTER_DEVICE 19
117 #define IKOT_TASK_NAME 20
118 #define IKOT_SUBSYSTEM 21
119 #define IKOT_IO_DONE_QUEUE 22
120 #define IKOT_SEMAPHORE 23
121 #define IKOT_LOCK_SET 24
122 #define IKOT_CLOCK 25
123 #define IKOT_CLOCK_CTRL 26
124 #define IKOT_IOKIT_SPARE 27
125 #define IKOT_NAMED_ENTRY 28
126 #define IKOT_IOKIT_CONNECT 29
127 #define IKOT_IOKIT_OBJECT 30
128 #define IKOT_UPL 31
129 #define IKOT_MEM_OBJ_CONTROL 32
130 #define IKOT_AU_SESSIONPORT 33
131 #define IKOT_FILEPORT 34
132 #define IKOT_LABELH 35
133 #define IKOT_TASK_RESUME 36
134 #define IKOT_VOUCHER 37
135 #define IKOT_VOUCHER_ATTR_CONTROL 38
136 #define IKOT_UNKNOWN 39 /* magic catchall */
137 #define IKOT_MAX_TYPE (IKOT_UNKNOWN+1) /* # of IKOT_ types */
138
139 #define SHOW_PORT_STATUS_FLAGS(flags) \
140 (flags & MACH_PORT_STATUS_FLAG_TEMPOWNER) ?"T":"-", \
141 (flags & MACH_PORT_STATUS_FLAG_GUARDED) ?"G":"-", \
142 (flags & MACH_PORT_STATUS_FLAG_STRICT_GUARD) ?"S":"-", \
143 (flags & MACH_PORT_STATUS_FLAG_IMP_DONATION) ?"I":"-", \
144 (flags & MACH_PORT_STATUS_FLAG_REVIVE) ?"R":"-", \
145 (flags & MACH_PORT_STATUS_FLAG_TASKPTR) ?"P":"-"
146
147
148 uint32_t show_recipe_detail(mach_voucher_attr_recipe_t recipe, char * voucher_outstr, uint32_t maxlen);
149 char *copy_voucher_detail(mach_port_t task, mach_port_name_t voucher);
150
151 /* mach port related functions */
152 const char * kobject_name(natural_t kotype);
153 void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context);
154 int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info);
155 void show_task_mach_ports(my_per_task_info_t *taskinfo, uint32_t taskCount, my_per_task_info_t *allTaskInfos);
156
157 /* task and thread related helper functions */
158 kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task);
159 my_per_task_info_t * allocate_taskinfo_memory(uint32_t taskCount);
160 void deallocate_taskinfo_memory(my_per_task_info_t *data);
161 kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo);
162 kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo);
163 my_per_task_info_t * get_taskinfo_by_kobject(natural_t kobj);
164
165 void get_exc_behavior_string(exception_behavior_t b, char *out_string, size_t len);
166 void get_exc_mask_string(exception_mask_t m, char *out_string, size_t len);
167 kern_return_t get_taskinfo_of_receiver_by_send_right(ipc_info_name_t *sendright, my_per_task_info_t **out_taskinfo, mach_port_name_t *out_recv_info);
168 kern_return_t get_ipc_info_from_lsmp_spaceinfo(mach_port_t port_name, ipc_info_name_t *out_sendright);
169
170 /* basic util functions */
171 uint32_t print_hex_data(char *outstr, size_t maxlen, char *prefix, char *desc, void *addr, int len);
172
173 #endif