#![allow(non_camel_case_types, unused)]
use crate::io;
use crate::mem::MaybeUninit;
use crate::os::raw::c_char;
use libc::{c_int, c_void, size_t};
pub type zx_handle_t = u32;
pub type zx_vaddr_t = usize;
pub type zx_rights_t = u32;
pub type zx_status_t = i32;
pub const ZX_HANDLE_INVALID: zx_handle_t = 0;
pub type zx_time_t = i64;
pub const ZX_TIME_INFINITE: zx_time_t = i64::MAX;
pub type zx_signals_t = u32;
pub const ZX_OBJECT_SIGNAL_3: zx_signals_t = 1 << 3;
pub const ZX_TASK_TERMINATED: zx_signals_t = ZX_OBJECT_SIGNAL_3;
pub const ZX_RIGHT_SAME_RIGHTS: zx_rights_t = 1 << 31;
pub type zx_object_info_topic_t = u32;
pub const ZX_INFO_PROCESS: zx_object_info_topic_t = 3 | (1 << 28);
pub type zx_info_process_flags_t = u32;
pub fn zx_cvt<T>(t: T) -> io::Result<T>
where
T: TryInto<zx_status_t> + Copy,
{
if let Ok(status) = TryInto::try_into(t) {
if status < 0 { Err(io::Error::from_raw_os_error(status)) } else { Ok(t) }
} else {
Err(io::Error::last_os_error())
}
}
pub struct Handle {
raw: zx_handle_t,
}
impl Handle {
pub fn new(raw: zx_handle_t) -> Handle {
Handle { raw }
}
pub fn raw(&self) -> zx_handle_t {
self.raw
}
}
impl Drop for Handle {
fn drop(&mut self) {
unsafe {
zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t");
}
}
}
#[derive(Default)]
#[repr(C)]
pub struct zx_info_process_t {
pub return_code: i64,
pub start_time: zx_time_t,
pub flags: zx_info_process_flags_t,
pub reserved1: u32,
}
extern "C" {
pub fn zx_job_default() -> zx_handle_t;
pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t;
pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t;
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;
}
#[derive(Default)]
#[repr(C)]
pub struct fdio_spawn_action_t {
pub action: u32,
pub reserved0: u32,
pub local_fd: i32,
pub target_fd: i32,
pub reserved1: u64,
}
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;
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;
}
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;
pub const FDIO_SPAWN_CLONE_UTC_CLOCK: u32 = 0x0020;
pub const FDIO_SPAWN_CLONE_ALL: u32 = 0xFFFF;
pub const FDIO_SPAWN_ACTION_CLONE_FD: u32 = 0x0001;
pub const FDIO_SPAWN_ACTION_TRANSFER_FD: u32 = 0x0002;
#[allow(unused)]
pub const ERR_INTERNAL: zx_status_t = -1;
#[allow(unused)]
pub const ERR_NOT_SUPPORTED: zx_status_t = -2;
#[allow(unused)]
pub const ERR_NO_RESOURCES: zx_status_t = -3;
#[allow(unused)]
pub const ERR_NO_MEMORY: zx_status_t = -4;
#[allow(unused)]
pub const ERR_CALL_FAILED: zx_status_t = -5;
#[allow(unused)]
pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6;
#[allow(unused)]
pub const ERR_INVALID_ARGS: zx_status_t = -10;
#[allow(unused)]
pub const ERR_BAD_HANDLE: zx_status_t = -11;
#[allow(unused)]
pub const ERR_WRONG_TYPE: zx_status_t = -12;
#[allow(unused)]
pub const ERR_BAD_SYSCALL: zx_status_t = -13;
#[allow(unused)]
pub const ERR_OUT_OF_RANGE: zx_status_t = -14;
#[allow(unused)]
pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15;
#[allow(unused)]
pub const ERR_BAD_STATE: zx_status_t = -20;
#[allow(unused)]
pub const ERR_TIMED_OUT: zx_status_t = -21;
#[allow(unused)]
pub const ERR_SHOULD_WAIT: zx_status_t = -22;
#[allow(unused)]
pub const ERR_CANCELED: zx_status_t = -23;
#[allow(unused)]
pub const ERR_PEER_CLOSED: zx_status_t = -24;
#[allow(unused)]
pub const ERR_NOT_FOUND: zx_status_t = -25;
#[allow(unused)]
pub const ERR_ALREADY_EXISTS: zx_status_t = -26;
#[allow(unused)]
pub const ERR_ALREADY_BOUND: zx_status_t = -27;
#[allow(unused)]
pub const ERR_UNAVAILABLE: zx_status_t = -28;
#[allow(unused)]
pub const ERR_ACCESS_DENIED: zx_status_t = -30;
#[allow(unused)]
pub const ERR_IO: zx_status_t = -40;
#[allow(unused)]
pub const ERR_IO_REFUSED: zx_status_t = -41;
#[allow(unused)]
pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42;
#[allow(unused)]
pub const ERR_IO_DATA_LOSS: zx_status_t = -43;
#[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;
#[allow(unused)]
pub const ERR_FILE_BIG: zx_status_t = -53;
#[allow(unused)]
pub const ERR_NO_SPACE: zx_status_t = -54;