18 kr = mach_port_deallocate(mach_task_self(), thread->
port);
19 if (kr != KERN_SUCCESS) {
20 eprintf(
"failed to deallocate thread port\n");
29 #if __x86_64__ || __i386__
31 thread->
count = x86_DEBUG_STATE_COUNT;
33 ?
sizeof(x86_debug_state64_t)
34 :
sizeof(x86_debug_state32_t);
35 thread->
state = &thread->drx.uds;
36 rc = thread_get_state(thread->
port, thread->
flavor,
37 (thread_state_t)&thread->drx, &thread->
count);
38 #elif __arm64__ || __arm64 || __aarch64 || __aarch64__
40 thread->
count = ARM_DEBUG_STATE64_COUNT;
41 thread->
flavor = ARM_DEBUG_STATE64;
42 rc = thread_get_state(thread->
port, thread->
flavor,
43 (thread_state_t)&thread->debug.drx64,
46 thread->
count = ARM_DEBUG_STATE32_COUNT;
47 thread->
flavor = ARM_DEBUG_STATE32;
48 rc = thread_get_state(thread->
port, thread->
flavor,
49 (thread_state_t)&thread->debug.drx32,
52 #elif __arm__ || __arm || __armv7__
53 thread->
count = ARM_DEBUG_STATE_COUNT;
54 thread->
flavor = ARM_DEBUG_STATE;
55 rc = thread_get_state(thread->
port, thread->
flavor,
56 (thread_state_t)&thread->debug.drx,
59 #warning xnu_thread_get_drx: Unsupported architecture
62 if (rc != KERN_SUCCESS) {
73 #if __i386__ || __x86_64__
74 x86_debug_state_t *
regs = &thread->drx;
79 thread->
count = x86_DEBUG_STATE_COUNT;
82 regs->dsh.count = x86_DEBUG_STATE64_COUNT;
85 regs->dsh.count = x86_DEBUG_STATE32_COUNT;
87 rc = thread_set_state(thread->
port, thread->
flavor,
89 #elif __arm64__ || __arm64 || __aarch64 || __aarch64__
91 thread->
count = ARM_DEBUG_STATE64_COUNT;
92 thread->
flavor = ARM_DEBUG_STATE64;
93 rc = thread_set_state(thread->
port, thread->
flavor,
94 (thread_state_t)&thread->debug.drx64,
97 thread->
count = ARM_DEBUG_STATE32_COUNT;
98 thread->
flavor = ARM_DEBUG_STATE32;
99 rc = thread_set_state(thread->
port, thread->
flavor,
100 (thread_state_t)&thread->debug.drx32,
103 #elif __arm__ || __arm || __armv7__
104 thread->
count = ARM_DEBUG_STATE_COUNT;
105 thread->
flavor = ARM_DEBUG_STATE;
106 rc = thread_set_state(thread->
port, thread->
flavor,
107 (thread_state_t)&thread->debug.drx,
111 #ifndef PPC_DEBUG_STATE32
112 #define PPC_DEBUG_STATE32 1
114 ppc_debug_state_t *
regs;
119 regs->dsh.flavor = 0;
122 if (rc != KERN_SUCCESS) {
133 RZ_REG_T *
regs = (RZ_REG_T *)&thread->
gpr;
137 #if __i386__ || __x86_64__
149 regs->tsh.count = x86_THREAD_STATE32_COUNT;
151 #elif __arm64 || __aarch64 || __arm64__ || __aarch64__
154 thread->
flavor = ARM_UNIFIED_THREAD_STATE;
155 thread->
count = ARM_UNIFIED_THREAD_STATE_COUNT;
160 thread->
flavor = ARM_THREAD_STATE64;
161 thread->
count = ARM_THREAD_STATE64_COUNT;
162 thread->
state_size =
sizeof(arm_thread_state64_t);
164 thread->
flavor = ARM_THREAD_STATE32;
165 thread->
count = ARM_THREAD_STATE32_COUNT;
166 thread->
state_size =
sizeof(arm_thread_state32_t);
168 #elif __arm || __arm__ || __armv7__
169 thread->
flavor = ARM_THREAD_STATE;
170 thread->
count = ARM_THREAD_STATE_COUNT;
171 thread->
state_size =
sizeof(arm_thread_state_t);
174 rc = thread_set_state(thread->
port, thread->
flavor,
176 if (rc != KERN_SUCCESS) {
193 #elif __arm64 || __aarch64 || __aarch64__ || __arm64__
197 thread->
flavor = ARM_THREAD_STATE64;
198 thread->
count = ARM_THREAD_STATE64_COUNT;
199 thread->
state_size =
sizeof(arm_thread_state64_t);
201 thread->
flavor = ARM_THREAD_STATE;
202 thread->
count = ARM_THREAD_STATE_COUNT;
203 thread->
state_size =
sizeof(arm_thread_state32_t);
205 #elif __arm || __arm__ || __armv7__
207 thread->
flavor = ARM_THREAD_STATE;
208 thread->
count = ARM_THREAD_STATE_COUNT;
209 thread->
state_size =
sizeof(arm_thread_state_t);
210 #elif __x86_64__ || __i386__
216 rc = thread_get_state(thread->
port, thread->
flavor,
218 if (rc != KERN_SUCCESS) {
231 mach_msg_type_number_t
count = THREAD_BASIC_INFO_COUNT;
232 thread_identifier_info_data_t identifier_info;
233 kern_return_t kr = thread_info(thread->
port, THREAD_BASIC_INFO,
235 if (kr != KERN_SUCCESS) {
236 eprintf(
"Fail to get thread_basic_info\n");
239 count = THREAD_IDENTIFIER_INFO_COUNT;
240 kr = thread_info(thread->
port, THREAD_IDENTIFIER_INFO,
241 (thread_info_t)&identifier_info, &
count);
242 if (kr != KERN_SUCCESS) {
243 eprintf(
"Fail to get thread_identifier_info\n");
251 struct proc_threadinfo proc_threadinfo;
252 int ret_proc = proc_pidinfo(
dbg->
pid, PROC_PIDTHREADINFO,
253 identifier_info.thread_handle,
254 &proc_threadinfo, PROC_PIDTHREADINFO_SIZE);
255 if (ret_proc && proc_threadinfo.pth_name[0]) {
256 thread->
name =
strdup(proc_threadinfo.pth_name);
287 return (
a && port && (
a->port == *port)) ? 0 : 1;
291 thread_array_t thread_list =
NULL;
292 unsigned int thread_count = 0;
310 kr = task_threads(task, &thread_list, &thread_count);
311 if (kr != KERN_SUCCESS) {
314 eprintf(
"Failed to get list of task's threads\n");
319 for (
i = 0;
i < thread_count;
i++) {
322 eprintf(
"Failed to fill_thread\n");
326 eprintf(
"Failed to add thread to list\n");
337 for (
i = 0;
i < thread_count;
i++) {
338 if (thread->
port == thread_list[
i]) {
353 for (
i = 0;
i < thread_count;
i++) {
360 kr = mach_port_deallocate(mach_task_self(),
362 if (kr != KERN_SUCCESS) {
363 eprintf(
"Failed to deallocate port\n");
373 (void)vm_deallocate(mach_task_self(), (mach_vm_address_t)thread_list,
374 thread_count *
sizeof(thread_t));
379 if (!
dbg || tid < 0) {
383 eprintf(
"Failed to update thread_list xnu_udpate_thread_list\n");
394 eprintf(
"Thread not found get_xnu_thread\n");
405 unsigned int n_threads = 0;
410 if (task_threads(t, &
threads, &n_threads) != KERN_SUCCESS) {
418 vm_deallocate(mach_task_self(), (vm_address_t)
threads, n_threads *
sizeof(thread_act_t));
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define x86_THREAD_STATE_COUNT
#define x86_THREAD_STATE64_COUNT
#define rz_return_val_if_fail(expr, val)
void(* RzListFree)(void *ptr)
int(* RzListComparator)(const void *value, const void *list_data)
thread_basic_info_data_t basic_info
static uv_thread_t * threads
if(dbg->bits==RZ_SYS_BITS_64)
task_t pid_to_task(int pid)
#define LOG_MACH_ERROR(name, rc)
RZ_IPI bool rz_xnu_thread_set_gpr(RzDebug *dbg, xnu_thread_t *thread)
RZ_IPI int rz_xnu_update_thread_list(RzDebug *dbg)
RZ_IPI xnu_thread_t * rz_xnu_get_thread(RzDebug *dbg, int tid)
static bool xnu_fill_info_thread(RzDebug *dbg, xnu_thread_t *thread)
static void xnu_thread_free(xnu_thread_t *thread)
static int xnu_update_thread_info(RzDebug *dbg, xnu_thread_t *thread)
static xnu_thread_t * xnu_get_thread_with_info(RzDebug *dbg, thread_t port)
RZ_IPI thread_t rz_xnu_get_cur_thread(RzDebug *dbg)
RZ_IPI bool rz_xnu_thread_set_drx(RzDebug *dbg, xnu_thread_t *thread)
RZ_IPI bool rz_xnu_thread_get_gpr(RzDebug *dbg, xnu_thread_t *thread)
static int thread_find(thread_t *port, xnu_thread_t *a)
RZ_IPI bool rz_xnu_thread_get_drx(RzDebug *dbg, xnu_thread_t *thread)