1#!/usr/bin/env python 2 3""" This file holds all static values that debugging macros need. These are typically object type strings, #defines in C etc. 4 The objective is to provide a single place to be the bridge between C code in xnu and the python macros used by lldb. 5 If you define a variable which has been copied/referred over from C code and has high chance of changing over time. It would 6 be best to define a supporting function of format "populate_<variable_name>". This will help in running them to repopulate. 7 8 Note: The Format of the function has to be populate_<variable_name> so that the automated updating will pick it up. 9""" 10import os, re 11 12def GetStateString(strings_dict, state): 13 """ Turn a dictionary from flag value to flag name and a state mask with 14 those flags into a space-separated string of names. 15 16 params: 17 strings_dict: a dictionary of flag values to flag names 18 state: the value to get the state string of 19 return: 20 a space separated list of flag names present in state 21 """ 22 max_mask = max(strings_dict.keys()) 23 24 first = True 25 output = '' 26 mask = 0x1 27 while mask <= max_mask: 28 bit = int(state & mask) 29 if bit: 30 if bit in strings_dict: 31 if not first: 32 output += ' ' 33 else: 34 first = False 35 output += strings_dict[int(state & mask)] 36 else: 37 output += '{:#x}'.format(mask) 38 mask = mask << 1 39 40 return output 41 42KDBG_NOWRAP = 0x00000002 43KDBG_WRAPPED = 0x00000008 44KDBG_TYPEFILTER_CHECK = 0x00400000 45KDBG_BUFINIT = 0x80000000 46KDCOPYBUF_COUNT = 8192 47KDS_PTR_NULL = 0xffffffff 48DBG_FUNC_START = 0x01 49DBG_FUNC_END = 0x02 50 51kdebug_flags_strings = { 0x00100000: 'RANGECHECK', 52 0x00200000: 'VALCHECK', 53 KDBG_TYPEFILTER_CHECK: 'TYPEFILTER_CHECK', 54 KDBG_BUFINIT: 'BUFINIT' } 55 56kperf_samplers_strings = { 1 << 0: 'TH_INFO', 57 1 << 1: 'TH_SNAP', 58 1 << 2: 'KSTACK', 59 1 << 3: 'USTACK', 60 1 << 4: 'PMC_THREAD', 61 1 << 5: 'PMC_CPU', 62 1 << 6: 'PMC_CONFIG', 63 1 << 7: 'MEMINFO', 64 1 << 8: 'TH_SCHED', 65 1 << 9: 'TH_DISP', 66 1 << 10: 'TK_SNAP' } 67 68lcpu_self = 0xFFFE 69arm_level2_access_strings = [ " noaccess", 70 " supervisor(readwrite) user(noaccess)", 71 " supervisor(readwrite) user(readonly)", 72 " supervisor(readwrite) user(readwrite)", 73 " noaccess(reserved)", 74 " supervisor(readonly) user(noaccess)", 75 " supervisor(readonly) user(readonly)", 76 " supervisor(readonly) user(readonly)", 77 " " 78 ] 79 80thread_qos_short_strings = { 0: '--', 81 1: 'MT', 82 2: 'BG', 83 3: 'UT', 84 4: 'DF', 85 5: 'IN', 86 6: 'UI', 87 7: 'MG' } 88 89KQWQ_NBUCKETS = 7 90KQWL_NBUCKETS = 6 91 92DTYPE_VNODE = 1 93DTYPE_SOCKET = 2 94DTYPE_PSXSHM = 3 95DTYPE_PSXSEM = 4 96DTYPE_KQUEUE = 5 97DTYPE_PIPE = 6 98DTYPE_FSEVENTS = 7 99DTYPE_ATALK = 8 100DTYPE_NETPOLICY = 9 101filetype_strings = { DTYPE_VNODE: 'VNODE', 102 DTYPE_SOCKET: 'SOCKET', 103 DTYPE_PSXSHM: 'PSXSHM', 104 DTYPE_PSXSEM: 'PSXSEM', 105 DTYPE_KQUEUE: 'KQUEUE', 106 DTYPE_PIPE: 'PIPE', 107 DTYPE_FSEVENTS: 'FSEVENTS', 108 DTYPE_ATALK: 'APLTALK', 109 DTYPE_NETPOLICY: 'NETPOLI' 110 } 111 112 113MACH_PORT_DEAD = 0xffffffffffffffff 114IPC_OBJECT_DEAD = MACH_PORT_DEAD 115 116mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"} 117 118proc_state_strings = ["", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping"] 119proc_flag_explain_strings = { 120 0x00000001: 'may hold advisory locks', 121 0x00000002: 'has a controlling tty', 122 # Also used to singal 32-bit process. 123 0x00000004: 'process is 64 bit', 124 0x00000008: 'No SIGCHLD on child stop', 125 0x00000010: 'waiting for child exec/exit', 126 0x00000020: 'has started profiling', 127 0x00000040: 'in select; wakeup/waiting danger', 128 0x00000080: 'was stopped and continued', 129 0x00000100: 'has set privileges since last exec', 130 0x00000200: 'system process: no signals, stats, or swap', 131 0x00000400: 'timing out during sleep', 132 0x00000800: 'debugged process being traced', 133 0x00001000: 'address space layout randomization disabled', 134 0x00002000: 'exit in progress', 135 0x00004000: 'process has called exec', 136 0x00008000: 'owe process an addupc()', 137 0x00010000: 'affinity for Rosetta children', 138 0x00020000: 'wants to run Rosetta', 139 0x00040000: 'has wait() in progress', 140 0x00080000: 'checks for OPENEVT flag set on open', 141 0x00100000: 'can call vfs_markdependency()', 142 0x00200000: 'has called reboot()', 143 0x00400000: 'Reserved', 144 0x00800000: 'Reserved', 145 0x01000000: 'has thread cwd', 146 0x02000000: 'Reserved', 147 0x04000000: 'process has adopted persona', 148 0x08000000: 'Reserved', 149 0x10000000: 'no shared libraries', 150 0x20000000: 'force quota on root', 151 0x40000000: 'no zombies when children exit', 152 0x80000000: 'no hangs on remote FS ops' 153 } 154 155FSHIFT = 11 156FSCALE = 1 << FSHIFT 157 158DBG_TRACE = 1 159DBG_TRACE_INFO = 2 160RAW_VERSION1 = 0x55aa0101 161EVENTS_PER_STORAGE_UNIT = 2048 162 163EMBEDDED_PANIC_MAGIC = 0x46554E4B 164EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x02 165 166MACOS_PANIC_MAGIC = 0x44454544 167MACOS_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x04 168 169AURR_PANIC_MAGIC = 0x41555252 170AURR_PANIC_VERSION = 1 171 172CRASHLOG_PANIC_STRING_LEN = 32 173AURR_CRASHLOG_PANIC_VERSION = 2 174 175# File:EXTERNAL_HEADER/mach-o/loader.h 176# (struct proc *)->p_proc_ro->p_platform_data.p_platform 177P_PLATFORM_MACOS = 1 178P_PLATFORM_IOS = 2 179P_PLATFORM_TVOS = 3 180P_PLATFORM_WATCHOS = 4 181P_PLATFORM_BRIDGEOS = 5 182P_PLATFORM_MACCATALYST = 6 183P_PLATFORM_IOSSIMULATOR = 7 184P_PLATFORM_TVOSSIMULATOR = 8 185P_PLATFORM_WATCHOSSIMULATOR = 9 186P_PLATFORM_DRIVERKIT = 10 187 188# File: osfmk/ipc/ipc_object.h 189IO_BITS_ACTIVE = 0x80000000 190IO_BITS_KOTYPE = 0x3ff 191 192# File: kern_memorystatus.h 193JETSAM_PRIORITY_MAX = 210 194P_MEMSTAT_FROZEN = 0x00000002 195 196 197P_PLATFORM_MACOSEXCLAVEKIT = 16 198P_PLATFORM_IOSEXCLAVEKIT = 18 199 200#File: osfmk/ipc/ipc_importance.h 201IIE_TYPE_BITS = 1 202IIE_TYPE_MASK = ((1 << IIE_TYPE_BITS) - 1) 203IIE_TYPE_TASK = 0x00000000 204IIE_TYPE_INHERIT = 0x00000001 205 206#File: osfmk/mach/mach_voucher_types.h 207MACH_VOUCHER_ATTR_KEY_NONE = 0 208MACH_VOUCHER_ATTR_KEY_NUM_WELL_KNOWN = 8 209IV_UNUSED_KEYINDEX = ~0 210MACH_VOUCHER_ATTR_KEY_ALL = ~0 211MACH_VOUCHER_ATTR_KEY_NUM = 8 212 213if __name__ == "__main__": 214 pass 215 216