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