Struct mach_sys::structs::x86_thread_state64_t
source · #[repr(C)]pub struct x86_thread_state64_t {Show 21 fields
pub __rax: u64,
pub __rbx: u64,
pub __rcx: u64,
pub __rdx: u64,
pub __rdi: u64,
pub __rsi: u64,
pub __rbp: u64,
pub __rsp: u64,
pub __r8: u64,
pub __r9: u64,
pub __r10: u64,
pub __r11: u64,
pub __r12: u64,
pub __r13: u64,
pub __r14: u64,
pub __r15: u64,
pub __rip: u64,
pub __rflags: u64,
pub __cs: u64,
pub __fs: u64,
pub __gs: u64,
}Fields§
§__rax: u64§__rbx: u64§__rcx: u64§__rdx: u64§__rdi: u64§__rsi: u64§__rbp: u64§__rsp: u64§__r8: u64§__r9: u64§__r10: u64§__r11: u64§__r12: u64§__r13: u64§__r14: u64§__r15: u64§__rip: u64§__rflags: u64§__cs: u64§__fs: u64§__gs: u64Implementations§
source§impl x86_thread_state64_t
impl x86_thread_state64_t
sourcepub const fn new() -> Self
pub const fn new() -> Self
Examples found in repository?
examples/dump_process_registers.rs (line 123)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn main() {
print!("Enter pid: ");
io::stdout().flush().ok();
let pid = match read_int() {
Ok(v) => v,
Err(_) => {
println!("Bad pid!");
return;
}
};
println!("pid = {}", &pid);
let task: mach_port_name_t = 0;
unsafe {
let kret = task_for_pid(
mach_task_self() as mach_port_name_t,
pid,
mem::transmute(&task),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task for pid {}", pid);
println!("kern_return_t error {}", kret);
println!("");
println!("Did you forget to run with 'sudo'? This script will");
println!("probably fail without it.");
return;
}
}
println!("task = 0x{:x}", &task);
unsafe {
let kret = task_suspend(task as task_t);
if kret != KERN_SUCCESS {
println!("Did not succeed in suspending task.");
println!("kern_return_t error {}", kret);
return;
}
}
let thread_list: thread_act_array_t = ptr::null_mut();
let thread_count: mach_msg_type_number_t = 0;
unsafe {
let kret = task_threads(
task as task_t,
mem::transmute(&thread_list),
mem::transmute(&thread_count),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task's threads");
println!("kern_return_t error {}", kret);
resume(task as task_t);
return;
}
}
println!("Task is running {} threads", &thread_count);
unsafe {
let threads = std::slice::from_raw_parts(thread_list, thread_count as usize);
let state = thread_state64_t::new();
let state_count = thread_state64_t::count();
for (idx, &thread) in threads.iter().enumerate() {
println!("Thread {}:", idx);
let kret = thread_get_state(
thread,
THREAD_STATE64,
mem::transmute(&state),
mem::transmute(&state_count),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task's thread state");
println!("kern_return_t error {}", kret);
continue;
}
println!("{:?}", state);
}
mach_vm_deallocate(
mach_task_self(),
thread_list as _,
((thread_count as usize) * mem::size_of::<c_int>()) as _,
);
}
resume(task as task_t);
println!("Success!");
}sourcepub const fn count() -> mach_msg_type_number_t
pub const fn count() -> mach_msg_type_number_t
Examples found in repository?
examples/dump_process_registers.rs (line 124)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn main() {
print!("Enter pid: ");
io::stdout().flush().ok();
let pid = match read_int() {
Ok(v) => v,
Err(_) => {
println!("Bad pid!");
return;
}
};
println!("pid = {}", &pid);
let task: mach_port_name_t = 0;
unsafe {
let kret = task_for_pid(
mach_task_self() as mach_port_name_t,
pid,
mem::transmute(&task),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task for pid {}", pid);
println!("kern_return_t error {}", kret);
println!("");
println!("Did you forget to run with 'sudo'? This script will");
println!("probably fail without it.");
return;
}
}
println!("task = 0x{:x}", &task);
unsafe {
let kret = task_suspend(task as task_t);
if kret != KERN_SUCCESS {
println!("Did not succeed in suspending task.");
println!("kern_return_t error {}", kret);
return;
}
}
let thread_list: thread_act_array_t = ptr::null_mut();
let thread_count: mach_msg_type_number_t = 0;
unsafe {
let kret = task_threads(
task as task_t,
mem::transmute(&thread_list),
mem::transmute(&thread_count),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task's threads");
println!("kern_return_t error {}", kret);
resume(task as task_t);
return;
}
}
println!("Task is running {} threads", &thread_count);
unsafe {
let threads = std::slice::from_raw_parts(thread_list, thread_count as usize);
let state = thread_state64_t::new();
let state_count = thread_state64_t::count();
for (idx, &thread) in threads.iter().enumerate() {
println!("Thread {}:", idx);
let kret = thread_get_state(
thread,
THREAD_STATE64,
mem::transmute(&state),
mem::transmute(&state_count),
);
if kret != KERN_SUCCESS {
println!("Did not succeed in getting task's thread state");
println!("kern_return_t error {}", kret);
continue;
}
println!("{:?}", state);
}
mach_vm_deallocate(
mach_task_self(),
thread_list as _,
((thread_count as usize) * mem::size_of::<c_int>()) as _,
);
}
resume(task as task_t);
println!("Success!");
}Trait Implementations§
source§impl Clone for x86_thread_state64_t
impl Clone for x86_thread_state64_t
source§fn clone(&self) -> x86_thread_state64_t
fn clone(&self) -> x86_thread_state64_t
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for x86_thread_state64_t
impl Debug for x86_thread_state64_t
source§impl Default for x86_thread_state64_t
impl Default for x86_thread_state64_t
source§fn default() -> x86_thread_state64_t
fn default() -> x86_thread_state64_t
Returns the “default value” for a type. Read more
source§impl Hash for x86_thread_state64_t
impl Hash for x86_thread_state64_t
source§impl Ord for x86_thread_state64_t
impl Ord for x86_thread_state64_t
source§fn cmp(&self, other: &x86_thread_state64_t) -> Ordering
fn cmp(&self, other: &x86_thread_state64_t) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for x86_thread_state64_t
impl PartialEq for x86_thread_state64_t
source§fn eq(&self, other: &x86_thread_state64_t) -> bool
fn eq(&self, other: &x86_thread_state64_t) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd for x86_thread_state64_t
impl PartialOrd for x86_thread_state64_t
source§fn partial_cmp(&self, other: &x86_thread_state64_t) -> Option<Ordering>
fn partial_cmp(&self, other: &x86_thread_state64_t) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Copy for x86_thread_state64_t
impl Eq for x86_thread_state64_t
impl StructuralPartialEq for x86_thread_state64_t
Auto Trait Implementations§
impl RefUnwindSafe for x86_thread_state64_t
impl Send for x86_thread_state64_t
impl Sync for x86_thread_state64_t
impl Unpin for x86_thread_state64_t
impl UnwindSafe for x86_thread_state64_t
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more