diff options
Diffstat (limited to 'third_party/rust/fuchsia-zircon-sys/src')
-rw-r--r-- | third_party/rust/fuchsia-zircon-sys/src/definitions.rs | 903 | ||||
-rw-r--r-- | third_party/rust/fuchsia-zircon-sys/src/lib.rs | 474 |
2 files changed, 1377 insertions, 0 deletions
diff --git a/third_party/rust/fuchsia-zircon-sys/src/definitions.rs b/third_party/rust/fuchsia-zircon-sys/src/definitions.rs new file mode 100644 index 0000000000..956313dc86 --- /dev/null +++ b/third_party/rust/fuchsia-zircon-sys/src/definitions.rs @@ -0,0 +1,903 @@ +// Copyright 2017 The Fuchsia Authors. All rights reserved. +// This is a GENERATED file, see //zircon/system/host/sysgen. +// The license governing this file can be found in the LICENSE file. + +#[link(name = "zircon")] +extern { + pub fn zx_time_get( + clock_id: u32 + ) -> zx_time_t; + + pub fn zx_nanosleep( + deadline: zx_time_t + ) -> zx_status_t; + + pub fn zx_ticks_get( + ) -> u64; + + pub fn zx_ticks_per_second( + ) -> u64; + + pub fn zx_deadline_after( + nanoseconds: zx_duration_t + ) -> zx_time_t; + + pub fn zx_clock_adjust( + handle: zx_handle_t, + clock_id: u32, + offset: i64 + ) -> zx_status_t; + + pub fn zx_system_get_num_cpus( + ) -> u32; + + pub fn zx_system_get_version( + version: *mut u8, + version_len: u32 + ) -> zx_status_t; + + pub fn zx_system_get_physmem( + ) -> u64; + + pub fn zx_cache_flush( + addr: *const u8, + len: usize, + options: u32 + ) -> 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: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_handle_replace( + handle: zx_handle_t, + rights: zx_rights_t, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_object_wait_one( + handle: zx_handle_t, + waitfor: zx_signals_t, + deadline: zx_time_t, + observed: *mut zx_signals_t + ) -> zx_status_t; + + pub fn zx_object_wait_many( + items: *mut zx_wait_item_t, + count: u32, + deadline: zx_time_t + ) -> zx_status_t; + + pub fn zx_object_wait_async( + handle: zx_handle_t, + port_handle: zx_handle_t, + key: u64, + signals: zx_signals_t, + options: u32 + ) -> zx_status_t; + + pub fn zx_object_signal( + handle: zx_handle_t, + clear_mask: u32, + set_mask: u32 + ) -> zx_status_t; + + pub fn zx_object_signal_peer( + handle: zx_handle_t, + clear_mask: u32, + set_mask: u32 + ) -> zx_status_t; + + pub fn zx_object_get_property( + handle: zx_handle_t, + property: u32, + value: *mut u8, + size: usize + ) -> zx_status_t; + + pub fn zx_object_set_property( + handle: zx_handle_t, + property: u32, + value: *const u8, + size: usize + ) -> zx_status_t; + + pub fn zx_object_set_cookie( + handle: zx_handle_t, + scope: zx_handle_t, + cookie: u64 + ) -> zx_status_t; + + pub fn zx_object_get_cookie( + handle: zx_handle_t, + scope: zx_handle_t, + cookie: *mut u64 + ) -> zx_status_t; + + pub fn zx_object_get_info( + handle: zx_handle_t, + topic: u32, + buffer: *mut u8, + buffer_size: usize, + actual_count: *mut usize, + avail_count: *mut usize + ) -> zx_status_t; + + pub fn zx_object_get_child( + handle: zx_handle_t, + koid: u64, + rights: zx_rights_t, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_channel_create( + options: u32, + out0: *mut zx_handle_t, + out1: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_channel_read( + handle: zx_handle_t, + options: u32, + bytes: *mut u8, + handles: *mut zx_handle_t, + num_bytes: u32, + num_handles: u32, + actual_bytes: *mut u32, + actual_handles: *mut u32 + ) -> zx_status_t; + + pub fn zx_channel_write( + handle: zx_handle_t, + options: u32, + bytes: *const u8, + num_bytes: u32, + handles: *const zx_handle_t, + num_handles: u32 + ) -> zx_status_t; + + pub fn zx_channel_call_noretry( + handle: zx_handle_t, + options: u32, + deadline: zx_time_t, + args: *const zx_channel_call_args_t, + actual_bytes: *mut u32, + actual_handles: *mut u32, + read_status: *mut zx_status_t + ) -> zx_status_t; + + pub fn zx_channel_call_finish( + deadline: zx_time_t, + args: *const zx_channel_call_args_t, + actual_bytes: *mut u32, + actual_handles: *mut u32, + read_status: *mut zx_status_t + ) -> zx_status_t; + + pub fn zx_channel_call( + handle: zx_handle_t, + options: u32, + deadline: zx_time_t, + args: *const zx_channel_call_args_t, + actual_bytes: *mut u32, + actual_handles: *mut u32, + read_status: *mut zx_status_t + ) -> zx_status_t; + + pub fn zx_socket_create( + options: u32, + out0: *mut zx_handle_t, + out1: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_socket_write( + handle: zx_handle_t, + options: u32, + buffer: *const u8, + size: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_socket_read( + handle: zx_handle_t, + options: u32, + buffer: *mut u8, + size: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_thread_exit( + ); + + pub fn zx_thread_create( + process: zx_handle_t, + name: *const u8, + name_len: u32, + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_thread_start( + handle: zx_handle_t, + thread_entry: usize, + stack: usize, + arg1: usize, + arg2: usize + ) -> zx_status_t; + + pub fn zx_thread_read_state( + handle: zx_handle_t, + kind: u32, + buffer: *mut u8, + len: u32, + actual: *mut u32 + ) -> zx_status_t; + + pub fn zx_thread_write_state( + handle: zx_handle_t, + kind: u32, + buffer: *const u8, + buffer_len: u32 + ) -> zx_status_t; + + pub fn zx_thread_set_priority( + prio: i32 + ) -> zx_status_t; + + pub fn zx_process_exit( + retcode: isize + ); + + pub fn zx_process_create( + job: zx_handle_t, + name: *const u8, + name_len: u32, + options: u32, + proc_handle: *mut zx_handle_t, + vmar_handle: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_process_start( + process_handle: zx_handle_t, + thread_handle: zx_handle_t, + entry: usize, + stack: usize, + arg_handle: zx_handle_t, + arg2: usize + ) -> zx_status_t; + + pub fn zx_process_read_memory( + proc_: zx_handle_t, + vaddr: usize, + buffer: *mut u8, + len: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_process_write_memory( + proc_: zx_handle_t, + vaddr: usize, + buffer: *const u8, + len: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_job_create( + parent_job: zx_handle_t, + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_job_set_policy( + job: zx_handle_t, + options: u32, + topic: u32, + policy: *const u8, + count: u32 + ) -> zx_status_t; + + pub fn zx_task_bind_exception_port( + object: zx_handle_t, + eport: zx_handle_t, + key: u64, + options: u32 + ) -> zx_status_t; + + pub fn zx_task_suspend( + task_handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_task_resume( + task_handle: zx_handle_t, + options: u32 + ) -> zx_status_t; + + pub fn zx_task_kill( + task_handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_event_create( + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_eventpair_create( + options: u32, + out0: *mut zx_handle_t, + out1: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_futex_wait( + value_ptr: *mut zx_futex_t, + current_value: isize, + deadline: zx_time_t + ) -> zx_status_t; + + pub fn zx_futex_wake( + value_ptr: *const zx_futex_t, + count: u32 + ) -> zx_status_t; + + pub fn zx_futex_requeue( + wake_ptr: *mut zx_futex_t, + wake_count: u32, + current_value: isize, + requeue_ptr: *mut zx_futex_t, + requeue_count: u32 + ) -> zx_status_t; + + pub fn zx_port_create( + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_port_queue( + handle: zx_handle_t, + packet: *const zx_port_packet_t, + size: usize + ) -> zx_status_t; + + pub fn zx_port_wait( + handle: zx_handle_t, + deadline: zx_time_t, + packet: *mut zx_port_packet_t, + size: usize + ) -> zx_status_t; + + pub fn zx_port_cancel( + handle: zx_handle_t, + source: zx_handle_t, + key: u64 + ) -> zx_status_t; + + pub fn zx_timer_create( + options: u32, + clock_id: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_timer_set( + handle: zx_handle_t, + deadline: zx_time_t, + slack: zx_duration_t + ) -> zx_status_t; + + pub fn zx_timer_cancel( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_vmo_create( + size: u64, + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_vmo_read( + handle: zx_handle_t, + data: *mut u8, + offset: u64, + len: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_vmo_write( + handle: zx_handle_t, + data: *const u8, + offset: u64, + len: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_vmo_get_size( + handle: zx_handle_t, + size: *mut u64 + ) -> zx_status_t; + + pub fn zx_vmo_set_size( + handle: zx_handle_t, + size: u64 + ) -> zx_status_t; + + pub fn zx_vmo_op_range( + handle: zx_handle_t, + op: u32, + offset: u64, + size: u64, + buffer: *mut u8, + buffer_size: usize + ) -> zx_status_t; + + pub fn zx_vmo_clone( + handle: zx_handle_t, + options: u32, + offset: u64, + size: u64, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_vmo_set_cache_policy( + handle: zx_handle_t, + cache_policy: u32 + ) -> zx_status_t; + + pub fn zx_vmar_allocate( + parent_vmar_handle: zx_handle_t, + offset: usize, + size: usize, + map_flags: u32, + child_vmar: *mut zx_handle_t, + child_addr: *mut usize + ) -> zx_status_t; + + pub fn zx_vmar_destroy( + vmar_handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_vmar_map( + vmar_handle: zx_handle_t, + vmar_offset: usize, + vmo_handle: zx_handle_t, + vmo_offset: u64, + len: usize, + map_flags: u32, + mapped_addr: *mut usize + ) -> zx_status_t; + + pub fn zx_vmar_unmap( + vmar_handle: zx_handle_t, + addr: usize, + len: usize + ) -> zx_status_t; + + pub fn zx_vmar_protect( + vmar_handle: zx_handle_t, + addr: usize, + len: usize, + prot_flags: u32 + ) -> zx_status_t; + + pub fn zx_vmar_root_self() -> zx_handle_t; + + pub fn zx_cprng_draw( + buffer: *mut u8, + len: usize, + actual: *mut usize + ) -> zx_status_t; + + pub fn zx_cprng_add_entropy( + buffer: *const u8, + len: usize + ) -> zx_status_t; + + pub fn zx_fifo_create( + elem_count: u32, + elem_size: u32, + options: u32, + out0: *mut zx_handle_t, + out1: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_fifo_read( + handle: zx_handle_t, + data: *mut u8, + len: usize, + num_written: *mut u32 + ) -> zx_status_t; + + pub fn zx_fifo_write( + handle: zx_handle_t, + data: *const u8, + len: usize, + num_written: *mut u32 + ) -> zx_status_t; + + pub fn zx_vmar_unmap_handle_close_thread_exit( + vmar_handle: zx_handle_t, + addr: usize, + len: usize, + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_futex_wake_handle_close_thread_exit( + value_ptr: *const zx_futex_t, + count: u32, + new_value: isize, + handle: zx_handle_t + ); + + pub fn zx_log_create( + options: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_log_write( + handle: zx_handle_t, + len: u32, + buffer: *const u8, + options: u32 + ) -> zx_status_t; + + pub fn zx_log_read( + handle: zx_handle_t, + len: u32, + buffer: *mut u8, + options: u32 + ) -> zx_status_t; + + pub fn zx_ktrace_read( + handle: zx_handle_t, + data: *mut u8, + offset: u32, + len: u32, + actual: *mut u32 + ) -> zx_status_t; + + pub fn zx_ktrace_control( + handle: zx_handle_t, + action: u32, + options: u32, + ptr: *mut u8 + ) -> zx_status_t; + + pub fn zx_ktrace_write( + handle: zx_handle_t, + id: u32, + arg0: u32, + arg1: u32 + ) -> zx_status_t; + + pub fn zx_mtrace_control( + handle: zx_handle_t, + kind: u32, + action: u32, + options: u32, + ptr: *mut u8, + size: u32 + ) -> zx_status_t; + + pub fn zx_debug_read( + handle: zx_handle_t, + buffer: *mut u8, + length: u32 + ) -> zx_status_t; + + pub fn zx_debug_write( + buffer: *const u8, + length: u32 + ) -> zx_status_t; + + pub fn zx_debug_send_command( + resource_handle: zx_handle_t, + buffer: *const u8, + length: u32 + ) -> zx_status_t; + + pub fn zx_interrupt_create( + handle: zx_handle_t, + vector: u32, + options: u32, + out_handle: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_interrupt_complete( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_interrupt_wait( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_interrupt_signal( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_mmap_device_io( + handle: zx_handle_t, + io_addr: u32, + len: u32 + ) -> zx_status_t; + + pub fn zx_vmo_create_contiguous( + rsrc_handle: zx_handle_t, + size: usize, + alignment_log2: u32, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_vmo_create_physical( + rsrc_handle: zx_handle_t, + paddr: zx_paddr_t, + size: usize, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_bootloader_fb_get_info( + format: *mut u32, + width: *mut u32, + height: *mut u32, + stride: *mut u32 + ) -> zx_status_t; + + pub fn zx_set_framebuffer( + handle: zx_handle_t, + vaddr: *mut u8, + len: u32, + format: u32, + width: u32, + height: u32, + stride: u32 + ) -> zx_status_t; + + pub fn zx_set_framebuffer_vmo( + handle: zx_handle_t, + vmo: zx_handle_t, + len: u32, + format: u32, + width: u32, + height: u32, + stride: u32 + ) -> zx_status_t; + + pub fn zx_pci_get_nth_device( + handle: zx_handle_t, + index: u32, + out_info: *mut zx_pcie_device_info_t, + out_handle: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_pci_enable_bus_master( + handle: zx_handle_t, + enable: bool + ) -> zx_status_t; + + pub fn zx_pci_enable_pio( + handle: zx_handle_t, + enable: bool + ) -> zx_status_t; + + pub fn zx_pci_reset_device( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_pci_cfg_pio_rw( + handle: zx_handle_t, + bus: u8, + dev: u8, + func: u8, + offset: u8, + val: *mut u32, + width: usize, + write: bool + ) -> zx_status_t; + + pub fn zx_pci_get_bar( + handle: zx_handle_t, + bar_num: u32, + out_bar: *mut zx_pci_resource_t + ) -> zx_status_t; + + pub fn zx_pci_get_config( + handle: zx_handle_t, + out_config: *mut zx_pci_resource_t + ) -> zx_status_t; + + pub fn zx_pci_io_write( + handle: zx_handle_t, + bar_num: u32, + offset: u32, + len: u32, + value: u32 + ) -> zx_status_t; + + pub fn zx_pci_io_read( + handle: zx_handle_t, + bar_num: u32, + offset: u32, + len: u32, + out_value: *mut u32 + ) -> zx_status_t; + + pub fn zx_pci_map_interrupt( + handle: zx_handle_t, + which_irq: i32, + out_handle: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_pci_query_irq_mode_caps( + handle: zx_handle_t, + mode: u32, + out_max_irqs: *mut u32 + ) -> zx_status_t; + + pub fn zx_pci_set_irq_mode( + handle: zx_handle_t, + mode: u32, + requested_irq_count: u32 + ) -> zx_status_t; + + pub fn zx_pci_init( + handle: zx_handle_t, + init_buf: *const zx_pci_init_arg_t, + len: u32 + ) -> zx_status_t; + + pub fn zx_pci_add_subtract_io_range( + handle: zx_handle_t, + mmio: bool, + base: u64, + len: u64, + add: bool + ) -> zx_status_t; + + pub fn zx_acpi_uefi_rsdp( + handle: zx_handle_t + ) -> u64; + + pub fn zx_acpi_cache_flush( + handle: zx_handle_t + ) -> zx_status_t; + + pub fn zx_resource_create( + parent_handle: zx_handle_t, + kind: u32, + low: u64, + high: u64, + resource_out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_guest_create( + resource: zx_handle_t, + options: u32, + physmem_vmo: zx_handle_t, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_guest_set_trap( + guest: zx_handle_t, + kind: u32, + addr: zx_vaddr_t, + len: usize, + fifo: zx_handle_t + ) -> zx_status_t; + + pub fn zx_vcpu_create( + guest: zx_handle_t, + options: u32, + args: *const zx_vcpu_create_args_t, + out: *mut zx_handle_t + ) -> zx_status_t; + + pub fn zx_vcpu_resume( + vcpu: zx_handle_t, + packet: *mut zx_guest_packet_t + ) -> zx_status_t; + + pub fn zx_vcpu_interrupt( + vcpu: zx_handle_t, + vector: u32 + ) -> zx_status_t; + + pub fn zx_vcpu_read_state( + vcpu: zx_handle_t, + kind: u32, + buffer: *mut u8, + len: u32 + ) -> zx_status_t; + + pub fn zx_vcpu_write_state( + vcpu: zx_handle_t, + kind: u32, + buffer: *const u8, + len: u32 + ) -> zx_status_t; + + pub fn zx_system_mexec( + kernel: zx_handle_t, + bootimage: zx_handle_t, + cmdline: *const u8, + cmdline_len: u32 + ) -> zx_status_t; + + pub fn zx_job_set_relative_importance( + root_resource: zx_handle_t, + job: zx_handle_t, + less_important_job: zx_handle_t + ) -> zx_status_t; + + pub fn zx_syscall_test_0( + ) -> zx_status_t; + + pub fn zx_syscall_test_1( + a: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_2( + a: isize, + b: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_3( + a: isize, + b: isize, + c: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_4( + a: isize, + b: isize, + c: isize, + d: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_5( + a: isize, + b: isize, + c: isize, + d: isize, + e: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_6( + a: isize, + b: isize, + c: isize, + d: isize, + e: isize, + f: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_7( + a: isize, + b: isize, + c: isize, + d: isize, + e: isize, + f: isize, + g: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_8( + a: isize, + b: isize, + c: isize, + d: isize, + e: isize, + f: isize, + g: isize, + h: isize + ) -> zx_status_t; + + pub fn zx_syscall_test_wrapper( + a: isize, + b: isize, + c: isize + ) -> zx_status_t; + + +} diff --git a/third_party/rust/fuchsia-zircon-sys/src/lib.rs b/third_party/rust/fuchsia-zircon-sys/src/lib.rs new file mode 100644 index 0000000000..e9d51f8ad3 --- /dev/null +++ b/third_party/rust/fuchsia-zircon-sys/src/lib.rs @@ -0,0 +1,474 @@ +// Copyright 2016 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#![allow(non_camel_case_types)] +#![deny(warnings)] + +use std::{cmp, fmt}; + +pub type zx_addr_t = usize; +pub type zx_duration_t = u64; +pub type zx_futex_t = i32; +pub type zx_handle_t = u32; +pub type zx_off_t = u64; +pub type zx_paddr_t = usize; +pub type zx_rights_t = u32; +pub type zx_signals_t = u32; +pub type zx_size_t = usize; +pub type zx_ssize_t = isize; +pub type zx_status_t = i32; +pub type zx_time_t = u64; +pub type zx_vaddr_t = usize; + +// TODO: combine these macros with the bitflags and assoc consts macros below +// so that we only have to do one macro invocation. +// The result would look something like: +// multiconst!(bitflags, zx_rights_t, Rights, [RIGHT_NONE => ZX_RIGHT_NONE = 0; ...]); +// multiconst!(assoc_consts, zx_status_t, Status, [OK => ZX_OK = 0; ...]); +// Note that the actual name of the inner macro (e.g. `bitflags`) can't be a variable. +// It'll just have to be matched on manually +macro_rules! multiconst { + ($typename:ident, [$($rawname:ident = $value:expr;)*]) => { + $( + pub const $rawname: $typename = $value; + )* + } +} + +multiconst!(zx_handle_t, [ + ZX_HANDLE_INVALID = 0; +]); + +multiconst!(zx_time_t, [ + ZX_TIME_INFINITE = ::std::u64::MAX; +]); + +multiconst!(zx_rights_t, [ + ZX_RIGHT_NONE = 0; + ZX_RIGHT_DUPLICATE = 1 << 0; + ZX_RIGHT_TRANSFER = 1 << 1; + ZX_RIGHT_READ = 1 << 2; + ZX_RIGHT_WRITE = 1 << 3; + ZX_RIGHT_EXECUTE = 1 << 4; + ZX_RIGHT_MAP = 1 << 5; + ZX_RIGHT_GET_PROPERTY = 1 << 6; + ZX_RIGHT_SET_PROPERTY = 1 << 7; + ZX_RIGHT_ENUMERATE = 1 << 8; + ZX_RIGHT_DESTROY = 1 << 9; + ZX_RIGHT_SET_POLICY = 1 << 10; + ZX_RIGHT_GET_POLICY = 1 << 11; + ZX_RIGHT_SIGNAL = 1 << 12; + ZX_RIGHT_SIGNAL_PEER = 1 << 13; + ZX_RIGHT_WAIT = 0 << 14; // Coming Soon! + ZX_RIGHT_SAME_RIGHTS = 1 << 31; +]); + +// TODO: add an alias for this type in the C headers. +multiconst!(u32, [ + ZX_VMO_OP_COMMIT = 1; + ZX_VMO_OP_DECOMMIT = 2; + ZX_VMO_OP_LOCK = 3; + ZX_VMO_OP_UNLOCK = 4; + ZX_VMO_OP_LOOKUP = 5; + ZX_VMO_OP_CACHE_SYNC = 6; + ZX_VMO_OP_CACHE_INVALIDATE = 7; + ZX_VMO_OP_CACHE_CLEAN = 8; + ZX_VMO_OP_CACHE_CLEAN_INVALIDATE = 9; +]); + +// TODO: add an alias for this type in the C headers. +multiconst!(u32, [ + ZX_VM_FLAG_PERM_READ = 1 << 0; + ZX_VM_FLAG_PERM_WRITE = 1 << 1; + ZX_VM_FLAG_PERM_EXECUTE = 1 << 2; + ZX_VM_FLAG_COMPACT = 1 << 3; + ZX_VM_FLAG_SPECIFIC = 1 << 4; + ZX_VM_FLAG_SPECIFIC_OVERWRITE = 1 << 5; + ZX_VM_FLAG_CAN_MAP_SPECIFIC = 1 << 6; + ZX_VM_FLAG_CAN_MAP_READ = 1 << 7; + ZX_VM_FLAG_CAN_MAP_WRITE = 1 << 8; + ZX_VM_FLAG_CAN_MAP_EXECUTE = 1 << 9; +]); + +multiconst!(zx_status_t, [ + ZX_OK = 0; + ZX_ERR_INTERNAL = -1; + ZX_ERR_NOT_SUPPORTED = -2; + ZX_ERR_NO_RESOURCES = -3; + ZX_ERR_NO_MEMORY = -4; + ZX_ERR_CALL_FAILED = -5; + ZX_ERR_INTERRUPTED_RETRY = -6; + ZX_ERR_INVALID_ARGS = -10; + ZX_ERR_BAD_HANDLE = -11; + ZX_ERR_WRONG_TYPE = -12; + ZX_ERR_BAD_SYSCALL = -13; + ZX_ERR_OUT_OF_RANGE = -14; + ZX_ERR_BUFFER_TOO_SMALL = -15; + ZX_ERR_BAD_STATE = -20; + ZX_ERR_TIMED_OUT = -21; + ZX_ERR_SHOULD_WAIT = -22; + ZX_ERR_CANCELED = -23; + ZX_ERR_PEER_CLOSED = -24; + ZX_ERR_NOT_FOUND = -25; + ZX_ERR_ALREADY_EXISTS = -26; + ZX_ERR_ALREADY_BOUND = -27; + ZX_ERR_UNAVAILABLE = -28; + ZX_ERR_ACCESS_DENIED = -30; + ZX_ERR_IO = -40; + ZX_ERR_IO_REFUSED = -41; + ZX_ERR_IO_DATA_INTEGRITY = -42; + ZX_ERR_IO_DATA_LOSS = -43; + ZX_ERR_BAD_PATH = -50; + ZX_ERR_NOT_DIR = -51; + ZX_ERR_NOT_FILE = -52; + ZX_ERR_FILE_BIG = -53; + ZX_ERR_NO_SPACE = -54; + ZX_ERR_STOP = -60; + ZX_ERR_NEXT = -61; +]); + +multiconst!(zx_signals_t, [ + ZX_SIGNAL_NONE = 0; + ZX_OBJECT_SIGNAL_ALL = 0x00ffffff; + ZX_USER_SIGNAL_ALL = 0xff000000; + ZX_OBJECT_SIGNAL_0 = 1 << 0; + ZX_OBJECT_SIGNAL_1 = 1 << 1; + ZX_OBJECT_SIGNAL_2 = 1 << 2; + ZX_OBJECT_SIGNAL_3 = 1 << 3; + ZX_OBJECT_SIGNAL_4 = 1 << 4; + ZX_OBJECT_SIGNAL_5 = 1 << 5; + ZX_OBJECT_SIGNAL_6 = 1 << 6; + ZX_OBJECT_SIGNAL_7 = 1 << 7; + ZX_OBJECT_SIGNAL_8 = 1 << 8; + ZX_OBJECT_SIGNAL_9 = 1 << 9; + ZX_OBJECT_SIGNAL_10 = 1 << 10; + ZX_OBJECT_SIGNAL_11 = 1 << 11; + ZX_OBJECT_SIGNAL_12 = 1 << 12; + ZX_OBJECT_SIGNAL_13 = 1 << 13; + ZX_OBJECT_SIGNAL_14 = 1 << 14; + ZX_OBJECT_SIGNAL_15 = 1 << 15; + ZX_OBJECT_SIGNAL_16 = 1 << 16; + ZX_OBJECT_SIGNAL_17 = 1 << 17; + ZX_OBJECT_SIGNAL_18 = 1 << 18; + ZX_OBJECT_SIGNAL_19 = 1 << 19; + ZX_OBJECT_SIGNAL_20 = 1 << 20; + ZX_OBJECT_SIGNAL_21 = 1 << 21; + ZX_OBJECT_SIGNAL_22 = 1 << 22; + ZX_OBJECT_HANDLE_CLOSED = 1 << 23; + ZX_USER_SIGNAL_0 = 1 << 24; + ZX_USER_SIGNAL_1 = 1 << 25; + ZX_USER_SIGNAL_2 = 1 << 26; + ZX_USER_SIGNAL_3 = 1 << 27; + ZX_USER_SIGNAL_4 = 1 << 28; + ZX_USER_SIGNAL_5 = 1 << 29; + ZX_USER_SIGNAL_6 = 1 << 30; + ZX_USER_SIGNAL_7 = 1 << 31; + + ZX_OBJECT_READABLE = ZX_OBJECT_SIGNAL_0; + ZX_OBJECT_WRITABLE = ZX_OBJECT_SIGNAL_1; + ZX_OBJECT_PEER_CLOSED = ZX_OBJECT_SIGNAL_2; + + // Cancelation (handle was closed while waiting with it) + ZX_SIGNAL_HANDLE_CLOSED = ZX_OBJECT_HANDLE_CLOSED; + + // Event + ZX_EVENT_SIGNALED = ZX_OBJECT_SIGNAL_3; + + // EventPair + ZX_EPAIR_SIGNALED = ZX_OBJECT_SIGNAL_3; + ZX_EPAIR_CLOSED = ZX_OBJECT_SIGNAL_2; + + // Task signals (process, thread, job) + ZX_TASK_TERMINATED = ZX_OBJECT_SIGNAL_3; + + // Channel + ZX_CHANNEL_READABLE = ZX_OBJECT_SIGNAL_0; + ZX_CHANNEL_WRITABLE = ZX_OBJECT_SIGNAL_1; + ZX_CHANNEL_PEER_CLOSED = ZX_OBJECT_SIGNAL_2; + + // Socket + ZX_SOCKET_READABLE = ZX_OBJECT_SIGNAL_0; + ZX_SOCKET_WRITABLE = ZX_OBJECT_SIGNAL_1; + ZX_SOCKET_PEER_CLOSED = ZX_OBJECT_SIGNAL_2; + + // Port + ZX_PORT_READABLE = ZX_OBJECT_READABLE; + + // Resource + ZX_RESOURCE_DESTROYED = ZX_OBJECT_SIGNAL_3; + ZX_RESOURCE_READABLE = ZX_OBJECT_READABLE; + ZX_RESOURCE_WRITABLE = ZX_OBJECT_WRITABLE; + ZX_RESOURCE_CHILD_ADDED = ZX_OBJECT_SIGNAL_4; + + // Fifo + ZX_FIFO_READABLE = ZX_OBJECT_READABLE; + ZX_FIFO_WRITABLE = ZX_OBJECT_WRITABLE; + ZX_FIFO_PEER_CLOSED = ZX_OBJECT_PEER_CLOSED; + + // Job + ZX_JOB_NO_PROCESSES = ZX_OBJECT_SIGNAL_3; + ZX_JOB_NO_JOBS = ZX_OBJECT_SIGNAL_4; + + // Process + ZX_PROCESS_TERMINATED = ZX_OBJECT_SIGNAL_3; + + // Thread + ZX_THREAD_TERMINATED = ZX_OBJECT_SIGNAL_3; + + // Log + ZX_LOG_READABLE = ZX_OBJECT_READABLE; + ZX_LOG_WRITABLE = ZX_OBJECT_WRITABLE; + + // Timer + ZX_TIMER_SIGNALED = ZX_OBJECT_SIGNAL_3; +]); + +// clock ids +pub const ZX_CLOCK_MONOTONIC: u32 = 0; + +// Buffer size limits on the cprng syscalls +pub const ZX_CPRNG_DRAW_MAX_LEN: usize = 256; +pub const ZX_CPRNG_ADD_ENTROPY_MAX_LEN: usize = 256; + +// Socket flags and limits. +pub const ZX_SOCKET_HALF_CLOSE: u32 = 1; + +// VM Object clone flags +pub const ZX_VMO_CLONE_COPY_ON_WRITE: u32 = 1; + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub enum zx_cache_policy_t { + ZX_CACHE_POLICY_CACHED = 0, + ZX_CACHE_POLICY_UNCACHED = 1, + ZX_CACHE_POLICY_UNCACHED_DEVICE = 2, + ZX_CACHE_POLICY_WRITE_COMBINING = 3, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_wait_item_t { + pub handle: zx_handle_t, + pub waitfor: zx_signals_t, + pub pending: zx_signals_t, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_waitset_result_t { + pub cookie: u64, + pub status: zx_status_t, + pub observed: zx_signals_t, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_channel_call_args_t { + pub wr_bytes: *const u8, + pub wr_handles: *const zx_handle_t, + pub rd_bytes: *mut u8, + pub rd_handles: *mut zx_handle_t, + pub wr_num_bytes: u32, + pub wr_num_handles: u32, + pub rd_num_bytes: u32, + pub rd_num_handles: u32, +} + +pub type zx_pci_irq_swizzle_lut_t = [[[u32; 4]; 8]; 32]; + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_pci_init_arg_t { + pub dev_pin_to_global_irq: zx_pci_irq_swizzle_lut_t, + pub num_irqs: u32, + pub irqs: [zx_irq_t; 32], + pub ecam_window_count: u32, + // Note: the ecam_windows field is actually a variable size array. + // We use a fixed size array to match the C repr. + pub ecam_windows: [zx_ecam_window_t; 1], +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_irq_t { + pub global_irq: u32, + pub level_triggered: bool, + pub active_high: bool, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_ecam_window_t { + pub base: u64, + pub size: usize, + pub bus_start: u8, + pub bus_end: u8, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_pcie_device_info_t { + pub vendor_id: u16, + pub device_id: u16, + pub base_class: u8, + pub sub_class: u8, + pub program_interface: u8, + pub revision_id: u8, + pub bus_id: u8, + pub dev_id: u8, + pub func_id: u8, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_pci_resource_t { + pub type_: u32, + pub size: usize, + // TODO: Actually a union + pub pio_addr: usize, +} + +// TODO: Actually a union +pub type zx_rrec_t = [u8; 64]; + +// Ports V2 +#[repr(u32)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub enum zx_packet_type_t { + ZX_PKT_TYPE_USER = 0, + ZX_PKT_TYPE_SIGNAL_ONE = 1, + ZX_PKT_TYPE_SIGNAL_REP = 2, +} + +impl Default for zx_packet_type_t { + fn default() -> Self { + zx_packet_type_t::ZX_PKT_TYPE_USER + } +} + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct zx_packet_signal_t { + pub trigger: zx_signals_t, + pub observed: zx_signals_t, + pub count: u64, +} + +pub const ZX_WAIT_ASYNC_ONCE: u32 = 0; +pub const ZX_WAIT_ASYNC_REPEATING: u32 = 1; + +// Actually a union of different integer types, but this should be good enough. +pub type zx_packet_user_t = [u8; 32]; + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +pub struct zx_port_packet_t { + pub key: u64, + pub packet_type: zx_packet_type_t, + pub status: i32, + pub union: [u8; 32], +} + +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_guest_io_t { + port: u16, + access_size: u8, + input: bool, + // TODO: Actually a union + data: [u8; 4], +} + +#[cfg(target_arch="aarch64")] +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_guest_memory_t { + addr: zx_vaddr_t, + inst: u32, +} + +pub const X86_MAX_INST_LEN: usize = 15; + +#[cfg(target_arch="x86_64")] +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_guest_memory_t { + addr: zx_vaddr_t, + inst_len: u8, + inst_buf: [u8; X86_MAX_INST_LEN], +} + +#[repr(u8)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub enum zx_guest_packet_t_type { + ZX_GUEST_PKT_MEMORY = 1, + ZX_GUEST_PKT_IO = 2, +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub union zx_guest_packet_t_union { + // ZX_GUEST_PKT_MEMORY + memory: zx_guest_memory_t, + // ZX_GUEST_PKT_IO + io: zx_guest_io_t, +} + +// Note: values of this type must maintain the invariant that +// `packet_type` correctly indicates the type of `contents`. +// Failure to do so will result in unsafety. +#[repr(C)] +#[derive(Copy, Clone)] +pub struct zx_guest_packet_t { + packet_type: zx_guest_packet_t_type, + contents: zx_guest_packet_t_union, +} + +impl fmt::Debug for zx_guest_packet_t { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "zx_guest_packet_t {{ packet_type: {:?}, contents: ", self.packet_type)?; + match self.packet_type { + zx_guest_packet_t_type::ZX_GUEST_PKT_MEMORY => + write!(f, "zx_guest_packet_t_union {{ memory: {:?} }} }}", + unsafe { self.contents.memory } + ), + zx_guest_packet_t_type::ZX_GUEST_PKT_IO => + write!(f, "zx_guest_packet_t_union {{ io: {:?} }} }}", + unsafe { self.contents.io } + ), + } + } +} + +impl cmp::PartialEq for zx_guest_packet_t { + fn eq(&self, other: &Self) -> bool { + (self.packet_type == other.packet_type) && + match self.packet_type { + zx_guest_packet_t_type::ZX_GUEST_PKT_MEMORY => + unsafe { self.contents.memory == other.contents.memory }, + zx_guest_packet_t_type::ZX_GUEST_PKT_IO => + unsafe { self.contents.io == other.contents.io }, + } + } +} + +impl cmp::Eq for zx_guest_packet_t {} + +#[cfg(target_arch="x86_64")] +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_vcpu_create_args_t { + pub ip: zx_vaddr_t, + pub cr3: zx_vaddr_t, + pub apic_vmo: zx_handle_t, +} + +#[cfg(not(target_arch="x86_64"))] +#[repr(C)] +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct zx_vcpu_create_args_t { + pub ip: zx_vaddr_t, +} + +include!("definitions.rs"); |