1/* 2 * Copyright (c) 2002-20014 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#define PROC_NAME_LEN 100 28#define BUFSTR_LEN 30 29 30 31/* common struct to hold all configurations, static and args based */ 32struct prog_configs { 33 boolean_t show_all_tasks; 34 boolean_t show_voucher_details; 35 boolean_t verbose; 36 int voucher_detail_length; 37 pid_t pid; /* if user focusing only one pid */ 38 39}; 40 41extern struct prog_configs lsmp_config; 42 43/* private structure to wrap up per-task info */ 44typedef struct my_per_task_info { 45 task_t task; 46 pid_t pid; 47 vm_address_t task_kobject; 48 ipc_info_space_t info; 49 ipc_info_name_array_t table; 50 mach_msg_type_number_t tableCount; 51 ipc_info_tree_name_array_t tree; 52 mach_msg_type_number_t treeCount; 53 boolean_t valid; /* TRUE if all data is accurately collected */ 54 char processName[PROC_NAME_LEN]; 55} my_per_task_info_t; 56 57 58/* 59 * WARNING - these types are copied from xnu/osfmk/kern/ipc_kobject.h 60 * Need to stay in sync to print accurate results. 61 */ 62#define IKOT_NONE 0 63#define IKOT_THREAD 1 64#define IKOT_TASK 2 65#define IKOT_HOST 3 66#define IKOT_HOST_PRIV 4 67#define IKOT_PROCESSOR 5 68#define IKOT_PSET 6 69#define IKOT_PSET_NAME 7 70#define IKOT_TIMER 8 71#define IKOT_PAGING_REQUEST 9 72#define IKOT_MIG 10 73#define IKOT_MEMORY_OBJECT 11 74#define IKOT_XMM_PAGER 12 75#define IKOT_XMM_KERNEL 13 76#define IKOT_XMM_REPLY 14 77#define IKOT_UND_REPLY 15 78#define IKOT_HOST_NOTIFY 16 79#define IKOT_HOST_SECURITY 17 80#define IKOT_LEDGER 18 81#define IKOT_MASTER_DEVICE 19 82#define IKOT_TASK_NAME 20 83#define IKOT_SUBSYSTEM 21 84#define IKOT_IO_DONE_QUEUE 22 85#define IKOT_SEMAPHORE 23 86#define IKOT_LOCK_SET 24 87#define IKOT_CLOCK 25 88#define IKOT_CLOCK_CTRL 26 89#define IKOT_IOKIT_SPARE 27 90#define IKOT_NAMED_ENTRY 28 91#define IKOT_IOKIT_CONNECT 29 92#define IKOT_IOKIT_OBJECT 30 93#define IKOT_UPL 31 94#define IKOT_MEM_OBJ_CONTROL 32 95#define IKOT_AU_SESSIONPORT 33 96#define IKOT_FILEPORT 34 97#define IKOT_LABELH 35 98#define IKOT_TASK_RESUME 36 99#define IKOT_VOUCHER 37 100#define IKOT_VOUCHER_ATTR_CONTROL 38 101#define IKOT_UNKNOWN 39 /* magic catchall */ 102#define IKOT_MAX_TYPE (IKOT_UNKNOWN+1) /* # of IKOT_ types */ 103 104#define SHOW_PORT_STATUS_FLAGS(flags) \ 105 (flags & MACH_PORT_STATUS_FLAG_TEMPOWNER) ?"T":"-", \ 106 (flags & MACH_PORT_STATUS_FLAG_GUARDED) ?"G":"-", \ 107 (flags & MACH_PORT_STATUS_FLAG_STRICT_GUARD) ?"S":"-", \ 108 (flags & MACH_PORT_STATUS_FLAG_IMP_DONATION) ?"I":"-", \ 109 (flags & MACH_PORT_STATUS_FLAG_REVIVE) ?"R":"-", \ 110 (flags & MACH_PORT_STATUS_FLAG_TASKPTR) ?"P":"-" 111 112 113void show_recipe_detail(mach_voucher_attr_recipe_t recipe); 114void show_voucher_detail(mach_port_t task, mach_port_name_t voucher); 115 116/* mach port related functions */ 117const char * kobject_name(natural_t kotype); 118void get_receive_port_context(task_t taskp, mach_port_name_t portname, mach_port_context_t *context); 119int get_recieve_port_status(task_t taskp, mach_port_name_t portname, mach_port_info_ext_t *info); 120void show_task_mach_ports(my_per_task_info_t *taskinfo, uint32_t taskCount, my_per_task_info_t *allTaskInfos); 121 122/* task and thread related helper functions */ 123kern_return_t collect_per_task_info(my_per_task_info_t *taskinfo, task_t target_task); 124my_per_task_info_t * allocate_taskinfo_memory(uint32_t taskCount); 125void deallocate_taskinfo_memory(my_per_task_info_t *data); 126kern_return_t print_task_exception_info(my_per_task_info_t *taskinfo); 127kern_return_t print_task_threads_special_ports(my_per_task_info_t *taskinfo); 128my_per_task_info_t * get_taskinfo_by_kobject(natural_t kobj); 129 130void get_exc_behavior_string(exception_behavior_t b, char *out_string, size_t len); 131void get_exc_mask_string(exception_mask_t m, char *out_string, size_t len); 132kern_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); 133 134/* basic util functions */ 135void print_hex_data(char *prefix, char *desc, void *addr, int len); 136 137#endif 138