2018-06-01 19:58:30 +00:00
|
|
|
#![allow(non_camel_case_types, unused)]
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
use crate::convert::TryInto;
|
2019-08-30 00:49:46 +00:00
|
|
|
use crate::i64;
|
2019-11-27 18:28:39 +00:00
|
|
|
use crate::io;
|
2019-08-31 01:21:57 +00:00
|
|
|
use crate::mem::MaybeUninit;
|
|
|
|
use crate::os::raw::c_char;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2017-10-04 22:29:01 +00:00
|
|
|
use libc::{c_int, c_void, size_t};
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2017-10-04 21:08:53 +00:00
|
|
|
pub type zx_handle_t = u32;
|
2017-09-15 19:38:08 +00:00
|
|
|
pub type zx_vaddr_t = usize;
|
|
|
|
pub type zx_rights_t = u32;
|
|
|
|
pub type zx_status_t = i32;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2017-09-15 21:11:04 +00:00
|
|
|
pub const ZX_HANDLE_INVALID: zx_handle_t = 0;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-08-30 00:49:46 +00:00
|
|
|
pub type zx_time_t = i64;
|
2019-11-27 18:28:39 +00:00
|
|
|
pub const ZX_TIME_INFINITE: zx_time_t = i64::MAX;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
pub type zx_signals_t = u32;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub const ZX_OBJECT_SIGNAL_3: zx_signals_t = 1 << 3;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub const ZX_TASK_TERMINATED: zx_signals_t = ZX_OBJECT_SIGNAL_3;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub const ZX_RIGHT_SAME_RIGHTS: zx_rights_t = 1 << 31;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
pub type zx_object_info_topic_t = u32;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub const ZX_INFO_PROCESS: zx_object_info_topic_t = 3;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub fn zx_cvt<T>(t: T) -> io::Result<T>
|
|
|
|
where
|
|
|
|
T: TryInto<zx_status_t> + Copy,
|
|
|
|
{
|
2016-12-01 20:01:07 +00:00
|
|
|
if let Ok(status) = TryInto::try_into(t) {
|
2019-11-27 18:28:39 +00:00
|
|
|
if status < 0 { Err(io::Error::from_raw_os_error(status)) } else { Ok(t) }
|
2016-12-01 20:01:07 +00:00
|
|
|
} else {
|
|
|
|
Err(io::Error::last_os_error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
// Safe wrapper around zx_handle_t
|
2016-11-30 22:20:44 +00:00
|
|
|
pub struct Handle {
|
2017-09-15 19:38:08 +00:00
|
|
|
raw: zx_handle_t,
|
2016-11-30 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Handle {
|
2017-09-15 19:38:08 +00:00
|
|
|
pub fn new(raw: zx_handle_t) -> Handle {
|
2019-11-27 18:28:39 +00:00
|
|
|
Handle { raw }
|
2016-11-30 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
pub fn raw(&self) -> zx_handle_t {
|
2016-11-30 22:20:44 +00:00
|
|
|
self.raw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Handle {
|
|
|
|
fn drop(&mut self) {
|
2019-11-27 18:28:39 +00:00
|
|
|
unsafe {
|
|
|
|
zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t");
|
|
|
|
}
|
2016-11-30 22:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 21:11:04 +00:00
|
|
|
// Returned for topic ZX_INFO_PROCESS
|
2016-11-12 02:21:03 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
#[repr(C)]
|
2017-09-15 19:38:08 +00:00
|
|
|
pub struct zx_info_process_t {
|
2019-09-25 04:34:44 +00:00
|
|
|
pub return_code: i64,
|
|
|
|
pub started: bool,
|
|
|
|
pub exited: bool,
|
|
|
|
pub debugger_attached: bool,
|
2016-11-12 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
extern "C" {
|
2017-09-15 19:38:08 +00:00
|
|
|
pub fn zx_job_default() -> zx_handle_t;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t;
|
2016-11-30 22:20:44 +00:00
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t;
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
pub fn zx_handle_duplicate(
|
|
|
|
handle: zx_handle_t,
|
|
|
|
rights: zx_rights_t,
|
|
|
|
out: *const zx_handle_t,
|
|
|
|
) -> zx_handle_t;
|
|
|
|
|
|
|
|
pub fn zx_object_wait_one(
|
|
|
|
handle: zx_handle_t,
|
|
|
|
signals: zx_signals_t,
|
|
|
|
timeout: zx_time_t,
|
|
|
|
pending: *mut zx_signals_t,
|
|
|
|
) -> zx_status_t;
|
|
|
|
|
|
|
|
pub fn zx_object_get_info(
|
|
|
|
handle: zx_handle_t,
|
|
|
|
topic: u32,
|
|
|
|
buffer: *mut c_void,
|
|
|
|
buffer_size: size_t,
|
|
|
|
actual_size: *mut size_t,
|
|
|
|
avail: *mut size_t,
|
|
|
|
) -> zx_status_t;
|
2016-11-12 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-01 19:58:30 +00:00
|
|
|
#[derive(Default)]
|
2016-11-12 02:21:03 +00:00
|
|
|
#[repr(C)]
|
2018-06-01 19:58:30 +00:00
|
|
|
pub struct fdio_spawn_action_t {
|
|
|
|
pub action: u32,
|
|
|
|
pub reserved0: u32,
|
|
|
|
pub local_fd: i32,
|
|
|
|
pub target_fd: i32,
|
|
|
|
pub reserved1: u64,
|
2016-11-12 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
extern "C" {
|
|
|
|
pub fn fdio_spawn_etc(
|
|
|
|
job: zx_handle_t,
|
|
|
|
flags: u32,
|
|
|
|
path: *const c_char,
|
|
|
|
argv: *const *const c_char,
|
|
|
|
envp: *const *const c_char,
|
|
|
|
action_count: size_t,
|
|
|
|
actions: *const fdio_spawn_action_t,
|
|
|
|
process: *mut zx_handle_t,
|
|
|
|
err_msg: *mut c_char,
|
|
|
|
) -> zx_status_t;
|
2019-08-31 01:21:57 +00:00
|
|
|
|
|
|
|
pub fn fdio_fd_clone(fd: c_int, out_handle: *mut zx_handle_t) -> zx_status_t;
|
|
|
|
pub fn fdio_fd_create(handle: zx_handle_t, fd: *mut c_int) -> zx_status_t;
|
2018-06-01 19:58:30 +00:00
|
|
|
}
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2018-06-01 19:58:30 +00:00
|
|
|
// fdio_spawn_etc flags
|
2016-11-12 02:21:03 +00:00
|
|
|
|
2018-06-01 19:58:30 +00:00
|
|
|
pub const FDIO_SPAWN_CLONE_JOB: u32 = 0x0001;
|
|
|
|
pub const FDIO_SPAWN_CLONE_LDSVC: u32 = 0x0002;
|
|
|
|
pub const FDIO_SPAWN_CLONE_NAMESPACE: u32 = 0x0004;
|
|
|
|
pub const FDIO_SPAWN_CLONE_STDIO: u32 = 0x0008;
|
|
|
|
pub const FDIO_SPAWN_CLONE_ENVIRON: u32 = 0x0010;
|
2020-09-15 20:54:46 +00:00
|
|
|
pub const FDIO_SPAWN_CLONE_UTC_CLOCK: u32 = 0x0020;
|
2018-06-01 19:58:30 +00:00
|
|
|
pub const FDIO_SPAWN_CLONE_ALL: u32 = 0xFFFF;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
2018-06-01 19:58:30 +00:00
|
|
|
// fdio_spawn_etc actions
|
2017-02-28 04:26:55 +00:00
|
|
|
|
2018-06-01 19:58:30 +00:00
|
|
|
pub const FDIO_SPAWN_ACTION_CLONE_FD: u32 = 0x0001;
|
|
|
|
pub const FDIO_SPAWN_ACTION_TRANSFER_FD: u32 = 0x0002;
|
2017-02-28 04:26:55 +00:00
|
|
|
|
2017-01-24 21:01:47 +00:00
|
|
|
// Errors
|
|
|
|
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_INTERNAL: zx_status_t = -1;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_NOT_SUPPORTED: The operation is not implemented, supported,
|
|
|
|
// or enabled.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NOT_SUPPORTED: zx_status_t = -2;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_NO_RESOURCES: The system was not able to allocate some resource
|
|
|
|
// needed for the operation.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NO_RESOURCES: zx_status_t = -3;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_NO_MEMORY: The system was not able to allocate memory needed
|
|
|
|
// for the operation.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NO_MEMORY: zx_status_t = -4;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
2017-09-15 19:38:08 +00:00
|
|
|
// ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete
|
2017-01-24 21:01:47 +00:00
|
|
|
// successfully.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_CALL_FAILED: zx_status_t = -5;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
|
|
|
// ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be
|
|
|
|
// retried. This should not be seen outside of the VDSO.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ======= Parameter errors =======
|
|
|
|
// ERR_INVALID_ARGS: an argument is invalid, ex. null pointer
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_INVALID_ARGS: zx_status_t = -10;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
2017-04-15 01:37:57 +00:00
|
|
|
// ERR_BAD_HANDLE: A specified handle value does not refer to a handle.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_BAD_HANDLE: zx_status_t = -11;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
2017-01-24 21:01:47 +00:00
|
|
|
// ERR_WRONG_TYPE: The subject of the operation is the wrong type to
|
|
|
|
// perform the operation.
|
|
|
|
// Example: Attempting a message_read on a thread handle.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_WRONG_TYPE: zx_status_t = -12;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_BAD_SYSCALL: The specified syscall number is invalid.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_BAD_SYSCALL: zx_status_t = -13;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_OUT_OF_RANGE: An argument is outside the valid range for this
|
|
|
|
// operation.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_OUT_OF_RANGE: zx_status_t = -14;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for
|
|
|
|
// this operation.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ======= Precondition or state errors =======
|
|
|
|
// ERR_BAD_STATE: operation failed because the current state of the
|
|
|
|
// object does not allow it, or a precondition of the operation is
|
|
|
|
// not satisfied
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_BAD_STATE: zx_status_t = -20;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
2017-04-15 01:37:57 +00:00
|
|
|
// ERR_TIMED_OUT: The time limit for the operation elapsed before
|
|
|
|
// the operation completed.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_TIMED_OUT: zx_status_t = -21;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
|
|
|
// ERR_SHOULD_WAIT: The operation cannot be performed currently but
|
|
|
|
// potentially could succeed if the caller waits for a prerequisite
|
|
|
|
// to be satisfied, for example waiting for a handle to be readable
|
|
|
|
// or writable.
|
|
|
|
// Example: Attempting to read from a message pipe that has no
|
|
|
|
// messages waiting but has an open remote will return ERR_SHOULD_WAIT.
|
|
|
|
// Attempting to read from a message pipe that has no messages waiting
|
|
|
|
// and has a closed remote end will return ERR_REMOTE_CLOSED.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_SHOULD_WAIT: zx_status_t = -22;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// ERR_CANCELED: The in-progress operation (e.g., a wait) has been
|
2017-04-15 01:37:57 +00:00
|
|
|
// // canceled.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_CANCELED: zx_status_t = -23;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
|
|
|
// ERR_PEER_CLOSED: The operation failed because the remote end
|
|
|
|
// of the subject of the operation was closed.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_PEER_CLOSED: zx_status_t = -24;
|
2017-04-15 01:37:57 +00:00
|
|
|
|
2017-01-24 21:01:47 +00:00
|
|
|
// ERR_NOT_FOUND: The requested entity is not found.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NOT_FOUND: zx_status_t = -25;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_ALREADY_EXISTS: An object with the specified identifier
|
|
|
|
// already exists.
|
|
|
|
// Example: Attempting to create a file when a file already exists
|
|
|
|
// with that name.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_ALREADY_EXISTS: zx_status_t = -26;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_ALREADY_BOUND: The operation failed because the named entity
|
|
|
|
// is already owned or controlled by another entity. The operation
|
|
|
|
// could succeed later if the current owner releases the entity.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_ALREADY_BOUND: zx_status_t = -27;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_UNAVAILABLE: The subject of the operation is currently unable
|
|
|
|
// to perform the operation.
|
|
|
|
// Note: This is used when there's no direct way for the caller to
|
|
|
|
// observe when the subject will be able to perform the operation
|
|
|
|
// and should thus retry.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_UNAVAILABLE: zx_status_t = -28;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ======= Permission check errors =======
|
|
|
|
// ERR_ACCESS_DENIED: The caller did not have permission to perform
|
|
|
|
// the specified operation.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_ACCESS_DENIED: zx_status_t = -30;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ======= Input-output errors =======
|
|
|
|
// ERR_IO: Otherwise unspecified error occurred during I/O.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_IO: zx_status_t = -40;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_REFUSED: The entity the I/O operation is being performed on
|
|
|
|
// rejected the operation.
|
|
|
|
// Example: an I2C device NAK'ing a transaction or a disk controller
|
|
|
|
// rejecting an invalid command.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_IO_REFUSED: zx_status_t = -41;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity
|
|
|
|
// check and is possibly corrupted.
|
|
|
|
// Example: CRC or Parity error.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// ERR_IO_DATA_LOSS: The data in the operation is currently unavailable
|
|
|
|
// and may be permanently lost.
|
|
|
|
// Example: A disk block is irrecoverably damaged.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_IO_DATA_LOSS: zx_status_t = -43;
|
2017-01-24 21:01:47 +00:00
|
|
|
|
|
|
|
// Filesystem specific errors
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_BAD_PATH: zx_status_t = -50;
|
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NOT_DIR: zx_status_t = -51;
|
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NOT_FILE: zx_status_t = -52;
|
2017-04-15 01:37:57 +00:00
|
|
|
// ERR_FILE_BIG: A file exceeds a filesystem-specific size limit.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_FILE_BIG: zx_status_t = -53;
|
2017-04-15 01:37:57 +00:00
|
|
|
// ERR_NO_SPACE: Filesystem or device space is exhausted.
|
2019-11-27 18:28:39 +00:00
|
|
|
#[allow(unused)]
|
|
|
|
pub const ERR_NO_SPACE: zx_status_t = -54;
|