1 #ifndef __PLATFORM_INTROSPECTION_H__
2 #define __PLATFORM_INTROSPECTION_H__
4 #include <mach/mach_types.h>
5 #include <mach/thread_info.h>
6 #include <mach/thread_status.h>
12 typedef struct platform_task_s
*platform_task_t
;
13 typedef struct platform_thread_s
*platform_thread_t
;
16 * @typedef platform_thread_id_t
19 * The type of the 64-bit system-wide unique thread ID.
21 typedef uint64_t platform_thread_id_t
;
23 /*! @functiongroup Tasks */
26 * @function platform_task_attach
29 * Attach to a process (specified by its mach task port) for debugging. This
30 * function creates a new task handle which must be disposed by a call to
31 * platform_task_detach().
34 * On output, a newly created task handle.
37 * The mach task port of the target process.
40 * KERN_SUCCESS if the process was successfully attached, otherwise a mach
44 platform_task_attach(platform_task_t
*task
, task_t target
);
47 * @function platform_task_detach
50 * Detaches from the target task and deallocates all memory associated with
54 * The task handle to detach.
57 * KERN_SUCCESS if the process was successfully detached, otherwise a mach
61 platform_task_detach(platform_task_t task
);
64 * @function platform_task_is_64_bit
67 * Returns true if the target task is LP64.
70 * A handle to the target task.
73 * true if the target task is LP64, otherwise false.
76 platform_task_is_64_bit(platform_task_t task
);
79 * @function platform_task_suspend_threads
82 * Suspends all the threads in the target task. This differs from task_suspend
83 * in that the task itself is not suspended, only the individual threads. While
84 * this suspension is in effect, any newly created threads will be created in
85 * a suspended state. The debuger may resume an individual thread for execution
86 * using platform_thread_resume() or evaluate an expression in the context of
87 * the task or a specific thread using platform_task_perform() and
88 * platform_thread_perform(), respectively. All threads in the task may be
89 * resumed with platform_task_resume_threads().
92 * A handle to the target task.
95 * KERN_SUCCESS if the threads were successfully suspended, otherwise a mach
99 platform_task_suspend_threads(platform_task_t task
);
102 * @function platform_task_resume_threads
105 * Resumes the threads in the target task. See platform_task_suspend_threads().
108 * A handle to the target task.
111 platform_task_resume_threads(platform_task_t task
);
114 * @function platform_task_perform
117 * Performs the specified function on a newly created thread in the target task.
118 * This newly created thread will execute even if the threads in the task are
119 * suspended as the result of a call to platform_task_suspend_threads().
121 * The function and context addresses are in the virtual address space of the
122 * target task. It is the responsiblity of the debugger to have previously
123 * mapped executable text and data at these addresses in the target task.
126 * A handle to the target task.
129 * The address (in the virtual address space of the target task) of the
130 * function to perform. The function should be of type (void (*)(void *))
131 * and will be passed the value of the data_addr parameter.
134 * The address (in the virtual address space of the target task) of the
135 * data to pass as a parameter to the function to perform.
138 * KERN_SUCCESS if the function was successfully performed, otherwise a mach
142 platform_task_perform(platform_task_t task
,
143 mach_vm_address_t func_addr
,
144 mach_vm_address_t data_addr
);
147 * @function platform_task_update_threads
150 * Updates an internal representation of all threads in the target task. The
151 * list of threads may then be iterated using platform_task_copy_next_thread().
153 * Calling this function resets any iteration currently in progress and a
154 * subsequent call to platform_task_copy_next_thread() will return the first
155 * thread in the list.
158 * A handle to the target task.
161 * KERN_SUCCESS if the threads were successfully updated, otherwise a mach
165 platform_task_update_threads(platform_task_t task
);
168 * @function platform_task_copy_next_thread
171 * Iterates the list of threads in the task. Returns a copied thread handle
172 * which must subsequently be released using platform_thread_release().
174 * The platform_task_update_threads() function must be called before this
175 * function will return any thread handles. A NULL pointer is returned to
176 * signify the end of the list
179 * A handle to the target task.
182 * A thread handle which must be released using platform_thread_release(),
183 * or NULL, signifying the end of the list.
186 platform_task_copy_next_thread(platform_task_t task
);
188 /*! @functiongroup Threads */
191 * @function platform_thread_get_unique_id
194 * Returns the 64-bit system-wide unique ID of the target thread.
197 * A handle to the target thread.
200 * The unique ID of the thread.
203 platform_thread_get_unique_id(platform_thread_t thread
);
206 * @function platform_thread_release
209 * Releases a thread handle obtained by platform_task_copy_next_thread().
212 * The thread handle to release.
215 platform_thread_release(platform_thread_t thread
);
218 * @function platform_thread_abort_safely
221 * Similar to thread_abort_safely().
224 * A handle to the thread to signal.
227 * KERN_SUCCESS if the thread was successfully signaled, otherwise a mach
231 platform_thread_abort_safely(platform_thread_t thread
);
234 * @function platform_thread_suspend
237 * Suspends execution of a thread similar to thread_suspend(). See also
238 * platform_task_suspend_threads().
241 * A handle to the thread to suspend.
244 * KERN_SUCCESS if the thread was successfully suspended, otherwise a mach
248 platform_thread_suspend(platform_thread_t thread
);
251 * @function platform_thread_resume
254 * Suspends execution of a thread similar to thread_suspend(). See also
255 * platform_task_suspend_threads() and platform_task_resume_threads().
258 * A handle to the thread to resume.
261 * KERN_SUCCESS if the thread was successfully resumed, otherwise a mach
265 platform_thread_resume(platform_thread_t thread
);
268 * @function platform_thread_info
271 * Similar to thread_info. Supported flavor structures:
272 * - THREAD_BASIC_INFO: struct thread_basic_info
273 * - THREAD_IDENTIFIER_INFO: struct thread_identifier_info
276 * A handle to the target thread.
279 * The desired thread info structure.
282 * A pointer to storage where the thread info structure should be written.
285 * On input, the size in bytes of the storage where the thread info structure
286 * is to be written. On output, the size of the thread info structure in bytes.
289 * KERN_SUCCESS if the function was successfully performed, otherwise a mach
293 platform_thread_info(platform_thread_t thread
,
294 thread_flavor_t flavor
,
299 * @function platform_thread_get_state
302 * Similar to thread_get_state. Supported flavor structures:
303 * - x86_THREAD_STATE32: struct ...
304 * - x86_FLOAT_STATE32: struct ...
305 * - x86_EXCEPTION_STATE32: struct ...
306 * - x86_DEBUG_STATE32: struct ...
307 * - x86_AVX_STATE32: struct ...
308 * - x86_THREAD_STATE64: struct ...
309 * - x86_FLOAT_STATE64: struct ...
310 * - x86_EXCEPTION_STATE64: struct ...
311 * - x86_DEBUG_STATE64: struct ...
312 * - x86_AVX_STATE64: struct ...
313 * - ARM_THREAD_STATE32: struct ...
314 * - ARM_FLOAT_STATE32: struct ...
315 * - ARM_EXCEPTION_STATE32: struct ...
316 * - ARM_DEBUG_STATE32: struct ...
317 * - ARM_THREAD_STATE64: struct ...
318 * - ARM_FLOAT_STATE64: struct ...
319 * - ARM_EXCEPTION_STATE64: struct ...
320 * - ARM_DEBUG_STATE64: struct ...
324 * A handle to the target thread.
327 * The desired thread state structure.
330 * A pointer to storage where the thread state structure should be written.
333 * On input, the size in bytes of the storage where the thread state structure
334 * is to be written. On output, the size of the thread state structure in bytes.
337 * KERN_SUCCESS if the function was successfully performed, otherwise a mach
341 platform_thread_get_state(platform_thread_t thread
,
342 thread_state_flavor_t flavor
,
347 * @function platform_thread_set_state
350 * Similar to thread_set_state. Supported flavor structures:
351 * - x86_THREAD_STATE32: struct ...
352 * - x86_FLOAT_STATE32: struct ...
353 * - x86_EXCEPTION_STATE32: struct ...
354 * - x86_DEBUG_STATE32: struct ...
355 * - x86_AVX_STATE32: struct ...
356 * - x86_THREAD_STATE64: struct ...
357 * - x86_FLOAT_STATE64: struct ...
358 * - x86_EXCEPTION_STATE64: struct ...
359 * - x86_DEBUG_STATE64: struct ...
360 * - x86_AVX_STATE64: struct ...
361 * - ARM_THREAD_STATE32: struct ...
362 * - ARM_FLOAT_STATE32: struct ...
363 * - ARM_EXCEPTION_STATE32: struct ...
364 * - ARM_DEBUG_STATE32: struct ...
365 * - ARM_THREAD_STATE64: struct ...
366 * - ARM_FLOAT_STATE64: struct ...
367 * - ARM_EXCEPTION_STATE64: struct ...
368 * - ARM_DEBUG_STATE64: struct ...
372 * A handle to the target thread.
375 * The desired thread state structure.
378 * A pointer to storage where the thread state structure should be written.
381 * The size of the thread state structure in bytes.
384 * KERN_SUCCESS if the function was successfully performed, otherwise a mach
388 platform_thread_set_state(platform_thread_t thread
,
389 thread_state_flavor_t flavor
,
394 * @function platform_thread_perform
397 * Performs the specified function within the context of the specified thread
398 * in the target task. The function will execute in the style of an
399 * asynchronous signal handler even if the thread is suspended as the result
400 * of a call to platform_task_suspend_threads() or platform_thread_suspend().
401 * The original state of the thread will be restored when the function returns.
403 * The function and context addresses are in the virtual address space of the
404 * target task. It is the responsiblity of the debugger to have previously
405 * mapped executable text and data at these addresses in the target task.
407 * See also platform_task_perform().
410 * A handle to the target thread.
413 * The address (in the virtual address space of the target task) of the
414 * function to perform. The function should be of type (void (*)(void *))
415 * and will be passed the value of the data_addr parameter.
418 * The address (in the virtual address space of the target task) of the
419 * data to pass as a parameter to the function to perform.
422 * KERN_SUCCESS if the function was successfully performed, otherwise a mach
426 platform_thread_perform(platform_thread_t thread
,
427 mach_vm_address_t func_addr
,
428 mach_vm_address_t data_addr
);
431 * @function platform_thread_get_pthread
434 * Returns a pointer to mapped memory which represents the pthread_t of the
435 * target process. Any embedded pointers will need to be mapped into the current
436 * process space on a case-by-case basis.
439 * A handle to the target thread.
445 platform_thread_get_pthread(platform_thread_t thread
);
447 #endif // __PLATFORM_INTROSPECTION_H__