Skip to content

Commit a5fcdf3

Browse files
authored
Merge pull request #55 from JohnTitor/feat/sync-existing-mod
2 parents 1884b2f + fae7270 commit a5fcdf3

File tree

17 files changed

+739
-11
lines changed

17 files changed

+739
-11
lines changed

mach-test/test/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ use mach2::clock_reply::*;
88
use mach2::clock_types::*;
99
use mach2::dyld::*;
1010
use mach2::dyld_kernel::*;
11+
use mach2::error::*;
1112
use mach2::exc::*;
1213
use mach2::exception_types::*;
1314
use mach2::kern_return::*;
1415
use mach2::loader::*;
16+
use mach2::mach_debug::ipc_info::*;
17+
use mach2::mach_debug::zone_info::*;
1518
use mach2::mach_init::*;
1619
use mach2::mach_port::*;
1720
use mach2::mach_time::*;
@@ -31,6 +34,7 @@ use mach2::structs::*;
3134
use mach2::sync_policy::*;
3235
use mach2::task::*;
3336
use mach2::task_info::*;
37+
use mach2::task_inspect::*;
3438
use mach2::task_special_ports::*;
3539
use mach2::thread_act::*;
3640
use mach2::thread_policy::*;

src/error.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! This module corresponds to `mach/error.h`.
2+
3+
use crate::kern_return::kern_return_t;
4+
use libc::c_int;
5+
6+
pub type mach_error_t = kern_return_t;
7+
pub type mach_error_fn_t = Option<unsafe extern "C" fn() -> mach_error_t>;
8+
9+
pub const err_none: mach_error_t = 0;
10+
pub const ERR_SUCCESS: mach_error_t = err_none;
11+
pub const ERR_ROUTINE_NIL: mach_error_fn_t = None;
12+
13+
#[inline]
14+
pub const fn err_system(x: c_int) -> mach_error_t {
15+
(((x as u32) & 0x3f) << 26) as mach_error_t
16+
}
17+
18+
#[inline]
19+
pub const fn err_sub(x: c_int) -> mach_error_t {
20+
(((x as u32) & 0xfff) << 14) as mach_error_t
21+
}
22+
23+
#[inline]
24+
pub const fn err_get_system(err: mach_error_t) -> c_int {
25+
(((err as u32) >> 26) & 0x3f) as c_int
26+
}
27+
28+
#[inline]
29+
pub const fn err_get_sub(err: mach_error_t) -> c_int {
30+
(((err as u32) >> 14) & 0xfff) as c_int
31+
}
32+
33+
#[inline]
34+
pub const fn err_get_code(err: mach_error_t) -> c_int {
35+
((err as u32) & 0x3fff) as c_int
36+
}
37+
38+
pub const system_emask: mach_error_t = err_system(0x3f);
39+
pub const sub_emask: mach_error_t = err_sub(0xfff);
40+
pub const code_emask: mach_error_t = 0x3fff;
41+
42+
pub const err_kern: mach_error_t = err_system(0x0);
43+
pub const err_us: mach_error_t = err_system(0x1);
44+
pub const err_server: mach_error_t = err_system(0x2);
45+
pub const err_ipc: mach_error_t = err_system(0x3);
46+
pub const err_mach_ipc: mach_error_t = err_system(0x4);
47+
pub const err_dipc: mach_error_t = err_system(0x7);
48+
pub const err_vm: mach_error_t = err_system(0x8);
49+
pub const err_local: mach_error_t = err_system(0x3e);
50+
pub const err_ipc_compat: mach_error_t = err_system(0x3f);
51+
52+
pub const err_max_system: c_int = 0x3f;
53+
54+
#[inline]
55+
pub const fn unix_err(errno: mach_error_t) -> mach_error_t {
56+
err_kern | err_sub(3) | errno
57+
}

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ pub mod bootstrap;
2121
pub mod clock;
2222
pub mod clock_priv;
2323
pub mod clock_reply;
24-
pub mod clock_types; // TODO: test
24+
pub mod clock_types;
2525
pub mod dyld;
2626
pub mod dyld_kernel;
27+
pub mod error;
2728
pub mod exc;
2829
pub mod exception_types;
2930
pub mod kern_return;
3031
pub mod loader;
32+
pub mod mach_debug;
3133
pub mod mach_init;
3234
pub mod mach_port;
3335
pub mod mach_time;
@@ -45,6 +47,7 @@ pub mod structs;
4547
pub mod sync_policy;
4648
pub mod task;
4749
pub mod task_info;
50+
pub mod task_inspect;
4851
pub mod task_special_ports;
4952
pub mod thread_act;
5053
pub mod thread_policy;

src/mach_debug/ipc_info.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//! This module corresponds to `mach_debug/ipc_info.h`.
2+
3+
use crate::port::{mach_port_name_t, mach_port_type_t, mach_port_urefs_t};
4+
use crate::vm_types::{integer_t, natural_t};
5+
6+
pub type ipc_info_object_type_t = natural_t;
7+
8+
pub const IPC_OTYPE_NONE: ipc_info_object_type_t = 0;
9+
pub const IPC_OTYPE_THREAD_CONTROL: ipc_info_object_type_t = 1;
10+
pub const IPC_OTYPE_TASK_CONTROL: ipc_info_object_type_t = 2;
11+
pub const IPC_OTYPE_HOST: ipc_info_object_type_t = 3;
12+
pub const IPC_OTYPE_HOST_PRIV: ipc_info_object_type_t = 4;
13+
pub const IPC_OTYPE_PROCESSOR: ipc_info_object_type_t = 5;
14+
pub const IPC_OTYPE_PROCESSOR_SET: ipc_info_object_type_t = 6;
15+
pub const IPC_OTYPE_PROCESSOR_SET_NAME: ipc_info_object_type_t = 7;
16+
pub const IPC_OTYPE_TIMER: ipc_info_object_type_t = 8;
17+
pub const IPC_OTYPE_PORT_SUBST_ONCE: ipc_info_object_type_t = 9;
18+
pub const IPC_OTYPE_MIG: ipc_info_object_type_t = 10;
19+
pub const IPC_OTYPE_MEMORY_OBJECT: ipc_info_object_type_t = 11;
20+
pub const IPC_OTYPE_XMM_PAGER: ipc_info_object_type_t = 12;
21+
pub const IPC_OTYPE_XMM_KERNEL: ipc_info_object_type_t = 13;
22+
pub const IPC_OTYPE_XMM_REPLY: ipc_info_object_type_t = 14;
23+
pub const IPC_OTYPE_UND_REPLY: ipc_info_object_type_t = 15;
24+
pub const IPC_OTYPE_HOST_NOTIFY: ipc_info_object_type_t = 16;
25+
pub const IPC_OTYPE_HOST_SECURITY: ipc_info_object_type_t = 17;
26+
pub const IPC_OTYPE_LEDGER: ipc_info_object_type_t = 18;
27+
pub const IPC_OTYPE_MAIN_DEVICE: ipc_info_object_type_t = 19;
28+
pub const IPC_OTYPE_TASK_NAME: ipc_info_object_type_t = 20;
29+
pub const IPC_OTYPE_SUBSYSTEM: ipc_info_object_type_t = 21;
30+
pub const IPC_OTYPE_IO_DONE_QUEUE: ipc_info_object_type_t = 22;
31+
pub const IPC_OTYPE_SEMAPHORE: ipc_info_object_type_t = 23;
32+
pub const IPC_OTYPE_LOCK_SET: ipc_info_object_type_t = 24;
33+
pub const IPC_OTYPE_CLOCK: ipc_info_object_type_t = 25;
34+
pub const IPC_OTYPE_CLOCK_CTRL: ipc_info_object_type_t = 26;
35+
pub const IPC_OTYPE_IOKIT_IDENT: ipc_info_object_type_t = 27;
36+
pub const IPC_OTYPE_NAMED_ENTRY: ipc_info_object_type_t = 28;
37+
pub const IPC_OTYPE_IOKIT_CONNECT: ipc_info_object_type_t = 29;
38+
pub const IPC_OTYPE_IOKIT_OBJECT: ipc_info_object_type_t = 30;
39+
pub const IPC_OTYPE_UPL: ipc_info_object_type_t = 31;
40+
pub const IPC_OTYPE_MEM_OBJ_CONTROL: ipc_info_object_type_t = 32;
41+
pub const IPC_OTYPE_AU_SESSIONPORT: ipc_info_object_type_t = 33;
42+
pub const IPC_OTYPE_FILEPORT: ipc_info_object_type_t = 34;
43+
pub const IPC_OTYPE_LABELH: ipc_info_object_type_t = 35;
44+
pub const IPC_OTYPE_TASK_RESUME: ipc_info_object_type_t = 36;
45+
pub const IPC_OTYPE_VOUCHER: ipc_info_object_type_t = 37;
46+
pub const IPC_OTYPE_VOUCHER_ATTR_CONTROL: ipc_info_object_type_t = 38;
47+
pub const IPC_OTYPE_WORK_INTERVAL: ipc_info_object_type_t = 39;
48+
pub const IPC_OTYPE_UX_HANDLER: ipc_info_object_type_t = 40;
49+
pub const IPC_OTYPE_UEXT_OBJECT: ipc_info_object_type_t = 41;
50+
pub const IPC_OTYPE_ARCADE_REG: ipc_info_object_type_t = 42;
51+
pub const IPC_OTYPE_EVENTLINK: ipc_info_object_type_t = 43;
52+
pub const IPC_OTYPE_TASK_INSPECT: ipc_info_object_type_t = 44;
53+
pub const IPC_OTYPE_TASK_READ: ipc_info_object_type_t = 45;
54+
pub const IPC_OTYPE_THREAD_INSPECT: ipc_info_object_type_t = 46;
55+
pub const IPC_OTYPE_THREAD_READ: ipc_info_object_type_t = 47;
56+
pub const IPC_OTYPE_SUID_CRED: ipc_info_object_type_t = 48;
57+
pub const IPC_OTYPE_HYPERVISOR: ipc_info_object_type_t = 49;
58+
pub const IPC_OTYPE_TASK_ID_TOKEN: ipc_info_object_type_t = 50;
59+
pub const IPC_OTYPE_TASK_FATAL: ipc_info_object_type_t = 51;
60+
pub const IPC_OTYPE_KCDATA: ipc_info_object_type_t = 52;
61+
pub const IPC_OTYPE_EXCLAVES_RESOURCE: ipc_info_object_type_t = 53;
62+
pub const IPC_OTYPE_UNKNOWN: ipc_info_object_type_t = !0;
63+
64+
#[repr(C)]
65+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
66+
pub struct ipc_info_space {
67+
pub iis_genno_mask: natural_t,
68+
pub iis_table_size: natural_t,
69+
pub iis_table_next: natural_t,
70+
pub iis_tree_size: natural_t,
71+
pub iis_tree_small: natural_t,
72+
pub iis_tree_hash: natural_t,
73+
}
74+
75+
pub type ipc_info_space_t = ipc_info_space;
76+
77+
#[repr(C)]
78+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
79+
pub struct ipc_info_space_basic {
80+
pub iisb_genno_mask: natural_t,
81+
pub iisb_table_size: natural_t,
82+
pub iisb_table_next: natural_t,
83+
pub iisb_table_inuse: natural_t,
84+
pub iisb_reserved: [natural_t; 2],
85+
}
86+
87+
pub type ipc_info_space_basic_t = ipc_info_space_basic;
88+
89+
#[repr(C)]
90+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
91+
pub struct ipc_info_name {
92+
pub iin_name: mach_port_name_t,
93+
pub iin_collision: integer_t,
94+
pub iin_type: mach_port_type_t,
95+
pub iin_urefs: mach_port_urefs_t,
96+
pub iin_object: natural_t,
97+
pub iin_next: natural_t,
98+
pub iin_hash: natural_t,
99+
}
100+
101+
pub type ipc_info_name_t = ipc_info_name;
102+
pub type ipc_info_name_array_t = *mut ipc_info_name_t;
103+
104+
#[repr(C)]
105+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
106+
pub struct ipc_info_tree_name {
107+
pub iitn_name: ipc_info_name_t,
108+
pub iitn_lchild: mach_port_name_t,
109+
pub iitn_rchild: mach_port_name_t,
110+
}
111+
112+
pub type ipc_info_tree_name_t = ipc_info_tree_name;
113+
pub type ipc_info_tree_name_array_t = *mut ipc_info_tree_name_t;
114+
115+
#[repr(C)]
116+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
117+
pub struct ipc_info_port {
118+
pub iip_port_object: natural_t,
119+
pub iip_receiver_object: natural_t,
120+
}
121+
122+
pub type ipc_info_port_t = ipc_info_port;
123+
pub type exception_port_info_array_t = *mut ipc_info_port_t;
124+
pub type exception_handler_info_array_t = *mut ipc_info_port_t;

src/mach_debug/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod ipc_info;
2+
pub mod zone_info;

src/mach_debug/zone_info.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//! This module corresponds to `mach_debug/zone_info.h`.
2+
3+
use crate::vm_types::{integer_t, vm_size_t};
4+
use libc::c_char;
5+
6+
pub const ZONE_NAME_MAX_LEN: usize = 80;
7+
pub const MACH_ZONE_NAME_MAX_LEN: usize = 80;
8+
pub const MACH_MEMORY_INFO_NAME_MAX_LEN: usize = 80;
9+
pub const MAX_ZTRACE_DEPTH: usize = 15;
10+
11+
pub const ZOP_ALLOC: u32 = 1;
12+
pub const ZOP_FREE: u32 = 0;
13+
14+
#[repr(C)]
15+
#[derive(Copy, Clone, Debug)]
16+
pub struct zone_name {
17+
pub zn_name: [c_char; ZONE_NAME_MAX_LEN],
18+
}
19+
20+
pub type zone_name_t = zone_name;
21+
pub type zone_name_array_t = *mut zone_name_t;
22+
23+
#[repr(C)]
24+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
25+
pub struct zone_info {
26+
pub zi_count: integer_t,
27+
pub zi_cur_size: vm_size_t,
28+
pub zi_max_size: vm_size_t,
29+
pub zi_elem_size: vm_size_t,
30+
pub zi_alloc_size: vm_size_t,
31+
pub zi_pageable: integer_t,
32+
pub zi_sleepable: integer_t,
33+
pub zi_exhaustible: integer_t,
34+
pub zi_collectable: integer_t,
35+
}
36+
37+
pub type zone_info_t = zone_info;
38+
pub type zone_info_array_t = *mut zone_info_t;
39+
40+
#[repr(C)]
41+
#[derive(Copy, Clone, Debug)]
42+
pub struct mach_zone_name {
43+
pub mzn_name: [c_char; ZONE_NAME_MAX_LEN],
44+
}
45+
46+
pub type mach_zone_name_t = mach_zone_name;
47+
pub type mach_zone_name_array_t = *mut mach_zone_name_t;
48+
49+
#[repr(C)]
50+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
51+
pub struct mach_zone_info_data {
52+
pub mzi_count: u64,
53+
pub mzi_cur_size: u64,
54+
pub mzi_max_size: u64,
55+
pub mzi_elem_size: u64,
56+
pub mzi_alloc_size: u64,
57+
pub mzi_sum_size: u64,
58+
pub mzi_exhaustible: u64,
59+
pub mzi_collectable: u64,
60+
}
61+
62+
pub type mach_zone_info_t = mach_zone_info_data;
63+
pub type mach_zone_info_array_t = *mut mach_zone_info_t;
64+
65+
#[inline]
66+
pub const fn get_mzi_collectable_bytes(val: u64) -> u64 {
67+
val >> 1
68+
}
69+
70+
#[inline]
71+
pub const fn get_mzi_collectable_flag(val: u64) -> u64 {
72+
val & 1
73+
}
74+
75+
#[inline]
76+
pub fn set_mzi_collectable_bytes(val: &mut u64, size: u64) {
77+
*val = (*val & 1) | (size << 1);
78+
}
79+
80+
#[inline]
81+
pub fn set_mzi_collectable_flag(val: &mut u64, flag: bool) {
82+
if flag {
83+
*val |= 1;
84+
} else {
85+
*val &= !1;
86+
}
87+
}
88+
89+
#[repr(C)]
90+
#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
91+
pub struct task_zone_info_data {
92+
pub tzi_count: u64,
93+
pub tzi_cur_size: u64,
94+
pub tzi_max_size: u64,
95+
pub tzi_elem_size: u64,
96+
pub tzi_alloc_size: u64,
97+
pub tzi_sum_size: u64,
98+
pub tzi_exhaustible: u64,
99+
pub tzi_collectable: u64,
100+
pub tzi_caller_acct: u64,
101+
pub tzi_task_alloc: u64,
102+
pub tzi_task_free: u64,
103+
}
104+
105+
pub type task_zone_info_t = task_zone_info_data;
106+
pub type task_zone_info_array_t = *mut task_zone_info_t;
107+
108+
#[repr(C)]
109+
#[derive(Copy, Clone, Debug)]
110+
#[allow(non_snake_case)]
111+
pub struct mach_memory_info {
112+
pub flags: u64,
113+
pub site: u64,
114+
pub size: u64,
115+
pub free: u64,
116+
pub largest: u64,
117+
pub collectable_bytes: u64,
118+
pub mapped: u64,
119+
pub peak: u64,
120+
pub tag: u16,
121+
pub zone: u16,
122+
pub _resvA: [u16; 2],
123+
pub _resv: [u64; 3],
124+
pub name: [c_char; MACH_MEMORY_INFO_NAME_MAX_LEN],
125+
}
126+
127+
pub type mach_memory_info_t = mach_memory_info;
128+
pub type mach_memory_info_array_t = *mut mach_memory_info_t;
129+
130+
#[repr(C)]
131+
#[derive(Copy, Clone, Debug)]
132+
pub struct zone_btrecord {
133+
pub ref_count: u32,
134+
pub operation_type: u32,
135+
pub bt: [u64; MAX_ZTRACE_DEPTH],
136+
}
137+
138+
pub type zone_btrecord_t = zone_btrecord;
139+
pub type zone_btrecord_array_t = *mut zone_btrecord_t;

0 commit comments

Comments
 (0)