]>
Commit | Line | Data |
---|---|---|
94b46f34 | 1 | #![allow(non_camel_case_types, unused)] |
476ff2be | 2 | |
532ac7d7 XL |
3 | use crate::convert::TryInto; |
4 | use crate::io; | |
5 | use crate::os::raw::c_char; | |
6 | use crate::u64; | |
476ff2be | 7 | |
ea8adc8c | 8 | use libc::{c_int, c_void, size_t}; |
476ff2be | 9 | |
ea8adc8c XL |
10 | pub type zx_handle_t = u32; |
11 | pub type zx_vaddr_t = usize; | |
12 | pub type zx_rights_t = u32; | |
13 | pub type zx_status_t = i32; | |
476ff2be | 14 | |
ea8adc8c | 15 | pub const ZX_HANDLE_INVALID: zx_handle_t = 0; |
476ff2be | 16 | |
ea8adc8c XL |
17 | pub type zx_time_t = u64; |
18 | pub const ZX_TIME_INFINITE : zx_time_t = u64::MAX; | |
476ff2be | 19 | |
ea8adc8c | 20 | pub type zx_signals_t = u32; |
476ff2be | 21 | |
ea8adc8c | 22 | pub const ZX_OBJECT_SIGNAL_3 : zx_signals_t = 1 << 3; |
476ff2be | 23 | |
ea8adc8c | 24 | pub const ZX_TASK_TERMINATED : zx_signals_t = ZX_OBJECT_SIGNAL_3; |
476ff2be | 25 | |
ea8adc8c | 26 | pub const ZX_RIGHT_SAME_RIGHTS : zx_rights_t = 1 << 31; |
476ff2be | 27 | |
ea8adc8c | 28 | pub type zx_object_info_topic_t = u32; |
476ff2be | 29 | |
ea8adc8c | 30 | pub const ZX_INFO_PROCESS : zx_object_info_topic_t = 3; |
476ff2be | 31 | |
ea8adc8c | 32 | pub fn zx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<zx_status_t>+Copy { |
476ff2be SL |
33 | if let Ok(status) = TryInto::try_into(t) { |
34 | if status < 0 { | |
35 | Err(io::Error::from_raw_os_error(status)) | |
36 | } else { | |
37 | Ok(t) | |
38 | } | |
39 | } else { | |
40 | Err(io::Error::last_os_error()) | |
41 | } | |
42 | } | |
43 | ||
ea8adc8c | 44 | // Safe wrapper around zx_handle_t |
476ff2be | 45 | pub struct Handle { |
ea8adc8c | 46 | raw: zx_handle_t, |
476ff2be SL |
47 | } |
48 | ||
49 | impl Handle { | |
ea8adc8c | 50 | pub fn new(raw: zx_handle_t) -> Handle { |
476ff2be | 51 | Handle { |
3b2f2976 | 52 | raw, |
476ff2be SL |
53 | } |
54 | } | |
55 | ||
ea8adc8c | 56 | pub fn raw(&self) -> zx_handle_t { |
476ff2be SL |
57 | self.raw |
58 | } | |
59 | } | |
60 | ||
61 | impl Drop for Handle { | |
62 | fn drop(&mut self) { | |
ea8adc8c | 63 | unsafe { zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t"); } |
476ff2be SL |
64 | } |
65 | } | |
66 | ||
ea8adc8c | 67 | // Common ZX_INFO header |
476ff2be SL |
68 | #[derive(Default)] |
69 | #[repr(C)] | |
ea8adc8c | 70 | pub struct zx_info_header_t { |
476ff2be SL |
71 | pub topic: u32, // identifies the info struct |
72 | pub avail_topic_size: u16, // “native” size of the struct | |
73 | pub topic_size: u16, // size of the returned struct (<=topic_size) | |
74 | pub avail_count: u32, // number of records the kernel has | |
75 | pub count: u32, // number of records returned (limited by buffer size) | |
76 | } | |
77 | ||
78 | #[derive(Default)] | |
79 | #[repr(C)] | |
ea8adc8c | 80 | pub struct zx_record_process_t { |
476ff2be SL |
81 | pub return_code: c_int, |
82 | } | |
83 | ||
ea8adc8c | 84 | // Returned for topic ZX_INFO_PROCESS |
476ff2be SL |
85 | #[derive(Default)] |
86 | #[repr(C)] | |
ea8adc8c XL |
87 | pub struct zx_info_process_t { |
88 | pub hdr: zx_info_header_t, | |
89 | pub rec: zx_record_process_t, | |
476ff2be SL |
90 | } |
91 | ||
92 | extern { | |
ea8adc8c | 93 | pub fn zx_job_default() -> zx_handle_t; |
32a655c1 | 94 | |
ea8adc8c | 95 | pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t; |
476ff2be | 96 | |
ea8adc8c | 97 | pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t; |
476ff2be | 98 | |
ea8adc8c XL |
99 | pub fn zx_handle_duplicate(handle: zx_handle_t, rights: zx_rights_t, |
100 | out: *const zx_handle_t) -> zx_handle_t; | |
476ff2be | 101 | |
ea8adc8c XL |
102 | pub fn zx_object_wait_one(handle: zx_handle_t, signals: zx_signals_t, timeout: zx_time_t, |
103 | pending: *mut zx_signals_t) -> zx_status_t; | |
476ff2be | 104 | |
ea8adc8c XL |
105 | pub fn zx_object_get_info(handle: zx_handle_t, topic: u32, buffer: *mut c_void, |
106 | buffer_size: size_t, actual_size: *mut size_t, | |
107 | avail: *mut size_t) -> zx_status_t; | |
476ff2be SL |
108 | } |
109 | ||
94b46f34 | 110 | #[derive(Default)] |
476ff2be | 111 | #[repr(C)] |
94b46f34 XL |
112 | pub struct fdio_spawn_action_t { |
113 | pub action: u32, | |
114 | pub reserved0: u32, | |
115 | pub local_fd: i32, | |
116 | pub target_fd: i32, | |
117 | pub reserved1: u64, | |
476ff2be SL |
118 | } |
119 | ||
120 | extern { | |
94b46f34 XL |
121 | pub fn fdio_spawn_etc(job: zx_handle_t, flags: u32, path: *const c_char, |
122 | argv: *const *const c_char, envp: *const *const c_char, | |
123 | action_count: u64, actions: *const fdio_spawn_action_t, | |
124 | process: *mut zx_handle_t, err_msg: *mut c_char) -> zx_status_t; | |
125 | } | |
476ff2be | 126 | |
94b46f34 | 127 | // fdio_spawn_etc flags |
476ff2be | 128 | |
94b46f34 XL |
129 | pub const FDIO_SPAWN_CLONE_JOB: u32 = 0x0001; |
130 | pub const FDIO_SPAWN_CLONE_LDSVC: u32 = 0x0002; | |
131 | pub const FDIO_SPAWN_CLONE_NAMESPACE: u32 = 0x0004; | |
132 | pub const FDIO_SPAWN_CLONE_STDIO: u32 = 0x0008; | |
133 | pub const FDIO_SPAWN_CLONE_ENVIRON: u32 = 0x0010; | |
134 | pub const FDIO_SPAWN_CLONE_ALL: u32 = 0xFFFF; | |
32a655c1 | 135 | |
94b46f34 | 136 | // fdio_spawn_etc actions |
8bb4bdeb | 137 | |
94b46f34 XL |
138 | pub const FDIO_SPAWN_ACTION_CLONE_FD: u32 = 0x0001; |
139 | pub const FDIO_SPAWN_ACTION_TRANSFER_FD: u32 = 0x0002; | |
8bb4bdeb | 140 | |
32a655c1 SL |
141 | // Errors |
142 | ||
ea8adc8c | 143 | #[allow(unused)] pub const ERR_INTERNAL: zx_status_t = -1; |
32a655c1 SL |
144 | |
145 | // ERR_NOT_SUPPORTED: The operation is not implemented, supported, | |
146 | // or enabled. | |
ea8adc8c | 147 | #[allow(unused)] pub const ERR_NOT_SUPPORTED: zx_status_t = -2; |
32a655c1 SL |
148 | |
149 | // ERR_NO_RESOURCES: The system was not able to allocate some resource | |
150 | // needed for the operation. | |
ea8adc8c | 151 | #[allow(unused)] pub const ERR_NO_RESOURCES: zx_status_t = -3; |
32a655c1 SL |
152 | |
153 | // ERR_NO_MEMORY: The system was not able to allocate memory needed | |
154 | // for the operation. | |
ea8adc8c | 155 | #[allow(unused)] pub const ERR_NO_MEMORY: zx_status_t = -4; |
32a655c1 | 156 | |
ea8adc8c | 157 | // ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete |
32a655c1 | 158 | // successfully. |
ea8adc8c | 159 | #[allow(unused)] pub const ERR_CALL_FAILED: zx_status_t = -5; |
cc61c64b XL |
160 | |
161 | // ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be | |
162 | // retried. This should not be seen outside of the VDSO. | |
ea8adc8c | 163 | #[allow(unused)] pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6; |
32a655c1 SL |
164 | |
165 | // ======= Parameter errors ======= | |
166 | // ERR_INVALID_ARGS: an argument is invalid, ex. null pointer | |
ea8adc8c | 167 | #[allow(unused)] pub const ERR_INVALID_ARGS: zx_status_t = -10; |
32a655c1 | 168 | |
cc61c64b | 169 | // ERR_BAD_HANDLE: A specified handle value does not refer to a handle. |
ea8adc8c | 170 | #[allow(unused)] pub const ERR_BAD_HANDLE: zx_status_t = -11; |
cc61c64b | 171 | |
32a655c1 SL |
172 | // ERR_WRONG_TYPE: The subject of the operation is the wrong type to |
173 | // perform the operation. | |
174 | // Example: Attempting a message_read on a thread handle. | |
ea8adc8c | 175 | #[allow(unused)] pub const ERR_WRONG_TYPE: zx_status_t = -12; |
32a655c1 SL |
176 | |
177 | // ERR_BAD_SYSCALL: The specified syscall number is invalid. | |
ea8adc8c | 178 | #[allow(unused)] pub const ERR_BAD_SYSCALL: zx_status_t = -13; |
32a655c1 SL |
179 | |
180 | // ERR_OUT_OF_RANGE: An argument is outside the valid range for this | |
181 | // operation. | |
ea8adc8c | 182 | #[allow(unused)] pub const ERR_OUT_OF_RANGE: zx_status_t = -14; |
32a655c1 SL |
183 | |
184 | // ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for | |
185 | // this operation. | |
ea8adc8c | 186 | #[allow(unused)] pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15; |
32a655c1 SL |
187 | |
188 | // ======= Precondition or state errors ======= | |
189 | // ERR_BAD_STATE: operation failed because the current state of the | |
190 | // object does not allow it, or a precondition of the operation is | |
191 | // not satisfied | |
ea8adc8c | 192 | #[allow(unused)] pub const ERR_BAD_STATE: zx_status_t = -20; |
32a655c1 | 193 | |
cc61c64b XL |
194 | // ERR_TIMED_OUT: The time limit for the operation elapsed before |
195 | // the operation completed. | |
ea8adc8c | 196 | #[allow(unused)] pub const ERR_TIMED_OUT: zx_status_t = -21; |
cc61c64b XL |
197 | |
198 | // ERR_SHOULD_WAIT: The operation cannot be performed currently but | |
199 | // potentially could succeed if the caller waits for a prerequisite | |
200 | // to be satisfied, for example waiting for a handle to be readable | |
201 | // or writable. | |
202 | // Example: Attempting to read from a message pipe that has no | |
203 | // messages waiting but has an open remote will return ERR_SHOULD_WAIT. | |
204 | // Attempting to read from a message pipe that has no messages waiting | |
205 | // and has a closed remote end will return ERR_REMOTE_CLOSED. | |
ea8adc8c | 206 | #[allow(unused)] pub const ERR_SHOULD_WAIT: zx_status_t = -22; |
cc61c64b | 207 | |
0731742a | 208 | // ERR_CANCELED: The in-progress operation (e.g., a wait) has been |
cc61c64b | 209 | // // canceled. |
ea8adc8c | 210 | #[allow(unused)] pub const ERR_CANCELED: zx_status_t = -23; |
cc61c64b XL |
211 | |
212 | // ERR_PEER_CLOSED: The operation failed because the remote end | |
213 | // of the subject of the operation was closed. | |
ea8adc8c | 214 | #[allow(unused)] pub const ERR_PEER_CLOSED: zx_status_t = -24; |
cc61c64b | 215 | |
32a655c1 | 216 | // ERR_NOT_FOUND: The requested entity is not found. |
ea8adc8c | 217 | #[allow(unused)] pub const ERR_NOT_FOUND: zx_status_t = -25; |
32a655c1 SL |
218 | |
219 | // ERR_ALREADY_EXISTS: An object with the specified identifier | |
220 | // already exists. | |
221 | // Example: Attempting to create a file when a file already exists | |
222 | // with that name. | |
ea8adc8c | 223 | #[allow(unused)] pub const ERR_ALREADY_EXISTS: zx_status_t = -26; |
32a655c1 SL |
224 | |
225 | // ERR_ALREADY_BOUND: The operation failed because the named entity | |
226 | // is already owned or controlled by another entity. The operation | |
227 | // could succeed later if the current owner releases the entity. | |
ea8adc8c | 228 | #[allow(unused)] pub const ERR_ALREADY_BOUND: zx_status_t = -27; |
32a655c1 SL |
229 | |
230 | // ERR_UNAVAILABLE: The subject of the operation is currently unable | |
231 | // to perform the operation. | |
232 | // Note: This is used when there's no direct way for the caller to | |
233 | // observe when the subject will be able to perform the operation | |
234 | // and should thus retry. | |
ea8adc8c | 235 | #[allow(unused)] pub const ERR_UNAVAILABLE: zx_status_t = -28; |
32a655c1 SL |
236 | |
237 | // ======= Permission check errors ======= | |
238 | // ERR_ACCESS_DENIED: The caller did not have permission to perform | |
239 | // the specified operation. | |
ea8adc8c | 240 | #[allow(unused)] pub const ERR_ACCESS_DENIED: zx_status_t = -30; |
32a655c1 SL |
241 | |
242 | // ======= Input-output errors ======= | |
243 | // ERR_IO: Otherwise unspecified error occurred during I/O. | |
ea8adc8c | 244 | #[allow(unused)] pub const ERR_IO: zx_status_t = -40; |
32a655c1 SL |
245 | |
246 | // ERR_REFUSED: The entity the I/O operation is being performed on | |
247 | // rejected the operation. | |
248 | // Example: an I2C device NAK'ing a transaction or a disk controller | |
249 | // rejecting an invalid command. | |
ea8adc8c | 250 | #[allow(unused)] pub const ERR_IO_REFUSED: zx_status_t = -41; |
32a655c1 SL |
251 | |
252 | // ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity | |
253 | // check and is possibly corrupted. | |
254 | // Example: CRC or Parity error. | |
ea8adc8c | 255 | #[allow(unused)] pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42; |
32a655c1 SL |
256 | |
257 | // ERR_IO_DATA_LOSS: The data in the operation is currently unavailable | |
258 | // and may be permanently lost. | |
259 | // Example: A disk block is irrecoverably damaged. | |
ea8adc8c | 260 | #[allow(unused)] pub const ERR_IO_DATA_LOSS: zx_status_t = -43; |
32a655c1 SL |
261 | |
262 | // Filesystem specific errors | |
ea8adc8c XL |
263 | #[allow(unused)] pub const ERR_BAD_PATH: zx_status_t = -50; |
264 | #[allow(unused)] pub const ERR_NOT_DIR: zx_status_t = -51; | |
265 | #[allow(unused)] pub const ERR_NOT_FILE: zx_status_t = -52; | |
cc61c64b | 266 | // ERR_FILE_BIG: A file exceeds a filesystem-specific size limit. |
ea8adc8c | 267 | #[allow(unused)] pub const ERR_FILE_BIG: zx_status_t = -53; |
cc61c64b | 268 | // ERR_NO_SPACE: Filesystem or device space is exhausted. |
ea8adc8c | 269 | #[allow(unused)] pub const ERR_NO_SPACE: zx_status_t = -54; |