mach_sys/
thread_status.rs

1//! This module corresponds to `mach/thread_status.h`.
2
3#[allow(unused_imports)]
4use crate::ffi::{c_uint, c_int};
5
6use crate::vm_types::natural_t;
7
8pub type thread_state_t = *mut natural_t;
9
10#[cfg(feature = "unstable")]
11pub type thread_state_flavor_t = c_uint; // from (modified) machx
12#[cfg(not(feature = "unstable"))]
13pub type thread_state_flavor_t = c_int;  // from (original) mach
14
15/* List of valid flavors */
16// TODO check if this type correct (compare from original C code)
17pub const THREAD_STATE_FLAVOR_LIST:       thread_state_flavor_t = 0;
18pub const THREAD_STATE_FLAVOR_LIST_NEW:   thread_state_flavor_t = 128;
19pub const THREAD_STATE_FLAVOR_LIST_10_9:  thread_state_flavor_t = 129;
20pub const THREAD_STATE_FLAVOR_LIST_10_13: thread_state_flavor_t = 130;
21pub const THREAD_STATE_FLAVOR_LIST_10_15: thread_state_flavor_t = 131;
22
23pub mod arm {
24    use super::thread_state_flavor_t;
25
26    pub const ARM_THREAD_STATE:         thread_state_flavor_t = 1;
27    pub const ARM_THREAD_STATE64:       thread_state_flavor_t = 6;
28    pub const ARM_UNIFIED_THREAD_STATE: thread_state_flavor_t = ARM_THREAD_STATE;
29
30    pub const ARM_VFP_STATE:            thread_state_flavor_t = 2;
31    pub const ARM_EXCEPTION_STATE:      thread_state_flavor_t = 3;
32    pub const ARM_EXCEPTION_STATE64:    thread_state_flavor_t = 7;
33
34    pub const THREAD_STATE_NONE:        thread_state_flavor_t = 5;
35
36    pub const ARM_DEBUG_STATE:          thread_state_flavor_t = 4;
37    pub const ARM_DEBUG_STATE32:        thread_state_flavor_t = 14;
38    pub const ARM_DEBUG_STATE64:        thread_state_flavor_t = 15;
39
40    pub const ARM_NEON_STATE:           thread_state_flavor_t = 16;
41    pub const ARM_NEON_STATE64:         thread_state_flavor_t = 17;
42    pub const ARM_CPMU_STATE64:         thread_state_flavor_t = 18;
43}
44
45pub mod x86 {
46    use super::thread_state_flavor_t;
47
48    pub const i386_THREAD_STATE:     thread_state_flavor_t = x86_THREAD_STATE32;
49    pub const i386_FLOAT_STATE:      thread_state_flavor_t = x86_FLOAT_STATE32;
50    pub const i386_EXCEPTION_STATE:  thread_state_flavor_t = x86_EXCEPTION_STATE32;
51
52    /*
53     * THREAD_STATE_FLAVOR_LIST 0
54     *      these are the supported flavors
55     */
56    pub const x86_THREAD_STATE32:    thread_state_flavor_t = 1;
57    pub const x86_FLOAT_STATE32:     thread_state_flavor_t = 2;
58    pub const x86_EXCEPTION_STATE32: thread_state_flavor_t = 3;
59
60    pub const x86_THREAD_STATE64:    thread_state_flavor_t = 4;
61    pub const x86_FLOAT_STATE64:     thread_state_flavor_t = 5;
62    pub const x86_EXCEPTION_STATE64: thread_state_flavor_t = 6;
63
64    pub const x86_THREAD_STATE:      thread_state_flavor_t = 7;
65    pub const x86_FLOAT_STATE:       thread_state_flavor_t = 8;
66    pub const x86_EXCEPTION_STATE:   thread_state_flavor_t = 9;
67
68    pub const x86_DEBUG_STATE32:     thread_state_flavor_t = 10;
69    pub const x86_DEBUG_STATE64:     thread_state_flavor_t = 11;
70    pub const x86_DEBUG_STATE:       thread_state_flavor_t = 12;
71
72    pub const THREAD_STATE_NONE:     thread_state_flavor_t = 13;
73
74    pub const x86_AVX_STATE32:    thread_state_flavor_t = 16;
75    pub const x86_AVX_STATE64:    thread_state_flavor_t = x86_AVX_STATE32 + 1;
76    pub const x86_AVX_STATE:      thread_state_flavor_t = x86_AVX_STATE32 + 2;
77
78    pub const x86_AVX512_STATE32: thread_state_flavor_t = 19;
79    pub const x86_AVX512_STATE64: thread_state_flavor_t = x86_AVX512_STATE32 + 1;
80    pub const x86_AVX512_STATE:   thread_state_flavor_t = x86_AVX512_STATE32 + 2;
81
82    pub const x86_PAGEIN_STATE:        thread_state_flavor_t = 22;
83    pub const x86_THREAD_FULL_STATE64: thread_state_flavor_t = 23;
84    pub const x86_INSTRUCTION_STATE:   thread_state_flavor_t = 24;
85    pub const x86_LAST_BRANCH_STATE:   thread_state_flavor_t = 25;
86
87    #[repr(C)]
88    #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
89    pub struct x86_state_hdr_t {
90        pub flavor: u32,
91        pub count: u32,
92    }
93    pub type x86_state_hdr = x86_state_hdr_t;
94
95    // TODO contiune porting from:
96    //
97    // https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/i386/thread_status.h#L177
98
99    //pub const
100}
101
102#[cfg(target_arch = "aarch64")]
103pub use arm::*;
104
105#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
106pub use x86::*;
107