Debian Codegraph @

third_party/rust/mach2/src/message.rs

raw
1 //! This module corresponds to `mach/message.h`.
2
3 use kern_return::kern_return_t;
4 use port::{mach_port_name_t, mach_port_t};
5 use vm_types::{integer_t, natural_t};
6
7 pub type mach_msg_timeout_t = natural_t;
8
9 pub type mach_msg_bits_t = ::libc::c_uint;
10 pub type mach_msg_id_t = integer_t;
11 pub type mach_msg_size_t = natural_t;
12
13 pub type mach_msg_copy_options_t = ::libc::c_uint;
14 pub type mach_msg_descriptor_type_t = ::libc::c_uint;
15 pub type mach_msg_type_name_t = ::libc::c_uint;
16
17 pub type mach_msg_trailer_type_t = ::libc::c_uint;
18 pub type mach_msg_trailer_size_t = ::libc::c_uint;
19
20 pub type mach_msg_option_t = integer_t;
21
22 pub type mach_msg_type_number_t = natural_t;
23 pub type mach_msg_type_size_t = natural_t;
24
25 pub type mach_msg_return_t = kern_return_t;
26
27 pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0;
28
29 pub const MACH_MSGH_BITS_ZERO: mach_msg_bits_t = 0x0000_0000;
30
31 pub const MACH_MSGH_BITS_REMOTE_MASK: mach_msg_bits_t = 0x0000_001f;
32 pub const MACH_MSGH_BITS_LOCAL_MASK: mach_msg_bits_t = 0x0000_1f00;
33 pub const MACH_MSGH_BITS_VOUCHER_MASK: mach_msg_bits_t = 0x001f_0000;
34
35 pub const MACH_MSGH_BITS_PORTS_MASK: mach_msg_bits_t =
36 MACH_MSGH_BITS_REMOTE_MASK | MACH_MSGH_BITS_LOCAL_MASK | MACH_MSGH_BITS_VOUCHER_MASK;
37
38 pub const MACH_MSGH_BITS_COMPLEX: mach_msg_bits_t = 0x8000_0000;
39
40 pub const MACH_MSGH_BITS_USER: mach_msg_bits_t = 0x801f_1f1f;
41
42 #[allow(non_snake_case)]
43 pub fn MACH_MSGH_BITS(remote: mach_msg_bits_t, local: mach_msg_bits_t) -> mach_msg_bits_t {
44 remote | (local << 8)
45 }
46
47 pub const MACH_MSG_TYPE_MOVE_RECEIVE: mach_msg_type_name_t = 16;
48 pub const MACH_MSG_TYPE_MOVE_SEND: mach_msg_type_name_t = 17;
49 pub const MACH_MSG_TYPE_MOVE_SEND_ONCE: mach_msg_type_name_t = 18;
50 pub const MACH_MSG_TYPE_COPY_SEND: mach_msg_type_name_t = 19;
51 pub const MACH_MSG_TYPE_MAKE_SEND: mach_msg_type_name_t = 20;
52 pub const MACH_MSG_TYPE_MAKE_SEND_ONCE: mach_msg_type_name_t = 21;
53 pub const MACH_MSG_TYPE_COPY_RECEIVE: mach_msg_type_name_t = 22;
54 pub const MACH_MSG_TYPE_DISPOSE_RECEIVE: mach_msg_type_name_t = 24;
55 pub const MACH_MSG_TYPE_DISPOSE_SEND: mach_msg_type_name_t = 25;
56 pub const MACH_MSG_TYPE_DISPOSE_SEND_ONCE: mach_msg_type_name_t = 26;
57
58 pub const MACH_MSG_PHYSICAL_COPY: mach_msg_copy_options_t = 0;
59 pub const MACH_MSG_VIRTUAL_COPY: mach_msg_copy_options_t = 1;
60 pub const MACH_MSG_ALLOCATE: mach_msg_copy_options_t = 2;
61
62 pub const MACH_MSG_PORT_DESCRIPTOR: mach_msg_descriptor_type_t = 0;
63 pub const MACH_MSG_OOL_DESCRIPTOR: mach_msg_descriptor_type_t = 1;
64 pub const MACH_MSG_OOL_PORTS_DESCRIPTOR: mach_msg_descriptor_type_t = 2;
65 pub const MACH_MSG_OOL_VOLATILE_DESCRIPTOR: mach_msg_descriptor_type_t = 3;
66
67 pub const MACH_MSG_OPTION_NONE: mach_msg_option_t = 0x0000_0000;
68
69 pub const MACH_SEND_MSG: mach_msg_option_t = 0x0000_0001;
70 pub const MACH_RCV_MSG: mach_msg_option_t = 0x0000_0002;
71
72 pub const MACH_RCV_LARGE: mach_msg_option_t = 0x0000_0004;
73 pub const MACH_RCV_LARGE_IDENTITY: mach_msg_option_t = 0x0000_0008;
74
75 pub const MACH_SEND_TIMEOUT: mach_msg_option_t = 0x0000_0010;
76 pub const MACH_SEND_INTERRUPT: mach_msg_option_t = 0x0000_0040;
77 pub const MACH_SEND_NOTIFY: mach_msg_option_t = 0x0000_0080;
78 pub const MACH_SEND_ALWAYS: mach_msg_option_t = 0x0001_0000;
79 pub const MACH_SEND_TRAILER: mach_msg_option_t = 0x0002_0000;
80 pub const MACH_SEND_NOIMPORTANCE: mach_msg_option_t = 0x0004_0000;
81 pub const MACH_SEND_NODENAP: mach_msg_option_t = MACH_SEND_NOIMPORTANCE;
82 pub const MACH_SEND_IMPORTANCE: mach_msg_option_t = 0x0008_0000;
83
84 pub const MACH_RCV_TIMEOUT: mach_msg_option_t = 0x0000_0100;
85 pub const MACH_RCV_NOTIFY: mach_msg_option_t = 0x0000_0000;
86 pub const MACH_RCV_INTERRUPT: mach_msg_option_t = 0x0000_0400;
87 pub const MACH_RCV_VOUCHER: mach_msg_option_t = 0x0000_0800;
88 pub const MACH_RCV_OVERWRITE: mach_msg_option_t = 0x0000_0000;
89
90 pub const MACH_MSG_SUCCESS: mach_msg_return_t = 0x0000_0000;
91
92 pub const MACH_MSG_MASK: mach_msg_return_t = 0x0000_3e00;
93 pub const MACH_MSG_IPC_SPACE: mach_msg_return_t = 0x0000_2000;
94 pub const MACH_MSG_VM_SPACE: mach_msg_return_t = 0x0000_1000;
95 pub const MACH_MSG_IPC_KERNEL: mach_msg_return_t = 0x0000_0800;
96 pub const MACH_MSG_VM_KERNEL: mach_msg_return_t = 0x0000_0400;
97
98 pub const MACH_SEND_IN_PROGRESS: mach_msg_return_t = 0x1000_0001;
99 pub const MACH_SEND_INVALID_DATA: mach_msg_return_t = 0x1000_0002;
100 pub const MACH_SEND_INVALID_DEST: mach_msg_return_t = 0x1000_0003;
101 pub const MACH_SEND_TIMED_OUT: mach_msg_return_t = 0x1000_0004;
102 pub const MACH_SEND_INVALID_VOUCHER: mach_msg_return_t = 0x1000_0005;
103 pub const MACH_SEND_INTERRUPTED: mach_msg_return_t = 0x1000_0007;
104 pub const MACH_SEND_MSG_TOO_SMALL: mach_msg_return_t = 0x1000_0008;
105 pub const MACH_SEND_INVALID_REPLY: mach_msg_return_t = 0x1000_0009;
106 pub const MACH_SEND_INVALID_RIGHT: mach_msg_return_t = 0x1000_000a;
107 pub const MACH_SEND_INVALID_NOTIFY: mach_msg_return_t = 0x1000_000b;
108 pub const MACH_SEND_INVALID_MEMORY: mach_msg_return_t = 0x1000_000c;
109 pub const MACH_SEND_NO_BUFFER: mach_msg_return_t = 0x1000_000d;
110 pub const MACH_SEND_TOO_LARGE: mach_msg_return_t = 0x1000_000e;
111 pub const MACH_SEND_INVALID_TYPE: mach_msg_return_t = 0x1000_000f;
112 pub const MACH_SEND_INVALID_HEADER: mach_msg_return_t = 0x1000_0010;
113 pub const MACH_SEND_INVALID_TRAILER: mach_msg_return_t = 0x1000_0011;
114 pub const MACH_SEND_INVALID_RT_OOL_SIZE: mach_msg_return_t = 0x1000_0015;
115
116 pub const MACH_RCV_IN_PROGRESS: mach_msg_return_t = 0x1000_4001;
117 pub const MACH_RCV_INVALID_NAME: mach_msg_return_t = 0x1000_4002;
118 pub const MACH_RCV_TIMED_OUT: mach_msg_return_t = 0x1000_4003;
119 pub const MACH_RCV_TOO_LARGE: mach_msg_return_t = 0x1000_4004;
120 pub const MACH_RCV_INTERRUPTED: mach_msg_return_t = 0x1000_4005;
121 pub const MACH_RCV_PORT_CHANGED: mach_msg_return_t = 0x1000_4006;
122 pub const MACH_RCV_INVALID_NOTIFY: mach_msg_return_t = 0x1000_4007;
123 pub const MACH_RCV_INVALID_DATA: mach_msg_return_t = 0x1000_4008;
124 pub const MACH_RCV_PORT_DIED: mach_msg_return_t = 0x1000_4009;
125 pub const MACH_RCV_IN_SET: mach_msg_return_t = 0x1000_400a;
126 pub const MACH_RCV_HEADER_ERROR: mach_msg_return_t = 0x1000_400b;
127 pub const MACH_RCV_BODY_ERROR: mach_msg_return_t = 0x1000_400c;
128 pub const MACH_RCV_INVALID_TYPE: mach_msg_return_t = 0x1000_400d;
129 pub const MACH_RCV_SCATTER_SMALL: mach_msg_return_t = 0x1000_400e;
130 pub const MACH_RCV_INVALID_TRAILER: mach_msg_return_t = 0x1000_400f;
131 pub const MACH_RCV_IN_PROGRESS_TIMED: mach_msg_return_t = 0x1000_4011;
132
133 #[repr(C)]
134 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
135 pub struct mach_msg_header_t {
136 pub msgh_bits: mach_msg_bits_t,
137 pub msgh_size: mach_msg_size_t,
138 pub msgh_remote_port: mach_port_t,
139 pub msgh_local_port: mach_port_t,
140 pub msgh_voucher_port: mach_port_name_t,
141 pub msgh_id: mach_msg_id_t,
142 }
143
144 #[repr(C)]
145 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
146 pub struct mach_msg_body_t {
147 pub msgh_descriptor_count: mach_msg_size_t,
148 }
149
150 #[repr(C)]
151 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
152 pub struct mach_msg_base_t {
153 pub header: mach_msg_header_t,
154 pub body: mach_msg_body_t,
155 }
156
157 pub const MACH_MSG_TRAILER_FORMAT_0: mach_msg_trailer_type_t = 0;
158
159 #[repr(C)]
160 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
161 pub struct mach_msg_trailer_t {
162 pub msgh_trailer_type: mach_msg_trailer_type_t,
163 pub msgh_trailer_size: mach_msg_trailer_size_t,
164 }
165
166 #[repr(C)]
167 #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)]
168 pub struct mach_msg_port_descriptor_t {
169 pub name: mach_port_t,
170 pub pad1: mach_msg_size_t,
171 pub pad2: u16,
172 pub disposition: u8, // mach_msg_type_name_t bitfield
173 pub type_: u8, // mach_msg_descriptor_type_t bitfield
174 }
175
176 impl mach_msg_port_descriptor_t {
177 pub fn new(name: mach_port_t, disposition: mach_msg_type_name_t) -> Self {
178 Self {
179 name,
180 pad1: 0,
181 pad2: 0,
182 disposition: disposition as u8,
183 type_: MACH_MSG_PORT_DESCRIPTOR as u8,
184 }
185 }
186 }
187
188 #[repr(C)]
189 #[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)]
190 pub struct mach_msg_ool_descriptor_t {
191 pub address: *mut ::libc::c_void,
192 #[cfg(not(target_pointer_width = "64"))]
193 pub size: mach_msg_size_t,
194 pub deallocate: u8, // boolean_t bitfield
195 pub copy: u8, // mach_msg_copy_options_t bitfield
196 pub pad1: u8,
197 pub type_: u8, // mach_msg_descriptor_type_t bitfield
198 #[cfg(target_pointer_width = "64")]
199 pub size: mach_msg_size_t,
200 }
201
202 impl mach_msg_ool_descriptor_t {
203 pub fn new(
204 address: *mut ::libc::c_void,
205 deallocate: bool,
206 copy: mach_msg_copy_options_t,
207 size: u32,
208 ) -> Self {
209 Self {
210 address,
211 deallocate: if deallocate { 1 } else { 0 },
212 copy: copy as u8,
213 pad1: 0,
214 type_: MACH_MSG_OOL_DESCRIPTOR as u8,
215 size,
216 }
217 }
218 }
219
220 #[repr(C)]
221 #[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)]
222 pub struct mach_msg_ool_ports_descriptor_t {
223 pub address: *mut ::libc::c_void,
224 #[cfg(not(target_pointer_width = "64"))]
225 pub count: mach_msg_size_t,
226 pub deallocate: u8, // boolean_t bitfield
227 pub copy: u8, // mach_msg_copy_options_t bitfield
228 pub disposition: u8, // mach_msg_type_name_t bitfield
229 pub type_: u8, // mach_msg_descriptor_type_t bitfield
230 #[cfg(target_pointer_width = "64")]
231 pub count: mach_msg_size_t,
232 }
233
234 extern "C" {
235 pub fn mach_msg(
236 msg: *mut mach_msg_header_t,
237 option: mach_msg_option_t,
238 send_size: mach_msg_size_t,
239 recv_size: mach_msg_size_t,
240 recv_name: mach_port_name_t,
241 timeout: mach_msg_timeout_t,
242 notify: mach_port_name_t,
243 ) -> mach_msg_return_t;
244
245 // from mach/mach.h
246 pub fn mach_msg_send(msg: *mut mach_msg_header_t) -> mach_msg_return_t;
247 pub fn mach_msg_destroy(msg: *mut mach_msg_header_t);
248 }