1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(non_camel_case_types, unused)]
18 use libc::{c_int, c_void, size_t};
20 pub type zx_handle_t = u32;
21 pub type zx_vaddr_t = usize;
22 pub type zx_rights_t = u32;
23 pub type zx_status_t = i32;
25 pub const ZX_HANDLE_INVALID: zx_handle_t = 0;
27 pub type zx_time_t = u64;
28 pub const ZX_TIME_INFINITE : zx_time_t = u64::MAX;
30 pub type zx_signals_t = u32;
32 pub const ZX_OBJECT_SIGNAL_3 : zx_signals_t = 1 << 3;
34 pub const ZX_TASK_TERMINATED : zx_signals_t = ZX_OBJECT_SIGNAL_3;
36 pub const ZX_RIGHT_SAME_RIGHTS : zx_rights_t = 1 << 31;
38 pub type zx_object_info_topic_t = u32;
40 pub const ZX_INFO_PROCESS : zx_object_info_topic_t = 3;
42 pub fn zx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<zx_status_t>+Copy {
43 if let Ok(status) = TryInto::try_into(t) {
45 Err(io::Error::from_raw_os_error(status))
50 Err(io::Error::last_os_error())
54 // Safe wrapper around zx_handle_t
60 pub fn new(raw: zx_handle_t) -> Handle {
66 pub fn raw(&self) -> zx_handle_t {
71 impl Drop for Handle {
73 unsafe { zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t"); }
77 // Common ZX_INFO header
80 pub struct zx_info_header_t {
81 pub topic: u32, // identifies the info struct
82 pub avail_topic_size: u16, // “native” size of the struct
83 pub topic_size: u16, // size of the returned struct (<=topic_size)
84 pub avail_count: u32, // number of records the kernel has
85 pub count: u32, // number of records returned (limited by buffer size)
90 pub struct zx_record_process_t {
91 pub return_code: c_int,
94 // Returned for topic ZX_INFO_PROCESS
97 pub struct zx_info_process_t {
98 pub hdr: zx_info_header_t,
99 pub rec: zx_record_process_t,
103 pub fn zx_job_default() -> zx_handle_t;
105 pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t;
107 pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t;
109 pub fn zx_handle_duplicate(handle: zx_handle_t, rights: zx_rights_t,
110 out: *const zx_handle_t) -> zx_handle_t;
112 pub fn zx_object_wait_one(handle: zx_handle_t, signals: zx_signals_t, timeout: zx_time_t,
113 pending: *mut zx_signals_t) -> zx_status_t;
115 pub fn zx_object_get_info(handle: zx_handle_t, topic: u32, buffer: *mut c_void,
116 buffer_size: size_t, actual_size: *mut size_t,
117 avail: *mut size_t) -> zx_status_t;
122 pub struct fdio_spawn_action_t {
131 pub fn fdio_spawn_etc(job: zx_handle_t, flags: u32, path: *const c_char,
132 argv: *const *const c_char, envp: *const *const c_char,
133 action_count: u64, actions: *const fdio_spawn_action_t,
134 process: *mut zx_handle_t, err_msg: *mut c_char) -> zx_status_t;
137 // fdio_spawn_etc flags
139 pub const FDIO_SPAWN_CLONE_JOB: u32 = 0x0001;
140 pub const FDIO_SPAWN_CLONE_LDSVC: u32 = 0x0002;
141 pub const FDIO_SPAWN_CLONE_NAMESPACE: u32 = 0x0004;
142 pub const FDIO_SPAWN_CLONE_STDIO: u32 = 0x0008;
143 pub const FDIO_SPAWN_CLONE_ENVIRON: u32 = 0x0010;
144 pub const FDIO_SPAWN_CLONE_ALL: u32 = 0xFFFF;
146 // fdio_spawn_etc actions
148 pub const FDIO_SPAWN_ACTION_CLONE_FD: u32 = 0x0001;
149 pub const FDIO_SPAWN_ACTION_TRANSFER_FD: u32 = 0x0002;
153 #[allow(unused)] pub const ERR_INTERNAL: zx_status_t = -1;
155 // ERR_NOT_SUPPORTED: The operation is not implemented, supported,
157 #[allow(unused)] pub const ERR_NOT_SUPPORTED: zx_status_t = -2;
159 // ERR_NO_RESOURCES: The system was not able to allocate some resource
160 // needed for the operation.
161 #[allow(unused)] pub const ERR_NO_RESOURCES: zx_status_t = -3;
163 // ERR_NO_MEMORY: The system was not able to allocate memory needed
164 // for the operation.
165 #[allow(unused)] pub const ERR_NO_MEMORY: zx_status_t = -4;
167 // ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete
169 #[allow(unused)] pub const ERR_CALL_FAILED: zx_status_t = -5;
171 // ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be
172 // retried. This should not be seen outside of the VDSO.
173 #[allow(unused)] pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6;
175 // ======= Parameter errors =======
176 // ERR_INVALID_ARGS: an argument is invalid, ex. null pointer
177 #[allow(unused)] pub const ERR_INVALID_ARGS: zx_status_t = -10;
179 // ERR_BAD_HANDLE: A specified handle value does not refer to a handle.
180 #[allow(unused)] pub const ERR_BAD_HANDLE: zx_status_t = -11;
182 // ERR_WRONG_TYPE: The subject of the operation is the wrong type to
183 // perform the operation.
184 // Example: Attempting a message_read on a thread handle.
185 #[allow(unused)] pub const ERR_WRONG_TYPE: zx_status_t = -12;
187 // ERR_BAD_SYSCALL: The specified syscall number is invalid.
188 #[allow(unused)] pub const ERR_BAD_SYSCALL: zx_status_t = -13;
190 // ERR_OUT_OF_RANGE: An argument is outside the valid range for this
192 #[allow(unused)] pub const ERR_OUT_OF_RANGE: zx_status_t = -14;
194 // ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for
196 #[allow(unused)] pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15;
198 // ======= Precondition or state errors =======
199 // ERR_BAD_STATE: operation failed because the current state of the
200 // object does not allow it, or a precondition of the operation is
202 #[allow(unused)] pub const ERR_BAD_STATE: zx_status_t = -20;
204 // ERR_TIMED_OUT: The time limit for the operation elapsed before
205 // the operation completed.
206 #[allow(unused)] pub const ERR_TIMED_OUT: zx_status_t = -21;
208 // ERR_SHOULD_WAIT: The operation cannot be performed currently but
209 // potentially could succeed if the caller waits for a prerequisite
210 // to be satisfied, for example waiting for a handle to be readable
212 // Example: Attempting to read from a message pipe that has no
213 // messages waiting but has an open remote will return ERR_SHOULD_WAIT.
214 // Attempting to read from a message pipe that has no messages waiting
215 // and has a closed remote end will return ERR_REMOTE_CLOSED.
216 #[allow(unused)] pub const ERR_SHOULD_WAIT: zx_status_t = -22;
218 // ERR_CANCELED: The in-progress operation (e.g., a wait) has been
220 #[allow(unused)] pub const ERR_CANCELED: zx_status_t = -23;
222 // ERR_PEER_CLOSED: The operation failed because the remote end
223 // of the subject of the operation was closed.
224 #[allow(unused)] pub const ERR_PEER_CLOSED: zx_status_t = -24;
226 // ERR_NOT_FOUND: The requested entity is not found.
227 #[allow(unused)] pub const ERR_NOT_FOUND: zx_status_t = -25;
229 // ERR_ALREADY_EXISTS: An object with the specified identifier
231 // Example: Attempting to create a file when a file already exists
233 #[allow(unused)] pub const ERR_ALREADY_EXISTS: zx_status_t = -26;
235 // ERR_ALREADY_BOUND: The operation failed because the named entity
236 // is already owned or controlled by another entity. The operation
237 // could succeed later if the current owner releases the entity.
238 #[allow(unused)] pub const ERR_ALREADY_BOUND: zx_status_t = -27;
240 // ERR_UNAVAILABLE: The subject of the operation is currently unable
241 // to perform the operation.
242 // Note: This is used when there's no direct way for the caller to
243 // observe when the subject will be able to perform the operation
244 // and should thus retry.
245 #[allow(unused)] pub const ERR_UNAVAILABLE: zx_status_t = -28;
247 // ======= Permission check errors =======
248 // ERR_ACCESS_DENIED: The caller did not have permission to perform
249 // the specified operation.
250 #[allow(unused)] pub const ERR_ACCESS_DENIED: zx_status_t = -30;
252 // ======= Input-output errors =======
253 // ERR_IO: Otherwise unspecified error occurred during I/O.
254 #[allow(unused)] pub const ERR_IO: zx_status_t = -40;
256 // ERR_REFUSED: The entity the I/O operation is being performed on
257 // rejected the operation.
258 // Example: an I2C device NAK'ing a transaction or a disk controller
259 // rejecting an invalid command.
260 #[allow(unused)] pub const ERR_IO_REFUSED: zx_status_t = -41;
262 // ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity
263 // check and is possibly corrupted.
264 // Example: CRC or Parity error.
265 #[allow(unused)] pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42;
267 // ERR_IO_DATA_LOSS: The data in the operation is currently unavailable
268 // and may be permanently lost.
269 // Example: A disk block is irrecoverably damaged.
270 #[allow(unused)] pub const ERR_IO_DATA_LOSS: zx_status_t = -43;
272 // Filesystem specific errors
273 #[allow(unused)] pub const ERR_BAD_PATH: zx_status_t = -50;
274 #[allow(unused)] pub const ERR_NOT_DIR: zx_status_t = -51;
275 #[allow(unused)] pub const ERR_NOT_FILE: zx_status_t = -52;
276 // ERR_FILE_BIG: A file exceeds a filesystem-specific size limit.
277 #[allow(unused)] pub const ERR_FILE_BIG: zx_status_t = -53;
278 // ERR_NO_SPACE: Filesystem or device space is exhausted.
279 #[allow(unused)] pub const ERR_NO_SPACE: zx_status_t = -54;