1use core::mem::size_of;
4use crate::ffi::{c_int, c_uint, c_uchar, c_ushort};
5
6use crate::boolean::boolean_t;
7use crate::memory_object_types::{memory_object_offset_t, vm_object_id_t};
8use crate::message::mach_msg_type_number_t;
9use crate::vm_behavior::vm_behavior_t;
10use crate::vm_inherit::vm_inherit_t;
11use crate::vm_prot::vm_prot_t;
12use crate::vm_types::{mach_vm_address_t, mach_vm_size_t};
13
14pub type vm32_object_id_t = u32;
15
16pub type vm_region_info_t = *mut c_int;
17pub type vm_region_info_64_t = *mut c_int;
18pub type vm_region_recurse_info_t = *mut c_int;
19pub type vm_region_recurse_info_64_t = *mut c_int;
20pub type vm_region_flavor_t = c_int;
21pub type vm_region_info_data_t = [c_int; VM_REGION_INFO_MAX as usize];
22
23pub type vm_region_basic_info_64_t = *mut vm_region_basic_info_64;
24pub type vm_region_basic_info_data_64_t = vm_region_basic_info_64;
25pub type vm_region_basic_info_t = *mut vm_region_basic_info;
26pub type vm_region_basic_info_data_t = vm_region_basic_info;
27pub type vm_region_extended_info_t = *mut vm_region_extended_info;
28pub type vm_region_extended_info_data_t = vm_region_extended_info;
29pub type vm_region_top_info_t = *mut vm_region_top_info;
30pub type vm_region_top_info_data_t = vm_region_top_info;
31pub type vm_region_submap_info_t = *mut vm_region_submap_info;
32pub type vm_region_submap_info_data_t = vm_region_submap_info;
33pub type vm_region_submap_info_64_t = *mut vm_region_submap_info_64;
34pub type vm_region_submap_info_data_64_t = vm_region_submap_info_64;
35pub type vm_region_submap_short_info_64_t = *mut vm_region_submap_short_info_64;
36pub type vm_region_submap_short_info_data_64_t = vm_region_submap_short_info_64;
37pub type vm_page_info_t = *mut c_int;
38pub type vm_page_info_flavor_t = c_int;
39pub type vm_page_info_basic_t = *mut vm_page_info_basic;
40pub type vm_page_info_basic_data_t = vm_page_info_basic;
41pub type mach_vm_read_entry_t = [mach_vm_read_entry; VM_MAP_ENTRY_MAX as usize];
42
43pub const VM_REGION_INFO_MAX: c_int = 1 << 10;
44pub const VM_MAP_ENTRY_MAX: c_int = 1 << 8;
45
46pub const VM_PAGE_INFO_BASIC: vm_page_info_flavor_t = 1;
47
48pub const VM_REGION_BASIC_INFO_64: vm_region_flavor_t = 9;
49pub const VM_REGION_BASIC_INFO: vm_region_flavor_t = 10;
50pub const VM_REGION_EXTENDED_INFO: vm_region_flavor_t = 13;
51pub const VM_REGION_TOP_INFO: vm_region_flavor_t = 12;
52
53pub const SM_COW: c_uchar = 1;
54pub const SM_PRIVATE: c_uchar = 2;
55pub const SM_EMPTY: c_uchar = 3;
56pub const SM_SHARED: c_uchar = 4;
57pub const SM_TRUESHARED: c_uchar = 5;
58pub const SM_PRIVATE_ALIASED: c_uchar = 6;
59pub const SM_SHARED_ALIASED: c_uchar = 7;
60
61#[repr(C, packed(4))]
62#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
63pub struct vm_region_basic_info_64 {
64 pub protection: vm_prot_t,
65 pub max_protection: vm_prot_t,
66 pub inheritance: vm_inherit_t,
67 pub shared: boolean_t,
68 pub reserved: boolean_t,
69 pub offset: memory_object_offset_t,
70 pub behavior: vm_behavior_t,
71 pub user_wired_count: c_ushort,
72}
73
74impl vm_region_basic_info_64 {
75 pub const COUNT: mach_msg_type_number_t = Self::count();
76 pub const fn count() -> mach_msg_type_number_t {
77 let n = size_of::<Self>() / size_of::<c_int>();
78 n as mach_msg_type_number_t
79 }
80}
81
82#[repr(C)]
83#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
84pub struct vm_region_basic_info {
85 pub protection: vm_prot_t,
86 pub max_protection: vm_prot_t,
87 pub inheritance: vm_inherit_t,
88 pub shared: boolean_t,
89 pub reserved: boolean_t,
90 pub offset: u32,
91 pub behavior: vm_behavior_t,
92 pub user_wired_count: c_ushort,
93}
94
95impl vm_region_basic_info {
96 pub const COUNT: mach_msg_type_number_t = Self::count();
97 pub const fn count() -> mach_msg_type_number_t {
98 let n = size_of::<Self>() / size_of::<c_int>();
99 n as mach_msg_type_number_t
100 }
101}
102
103#[repr(C)]
104#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
105pub struct vm_region_extended_info {
106 pub protection: vm_prot_t,
107 pub user_tag: c_uint,
108 pub pages_resident: c_uint,
109 pub pages_shared_now_private: c_uint,
110 pub pages_swapped_out: c_uint,
111 pub pages_dirtied: c_uint,
112 pub ref_count: c_uint,
113 pub shadow_depth: c_ushort,
114 pub external_pager: c_uchar,
115 pub share_mode: c_uchar,
116 pub pages_reusable: c_uint,
117}
118
119impl vm_region_extended_info {
120 pub const COUNT: mach_msg_type_number_t = Self::count();
121 pub const fn count() -> mach_msg_type_number_t {
122 let n = size_of::<Self>() / size_of::<c_int>();
123 n as mach_msg_type_number_t
124 }
125}
126
127#[repr(C)]
128#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
129pub struct vm_region_top_info {
130 pub obj_id: c_uint,
131 pub ref_count: c_uint,
132 pub private_pages_resident: c_uint,
133 pub shared_pages_resident: c_uint,
134 pub share_mode: c_uchar,
135}
136
137impl vm_region_top_info {
138 pub const COUNT: mach_msg_type_number_t = Self::count();
139 pub const fn count() -> mach_msg_type_number_t {
140 let n = size_of::<Self>() / size_of::<c_int>();
141 n as mach_msg_type_number_t
142 }
143}
144
145#[repr(C)]
146#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
147pub struct vm_region_submap_info {
148 pub protection: vm_prot_t,
149 pub max_protection: vm_prot_t,
150 pub inheritance: vm_inherit_t,
151 pub offset: u32,
152 pub user_tag: c_uint,
153 pub pages_resident: c_uint,
154 pub pages_shared_now_private: c_uint,
155 pub pages_swapped_out: c_uint,
156 pub pages_dirtied: c_uint,
157 pub ref_count: c_uint,
158 pub shadow_depth: c_ushort,
159 pub external_pager: c_uchar,
160 pub share_mode: c_uchar,
161 pub is_submap: boolean_t,
162 pub behavior: vm_behavior_t,
163 pub object_id: vm32_object_id_t,
164 pub user_wired_count: c_ushort,
165}
166
167impl vm_region_submap_info {
168 pub const COUNT: mach_msg_type_number_t = Self::count();
169 pub const fn count() -> mach_msg_type_number_t {
170 let n = size_of::<Self>() / size_of::<c_int>();
171 n as mach_msg_type_number_t
172 }
173}
174
175#[repr(C, packed(4))]
176#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
177pub struct vm_region_submap_info_64 {
178 pub protection: vm_prot_t,
179 pub max_protection: vm_prot_t,
180 pub inheritance: vm_inherit_t,
181 pub offset: memory_object_offset_t,
182 pub user_tag: c_uint,
183 pub pages_resident: c_uint,
184 pub pages_shared_now_private: c_uint,
185 pub pages_swapped_out: c_uint,
186 pub pages_dirtied: c_uint,
187 pub ref_count: c_uint,
188 pub shadow_depth: c_ushort,
189 pub external_pager: c_uchar,
190 pub share_mode: c_uchar,
191 pub is_submap: boolean_t,
192 pub behavior: vm_behavior_t,
193 pub object_id: vm32_object_id_t,
194 pub user_wired_count: c_ushort,
195 pub pages_reusable: c_uint,
196}
197
198impl vm_region_submap_info_64 {
199 pub const COUNT: mach_msg_type_number_t = Self::count();
200 pub const fn count() -> mach_msg_type_number_t {
201 let n = size_of::<Self>() / size_of::<c_int>();
202 n as mach_msg_type_number_t
203 }
204}
205
206#[repr(C, packed(4))]
207#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
208pub struct vm_region_submap_short_info_64 {
209 pub protection: vm_prot_t,
210 pub max_protection: vm_prot_t,
211 pub inheritance: vm_inherit_t,
212 pub offset: memory_object_offset_t,
213 pub user_tag: c_uint,
214 pub ref_count: c_uint,
215 pub shadow_depth: c_ushort,
216 pub external_pager: c_uchar,
217 pub share_mode: c_uchar,
218 pub is_submap: boolean_t,
219 pub behavior: vm_behavior_t,
220 pub object_id: vm32_object_id_t,
221 pub user_wired_count: c_ushort,
222}
223
224impl vm_region_submap_short_info_64 {
225 pub const COUNT: mach_msg_type_number_t = Self::count();
226 pub const fn count() -> mach_msg_type_number_t {
227 let n = size_of::<Self>() / size_of::<c_int>();
228 n as mach_msg_type_number_t
229 }
230}
231
232#[repr(C)]
233#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
234pub struct vm_page_info_basic {
235 pub disposition: c_int,
236 pub ref_count: c_int,
237 pub object_id: vm_object_id_t,
238 pub offset: memory_object_offset_t,
239 pub depth: c_int,
240 pub __pad: c_int,
241}
242
243impl vm_page_info_basic {
244 pub const COUNT: mach_msg_type_number_t = Self::count();
245 pub const fn count() -> mach_msg_type_number_t {
246 let n = size_of::<Self>() / size_of::<c_int>();
247 n as mach_msg_type_number_t
248 }
249}
250
251#[repr(C, packed(4))]
252#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
253pub struct mach_vm_read_entry {
254 pub address: mach_vm_address_t,
255 pub size: mach_vm_size_t,
256}
257