Skip to main content

zx_types/
lib.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#![allow(non_camel_case_types)]
6#![no_std]
7
8use core::fmt::{self, Debug};
9use core::hash::{Hash, Hasher};
10use core::sync::atomic::AtomicI32;
11#[cfg(feature = "zerocopy")]
12use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout};
13
14pub type zx_addr_t = usize;
15pub type zx_stream_seek_origin_t = u32;
16pub type zx_clock_t = u32;
17pub type zx_duration_t = i64;
18pub type zx_duration_mono_t = i64;
19pub type zx_duration_mono_ticks_t = i64;
20pub type zx_duration_boot_t = i64;
21pub type zx_duration_boot_ticks_t = i64;
22pub type zx_futex_t = AtomicI32;
23pub type zx_gpaddr_t = usize;
24pub type zx_vcpu_option_t = u32;
25pub type zx_guest_trap_t = u32;
26pub type zx_handle_t = u32;
27pub type zx_handle_op_t = u32;
28pub type zx_koid_t = u64;
29pub type zx_obj_type_t = u32;
30pub type zx_object_info_topic_t = u32;
31pub type zx_info_maps_type_t = u32;
32pub type zx_instant_boot_t = i64;
33pub type zx_instant_boot_ticks_t = i64;
34pub type zx_instant_mono_t = i64;
35pub type zx_instant_mono_ticks_t = i64;
36pub type zx_iob_access_t = u32;
37pub type zx_iob_allocate_id_options_t = u32;
38pub type zx_iob_discipline_type_t = u64;
39pub type zx_iob_region_type_t = u32;
40pub type zx_iob_write_options_t = u64;
41pub type zx_off_t = u64;
42pub type zx_paddr_t = usize;
43pub type zx_rights_t = u32;
44pub type zx_rsrc_flags_t = u32;
45pub type zx_rsrc_kind_t = u32;
46pub type zx_signals_t = u32;
47pub type zx_ssize_t = isize;
48pub type zx_status_t = i32;
49pub type zx_rsrc_system_base_t = u64;
50pub type zx_ticks_t = i64;
51pub type zx_time_t = i64;
52pub type zx_txid_t = u32;
53pub type zx_vaddr_t = usize;
54pub type zx_vm_option_t = u32;
55pub type zx_thread_state_topic_t = u32;
56pub type zx_vcpu_state_topic_t = u32;
57pub type zx_restricted_reason_t = u64;
58pub type zx_processor_power_level_options_t = u64;
59pub type zx_processor_power_control_t = u64;
60pub type zx_system_event_type_t = u32;
61pub type zx_system_memory_stall_type_t = u32;
62pub type zx_system_suspend_option_t = u64;
63pub type zx_system_wake_report_entry_flag_t = u32;
64pub type zx_system_powerctl_cmd_t = u32;
65
66macro_rules! const_assert {
67    ($e:expr $(,)?) => {
68        const _: [(); 1 - { const ASSERT: bool = $e; ASSERT as usize }] = [];
69    };
70}
71macro_rules! const_assert_eq {
72    ($lhs:expr, $rhs:expr $(,)?) => {
73        const_assert!($lhs == $rhs);
74    };
75}
76
77// TODO: magically coerce this to &`static str somehow?
78#[repr(C)]
79#[derive(Debug, Copy, Clone, Eq, PartialEq)]
80pub struct zx_string_view_t {
81    pub c_str: *const u8, // Guaranteed NUL-terminated valid UTF-8.
82    pub length: usize,
83}
84
85pub const ZX_MAX_NAME_LEN: usize = 32;
86
87// TODO: combine these macros with the bitflags and assoc consts macros below
88// so that we only have to do one macro invocation.
89// The result would look something like:
90// multiconst!(bitflags, zx_rights_t, Rights, [RIGHT_NONE => ZX_RIGHT_NONE = 0; ...]);
91// multiconst!(assoc_consts, zx_status_t, Status, [OK => ZX_OK = 0; ...]);
92// Note that the actual name of the inner macro (e.g. `bitflags`) can't be a variable.
93// It'll just have to be matched on manually
94macro_rules! multiconst {
95    ($typename:ident, [$($(#[$attr:meta])* $rawname:ident = $value:expr;)*]) => {
96        $(
97            $(#[$attr])*
98            pub const $rawname: $typename = $value;
99        )*
100    }
101}
102
103multiconst!(zx_handle_t, [
104    ZX_HANDLE_INVALID = 0;
105    ZX_HANDLE_FIXED_BITS_MASK = 0x3;
106]);
107
108multiconst!(zx_handle_op_t, [
109    ZX_HANDLE_OP_MOVE = 0;
110    ZX_HANDLE_OP_DUPLICATE = 1;
111]);
112
113multiconst!(zx_koid_t, [
114    ZX_KOID_INVALID = 0;
115    ZX_KOID_KERNEL = 1;
116    ZX_KOID_FIRST = 1024;
117]);
118
119multiconst!(zx_time_t, [
120    ZX_TIME_INFINITE = i64::MAX;
121    ZX_TIME_INFINITE_PAST = i64::MIN;
122]);
123
124multiconst!(zx_rights_t, [
125    ZX_RIGHT_NONE           = 0;
126    ZX_RIGHT_DUPLICATE      = 1 << 0;
127    ZX_RIGHT_TRANSFER       = 1 << 1;
128    ZX_RIGHT_READ           = 1 << 2;
129    ZX_RIGHT_WRITE          = 1 << 3;
130    ZX_RIGHT_EXECUTE        = 1 << 4;
131    ZX_RIGHT_MAP            = 1 << 5;
132    ZX_RIGHT_GET_PROPERTY   = 1 << 6;
133    ZX_RIGHT_SET_PROPERTY   = 1 << 7;
134    ZX_RIGHT_ENUMERATE      = 1 << 8;
135    ZX_RIGHT_DESTROY        = 1 << 9;
136    ZX_RIGHT_SET_POLICY     = 1 << 10;
137    ZX_RIGHT_GET_POLICY     = 1 << 11;
138    ZX_RIGHT_SIGNAL         = 1 << 12;
139    ZX_RIGHT_SIGNAL_PEER    = 1 << 13;
140    ZX_RIGHT_WAIT           = 1 << 14;
141    ZX_RIGHT_INSPECT        = 1 << 15;
142    ZX_RIGHT_MANAGE_JOB     = 1 << 16;
143    ZX_RIGHT_MANAGE_PROCESS = 1 << 17;
144    ZX_RIGHT_MANAGE_THREAD  = 1 << 18;
145    ZX_RIGHT_APPLY_PROFILE  = 1 << 19;
146    ZX_RIGHT_MANAGE_SOCKET  = 1 << 20;
147    ZX_RIGHT_OP_CHILDREN    = 1 << 21;
148    ZX_RIGHT_RESIZE         = 1 << 22;
149    ZX_RIGHT_ATTACH_VMO     = 1 << 23;
150    ZX_RIGHT_MANAGE_VMO     = 1 << 24;
151    ZX_RIGHT_SAME_RIGHTS    = 1 << 31;
152]);
153
154// From //zircon/system/public/zircon/rights.h
155// Convenient names for commonly grouped rights.
156multiconst!(zx_rights_t, [
157    ZX_RIGHTS_BASIC    = ZX_RIGHT_TRANSFER | ZX_RIGHT_DUPLICATE | ZX_RIGHT_WAIT | ZX_RIGHT_INSPECT;
158    ZX_RIGHTS_IO       = ZX_RIGHT_READ | ZX_RIGHT_WRITE;
159    ZX_RIGHTS_PROPERTY = ZX_RIGHT_GET_PROPERTY | ZX_RIGHT_SET_PROPERTY;
160    ZX_RIGHTS_POLICY   = ZX_RIGHT_GET_POLICY | ZX_RIGHT_SET_POLICY;
161]);
162
163// From //zircon/system/public/zircon/rights.h
164multiconst!(zx_rights_t, [
165    ZX_DEFAULT_CHANNEL_RIGHTS = (ZX_RIGHTS_BASIC & !ZX_RIGHT_DUPLICATE)
166        | ZX_RIGHTS_IO
167        | ZX_RIGHT_SIGNAL
168        | ZX_RIGHT_SIGNAL_PEER;
169    ZX_DEFAULT_EVENT_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHT_SIGNAL;
170    ZX_DEFAULT_SYSTEM_EVENT_LOW_MEMORY_RIGHTS =
171        ZX_RIGHT_WAIT | ZX_RIGHT_DUPLICATE | ZX_RIGHT_TRANSFER;
172    ZX_DEFAULT_SYSTEM_MEMORY_STALL_EVENT_RIGHTS =
173        ZX_RIGHT_WAIT | ZX_RIGHT_DUPLICATE | ZX_RIGHT_TRANSFER;
174    ZX_DEFAULT_EVENTPAIR_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHT_SIGNAL | ZX_RIGHT_SIGNAL_PEER;
175    ZX_DEFAULT_FIFO_RIGHTS =
176        ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_SIGNAL | ZX_RIGHT_SIGNAL_PEER;
177    ZX_DEFAULT_GUEST_RIGHTS = ZX_RIGHT_TRANSFER
178        | ZX_RIGHT_DUPLICATE
179        | ZX_RIGHT_WRITE
180        | ZX_RIGHT_INSPECT
181        | ZX_RIGHT_MANAGE_THREAD;
182    ZX_DEFAULT_INTERRUPT_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_SIGNAL;
183    ZX_DEFAULT_JOB_RIGHTS = ZX_RIGHTS_BASIC
184        | ZX_RIGHTS_IO
185        | ZX_RIGHTS_PROPERTY
186        | ZX_RIGHTS_POLICY
187        | ZX_RIGHT_ENUMERATE
188        | ZX_RIGHT_DESTROY
189        | ZX_RIGHT_SIGNAL
190        | ZX_RIGHT_MANAGE_JOB
191        | ZX_RIGHT_MANAGE_PROCESS
192        | ZX_RIGHT_MANAGE_THREAD;
193    ZX_DEFAULT_LOG_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHT_WRITE | ZX_RIGHT_SIGNAL;
194    ZX_DEFAULT_MSI_RIGHTS = ZX_RIGHTS_BASIC;
195    ZX_DEFAULT_PCI_DEVICE_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHTS_IO;
196    ZX_DEFAULT_PCI_INTERRUPT_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_SIGNAL;
197    ZX_DEFAULT_PORT_RIGHTS = (ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT) | ZX_RIGHTS_IO;
198    ZX_DEFAULT_PROCESS_RIGHTS = ZX_RIGHTS_BASIC
199        | ZX_RIGHTS_IO
200        | ZX_RIGHTS_PROPERTY
201        | ZX_RIGHT_ENUMERATE
202        | ZX_RIGHT_DESTROY
203        | ZX_RIGHT_SIGNAL
204        | ZX_RIGHT_MANAGE_PROCESS
205        | ZX_RIGHT_MANAGE_THREAD;
206    ZX_DEFAULT_RESOURCE_RIGHTS =
207        (ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT) | ZX_RIGHT_WRITE | ZX_RIGHT_GET_PROPERTY;
208    ZX_DEFAULT_SOCKET_RIGHTS = ZX_RIGHTS_BASIC
209        | ZX_RIGHTS_IO
210        | ZX_RIGHT_GET_PROPERTY
211        | ZX_RIGHT_SET_PROPERTY
212        | ZX_RIGHT_SIGNAL
213        | ZX_RIGHT_SIGNAL_PEER
214        | ZX_RIGHT_MANAGE_SOCKET;
215    ZX_DEFAULT_STREAM_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHTS_PROPERTY | ZX_RIGHT_SIGNAL;
216    ZX_DEFAULT_THREAD_RIGHTS = ZX_RIGHTS_BASIC
217        | ZX_RIGHTS_IO
218        | ZX_RIGHTS_PROPERTY
219        | ZX_RIGHT_DESTROY
220        | ZX_RIGHT_SIGNAL
221        | ZX_RIGHT_MANAGE_THREAD;
222    ZX_DEFAULT_TIMER_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHT_WRITE | ZX_RIGHT_SIGNAL;
223    ZX_DEFAULT_VCPU_RIGHTS =
224        ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_EXECUTE | ZX_RIGHT_SIGNAL;
225    ZX_DEFAULT_VMAR_RIGHTS = (ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT) | ZX_RIGHT_OP_CHILDREN;
226    ZX_DEFAULT_VMO_RIGHTS =
227        ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHTS_PROPERTY | ZX_RIGHT_MAP | ZX_RIGHT_SIGNAL;
228    ZX_DEFAULT_IOMMU_RIGHTS = ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT;
229    ZX_DEFAULT_BTI_RIGHTS =
230        (ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT) | ZX_RIGHTS_IO | ZX_RIGHTS_PROPERTY | ZX_RIGHT_MAP;
231    ZX_DEFAULT_PROFILE_RIGHTS = (ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT) | ZX_RIGHT_APPLY_PROFILE;
232    ZX_DEFAULT_PMT_RIGHTS = ZX_RIGHT_INSPECT;
233    ZX_DEFAULT_SUSPEND_TOKEN_RIGHTS = ZX_RIGHT_TRANSFER | ZX_RIGHT_INSPECT;
234    ZX_DEFAULT_PAGER_RIGHTS =
235        ZX_RIGHT_INSPECT | ZX_RIGHT_TRANSFER | ZX_RIGHT_ATTACH_VMO | ZX_RIGHT_MANAGE_VMO;
236    ZX_DEFAULT_EXCEPTION_RIGHTS = ZX_RIGHT_TRANSFER | ZX_RIGHTS_PROPERTY | ZX_RIGHT_INSPECT;
237    // Default rights applied to a created clock handle. The creator should consider whether
238    // ZX_RIGHT_SIGNAL is to be retained or removed when duplicating the clock handle.
239    ZX_DEFAULT_CLOCK_RIGHTS =
240        ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_SIGNAL | ZX_RIGHTS_PROPERTY;
241    ZX_DEFAULT_IOB_RIGHTS = ZX_RIGHTS_BASIC
242        | ZX_RIGHT_WAIT
243        | ZX_RIGHTS_IO
244        | ZX_RIGHTS_PROPERTY
245        | ZX_RIGHT_MAP
246        | ZX_RIGHT_SIGNAL
247        | ZX_RIGHT_SIGNAL_PEER;
248    ZX_DEFAULT_COUNTER_RIGHTS = ZX_RIGHTS_BASIC | ZX_RIGHTS_IO | ZX_RIGHT_SIGNAL;
249    ZX_DEFAULT_IOB_SHARED_REGION_RIGHTS =
250        ZX_RIGHTS_BASIC | ZX_RIGHT_WAIT | ZX_RIGHTS_PROPERTY | ZX_RIGHT_SIGNAL;
251    ZX_DEFAULT_SAMPLER_RIGHTS = ZX_RIGHTS_BASIC & !ZX_RIGHT_WAIT;
252]);
253
254multiconst!(u32, [
255    ZX_VMO_RESIZABLE = 1 << 1;
256    ZX_VMO_DISCARDABLE = 1 << 2;
257    ZX_VMO_TRAP_DIRTY = 1 << 3;
258    ZX_VMO_UNBOUNDED = 1 << 4;
259]);
260
261multiconst!(u64, [
262    ZX_VMO_DIRTY_RANGE_IS_ZERO = 1;
263]);
264
265multiconst!(u32, [
266    ZX_INFO_VMO_TYPE_PAGED = 1 << 0;
267    ZX_INFO_VMO_RESIZABLE = 1 << 1;
268    ZX_INFO_VMO_IS_COW_CLONE = 1 << 2;
269    ZX_INFO_VMO_VIA_HANDLE = 1 << 3;
270    ZX_INFO_VMO_VIA_MAPPING = 1 << 4;
271    ZX_INFO_VMO_PAGER_BACKED = 1 << 5;
272    ZX_INFO_VMO_CONTIGUOUS = 1 << 6;
273    ZX_INFO_VMO_DISCARDABLE = 1 << 7;
274    ZX_INFO_VMO_IMMUTABLE = 1 << 8;
275    ZX_INFO_VMO_VIA_IOB_HANDLE = 1 << 9;
276]);
277
278multiconst!(u32, [
279    ZX_VMO_OP_COMMIT = 1;
280    ZX_VMO_OP_DECOMMIT = 2;
281    ZX_VMO_OP_LOCK = 3;
282    ZX_VMO_OP_UNLOCK = 4;
283    ZX_VMO_OP_CACHE_SYNC = 6;
284    ZX_VMO_OP_CACHE_INVALIDATE = 7;
285    ZX_VMO_OP_CACHE_CLEAN = 8;
286    ZX_VMO_OP_CACHE_CLEAN_INVALIDATE = 9;
287    ZX_VMO_OP_ZERO = 10;
288    ZX_VMO_OP_TRY_LOCK = 11;
289    ZX_VMO_OP_DONT_NEED = 12;
290    ZX_VMO_OP_ALWAYS_NEED = 13;
291    ZX_VMO_OP_PREFETCH = 14;
292]);
293
294multiconst!(u32, [
295    ZX_VMAR_OP_COMMIT = 1;
296    ZX_VMAR_OP_DECOMMIT = 2;
297    ZX_VMAR_OP_MAP_RANGE = 3;
298    ZX_VMAR_OP_ZERO = 10;
299    ZX_VMAR_OP_DONT_NEED = 12;
300    ZX_VMAR_OP_ALWAYS_NEED = 13;
301    ZX_VMAR_OP_PREFETCH = 14;
302]);
303
304multiconst!(zx_vm_option_t, [
305    ZX_VM_PERM_READ                    = 1 << 0;
306    ZX_VM_PERM_WRITE                   = 1 << 1;
307    ZX_VM_PERM_EXECUTE                 = 1 << 2;
308    ZX_VM_COMPACT                      = 1 << 3;
309    ZX_VM_SPECIFIC                     = 1 << 4;
310    ZX_VM_SPECIFIC_OVERWRITE           = 1 << 5;
311    ZX_VM_CAN_MAP_SPECIFIC             = 1 << 6;
312    ZX_VM_CAN_MAP_READ                 = 1 << 7;
313    ZX_VM_CAN_MAP_WRITE                = 1 << 8;
314    ZX_VM_CAN_MAP_EXECUTE              = 1 << 9;
315    ZX_VM_MAP_RANGE                    = 1 << 10;
316    ZX_VM_REQUIRE_NON_RESIZABLE        = 1 << 11;
317    ZX_VM_ALLOW_FAULTS                 = 1 << 12;
318    ZX_VM_OFFSET_IS_UPPER_LIMIT        = 1 << 13;
319    ZX_VM_PERM_READ_IF_XOM_UNSUPPORTED = 1 << 14;
320    ZX_VM_FAULT_BEYOND_STREAM_SIZE     = 1 << 15;
321
322    // VM alignment options
323    ZX_VM_ALIGN_BASE                   = 24;
324    ZX_VM_ALIGN_1KB                    = 10 << ZX_VM_ALIGN_BASE;
325    ZX_VM_ALIGN_2KB                    = 11 << ZX_VM_ALIGN_BASE;
326    ZX_VM_ALIGN_4KB                    = 12 << ZX_VM_ALIGN_BASE;
327    ZX_VM_ALIGN_8KB                    = 13 << ZX_VM_ALIGN_BASE;
328    ZX_VM_ALIGN_16KB                   = 14 << ZX_VM_ALIGN_BASE;
329    ZX_VM_ALIGN_32KB                   = 15 << ZX_VM_ALIGN_BASE;
330    ZX_VM_ALIGN_64KB                   = 16 << ZX_VM_ALIGN_BASE;
331    ZX_VM_ALIGN_128KB                  = 17 << ZX_VM_ALIGN_BASE;
332    ZX_VM_ALIGN_256KB                  = 18 << ZX_VM_ALIGN_BASE;
333    ZX_VM_ALIGN_512KB                  = 19 << ZX_VM_ALIGN_BASE;
334    ZX_VM_ALIGN_1MB                    = 20 << ZX_VM_ALIGN_BASE;
335    ZX_VM_ALIGN_2MB                    = 21 << ZX_VM_ALIGN_BASE;
336    ZX_VM_ALIGN_4MB                    = 22 << ZX_VM_ALIGN_BASE;
337    ZX_VM_ALIGN_8MB                    = 23 << ZX_VM_ALIGN_BASE;
338    ZX_VM_ALIGN_16MB                   = 24 << ZX_VM_ALIGN_BASE;
339    ZX_VM_ALIGN_32MB                   = 25 << ZX_VM_ALIGN_BASE;
340    ZX_VM_ALIGN_64MB                   = 26 << ZX_VM_ALIGN_BASE;
341    ZX_VM_ALIGN_128MB                  = 27 << ZX_VM_ALIGN_BASE;
342    ZX_VM_ALIGN_256MB                  = 28 << ZX_VM_ALIGN_BASE;
343    ZX_VM_ALIGN_512MB                  = 29 << ZX_VM_ALIGN_BASE;
344    ZX_VM_ALIGN_1GB                    = 30 << ZX_VM_ALIGN_BASE;
345    ZX_VM_ALIGN_2GB                    = 31 << ZX_VM_ALIGN_BASE;
346    ZX_VM_ALIGN_4GB                    = 32 << ZX_VM_ALIGN_BASE;
347]);
348
349multiconst!(u32, [
350    ZX_PROCESS_SHARED = 1 << 0;
351]);
352
353multiconst!(u32, [
354    ZX_SYSTEM_BARRIER_DATA_MEMORY = 0;
355]);
356
357// From //zircon/system/public/zircon/syscalls-next.h
358// Options for zx_system_suspend_enter().
359multiconst!(u64, [
360    ZX_SYSTEM_SUSPEND_OPTION_DISCARD     = 1 << 0;
361    ZX_SYSTEM_SUSPEND_OPTION_REPORT_ONLY = 1 << 1;
362    ZX_SYSTEM_SUSPEND_OPTION_DEEP        = 1 << 2;
363]);
364
365multiconst!(u32, [
366    ZX_SYSTEM_WAKE_REPORT_ENTRY_FLAG_SIGNALED            = 1 << 0;
367    ZX_SYSTEM_WAKE_REPORT_ENTRY_FLAG_PREVIOUSLY_REPORTED = 1 << 1;
368]);
369
370// LINT.IfChange(zx_status_t)
371// matches ///zircon/system/public/zircon/errors.h
372multiconst!(zx_status_t, [
373    /// Indicates an operation was successful.
374    ZX_OK                         = 0;
375    /// The system encountered an otherwise unspecified error while performing the
376    /// operation.
377    ZX_ERR_INTERNAL               = -1;
378    /// The operation is not implemented, supported, or enabled.
379    ZX_ERR_NOT_SUPPORTED          = -2;
380    /// The system was not able to allocate some resource needed for the operation.
381    ZX_ERR_NO_RESOURCES           = -3;
382    /// The system was not able to allocate memory needed for the operation.
383    ZX_ERR_NO_MEMORY              = -4;
384    /// The system call was interrupted, but should be retried. This should not be
385    /// seen outside of the VDSO.
386    ZX_ERR_INTERRUPTED_RETRY      = -6;
387    /// An argument is invalid. For example, a null pointer when a null pointer is
388    /// not permitted.
389    ZX_ERR_INVALID_ARGS           = -10;
390    /// A specified handle value does not refer to a handle.
391    ZX_ERR_BAD_HANDLE             = -11;
392    /// The subject of the operation is the wrong type to perform the operation.
393    ///
394    /// For example: Attempting a message_read on a thread handle.
395    ZX_ERR_WRONG_TYPE             = -12;
396    /// The specified syscall number is invalid.
397    ZX_ERR_BAD_SYSCALL            = -13;
398    /// An argument is outside the valid range for this operation.
399    ZX_ERR_OUT_OF_RANGE           = -14;
400    /// The caller-provided buffer is too small for this operation.
401    ZX_ERR_BUFFER_TOO_SMALL       = -15;
402    /// The operation failed because the current state of the object does not allow
403    /// it, or a precondition of the operation is not satisfied.
404    ZX_ERR_BAD_STATE              = -20;
405    /// The time limit for the operation elapsed before the operation completed.
406    ZX_ERR_TIMED_OUT              = -21;
407    /// The operation cannot be performed currently but potentially could succeed if
408    /// the caller waits for a prerequisite to be satisfied, like waiting for a
409    /// handle to be readable or writable.
410    ///
411    /// Example: Attempting to read from a channel that has no messages waiting but
412    /// has an open remote will return `ZX_ERR_SHOULD_WAIT`. In contrast, attempting
413    /// to read from a channel that has no messages waiting and has a closed remote
414    /// end will return `ZX_ERR_PEER_CLOSED`.
415    ZX_ERR_SHOULD_WAIT            = -22;
416    /// The in-progress operation, for example, a wait, has been canceled.
417    ZX_ERR_CANCELED               = -23;
418    /// The operation failed because the remote end of the subject of the operation
419    /// was closed.
420    ZX_ERR_PEER_CLOSED            = -24;
421    /// The requested entity is not found.
422    ZX_ERR_NOT_FOUND              = -25;
423    /// An object with the specified identifier already exists.
424    ///
425    /// Example: Attempting to create a file when a file already exists with that
426    /// name.
427    ZX_ERR_ALREADY_EXISTS         = -26;
428    /// The operation failed because the named entity is already owned or controlled
429    /// by another entity. The operation could succeed later if the current owner
430    /// releases the entity.
431    ZX_ERR_ALREADY_BOUND          = -27;
432    /// The subject of the operation is currently unable to perform the operation.
433    ///
434    /// This is used when there's no direct way for the caller to observe when the
435    /// subject will be able to perform the operation and should thus retry.
436    ZX_ERR_UNAVAILABLE            = -28;
437    /// The caller did not have permission to perform the specified operation.
438    ZX_ERR_ACCESS_DENIED          = -30;
439    /// Otherwise-unspecified error occurred during I/O.
440    ZX_ERR_IO                     = -40;
441    /// The entity the I/O operation is being performed on rejected the operation.
442    ///
443    /// Example: an I2C device NAK'ing a transaction or a disk controller rejecting
444    /// an invalid command, or a stalled USB endpoint.
445    ZX_ERR_IO_REFUSED             = -41;
446    /// The data in the operation failed an integrity check and is possibly
447    /// corrupted.
448    ///
449    /// Example: CRC or Parity error.
450    ZX_ERR_IO_DATA_INTEGRITY      = -42;
451    /// The data in the operation is currently unavailable and may be permanently
452    /// lost.
453    ///
454    /// Example: A disk block is irrecoverably damaged.
455    ZX_ERR_IO_DATA_LOSS           = -43;
456    /// The device is no longer available (has been unplugged from the system,
457    /// powered down, or the driver has been unloaded).
458    ZX_ERR_IO_NOT_PRESENT         = -44;
459    /// More data was received from the device than expected.
460    ///
461    /// Example: a USB "babble" error due to a device sending more data than the
462    /// host queued to receive.
463    ZX_ERR_IO_OVERRUN             = -45;
464    /// An operation did not complete within the required timeframe.
465    ///
466    /// Example: A USB isochronous transfer that failed to complete due to an
467    /// overrun or underrun.
468    ZX_ERR_IO_MISSED_DEADLINE     = -46;
469    /// The data in the operation is invalid parameter or is out of range.
470    ///
471    /// Example: A USB transfer that failed to complete with TRB Error
472    ZX_ERR_IO_INVALID             = -47;
473    /// Path name is too long.
474    ZX_ERR_BAD_PATH               = -50;
475    /// The object is not a directory or does not support directory operations.
476    ///
477    /// Example: Attempted to open a file as a directory or attempted to do
478    /// directory operations on a file.
479    ZX_ERR_NOT_DIR                = -51;
480    /// Object is not a regular file.
481    ZX_ERR_NOT_FILE               = -52;
482    /// This operation would cause a file to exceed a filesystem-specific size
483    /// limit.
484    ZX_ERR_FILE_BIG               = -53;
485    /// The filesystem or device space is exhausted.
486    ZX_ERR_NO_SPACE               = -54;
487    /// The directory is not empty for an operation that requires it to be empty.
488    ///
489    /// For example, non-recursively deleting a directory with files still in it.
490    ZX_ERR_NOT_EMPTY              = -55;
491    /// An indicate to not call again.
492    ///
493    /// The flow control values `ZX_ERR_STOP`, `ZX_ERR_NEXT`, and `ZX_ERR_ASYNC` are
494    /// not errors and will never be returned by a system call or public API. They
495    /// allow callbacks to request their caller perform some other operation.
496    ///
497    /// For example, a callback might be called on every event until it returns
498    /// something other than `ZX_OK`. This status allows differentiation between
499    /// "stop due to an error" and "stop because work is done."
500    ZX_ERR_STOP                   = -60;
501    /// Advance to the next item.
502    ///
503    /// The flow control values `ZX_ERR_STOP`, `ZX_ERR_NEXT`, and `ZX_ERR_ASYNC` are
504    /// not errors and will never be returned by a system call or public API. They
505    /// allow callbacks to request their caller perform some other operation.
506    ///
507    /// For example, a callback could use this value to indicate it did not consume
508    /// an item passed to it, but by choice, not due to an error condition.
509    ZX_ERR_NEXT                   = -61;
510    /// Ownership of the item has moved to an asynchronous worker.
511    ///
512    /// The flow control values `ZX_ERR_STOP`, `ZX_ERR_NEXT`, and `ZX_ERR_ASYNC` are
513    /// not errors and will never be returned by a system call or public API. They
514    /// allow callbacks to request their caller perform some other operation.
515    ///
516    /// Unlike `ZX_ERR_STOP`, which implies that iteration on an object
517    /// should stop, and `ZX_ERR_NEXT`, which implies that iteration
518    /// should continue to the next item, `ZX_ERR_ASYNC` implies
519    /// that an asynchronous worker is responsible for continuing iteration.
520    ///
521    /// For example, a callback will be called on every event, but one event needs
522    /// to handle some work asynchronously before it can continue. `ZX_ERR_ASYNC`
523    /// implies the worker is responsible for resuming iteration once its work has
524    /// completed.
525    ZX_ERR_ASYNC                  = -62;
526    /// The specified protocol is not supported.
527    ZX_ERR_PROTOCOL_NOT_SUPPORTED = -70;
528    /// The host is unreachable.
529    ZX_ERR_ADDRESS_UNREACHABLE    = -71;
530    /// Address is being used by someone else.
531    ZX_ERR_ADDRESS_IN_USE         = -72;
532    /// The socket is not connected.
533    ZX_ERR_NOT_CONNECTED          = -73;
534    /// The remote peer rejected the connection.
535    ZX_ERR_CONNECTION_REFUSED     = -74;
536    /// The connection was reset.
537    ZX_ERR_CONNECTION_RESET       = -75;
538    /// The connection was aborted.
539    ZX_ERR_CONNECTION_ABORTED     = -76;
540    /// A task was killed during an operation. This is a private error that should
541    /// not be seen outside of the VDSO.
542    ZX_ERR_INTERNAL_INTR_KILLED   = -502;
543]);
544// LINT.ThenChange(//zircon/vdso/errors.fidl)
545
546multiconst!(zx_signals_t, [
547    ZX_SIGNAL_NONE              = 0;
548    ZX_OBJECT_SIGNAL_ALL        = 0x00ffffff;
549    ZX_USER_SIGNAL_ALL          = 0xff000000;
550    ZX_OBJECT_SIGNAL_0          = 1 << 0;
551    ZX_OBJECT_SIGNAL_1          = 1 << 1;
552    ZX_OBJECT_SIGNAL_2          = 1 << 2;
553    ZX_OBJECT_SIGNAL_3          = 1 << 3;
554    ZX_OBJECT_SIGNAL_4          = 1 << 4;
555    ZX_OBJECT_SIGNAL_5          = 1 << 5;
556    ZX_OBJECT_SIGNAL_6          = 1 << 6;
557    ZX_OBJECT_SIGNAL_7          = 1 << 7;
558    ZX_OBJECT_SIGNAL_8          = 1 << 8;
559    ZX_OBJECT_SIGNAL_9          = 1 << 9;
560    ZX_OBJECT_SIGNAL_10         = 1 << 10;
561    ZX_OBJECT_SIGNAL_11         = 1 << 11;
562    ZX_OBJECT_SIGNAL_12         = 1 << 12;
563    ZX_OBJECT_SIGNAL_13         = 1 << 13;
564    ZX_OBJECT_SIGNAL_14         = 1 << 14;
565    ZX_OBJECT_SIGNAL_15         = 1 << 15;
566    ZX_OBJECT_SIGNAL_16         = 1 << 16;
567    ZX_OBJECT_SIGNAL_17         = 1 << 17;
568    ZX_OBJECT_SIGNAL_18         = 1 << 18;
569    ZX_OBJECT_SIGNAL_19         = 1 << 19;
570    ZX_OBJECT_SIGNAL_20         = 1 << 20;
571    ZX_OBJECT_SIGNAL_21         = 1 << 21;
572    ZX_OBJECT_SIGNAL_22         = 1 << 22;
573    ZX_OBJECT_HANDLE_CLOSED     = 1 << 23;
574    ZX_USER_SIGNAL_0            = 1 << 24;
575    ZX_USER_SIGNAL_1            = 1 << 25;
576    ZX_USER_SIGNAL_2            = 1 << 26;
577    ZX_USER_SIGNAL_3            = 1 << 27;
578    ZX_USER_SIGNAL_4            = 1 << 28;
579    ZX_USER_SIGNAL_5            = 1 << 29;
580    ZX_USER_SIGNAL_6            = 1 << 30;
581    ZX_USER_SIGNAL_7            = 1 << 31;
582
583    ZX_OBJECT_READABLE          = ZX_OBJECT_SIGNAL_0;
584    ZX_OBJECT_WRITABLE          = ZX_OBJECT_SIGNAL_1;
585    ZX_OBJECT_PEER_CLOSED       = ZX_OBJECT_SIGNAL_2;
586
587    // Cancelation (handle was closed while waiting with it)
588    ZX_SIGNAL_HANDLE_CLOSED     = ZX_OBJECT_HANDLE_CLOSED;
589
590    // Event
591    ZX_EVENT_SIGNALED           = ZX_OBJECT_SIGNAL_3;
592
593    // EventPair
594    ZX_EVENTPAIR_SIGNALED       = ZX_OBJECT_SIGNAL_3;
595    ZX_EVENTPAIR_PEER_CLOSED    = ZX_OBJECT_SIGNAL_2;
596
597    // Task signals (process, thread, job)
598    ZX_TASK_TERMINATED          = ZX_OBJECT_SIGNAL_3;
599
600    // Channel
601    ZX_CHANNEL_READABLE         = ZX_OBJECT_SIGNAL_0;
602    ZX_CHANNEL_WRITABLE         = ZX_OBJECT_SIGNAL_1;
603    ZX_CHANNEL_PEER_CLOSED      = ZX_OBJECT_SIGNAL_2;
604
605    // Clock
606    ZX_CLOCK_STARTED            = ZX_OBJECT_SIGNAL_4;
607    ZX_CLOCK_UPDATED            = ZX_OBJECT_SIGNAL_5;
608
609    // Socket
610    ZX_SOCKET_READABLE            = ZX_OBJECT_READABLE;
611    ZX_SOCKET_WRITABLE            = ZX_OBJECT_WRITABLE;
612    ZX_SOCKET_PEER_CLOSED         = ZX_OBJECT_PEER_CLOSED;
613    ZX_SOCKET_PEER_WRITE_DISABLED = ZX_OBJECT_SIGNAL_4;
614    ZX_SOCKET_WRITE_DISABLED      = ZX_OBJECT_SIGNAL_5;
615    ZX_SOCKET_READ_THRESHOLD      = ZX_OBJECT_SIGNAL_10;
616    ZX_SOCKET_WRITE_THRESHOLD     = ZX_OBJECT_SIGNAL_11;
617
618    // Resource
619    ZX_RESOURCE_DESTROYED       = ZX_OBJECT_SIGNAL_3;
620    ZX_RESOURCE_READABLE        = ZX_OBJECT_READABLE;
621    ZX_RESOURCE_WRITABLE        = ZX_OBJECT_WRITABLE;
622    ZX_RESOURCE_CHILD_ADDED     = ZX_OBJECT_SIGNAL_4;
623
624    // Fifo
625    ZX_FIFO_READABLE            = ZX_OBJECT_READABLE;
626    ZX_FIFO_WRITABLE            = ZX_OBJECT_WRITABLE;
627    ZX_FIFO_PEER_CLOSED         = ZX_OBJECT_PEER_CLOSED;
628
629    // Iob
630    ZX_IOB_PEER_CLOSED           = ZX_OBJECT_PEER_CLOSED;
631    ZX_IOB_SHARED_REGION_UPDATED = ZX_OBJECT_SIGNAL_3;
632
633    // Job
634    ZX_JOB_TERMINATED           = ZX_OBJECT_SIGNAL_3;
635    ZX_JOB_NO_JOBS              = ZX_OBJECT_SIGNAL_4;
636    ZX_JOB_NO_PROCESSES         = ZX_OBJECT_SIGNAL_5;
637
638    // Process
639    ZX_PROCESS_TERMINATED       = ZX_OBJECT_SIGNAL_3;
640
641    // Thread
642    ZX_THREAD_TERMINATED        = ZX_OBJECT_SIGNAL_3;
643    ZX_THREAD_RUNNING           = ZX_OBJECT_SIGNAL_4;
644    ZX_THREAD_SUSPENDED         = ZX_OBJECT_SIGNAL_5;
645
646    // Log
647    ZX_LOG_READABLE             = ZX_OBJECT_READABLE;
648    ZX_LOG_WRITABLE             = ZX_OBJECT_WRITABLE;
649
650    // Timer
651    ZX_TIMER_SIGNALED           = ZX_OBJECT_SIGNAL_3;
652
653    // Vmo
654    ZX_VMO_ZERO_CHILDREN        = ZX_OBJECT_SIGNAL_3;
655
656    // Virtual Interrupt
657    ZX_VIRTUAL_INTERRUPT_UNTRIGGERED = ZX_OBJECT_SIGNAL_4;
658
659    // Counter
660    ZX_COUNTER_SIGNALED          = ZX_OBJECT_SIGNAL_3;
661    ZX_COUNTER_POSITIVE          = ZX_OBJECT_SIGNAL_4;
662    ZX_COUNTER_NON_POSITIVE      = ZX_OBJECT_SIGNAL_5;
663]);
664
665multiconst!(zx_obj_type_t, [
666    ZX_OBJ_TYPE_NONE                = 0;
667    ZX_OBJ_TYPE_PROCESS             = 1;
668    ZX_OBJ_TYPE_THREAD              = 2;
669    ZX_OBJ_TYPE_VMO                 = 3;
670    ZX_OBJ_TYPE_CHANNEL             = 4;
671    ZX_OBJ_TYPE_EVENT               = 5;
672    ZX_OBJ_TYPE_PORT                = 6;
673    ZX_OBJ_TYPE_INTERRUPT           = 9;
674    ZX_OBJ_TYPE_PCI_DEVICE          = 11;
675    ZX_OBJ_TYPE_DEBUGLOG            = 12;
676    ZX_OBJ_TYPE_SOCKET              = 14;
677    ZX_OBJ_TYPE_RESOURCE            = 15;
678    ZX_OBJ_TYPE_EVENTPAIR           = 16;
679    ZX_OBJ_TYPE_JOB                 = 17;
680    ZX_OBJ_TYPE_VMAR                = 18;
681    ZX_OBJ_TYPE_FIFO                = 19;
682    ZX_OBJ_TYPE_GUEST               = 20;
683    ZX_OBJ_TYPE_VCPU                = 21;
684    ZX_OBJ_TYPE_TIMER               = 22;
685    ZX_OBJ_TYPE_IOMMU               = 23;
686    ZX_OBJ_TYPE_BTI                 = 24;
687    ZX_OBJ_TYPE_PROFILE             = 25;
688    ZX_OBJ_TYPE_PMT                 = 26;
689    ZX_OBJ_TYPE_SUSPEND_TOKEN       = 27;
690    ZX_OBJ_TYPE_PAGER               = 28;
691    ZX_OBJ_TYPE_EXCEPTION           = 29;
692    ZX_OBJ_TYPE_CLOCK               = 30;
693    ZX_OBJ_TYPE_STREAM              = 31;
694    ZX_OBJ_TYPE_MSI                 = 32;
695    ZX_OBJ_TYPE_IOB                 = 33;
696    ZX_OBJ_TYPE_COUNTER             = 34;
697    ZX_OBJ_TYPE_IOB_SHARED_REGION   = 35;
698    ZX_OBJ_TYPE_SAMPLER             = 36;
699]);
700
701// System ABI commits to having no more than 64 object types.
702//
703// See zx_info_process_handle_stats_t for an example of a binary interface that
704// depends on having an upper bound for the number of object types.
705pub const ZX_OBJ_TYPE_UPPER_BOUND: usize = 64;
706
707// TODO: add an alias for this type in the C headers.
708multiconst!(u32, [
709    // Argument is a char[ZX_MAX_NAME_LEN].
710    ZX_PROP_NAME                      = 3;
711
712    // Argument is a uintptr_t.
713    #[cfg(target_arch = "x86_64")]
714    ZX_PROP_REGISTER_GS               = 2;
715    #[cfg(target_arch = "x86_64")]
716    ZX_PROP_REGISTER_FS               = 4;
717
718    // Argument is the value of ld.so's _dl_debug_addr, a uintptr_t.
719    ZX_PROP_PROCESS_DEBUG_ADDR        = 5;
720
721    // Argument is the base address of the vDSO mapping (or zero), a uintptr_t.
722    ZX_PROP_PROCESS_VDSO_BASE_ADDRESS = 6;
723
724    // Whether the dynamic loader should issue a debug trap when loading a shared
725    // library, either initially or when running (e.g. dlopen).
726    ZX_PROP_PROCESS_BREAK_ON_LOAD = 7;
727
728    // A context ID used for hardware tracing. Argument is a uintptr_t.
729    ZX_PROP_PROCESS_HW_TRACE_CONTEXT_ID = 8;
730
731    // Argument is a size_t.
732    ZX_PROP_SOCKET_RX_THRESHOLD       = 12;
733    ZX_PROP_SOCKET_TX_THRESHOLD       = 13;
734
735    // Argument is a size_t, describing the number of packets a channel
736    // endpoint can have pending in its tx direction.
737    ZX_PROP_CHANNEL_TX_MSG_MAX        = 14;
738
739    // Terminate this job if the system is low on memory.
740    ZX_PROP_JOB_KILL_ON_OOM           = 15;
741
742    // Exception close behavior.
743    ZX_PROP_EXCEPTION_STATE           = 16;
744
745    // The size of the content in a VMO, in bytes.
746    ZX_PROP_VMO_CONTENT_SIZE          = 17;
747
748    // How an exception should be handled.
749    ZX_PROP_EXCEPTION_STRATEGY        = 18;
750
751    // Whether the stream is in append mode or not.
752    ZX_PROP_STREAM_MODE_APPEND        = 19;
753]);
754
755// Value for ZX_THREAD_STATE_SINGLE_STEP. The value can be 0 (not single-stepping), or 1
756// (single-stepping). Other values will give ZX_ERR_INVALID_ARGS.
757pub type zx_thread_state_single_step_t = u32;
758
759// Possible values for "kind" in zx_thread_read_state and zx_thread_write_state.
760multiconst!(zx_thread_state_topic_t, [
761    ZX_THREAD_STATE_GENERAL_REGS       = 0;
762    ZX_THREAD_STATE_FP_REGS            = 1;
763    ZX_THREAD_STATE_VECTOR_REGS        = 2;
764    // No 3 at the moment.
765    ZX_THREAD_STATE_DEBUG_REGS         = 4;
766    ZX_THREAD_STATE_SINGLE_STEP        = 5;
767]);
768
769// Possible values for "kind" in zx_vcpu_read_state and zx_vcpu_write_state.
770multiconst!(zx_vcpu_state_topic_t, [
771    ZX_VCPU_STATE   = 0;
772    ZX_VCPU_IO      = 1;
773]);
774
775// From //zircon/system/public/zircon/features.h
776multiconst!(u32, [
777    ZX_FEATURE_KIND_CPU                        = 0;
778    ZX_FEATURE_KIND_HW_BREAKPOINT_COUNT        = 1;
779    ZX_FEATURE_KIND_HW_WATCHPOINT_COUNT        = 2;
780    ZX_FEATURE_KIND_ADDRESS_TAGGING            = 3;
781    ZX_FEATURE_KIND_VM                         = 4;
782    ZX_FEATURE_KIND_CPU_SVE                    = 5;
783]);
784
785// From //zircon/system/public/zircon/features.h
786multiconst!(u32, [
787    // Arch-independent CPU features.
788    ZX_HAS_CPU_FEATURES                   = 1 << 0;
789
790    // Virtual memory features.
791    ZX_VM_FEATURE_CAN_MAP_XOM             = 1 << 0;
792
793    // arm64 CPU features.
794    ZX_ARM64_FEATURE_ISA_FP               = 1 << 1;
795    ZX_ARM64_FEATURE_ISA_ASIMD            = 1 << 2;
796    ZX_ARM64_FEATURE_ISA_AES              = 1 << 3;
797    ZX_ARM64_FEATURE_ISA_PMULL            = 1 << 4;
798    ZX_ARM64_FEATURE_ISA_SHA1             = 1 << 5;
799    ZX_ARM64_FEATURE_ISA_SHA256           = 1 << 6;
800    ZX_ARM64_FEATURE_ISA_CRC32            = 1 << 7;
801    ZX_ARM64_FEATURE_ISA_ATOMICS          = 1 << 8;
802    ZX_ARM64_FEATURE_ISA_RDM              = 1 << 9;
803    ZX_ARM64_FEATURE_ISA_SHA3             = 1 << 10;
804    ZX_ARM64_FEATURE_ISA_SM3              = 1 << 11;
805    ZX_ARM64_FEATURE_ISA_SM4              = 1 << 12;
806    ZX_ARM64_FEATURE_ISA_DP               = 1 << 13;
807    ZX_ARM64_FEATURE_ISA_DPB              = 1 << 14;
808    ZX_ARM64_FEATURE_ISA_FHM              = 1 << 15;
809    ZX_ARM64_FEATURE_ISA_TS               = 1 << 16;
810    ZX_ARM64_FEATURE_ISA_RNDR             = 1 << 17;
811    ZX_ARM64_FEATURE_ISA_SHA512           = 1 << 18;
812    ZX_ARM64_FEATURE_ISA_I8MM             = 1 << 19;
813    ZX_ARM64_FEATURE_ISA_SVE              = 1 << 20;
814    ZX_ARM64_FEATURE_ISA_ARM32            = 1 << 21;
815    ZX_ARM64_FEATURE_ISA_MOPS             = 1 << 22;
816    ZX_ARM64_FEATURE_ISA_SHA2             = 1 << 6;
817
818    // arm64 address-tagging features.
819    ZX_ARM64_FEATURE_ADDRESS_TAGGING_TBI  = 1 << 0;
820
821    // arm64 SVE CPU features.
822    ZX_ARM64_FEATURE_ISA_SVEI8MM          = 1 << 0;
823    ZX_ARM64_FEATURE_ISA_SVEF32MM         = 1 << 1;
824    ZX_ARM64_FEATURE_ISA_SVEF64MM         = 1 << 2;
825    ZX_ARM64_FEATURE_ISA_SVEBF16          = 1 << 3;
826    ZX_ARM64_FEATURE_ISA_SVE2             = 1 << 4;
827    ZX_ARM64_FEATURE_ISA_SVEAES           = 1 << 5;
828    ZX_ARM64_FEATURE_ISA_SVEPMULL         = 1 << 6;
829    ZX_ARM64_FEATURE_ISA_SVEBITPERM       = 1 << 7;
830    ZX_ARM64_FEATURE_ISA_SVESHA3          = 1 << 8;
831    ZX_ARM64_FEATURE_ISA_SVESM4           = 1 << 9;
832]);
833
834// From //zircon/system/public/zircon/syscalls/resource.h
835multiconst!(zx_rsrc_kind_t, [
836    ZX_RSRC_KIND_MMIO       = 0;
837    ZX_RSRC_KIND_IRQ        = 1;
838    ZX_RSRC_KIND_IOPORT     = 2;
839    ZX_RSRC_KIND_SMC        = 4;
840    ZX_RSRC_KIND_SYSTEM     = 5;
841    #[cfg(feature = "kernel")]
842    ZX_RSRC_KIND_COUNT      = 6;
843]);
844
845// From //zircon/system/public/zircon/syscalls/resource.h
846multiconst!(zx_rsrc_system_base_t, [
847    ZX_RSRC_SYSTEM_HYPERVISOR_BASE  = 0;
848    ZX_RSRC_SYSTEM_VMEX_BASE        = 1;
849    ZX_RSRC_SYSTEM_DEBUG_BASE       = 2;
850    ZX_RSRC_SYSTEM_INFO_BASE        = 3;
851    ZX_RSRC_SYSTEM_CPU_BASE         = 4;
852    ZX_RSRC_SYSTEM_POWER_BASE       = 5;
853    // 6 was ZX_RSRC_SYSTEM_MEXEC_BASE, now retired.
854    ZX_RSRC_SYSTEM_ENERGY_INFO_BASE = 7;
855    ZX_RSRC_SYSTEM_IOMMU_BASE       = 8;
856    ZX_RSRC_SYSTEM_FRAMEBUFFER_BASE = 9;
857    ZX_RSRC_SYSTEM_PROFILE_BASE     = 10;
858    ZX_RSRC_SYSTEM_MSI_BASE         = 11;
859    ZX_RSRC_SYSTEM_DEBUGLOG_BASE    = 12;
860    ZX_RSRC_SYSTEM_STALL_BASE       = 13;
861    ZX_RSRC_SYSTEM_TRACING_BASE     = 14;
862    // A resource representing the ability to sample callstack information about other processes.
863    ZX_RSRC_SYSTEM_SAMPLING_BASE    = 15;
864    #[cfg(feature = "kernel")]
865    ZX_RSRC_SYSTEM_COUNT            = 16;
866]);
867
868// clock ids
869multiconst!(zx_clock_t, [
870    ZX_CLOCK_MONOTONIC = 0;
871    ZX_CLOCK_BOOT      = 1;
872]);
873
874// from //zircon/system/public/zircon/syscalls/clock.h
875multiconst!(u64, [
876    // Argument version identifiers.
877    //
878    // All zx_clock_* syscalls which fetch or receive a structure's worth of
879    // arguments encode a version number in the options field of the syscall.  This
880    // version field is in the same location and is the same size for each syscall,
881    // so a common set of macros may be used for encoding and decoding.
882    ZX_CLOCK_ARGS_VERSION_SHIFT = 58;
883    ZX_CLOCK_ARGS_VERSION_BITS = 6;
884    ZX_CLOCK_ARGS_VERSION_MASK = ((1u64 << ZX_CLOCK_ARGS_VERSION_BITS) - 1) << ZX_CLOCK_ARGS_VERSION_SHIFT;
885
886    // Clock creation options.
887    ZX_CLOCK_OPT_MONOTONIC = 1 << 0;
888    ZX_CLOCK_OPT_CONTINUOUS = 1 << 1;
889    ZX_CLOCK_OPT_AUTO_START = 1 << 2;
890    ZX_CLOCK_OPT_BOOT = 1 << 3;
891    ZX_CLOCK_OPT_MAPPABLE = 1 << 4;
892
893    ZX_CLOCK_OPTS_ALL = ZX_CLOCK_OPT_MONOTONIC
894        | ZX_CLOCK_OPT_CONTINUOUS
895        | ZX_CLOCK_OPT_AUTO_START
896        | ZX_CLOCK_OPT_BOOT
897        | ZX_CLOCK_OPT_MAPPABLE;
898
899    // v1 clock update flags
900    ZX_CLOCK_UPDATE_OPTION_VALUE_VALID = 1 << 0;
901    ZX_CLOCK_UPDATE_OPTION_RATE_ADJUST_VALID = 1 << 1;
902    ZX_CLOCK_UPDATE_OPTION_ERROR_BOUND_VALID = 1 << 2;
903
904    // Additional v2 clock update flags
905    ZX_CLOCK_UPDATE_OPTION_REFERENCE_VALUE_VALID = 1 << 3;
906    ZX_CLOCK_UPDATE_OPTION_SYNTHETIC_VALUE_VALID = ZX_CLOCK_UPDATE_OPTION_VALUE_VALID;
907    ZX_CLOCK_UPDATE_OPTION_BOTH_VALUES_VALID =
908        ZX_CLOCK_UPDATE_OPTION_REFERENCE_VALUE_VALID | ZX_CLOCK_UPDATE_OPTION_SYNTHETIC_VALUE_VALID;
909
910    ZX_CLOCK_UPDATE_OPTIONS_ALL = ZX_CLOCK_UPDATE_OPTION_SYNTHETIC_VALUE_VALID
911        | ZX_CLOCK_UPDATE_OPTION_RATE_ADJUST_VALID
912        | ZX_CLOCK_UPDATE_OPTION_ERROR_BOUND_VALID
913        | ZX_CLOCK_UPDATE_OPTION_REFERENCE_VALUE_VALID;
914
915    ZX_CLOCK_ARGS_VERSION_1 = 1 << 58;
916    ZX_CLOCK_ARGS_VERSION_2 = 2 << 58;
917
918    // Special clock error values
919    ZX_CLOCK_UNKNOWN_ERROR = 0xFFFFFFFFFFFFFFFF;
920]);
921
922// Clock rate adjustment limits
923multiconst!(i32, [
924    ZX_CLOCK_UPDATE_MIN_RATE_ADJUST = -1000;
925    ZX_CLOCK_UPDATE_MAX_RATE_ADJUST = 1000;
926]);
927
928/// Encodes a version number into the options bitfield for clock syscalls.
929pub const fn zx_clock_args_version(n: u64) -> u64 {
930    (n << ZX_CLOCK_ARGS_VERSION_SHIFT) & ZX_CLOCK_ARGS_VERSION_MASK
931}
932
933// from //zircon/system/public/zircon/syscalls/exception.h
934multiconst!(u32, [
935    ZX_EXCEPTION_CHANNEL_DEBUGGER = 1 << 0;
936    ZX_EXCEPTION_TARGET_JOB_DEBUGGER = 1 << 0;
937
938    // Returned when probing a thread for its blocked state.
939    ZX_EXCEPTION_CHANNEL_TYPE_NONE = 0;
940    ZX_EXCEPTION_CHANNEL_TYPE_DEBUGGER = 1;
941    ZX_EXCEPTION_CHANNEL_TYPE_THREAD = 2;
942    ZX_EXCEPTION_CHANNEL_TYPE_PROCESS = 3;
943    ZX_EXCEPTION_CHANNEL_TYPE_JOB = 4;
944    ZX_EXCEPTION_CHANNEL_TYPE_JOB_DEBUGGER = 5;
945]);
946
947/// A byte used only to control memory alignment. All padding bytes are considered equal
948/// regardless of their content.
949///
950/// Note that the kernel C/C++ struct definitions use explicit padding fields to ensure no implicit
951/// padding is added. This is important for security since implicit padding bytes are not always
952/// safely initialized. These explicit padding fields are mirrored in the Rust struct definitions
953/// to minimize the opportunities for mistakes and inconsistencies.
954#[repr(transparent)]
955#[derive(Copy, Clone, Eq, Default)]
956#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes))]
957pub struct PadByte(u8);
958
959impl PartialEq for PadByte {
960    fn eq(&self, _other: &Self) -> bool {
961        true
962    }
963}
964
965impl Hash for PadByte {
966    fn hash<H: Hasher>(&self, state: &mut H) {
967        state.write_u8(0);
968    }
969}
970
971impl Debug for PadByte {
972    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
973        f.write_str("-")
974    }
975}
976
977#[repr(C)]
978#[derive(Debug, Default, Clone, Eq, PartialEq)]
979#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
980pub struct zx_clock_create_args_v1_t {
981    pub backstop_time: zx_time_t,
982}
983
984#[repr(C)]
985#[derive(Debug, Default, Clone, Eq, PartialEq)]
986#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
987pub struct zx_clock_rate_t {
988    pub synthetic_ticks: u32,
989    pub reference_ticks: u32,
990}
991
992#[repr(C)]
993#[derive(Debug, Default, Clone, Eq, PartialEq)]
994#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
995pub struct zx_clock_transformation_t {
996    pub reference_offset: i64,
997    pub synthetic_offset: i64,
998    pub rate: zx_clock_rate_t,
999}
1000
1001#[repr(C)]
1002#[derive(Debug, Default, Clone, Eq, PartialEq)]
1003#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1004pub struct zx_clock_details_v1_t {
1005    pub options: u64,
1006    pub backstop_time: zx_time_t,
1007    pub reference_ticks_to_synthetic: zx_clock_transformation_t,
1008    pub reference_to_synthetic: zx_clock_transformation_t,
1009    pub error_bound: u64,
1010    pub query_ticks: zx_ticks_t,
1011    pub last_value_update_ticks: zx_ticks_t,
1012    pub last_rate_adjust_update_ticks: zx_ticks_t,
1013    pub last_error_bounds_update_ticks: zx_ticks_t,
1014    pub generation_counter: u32,
1015    // Public so that in-tree producers (for example the kernel's clock
1016    // dispatcher) can build this record with a struct literal.
1017    pub padding1: [PadByte; 4],
1018}
1019
1020#[repr(C)]
1021#[derive(Debug, Default, Clone, Eq, PartialEq)]
1022#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1023pub struct zx_clock_update_args_v1_t {
1024    pub rate_adjust: i32,
1025    padding1: [PadByte; 4],
1026    pub value: i64,
1027    pub error_bound: u64,
1028}
1029
1030#[repr(C)]
1031#[derive(Debug, Default, Clone, Eq, PartialEq)]
1032#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1033pub struct zx_clock_update_args_v2_t {
1034    pub rate_adjust: i32,
1035    padding1: [PadByte; 4],
1036    pub synthetic_value: i64,
1037    pub reference_value: i64,
1038    pub error_bound: u64,
1039}
1040
1041multiconst!(zx_stream_seek_origin_t, [
1042    ZX_STREAM_SEEK_ORIGIN_START        = 0;
1043    ZX_STREAM_SEEK_ORIGIN_CURRENT      = 1;
1044    ZX_STREAM_SEEK_ORIGIN_END          = 2;
1045]);
1046
1047// Stream constants
1048pub const ZX_STREAM_MODE_READ: u32 = 1 << 0;
1049pub const ZX_STREAM_MODE_WRITE: u32 = 1 << 1;
1050pub const ZX_STREAM_MODE_APPEND: u32 = 1 << 2;
1051pub const ZX_STREAM_CREATE_MASK: u32 =
1052    ZX_STREAM_MODE_READ | ZX_STREAM_MODE_WRITE | ZX_STREAM_MODE_APPEND;
1053
1054pub const ZX_STREAM_APPEND: u32 = 1 << 0;
1055
1056pub const ZX_CPRNG_DRAW_MAX_LEN: usize = 256;
1057pub const ZX_CPRNG_ADD_ENTROPY_MAX_LEN: usize = 256;
1058
1059// Socket flags and limits.
1060pub const ZX_SOCKET_STREAM: u32 = 0;
1061pub const ZX_SOCKET_DATAGRAM: u32 = 1 << 0;
1062pub const ZX_SOCKET_CREATE_MASK: u32 = ZX_SOCKET_DATAGRAM;
1063pub const ZX_SOCKET_PEEK: u32 = 1 << 3;
1064pub const ZX_SOCKET_DISPOSITION_WRITE_DISABLED: u32 = 1 << 0;
1065pub const ZX_SOCKET_DISPOSITION_WRITE_ENABLED: u32 = 1 << 1;
1066
1067// VM Object clone flags
1068pub const ZX_VMO_CHILD_SNAPSHOT: u32 = 1 << 0;
1069pub const ZX_VMO_CHILD_SNAPSHOT_AT_LEAST_ON_WRITE: u32 = 1 << 4;
1070pub const ZX_VMO_CHILD_RESIZABLE: u32 = 1 << 2;
1071pub const ZX_VMO_CHILD_SLICE: u32 = 1 << 3;
1072pub const ZX_VMO_CHILD_NO_WRITE: u32 = 1 << 5;
1073pub const ZX_VMO_CHILD_REFERENCE: u32 = 1 << 6;
1074pub const ZX_VMO_CHILD_SNAPSHOT_MODIFIED: u32 = 1 << 7;
1075
1076// channel write size constants
1077pub const ZX_CHANNEL_MAX_MSG_HANDLES: u32 = 64;
1078pub const ZX_CHANNEL_MAX_MSG_BYTES: u32 = 65536;
1079pub const ZX_CHANNEL_MAX_MSG_IOVEC: u32 = 8192;
1080
1081// wait_many constants
1082pub const ZX_WAIT_MANY_MAX_ITEMS: usize = 64;
1083
1084// fifo write size constants
1085pub const ZX_FIFO_MAX_SIZE_BYTES: u32 = 4096;
1086
1087// Min/max page size constants
1088#[cfg(target_arch = "x86_64")]
1089pub const ZX_MIN_PAGE_SHIFT: u32 = 12;
1090#[cfg(target_arch = "x86_64")]
1091pub const ZX_MAX_PAGE_SHIFT: u32 = 21;
1092
1093#[cfg(target_arch = "aarch64")]
1094pub const ZX_MIN_PAGE_SHIFT: u32 = 12;
1095#[cfg(target_arch = "aarch64")]
1096pub const ZX_MAX_PAGE_SHIFT: u32 = 16;
1097
1098#[cfg(target_arch = "riscv64")]
1099pub const ZX_MIN_PAGE_SHIFT: u32 = 12;
1100#[cfg(target_arch = "riscv64")]
1101pub const ZX_MAX_PAGE_SHIFT: u32 = 21;
1102
1103// Task response codes if a process is externally killed
1104pub const ZX_TASK_RETCODE_SYSCALL_KILL: i64 = -1024;
1105pub const ZX_TASK_RETCODE_OOM_KILL: i64 = -1025;
1106pub const ZX_TASK_RETCODE_POLICY_KILL: i64 = -1026;
1107pub const ZX_TASK_RETCODE_VDSO_KILL: i64 = -1027;
1108pub const ZX_TASK_RETCODE_EXCEPTION_KILL: i64 = -1028;
1109pub const ZX_TASK_RETCODE_CRITICAL_PROCESS_KILL: i64 = -1029;
1110
1111// Resource flags.
1112pub const ZX_RSRC_FLAG_EXCLUSIVE: zx_rsrc_flags_t = 0x00010000;
1113pub const ZX_RSRC_FLAGS_MASK: zx_rsrc_flags_t = ZX_RSRC_FLAG_EXCLUSIVE;
1114
1115// System event types.
1116multiconst!(zx_system_event_type_t, [
1117    ZX_SYSTEM_EVENT_OUT_OF_MEMORY = 1;
1118    ZX_SYSTEM_EVENT_MEMORY_PRESSURE_CRITICAL = 2;
1119    ZX_SYSTEM_EVENT_MEMORY_PRESSURE_WARNING = 3;
1120    ZX_SYSTEM_EVENT_MEMORY_PRESSURE_NORMAL = 4;
1121    ZX_SYSTEM_EVENT_IMMINENT_OUT_OF_MEMORY = 5;
1122]);
1123
1124// Topics for CPU performance info syscalls
1125pub const ZX_CPU_PERF_SCALE: u32 = 1;
1126pub const ZX_CPU_DEFAULT_PERF_SCALE: u32 = 2;
1127pub const ZX_CPU_PERF_LIMIT: u32 = 3;
1128
1129// Perf limit types.
1130pub const ZX_CPU_PERF_LIMIT_TYPE_RATE: u32 = 0;
1131pub const ZX_CPU_PERF_LIMIT_TYPE_POWER: u32 = 1;
1132
1133// Cache policy flags.
1134pub const ZX_CACHE_POLICY_CACHED: u32 = 0;
1135pub const ZX_CACHE_POLICY_UNCACHED: u32 = 1;
1136pub const ZX_CACHE_POLICY_UNCACHED_DEVICE: u32 = 2;
1137pub const ZX_CACHE_POLICY_WRITE_COMBINING: u32 = 3;
1138pub const ZX_CACHE_POLICY_MASK: u32 = 3;
1139
1140// Flag bits for zx_cache_flush.
1141multiconst!(u32, [
1142    ZX_CACHE_FLUSH_INSN         = 1 << 0;
1143    ZX_CACHE_FLUSH_DATA         = 1 << 1;
1144    ZX_CACHE_FLUSH_INVALIDATE   = 1 << 2;
1145]);
1146
1147#[repr(C)]
1148#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
1149#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1150pub struct zx_wait_item_t {
1151    pub handle: zx_handle_t,
1152    pub waitfor: zx_signals_t,
1153    pub pending: zx_signals_t,
1154}
1155
1156#[repr(C)]
1157#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1158pub struct zx_waitset_result_t {
1159    pub cookie: u64,
1160    pub status: zx_status_t,
1161    pub observed: zx_signals_t,
1162}
1163
1164#[repr(C)]
1165#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1166pub struct zx_handle_info_t {
1167    pub handle: zx_handle_t,
1168    pub ty: zx_obj_type_t,
1169    pub rights: zx_rights_t,
1170    pub unused: u32,
1171}
1172
1173pub const ZX_CHANNEL_READ_MAY_DISCARD: u32 = 1;
1174pub const ZX_CHANNEL_WRITE_USE_IOVEC: u32 = 2;
1175
1176#[repr(C)]
1177#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1178pub struct zx_channel_call_args_t {
1179    pub wr_bytes: *const u8,
1180    pub wr_handles: *const zx_handle_t,
1181    pub rd_bytes: *mut u8,
1182    pub rd_handles: *mut zx_handle_t,
1183    pub wr_num_bytes: u32,
1184    pub wr_num_handles: u32,
1185    pub rd_num_bytes: u32,
1186    pub rd_num_handles: u32,
1187}
1188
1189#[repr(C)]
1190#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1191pub struct zx_channel_call_etc_args_t {
1192    pub wr_bytes: *const u8,
1193    pub wr_handles: *mut zx_handle_disposition_t,
1194    pub rd_bytes: *mut u8,
1195    pub rd_handles: *mut zx_handle_info_t,
1196    pub wr_num_bytes: u32,
1197    pub wr_num_handles: u32,
1198    pub rd_num_bytes: u32,
1199    pub rd_num_handles: u32,
1200}
1201
1202#[repr(C)]
1203#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
1204pub struct zx_channel_iovec_t {
1205    pub buffer: *const u8,
1206    pub capacity: u32,
1207    padding1: [PadByte; 4],
1208}
1209
1210#[repr(C)]
1211#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1212pub struct zx_handle_disposition_t {
1213    pub operation: zx_handle_op_t,
1214    pub handle: zx_handle_t,
1215    pub type_: zx_obj_type_t,
1216    pub rights: zx_rights_t,
1217    pub result: zx_status_t,
1218}
1219
1220#[repr(C)]
1221#[derive(Debug, Copy, Clone)]
1222pub struct zx_iovec_t {
1223    pub buffer: *const u8,
1224    pub capacity: usize,
1225}
1226
1227#[repr(C)]
1228#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1229pub struct zx_irq_t {
1230    pub global_irq: u32,
1231    pub level_triggered: bool,
1232    pub active_high: bool,
1233}
1234
1235#[repr(C)]
1236#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1237pub struct zx_ecam_window_t {
1238    pub base: u64,
1239    pub size: usize,
1240    pub bus_start: u8,
1241    pub bus_end: u8,
1242}
1243
1244#[repr(C)]
1245#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1246pub struct zx_pcie_device_info_t {
1247    pub vendor_id: u16,
1248    pub device_id: u16,
1249    pub base_class: u8,
1250    pub sub_class: u8,
1251    pub program_interface: u8,
1252    pub revision_id: u8,
1253    pub bus_id: u8,
1254    pub dev_id: u8,
1255    pub func_id: u8,
1256}
1257
1258#[repr(C)]
1259#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1260pub struct zx_pci_resource_t {
1261    pub type_: u32,
1262    pub size: usize,
1263    // TODO: Actually a union
1264    pub pio_addr: usize,
1265}
1266
1267// TODO: Actually a union
1268pub type zx_rrec_t = [u8; 64];
1269
1270// Ports V2
1271#[repr(u32)]
1272#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
1273#[cfg_attr(feature = "zerocopy", derive(Immutable, IntoBytes, KnownLayout))]
1274#[non_exhaustive]
1275pub enum zx_packet_type_t {
1276    #[default]
1277    ZX_PKT_TYPE_USER = 0,
1278    ZX_PKT_TYPE_SIGNAL_ONE = 1,
1279    ZX_PKT_TYPE_GUEST_BELL = 3,
1280    ZX_PKT_TYPE_GUEST_MEM = 4,
1281    ZX_PKT_TYPE_GUEST_IO = 5,
1282    ZX_PKT_TYPE_GUEST_VCPU = 6,
1283    ZX_PKT_TYPE_INTERRUPT = 7,
1284    ZX_PKT_TYPE_PAGE_REQUEST = 9,
1285    ZX_PKT_TYPE_PROCESSOR_POWER_LEVEL_TRANSITION_REQUEST = 10,
1286}
1287
1288#[repr(u32)]
1289#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1290#[non_exhaustive]
1291pub enum zx_packet_guest_vcpu_type_t {
1292    #[default]
1293    ZX_PKT_GUEST_VCPU_INTERRUPT = 0,
1294    ZX_PKT_GUEST_VCPU_STARTUP = 1,
1295}
1296
1297#[repr(C)]
1298#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1299pub struct zx_packet_signal_t {
1300    pub trigger: zx_signals_t,
1301    pub observed: zx_signals_t,
1302    pub count: u64,
1303    pub timestamp: zx_time_t,
1304}
1305
1306pub const ZX_WAIT_ASYNC_TIMESTAMP: u32 = 1;
1307pub const ZX_WAIT_ASYNC_EDGE: u32 = 2;
1308pub const ZX_WAIT_ASYNC_BOOT_TIMESTAMP: u32 = 4;
1309
1310// Actually a union of different integer types, but this should be good enough.
1311pub type zx_packet_user_t = [u8; 32];
1312
1313#[repr(C)]
1314#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1315#[cfg_attr(feature = "zerocopy", derive(Immutable, IntoBytes, KnownLayout))]
1316pub struct zx_port_packet_t {
1317    pub key: u64,
1318    pub packet_type: zx_packet_type_t,
1319    pub status: i32,
1320    pub union: [u8; 32],
1321}
1322
1323#[repr(C)]
1324#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1325pub struct zx_packet_guest_bell_t {
1326    pub addr: zx_gpaddr_t,
1327}
1328
1329#[repr(C)]
1330#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1331pub struct zx_packet_guest_io_t {
1332    pub port: u16,
1333    pub access_size: u8,
1334    pub input: bool,
1335    pub data: [u8; 4],
1336}
1337
1338#[repr(C)]
1339#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1340#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1341pub struct zx_packet_guest_vcpu_interrupt_t {
1342    pub mask: u64,
1343    pub vector: u8,
1344    padding1: [PadByte; 15],
1345}
1346
1347#[repr(C)]
1348#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1349#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1350pub struct zx_packet_guest_vcpu_startup_t {
1351    pub target: u64,
1352    pub entry: zx_gpaddr_t,
1353    pub context: u64,
1354}
1355
1356#[repr(C)]
1357#[derive(Copy, Clone)]
1358#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1359pub union zx_packet_guest_vcpu_union_t {
1360    pub interrupt: zx_packet_guest_vcpu_interrupt_t,
1361    pub startup: zx_packet_guest_vcpu_startup_t,
1362}
1363
1364#[cfg(feature = "zerocopy")]
1365impl Default for zx_packet_guest_vcpu_union_t {
1366    fn default() -> Self {
1367        Self::new_zeroed()
1368    }
1369}
1370
1371#[repr(C)]
1372#[derive(Copy, Clone, Default)]
1373pub struct zx_packet_guest_vcpu_t {
1374    pub r#type: zx_packet_guest_vcpu_type_t,
1375    padding1: [PadByte; 4],
1376    pub union: zx_packet_guest_vcpu_union_t,
1377}
1378
1379impl PartialEq for zx_packet_guest_vcpu_t {
1380    fn eq(&self, other: &Self) -> bool {
1381        if self.r#type != other.r#type {
1382            return false;
1383        }
1384        match self.r#type {
1385            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT => unsafe {
1386                self.union.interrupt == other.union.interrupt
1387            },
1388            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP => unsafe {
1389                self.union.startup == other.union.startup
1390            },
1391        }
1392    }
1393}
1394
1395impl Eq for zx_packet_guest_vcpu_t {}
1396
1397impl Debug for zx_packet_guest_vcpu_t {
1398    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1399        match self.r#type {
1400            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT => {
1401                write!(f, "type: {:?} union: {:?}", self.r#type, unsafe { self.union.interrupt })
1402            }
1403            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP => {
1404                write!(f, "type: {:?} union: {:?}", self.r#type, unsafe { self.union.startup })
1405            }
1406        }
1407    }
1408}
1409
1410#[repr(C)]
1411#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1412pub struct zx_packet_page_request_t {
1413    pub command: zx_page_request_command_t,
1414    pub flags: u16,
1415    padding1: [PadByte; 4],
1416    pub offset: u64,
1417    pub length: u64,
1418    padding2: [PadByte; 8],
1419}
1420
1421#[repr(u16)]
1422#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1423#[non_exhaustive]
1424pub enum zx_page_request_command_t {
1425    #[default]
1426    ZX_PAGER_VMO_READ = 0x0000,
1427    ZX_PAGER_VMO_COMPLETE = 0x0001,
1428    ZX_PAGER_VMO_DIRTY = 0x0002,
1429}
1430
1431multiconst!(u32, [
1432    ZX_PAGER_OP_FAIL = 1;
1433    ZX_PAGER_OP_DIRTY = 2;
1434    ZX_PAGER_OP_WRITEBACK_BEGIN = 3;
1435    ZX_PAGER_OP_WRITEBACK_END = 4;
1436]);
1437
1438// Values for zx_pager_vmo_stats_t.modified.
1439pub const ZX_PAGER_VMO_STATS_MODIFIED: u32 = 1;
1440
1441// Options for zx_pager_query_vmo_stats().
1442pub const ZX_PAGER_RESET_VMO_STATS: u32 = 1;
1443
1444#[repr(C)]
1445#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1446#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1447pub struct zx_pager_vmo_stats_t {
1448    pub modified: u32,
1449}
1450
1451#[repr(C)]
1452#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1453#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1454pub struct zx_vmo_dirty_range_t {
1455    pub offset: u64,
1456    pub length: u64,
1457    pub options: u64,
1458}
1459
1460pub type zx_excp_type_t = u32;
1461
1462multiconst!(zx_excp_type_t, [
1463    ZX_EXCP_GENERAL               = 0x008;
1464    ZX_EXCP_FATAL_PAGE_FAULT      = 0x108;
1465    ZX_EXCP_UNDEFINED_INSTRUCTION = 0x208;
1466    ZX_EXCP_SW_BREAKPOINT         = 0x308;
1467    ZX_EXCP_HW_BREAKPOINT         = 0x408;
1468    ZX_EXCP_UNALIGNED_ACCESS      = 0x508;
1469
1470    ZX_EXCP_SYNTH                 = 0x8000;
1471
1472    ZX_EXCP_THREAD_STARTING       = 0x008 | ZX_EXCP_SYNTH;
1473    ZX_EXCP_THREAD_EXITING        = 0x108 | ZX_EXCP_SYNTH;
1474    ZX_EXCP_POLICY_ERROR          = 0x208 | ZX_EXCP_SYNTH;
1475    ZX_EXCP_PROCESS_STARTING      = 0x308 | ZX_EXCP_SYNTH;
1476    ZX_EXCP_USER                  = 0x309 | ZX_EXCP_SYNTH;
1477]);
1478
1479multiconst!(u32, [
1480    ZX_EXCP_USER_CODE_PROCESS_NAME_CHANGED = 0x0001;
1481
1482    ZX_EXCP_USER_CODE_USER0                = 0xF000;
1483    ZX_EXCP_USER_CODE_USER1                = 0xF001;
1484    ZX_EXCP_USER_CODE_USER2                = 0xF002;
1485]);
1486
1487#[repr(C)]
1488#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1489#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes))]
1490pub struct zx_exception_info_t {
1491    pub pid: zx_koid_t,
1492    pub tid: zx_koid_t,
1493    pub type_: zx_excp_type_t,
1494    padding1: [PadByte; 4],
1495}
1496
1497#[repr(C)]
1498#[derive(Default, Copy, Clone, Eq, PartialEq)]
1499#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1500pub struct zx_x86_64_exc_data_t {
1501    pub vector: u64,
1502    pub err_code: u64,
1503    pub cr2: u64,
1504}
1505
1506impl Debug for zx_x86_64_exc_data_t {
1507    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1508        write!(f, "vector 0x{:x} err_code {} cr2 0x{:x}", self.vector, self.err_code, self.cr2)
1509    }
1510}
1511
1512#[repr(C)]
1513#[derive(Default, Copy, Clone, Eq, PartialEq)]
1514#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1515pub struct zx_arm64_exc_data_t {
1516    pub esr: u32,
1517    padding1: [PadByte; 4],
1518    pub far: u64,
1519    padding2: [PadByte; 8],
1520}
1521
1522impl Debug for zx_arm64_exc_data_t {
1523    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1524        write!(f, "esr 0x{:x} far 0x{:x}", self.esr, self.far)
1525    }
1526}
1527
1528#[repr(C)]
1529#[derive(Default, Copy, Clone, Eq, PartialEq)]
1530#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1531pub struct zx_riscv64_exc_data_t {
1532    pub cause: u64,
1533    pub tval: u64,
1534    padding1: [PadByte; 8],
1535}
1536
1537impl Debug for zx_riscv64_exc_data_t {
1538    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1539        write!(f, "cause {} tval {}", self.cause, self.tval)
1540    }
1541}
1542
1543#[repr(C)]
1544#[derive(Copy, Clone)]
1545#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1546pub union zx_exception_header_arch_t {
1547    pub x86_64: zx_x86_64_exc_data_t,
1548    pub arm_64: zx_arm64_exc_data_t,
1549    pub riscv_64: zx_riscv64_exc_data_t,
1550}
1551
1552impl Debug for zx_exception_header_arch_t {
1553    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1554        write!(f, "zx_exception_header_arch_t ")?;
1555        #[cfg(target_arch = "x86_64")]
1556        {
1557            // SAFETY: Exception reports are presumed to be from the target architecture.
1558            // Even if it was not, it's sound to treat the union as another variant as
1559            // the size and alignment are the same, there is no internal padding, and
1560            // the variants have no validity invariants.
1561            let x86_64 = unsafe { self.x86_64 };
1562            write!(f, "{x86_64:?}")
1563        }
1564        #[cfg(target_arch = "aarch64")]
1565        {
1566            // SAFETY: Exception reports are presumed to be from the target architecture.
1567            // Even if it was not, it's sound to treat the union as another variant as
1568            // the size and alignment are the same, there is no internal padding, and
1569            // the variants have no validity invariants.
1570            let arm_64 = unsafe { self.arm_64 };
1571            write!(f, "{arm_64:?}")
1572        }
1573        #[cfg(target_arch = "riscv64")]
1574        {
1575            // SAFETY: Exception reports are presumed to be from the target architecture.
1576            // Even if it was not, it's sound to treat the union as another variant as
1577            // the size and alignment are the same, there is no internal padding, and
1578            // the variants have no validity invariants.
1579            let riscv_64 = unsafe { self.riscv_64 };
1580            write!(f, "{riscv_64:?}")
1581        }
1582    }
1583}
1584
1585#[repr(C)]
1586#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1587#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1588pub struct zx_exception_header_t {
1589    pub size: u32,
1590    pub type_: zx_excp_type_t,
1591}
1592
1593pub type zx_excp_policy_code_t = u32;
1594
1595multiconst!(zx_excp_policy_code_t, [
1596    ZX_EXCP_POLICY_CODE_BAD_HANDLE              = 0;
1597    ZX_EXCP_POLICY_CODE_WRONG_OBJECT            = 1;
1598    ZX_EXCP_POLICY_CODE_VMAR_WX                 = 2;
1599    ZX_EXCP_POLICY_CODE_NEW_ANY                 = 3;
1600    ZX_EXCP_POLICY_CODE_NEW_VMO                 = 4;
1601    ZX_EXCP_POLICY_CODE_NEW_CHANNEL             = 5;
1602    ZX_EXCP_POLICY_CODE_NEW_EVENT               = 6;
1603    ZX_EXCP_POLICY_CODE_NEW_EVENTPAIR           = 7;
1604    ZX_EXCP_POLICY_CODE_NEW_PORT                = 8;
1605    ZX_EXCP_POLICY_CODE_NEW_SOCKET              = 9;
1606    ZX_EXCP_POLICY_CODE_NEW_FIFO                = 10;
1607    ZX_EXCP_POLICY_CODE_NEW_TIMER               = 11;
1608    ZX_EXCP_POLICY_CODE_NEW_PROCESS             = 12;
1609    ZX_EXCP_POLICY_CODE_NEW_PROFILE             = 13;
1610    ZX_EXCP_POLICY_CODE_NEW_PAGER               = 14;
1611    ZX_EXCP_POLICY_CODE_AMBIENT_MARK_VMO_EXEC   = 15;
1612    ZX_EXCP_POLICY_CODE_CHANNEL_FULL_WRITE      = 16;
1613    ZX_EXCP_POLICY_CODE_PORT_TOO_MANY_PACKETS   = 17;
1614    ZX_EXCP_POLICY_CODE_BAD_SYSCALL             = 18;
1615    ZX_EXCP_POLICY_CODE_PORT_TOO_MANY_OBSERVERS = 19;
1616    ZX_EXCP_POLICY_CODE_HANDLE_LEAK             = 20;
1617    ZX_EXCP_POLICY_CODE_NEW_IOB                 = 21;
1618]);
1619
1620#[repr(C)]
1621#[derive(Debug, Copy, Clone)]
1622#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1623pub struct zx_exception_context_t {
1624    pub arch: zx_exception_header_arch_t,
1625    pub synth_code: zx_excp_policy_code_t,
1626    pub synth_data: u32,
1627}
1628
1629#[repr(C)]
1630#[derive(Debug, Copy, Clone)]
1631#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1632pub struct zx_exception_report_t {
1633    pub header: zx_exception_header_t,
1634    pub context: zx_exception_context_t,
1635}
1636
1637const_assert_eq!(core::mem::size_of::<zx_exception_report_t>(), 40);
1638const_assert_eq!(core::mem::align_of::<zx_exception_report_t>(), 8);
1639
1640#[repr(C, align(8))]
1641#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1642#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1643pub struct zx_exception_report_v1_t {
1644    pub header: zx_exception_header_t,
1645    pub context: [u8; 24],
1646}
1647
1648const_assert_eq!(core::mem::size_of::<zx_exception_report_v1_t>(), 32);
1649const_assert_eq!(core::mem::align_of::<zx_exception_report_v1_t>(), 8);
1650
1651pub type zx_exception_state_t = u32;
1652
1653multiconst!(zx_exception_state_t, [
1654    ZX_EXCEPTION_STATE_TRY_NEXT    = 0;
1655    ZX_EXCEPTION_STATE_HANDLED     = 1;
1656    ZX_EXCEPTION_STATE_THREAD_EXIT = 2;
1657]);
1658
1659pub type zx_exception_strategy_t = u32;
1660
1661multiconst!(zx_exception_state_t, [
1662    ZX_EXCEPTION_STRATEGY_FIRST_CHANCE   = 0;
1663    ZX_EXCEPTION_STRATEGY_SECOND_CHANCE  = 1;
1664]);
1665
1666#[cfg(target_arch = "x86_64")]
1667#[repr(C)]
1668#[derive(Default, Copy, Clone, Eq, PartialEq)]
1669#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable))]
1670pub struct zx_thread_state_general_regs_t {
1671    pub rax: u64,
1672    pub rbx: u64,
1673    pub rcx: u64,
1674    pub rdx: u64,
1675    pub rsi: u64,
1676    pub rdi: u64,
1677    pub rbp: u64,
1678    pub rsp: u64,
1679    pub r8: u64,
1680    pub r9: u64,
1681    pub r10: u64,
1682    pub r11: u64,
1683    pub r12: u64,
1684    pub r13: u64,
1685    pub r14: u64,
1686    pub r15: u64,
1687    pub rip: u64,
1688    pub rflags: u64,
1689    pub fs_base: u64,
1690    pub gs_base: u64,
1691}
1692
1693#[cfg(target_arch = "x86_64")]
1694impl core::fmt::Debug for zx_thread_state_general_regs_t {
1695    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1696        f.debug_struct(core::any::type_name::<Self>())
1697            .field("rax", &format_args!("{:#x}", self.rax))
1698            .field("rbx", &format_args!("{:#x}", self.rbx))
1699            .field("rcx", &format_args!("{:#x}", self.rcx))
1700            .field("rdx", &format_args!("{:#x}", self.rdx))
1701            .field("rsi", &format_args!("{:#x}", self.rsi))
1702            .field("rdi", &format_args!("{:#x}", self.rdi))
1703            .field("rbp", &format_args!("{:#x}", self.rbp))
1704            .field("rsp", &format_args!("{:#x}", self.rsp))
1705            .field("r8", &format_args!("{:#x}", self.r8))
1706            .field("r9", &format_args!("{:#x}", self.r9))
1707            .field("r10", &format_args!("{:#x}", self.r10))
1708            .field("r11", &format_args!("{:#x}", self.r11))
1709            .field("r12", &format_args!("{:#x}", self.r12))
1710            .field("r13", &format_args!("{:#x}", self.r13))
1711            .field("r14", &format_args!("{:#x}", self.r14))
1712            .field("r15", &format_args!("{:#x}", self.r15))
1713            .field("rip", &format_args!("{:#x}", self.rip))
1714            .field("rflags", &format_args!("{:#x}", self.rflags))
1715            .field("fs_base", &format_args!("{:#x}", self.fs_base))
1716            .field("gs_base", &format_args!("{:#x}", self.gs_base))
1717            .finish()
1718    }
1719}
1720
1721#[cfg(target_arch = "x86_64")]
1722impl From<&zx_restricted_state_t> for zx_thread_state_general_regs_t {
1723    fn from(state: &zx_restricted_state_t) -> Self {
1724        Self {
1725            rdi: state.rdi,
1726            rsi: state.rsi,
1727            rbp: state.rbp,
1728            rbx: state.rbx,
1729            rdx: state.rdx,
1730            rcx: state.rcx,
1731            rax: state.rax,
1732            rsp: state.rsp,
1733            r8: state.r8,
1734            r9: state.r9,
1735            r10: state.r10,
1736            r11: state.r11,
1737            r12: state.r12,
1738            r13: state.r13,
1739            r14: state.r14,
1740            r15: state.r15,
1741            rip: state.ip,
1742            rflags: state.flags,
1743            fs_base: state.fs_base,
1744            gs_base: state.gs_base,
1745        }
1746    }
1747}
1748
1749#[cfg(target_arch = "aarch64")]
1750multiconst!(u64, [
1751    ZX_REG_CPSR_ARCH_32_MASK = 0x10;
1752    ZX_REG_CPSR_THUMB_MASK = 0x20;
1753]);
1754
1755#[cfg(target_arch = "aarch64")]
1756#[repr(C)]
1757#[derive(Default, Copy, Clone, Eq, PartialEq)]
1758pub struct zx_thread_state_general_regs_t {
1759    pub r: [u64; 30],
1760    pub lr: u64,
1761    pub sp: u64,
1762    pub pc: u64,
1763    pub cpsr: u64,
1764    pub tpidr: u64,
1765}
1766
1767#[cfg(target_arch = "aarch64")]
1768impl core::fmt::Debug for zx_thread_state_general_regs_t {
1769    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1770        struct RegisterAsHex(u64);
1771        impl core::fmt::Debug for RegisterAsHex {
1772            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1773                write!(f, "{:#x}", self.0)
1774            }
1775        }
1776
1777        f.debug_struct(core::any::type_name::<Self>())
1778            .field("r", &self.r.map(RegisterAsHex))
1779            .field("lr", &format_args!("{:#x}", self.lr))
1780            .field("sp", &format_args!("{:#x}", self.sp))
1781            .field("pc", &format_args!("{:#x}", self.pc))
1782            .field("cpsr", &format_args!("{:#x}", self.cpsr))
1783            .field("tpidr", &format_args!("{:#x}", self.tpidr))
1784            .finish()
1785    }
1786}
1787
1788#[cfg(target_arch = "aarch64")]
1789impl From<&zx_restricted_state_t> for zx_thread_state_general_regs_t {
1790    fn from(state: &zx_restricted_state_t) -> Self {
1791        if state.cpsr as u64 & ZX_REG_CPSR_ARCH_32_MASK == ZX_REG_CPSR_ARCH_32_MASK {
1792            // aarch32
1793            Self {
1794                r: [
1795                    state.r[0],
1796                    state.r[1],
1797                    state.r[2],
1798                    state.r[3],
1799                    state.r[4],
1800                    state.r[5],
1801                    state.r[6],
1802                    state.r[7],
1803                    state.r[8],
1804                    state.r[9],
1805                    state.r[10],
1806                    state.r[11],
1807                    state.r[12],
1808                    state.r[13],
1809                    state.r[14],
1810                    state.pc, // ELR overwrites this.
1811                    state.r[16],
1812                    state.r[17],
1813                    state.r[18],
1814                    state.r[19],
1815                    state.r[20],
1816                    state.r[21],
1817                    state.r[22],
1818                    state.r[23],
1819                    state.r[24],
1820                    state.r[25],
1821                    state.r[26],
1822                    state.r[27],
1823                    state.r[28],
1824                    state.r[29],
1825                ],
1826                lr: state.r[14], // R[14] for aarch32
1827                sp: state.r[13], // R[13] for aarch32
1828                // TODO(https://fxbug.dev/379669623) Should it be checked for thumb and make
1829                // sure it isn't over incrementing?
1830                pc: state.pc, // Zircon populated this from elr.
1831                cpsr: state.cpsr as u64,
1832                tpidr: state.tpidr_el0,
1833            }
1834        } else {
1835            Self {
1836                r: [
1837                    state.r[0],
1838                    state.r[1],
1839                    state.r[2],
1840                    state.r[3],
1841                    state.r[4],
1842                    state.r[5],
1843                    state.r[6],
1844                    state.r[7],
1845                    state.r[8],
1846                    state.r[9],
1847                    state.r[10],
1848                    state.r[11],
1849                    state.r[12],
1850                    state.r[13],
1851                    state.r[14],
1852                    state.r[15],
1853                    state.r[16],
1854                    state.r[17],
1855                    state.r[18],
1856                    state.r[19],
1857                    state.r[20],
1858                    state.r[21],
1859                    state.r[22],
1860                    state.r[23],
1861                    state.r[24],
1862                    state.r[25],
1863                    state.r[26],
1864                    state.r[27],
1865                    state.r[28],
1866                    state.r[29],
1867                ],
1868                lr: state.r[30],
1869                sp: state.sp,
1870                pc: state.pc,
1871                cpsr: state.cpsr as u64,
1872                tpidr: state.tpidr_el0,
1873            }
1874        }
1875    }
1876}
1877
1878#[cfg(target_arch = "riscv64")]
1879#[repr(C)]
1880#[derive(Default, Copy, Clone, Eq, PartialEq)]
1881pub struct zx_thread_state_general_regs_t {
1882    pub pc: u64,
1883    pub ra: u64,  // x1
1884    pub sp: u64,  // x2
1885    pub gp: u64,  // x3
1886    pub tp: u64,  // x4
1887    pub t0: u64,  // x5
1888    pub t1: u64,  // x6
1889    pub t2: u64,  // x7
1890    pub s0: u64,  // x8
1891    pub s1: u64,  // x9
1892    pub a0: u64,  // x10
1893    pub a1: u64,  // x11
1894    pub a2: u64,  // x12
1895    pub a3: u64,  // x13
1896    pub a4: u64,  // x14
1897    pub a5: u64,  // x15
1898    pub a6: u64,  // x16
1899    pub a7: u64,  // x17
1900    pub s2: u64,  // x18
1901    pub s3: u64,  // x19
1902    pub s4: u64,  // x20
1903    pub s5: u64,  // x21
1904    pub s6: u64,  // x22
1905    pub s7: u64,  // x23
1906    pub s8: u64,  // x24
1907    pub s9: u64,  // x25
1908    pub s10: u64, // x26
1909    pub s11: u64, // x27
1910    pub t3: u64,  // x28
1911    pub t4: u64,  // x29
1912    pub t5: u64,  // x30
1913    pub t6: u64,  // x31
1914}
1915
1916#[cfg(target_arch = "riscv64")]
1917impl core::fmt::Debug for zx_thread_state_general_regs_t {
1918    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919        f.debug_struct(core::any::type_name::<Self>())
1920            .field("pc", &format_args!("{:#x}", self.pc))
1921            .field("ra", &format_args!("{:#x}", self.ra)) // x1
1922            .field("sp", &format_args!("{:#x}", self.sp)) // x2
1923            .field("gp", &format_args!("{:#x}", self.gp)) // x3
1924            .field("tp", &format_args!("{:#x}", self.tp)) // x4
1925            .field("t0", &format_args!("{:#x}", self.t0)) // x5
1926            .field("t1", &format_args!("{:#x}", self.t1)) // x6
1927            .field("t2", &format_args!("{:#x}", self.t2)) // x7
1928            .field("s0", &format_args!("{:#x}", self.s0)) // x8
1929            .field("s1", &format_args!("{:#x}", self.s1)) // x9
1930            .field("a0", &format_args!("{:#x}", self.a0)) // x10
1931            .field("a1", &format_args!("{:#x}", self.a1)) // x11
1932            .field("a2", &format_args!("{:#x}", self.a2)) // x12
1933            .field("a3", &format_args!("{:#x}", self.a3)) // x13
1934            .field("a4", &format_args!("{:#x}", self.a4)) // x14
1935            .field("a5", &format_args!("{:#x}", self.a5)) // x15
1936            .field("a6", &format_args!("{:#x}", self.a6)) // x16
1937            .field("a7", &format_args!("{:#x}", self.a7)) // x17
1938            .field("s2", &format_args!("{:#x}", self.s2)) // x18
1939            .field("s3", &format_args!("{:#x}", self.s3)) // x19
1940            .field("s4", &format_args!("{:#x}", self.s4)) // x20
1941            .field("s5", &format_args!("{:#x}", self.s5)) // x21
1942            .field("s6", &format_args!("{:#x}", self.s6)) // x22
1943            .field("s7", &format_args!("{:#x}", self.s7)) // x23
1944            .field("s8", &format_args!("{:#x}", self.s8)) // x24
1945            .field("s9", &format_args!("{:#x}", self.s9)) // x25
1946            .field("s10", &format_args!("{:#x}", self.s10)) // x26
1947            .field("s11", &format_args!("{:#x}", self.s11)) // x27
1948            .field("t3", &format_args!("{:#x}", self.t3)) // x28
1949            .field("t4", &format_args!("{:#x}", self.t4)) // x29
1950            .field("t5", &format_args!("{:#x}", self.t5)) // x30
1951            .field("t6", &format_args!("{:#x}", self.t6)) // x31
1952            .finish()
1953    }
1954}
1955
1956multiconst!(zx_restricted_reason_t, [
1957    ZX_RESTRICTED_REASON_SYSCALL = 0;
1958    ZX_RESTRICTED_REASON_EXCEPTION = 1;
1959    ZX_RESTRICTED_REASON_KICK = 2;
1960    ZX_RESTRICTED_REASON_EXCEPTION_LOST = 3;
1961]);
1962
1963#[cfg(target_arch = "x86_64")]
1964#[repr(C)]
1965#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1966pub struct zx_restricted_state_t {
1967    pub rdi: u64,
1968    pub rsi: u64,
1969    pub rbp: u64,
1970    pub rbx: u64,
1971    pub rdx: u64,
1972    pub rcx: u64,
1973    pub rax: u64,
1974    pub rsp: u64,
1975    pub r8: u64,
1976    pub r9: u64,
1977    pub r10: u64,
1978    pub r11: u64,
1979    pub r12: u64,
1980    pub r13: u64,
1981    pub r14: u64,
1982    pub r15: u64,
1983    pub ip: u64,
1984    pub flags: u64,
1985    pub fs_base: u64,
1986    pub gs_base: u64,
1987}
1988
1989#[cfg(target_arch = "x86_64")]
1990impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
1991    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
1992        Self {
1993            rdi: registers.rdi,
1994            rsi: registers.rsi,
1995            rbp: registers.rbp,
1996            rbx: registers.rbx,
1997            rdx: registers.rdx,
1998            rcx: registers.rcx,
1999            rax: registers.rax,
2000            rsp: registers.rsp,
2001            r8: registers.r8,
2002            r9: registers.r9,
2003            r10: registers.r10,
2004            r11: registers.r11,
2005            r12: registers.r12,
2006            r13: registers.r13,
2007            r14: registers.r14,
2008            r15: registers.r15,
2009            ip: registers.rip,
2010            flags: registers.rflags,
2011            fs_base: registers.fs_base,
2012            gs_base: registers.gs_base,
2013        }
2014    }
2015}
2016
2017#[cfg(target_arch = "aarch64")]
2018#[repr(C)]
2019#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2020pub struct zx_restricted_state_t {
2021    pub r: [u64; 31], // Note: r[30] is `lr` which is separated out in the general regs.
2022    pub sp: u64,
2023    pub pc: u64,
2024    pub tpidr_el0: u64,
2025    // Contains only the user-controllable upper 4-bits (NZCV).
2026    pub cpsr: u32,
2027    padding1: [PadByte; 4],
2028}
2029
2030#[cfg(target_arch = "aarch64")]
2031impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
2032    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
2033        Self {
2034            r: [
2035                registers.r[0],
2036                registers.r[1],
2037                registers.r[2],
2038                registers.r[3],
2039                registers.r[4],
2040                registers.r[5],
2041                registers.r[6],
2042                registers.r[7],
2043                registers.r[8],
2044                registers.r[9],
2045                registers.r[10],
2046                registers.r[11],
2047                registers.r[12],
2048                registers.r[13],
2049                registers.r[14],
2050                registers.r[15],
2051                registers.r[16],
2052                registers.r[17],
2053                registers.r[18],
2054                registers.r[19],
2055                registers.r[20],
2056                registers.r[21],
2057                registers.r[22],
2058                registers.r[23],
2059                registers.r[24],
2060                registers.r[25],
2061                registers.r[26],
2062                registers.r[27],
2063                registers.r[28],
2064                registers.r[29],
2065                registers.lr, // for compat this works nicely with zircon.
2066            ],
2067            pc: registers.pc,
2068            tpidr_el0: registers.tpidr,
2069            sp: registers.sp,
2070            cpsr: registers.cpsr as u32,
2071            padding1: Default::default(),
2072        }
2073    }
2074}
2075
2076#[cfg(target_arch = "riscv64")]
2077pub type zx_restricted_state_t = zx_thread_state_general_regs_t;
2078
2079#[cfg(target_arch = "riscv64")]
2080impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
2081    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
2082        *registers
2083    }
2084}
2085
2086#[repr(C)]
2087#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2088#[cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "riscv64"))]
2089pub struct zx_restricted_syscall_t {
2090    pub state: zx_restricted_state_t,
2091}
2092
2093#[repr(C)]
2094#[derive(Copy, Clone)]
2095#[cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "riscv64"))]
2096pub struct zx_restricted_exception_t {
2097    pub state: zx_restricted_state_t,
2098    pub exception: zx_exception_report_t,
2099}
2100
2101#[cfg(target_arch = "x86_64")]
2102#[repr(C)]
2103#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2104#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2105pub struct zx_vcpu_state_t {
2106    pub rax: u64,
2107    pub rcx: u64,
2108    pub rdx: u64,
2109    pub rbx: u64,
2110    pub rsp: u64,
2111    pub rbp: u64,
2112    pub rsi: u64,
2113    pub rdi: u64,
2114    pub r8: u64,
2115    pub r9: u64,
2116    pub r10: u64,
2117    pub r11: u64,
2118    pub r12: u64,
2119    pub r13: u64,
2120    pub r14: u64,
2121    pub r15: u64,
2122    // Contains only the user-controllable lower 32-bits.
2123    pub rflags: u64,
2124}
2125
2126#[cfg(target_arch = "aarch64")]
2127#[repr(C)]
2128#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2129#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2130pub struct zx_vcpu_state_t {
2131    pub x: [u64; 31],
2132    pub sp: u64,
2133    // Contains only the user-controllable upper 4-bits (NZCV).
2134    pub cpsr: u32,
2135    padding1: [PadByte; 4],
2136}
2137
2138#[cfg(target_arch = "riscv64")]
2139#[repr(C)]
2140#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2141#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2142pub struct zx_vcpu_state_t {
2143    pub empty: u32,
2144}
2145
2146#[repr(C)]
2147#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2148#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2149pub struct zx_vcpu_io_t {
2150    pub access_size: u8,
2151    padding1: [PadByte; 3],
2152    pub data: [u8; 4],
2153}
2154
2155#[cfg(target_arch = "aarch64")]
2156#[repr(C)]
2157#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2158pub struct zx_packet_guest_mem_t {
2159    pub addr: zx_gpaddr_t,
2160    pub access_size: u8,
2161    pub sign_extend: bool,
2162    pub xt: u8,
2163    pub read: bool,
2164    pub data: u64,
2165}
2166
2167#[cfg(target_arch = "riscv64")]
2168#[repr(C)]
2169#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2170pub struct zx_packet_guest_mem_t {
2171    pub addr: zx_gpaddr_t,
2172    padding1: [PadByte; 24],
2173}
2174
2175pub const X86_MAX_INST_LEN: usize = 15;
2176
2177#[cfg(target_arch = "x86_64")]
2178#[repr(C)]
2179#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2180pub struct zx_packet_guest_mem_t {
2181    pub addr: zx_gpaddr_t,
2182    pub cr3: zx_gpaddr_t,
2183    pub rip: zx_vaddr_t,
2184    pub instruction_size: u8,
2185    pub default_operand_size: u8,
2186}
2187
2188#[repr(C)]
2189#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2190pub struct zx_packet_interrupt_t {
2191    pub timestamp: zx_time_t,
2192    padding1: [PadByte; 24],
2193}
2194
2195// Helper for constructing topics that have been versioned.
2196const fn info_topic(topic: u32, version: u32) -> u32 {
2197    (version << 28) | topic
2198}
2199
2200multiconst!(zx_object_info_topic_t, [
2201    ZX_INFO_NONE                       = 0;
2202    ZX_INFO_HANDLE_VALID               = 1;
2203    ZX_INFO_HANDLE_BASIC               = 2;  // zx_info_handle_basic_t[1]
2204    ZX_INFO_PROCESS                    = info_topic(3, 1);  // zx_info_process_t[1]
2205    ZX_INFO_PROCESS_THREADS            = 4;  // zx_koid_t[n]
2206    ZX_INFO_VMAR                       = 7;  // zx_info_vmar_t[1]
2207    ZX_INFO_JOB_CHILDREN               = 8;  // zx_koid_t[n]
2208    ZX_INFO_JOB_PROCESSES              = 9;  // zx_koid_t[n]
2209    ZX_INFO_THREAD                     = 10; // zx_info_thread_t[1]
2210    ZX_INFO_THREAD_EXCEPTION_REPORT_V1 = info_topic(11, 0); // zx_exception_report_v1_t[1]
2211    ZX_INFO_THREAD_EXCEPTION_REPORT    = info_topic(11, 1); // zx_exception_report_t[1]
2212    ZX_INFO_TASK_STATS_V1              = info_topic(12, 0); // zx_info_task_stats_v1_t[1]
2213    ZX_INFO_TASK_STATS                 = info_topic(12, 1); // zx_info_task_stats_t[1]
2214    ZX_INFO_PROCESS_MAPS_V1            = info_topic(13, 0); // zx_info_maps_t[n]
2215    ZX_INFO_PROCESS_MAPS_V2            = info_topic(13, 1); // zx_info_maps_t[n]
2216    ZX_INFO_PROCESS_MAPS               = info_topic(13, 2); // zx_info_maps_t[n]
2217    ZX_INFO_PROCESS_VMOS_V1            = info_topic(14, 0); // zx_info_vmo_t[n]
2218    ZX_INFO_PROCESS_VMOS_V2            = info_topic(14, 1); // zx_info_vmo_t[n]
2219    ZX_INFO_PROCESS_VMOS_V3            = info_topic(14, 2); // zx_info_vmo_t[n]
2220    ZX_INFO_PROCESS_VMOS               = info_topic(14, 3); // zx_info_vmo_t[n]
2221    ZX_INFO_THREAD_STATS               = 15; // zx_info_thread_stats_t[1]
2222    ZX_INFO_CPU_STATS                  = 16; // zx_info_cpu_stats_t[n]
2223    ZX_INFO_KMEM_STATS_V1              = info_topic(17, 0); // zx_info_kmem_stats_v1_t[1]
2224    ZX_INFO_KMEM_STATS                 = info_topic(17, 1); // zx_info_kmem_stats_t[1]
2225    ZX_INFO_RESOURCE                   = 18; // zx_info_resource_t[1]
2226    ZX_INFO_HANDLE_COUNT               = 19; // zx_info_handle_count_t[1]
2227    ZX_INFO_BTI                        = 20; // zx_info_bti_t[1]
2228    ZX_INFO_PROCESS_HANDLE_STATS       = 21; // zx_info_process_handle_stats_t[1]
2229    ZX_INFO_SOCKET                     = 22; // zx_info_socket_t[1]
2230    ZX_INFO_VMO_V1                     = info_topic(23, 0); // zx_info_vmo_v1_t[1]
2231    ZX_INFO_VMO_V2                     = info_topic(23, 1); // zx_info_vmo_v2_t[1]
2232    ZX_INFO_VMO_V3                     = info_topic(23, 2); // zx_info_vmo_v3_t[1]
2233    ZX_INFO_VMO                        = info_topic(23, 3); // zx_info_vmo_t[1]
2234    ZX_INFO_JOB                        = 24; // zx_info_job_t[1]
2235    ZX_INFO_TIMER                      = 25; // zx_info_timer_t[1]
2236    ZX_INFO_STREAM                     = 26; // zx_info_stream_t[1]
2237    ZX_INFO_HANDLE_TABLE               = 27; // zx_info_handle_extended_t[n]
2238    ZX_INFO_MSI                        = 28; // zx_info_msi_t[1]
2239    ZX_INFO_GUEST_STATS                = 29; // zx_info_guest_stats_t[1]
2240    ZX_INFO_TASK_RUNTIME_V1            = info_topic(30, 0); // zx_info_task_runtime_v1_t[1]
2241    ZX_INFO_TASK_RUNTIME               = info_topic(30, 1); // zx_info_task_runtime_t[1]
2242    ZX_INFO_KMEM_STATS_EXTENDED        = 31; // zx_info_kmem_stats_extended_t[1]
2243    ZX_INFO_VCPU                       = 32; // zx_info_vcpu_t[1]
2244    ZX_INFO_KMEM_STATS_COMPRESSION     = 33; // zx_info_kmem_stats_compression_t[1]
2245    ZX_INFO_IOB                        = 34; // zx_info_iob_t[1]
2246    ZX_INFO_IOB_REGIONS                = 35; // zx_iob_region_info_t[n]
2247    ZX_INFO_VMAR_MAPS                  = 36; // zx_info_maps_t[n]
2248    ZX_INFO_POWER_DOMAINS              = 37; // zx_info_power_domain_info_t[n]
2249    ZX_INFO_MEMORY_STALL               = 38; // zx_info_memory_stall_t[1]
2250    ZX_INFO_INTERRUPT                  = 39; // zx_info_interrupt_t[1]
2251    ZX_INFO_CLOCK_MAPPED_SIZE          = 40; // usize[1]
2252]);
2253
2254multiconst!(zx_system_memory_stall_type_t, [
2255    ZX_SYSTEM_MEMORY_STALL_SOME        = 0;
2256    ZX_SYSTEM_MEMORY_STALL_FULL        = 1;
2257]);
2258
2259// This macro takes struct-like syntax and creates another macro that can be used to create
2260// different instances of the struct with different names. This is used to keep struct definitions
2261// from drifting between this crate and the fuchsia-zircon crate where they are identical other
2262// than in name and location.
2263macro_rules! struct_decl_macro {
2264    ( $(#[$attrs:meta])* $vis:vis struct <$macro_name:ident> $($any:tt)* ) => {
2265        #[macro_export]
2266        macro_rules! $macro_name {
2267            ($name:ident) => {
2268                $(#[$attrs])* $vis struct $name $($any)*
2269            }
2270        }
2271    }
2272}
2273
2274// Don't need struct_decl_macro for this, the wrapper is different.
2275#[repr(C)]
2276#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2277#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2278pub struct zx_info_handle_basic_t {
2279    pub koid: zx_koid_t,
2280    pub rights: zx_rights_t,
2281    pub type_: zx_obj_type_t,
2282    pub related_koid: zx_koid_t,
2283    pub reserved: u32,
2284    pub padding1: [PadByte; 4],
2285}
2286
2287const_assert_eq!(core::mem::size_of::<zx_info_handle_basic_t>(), 32);
2288const_assert_eq!(core::mem::align_of::<zx_info_handle_basic_t>(), 8);
2289
2290// Don't need struct_decl_macro for this, the wrapper is different.
2291#[repr(C)]
2292#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2293#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2294pub struct zx_info_handle_extended_t {
2295    pub type_: zx_obj_type_t,
2296    pub handle_value: zx_handle_t,
2297    pub rights: zx_rights_t,
2298    pub reserved: u32,
2299    pub koid: zx_koid_t,
2300    pub related_koid: zx_koid_t,
2301    pub peer_owner_koid: zx_koid_t,
2302}
2303
2304struct_decl_macro! {
2305    #[repr(C)]
2306    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2307    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2308    pub struct <zx_info_handle_count_t> {
2309        pub handle_count: u32,
2310    }
2311}
2312
2313zx_info_handle_count_t!(zx_info_handle_count_t);
2314
2315// Don't need struct_decl_macro for this, the wrapper is different.
2316#[repr(C)]
2317#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2318#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2319pub struct zx_info_socket_t {
2320    pub options: u32,
2321    pub padding1: [PadByte; 4],
2322    pub rx_buf_max: usize,
2323    pub rx_buf_size: usize,
2324    pub rx_buf_available: usize,
2325    pub tx_buf_max: usize,
2326    pub tx_buf_size: usize,
2327}
2328
2329const_assert_eq!(core::mem::size_of::<zx_info_socket_t>(), 48);
2330const_assert_eq!(core::mem::align_of::<zx_info_socket_t>(), 8);
2331
2332#[repr(C)]
2333#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2334#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2335pub struct zx_info_iob_t {
2336    pub options: u64,
2337    pub region_count: u32,
2338    pub padding1: [PadByte; 4],
2339}
2340
2341#[repr(C)]
2342#[derive(Copy, Clone)]
2343#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2344pub struct zx_iob_region_info_t {
2345    pub region: zx_iob_region_t,
2346    pub koid: zx_koid_t,
2347}
2348
2349#[repr(C)]
2350#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2351#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2352pub struct zx_info_vcpu_t {
2353    // Bitwise OR of ZX_INFO_VCPU_FLAG_* values.
2354    pub flags: u32,
2355}
2356
2357multiconst!(u32, [
2358    ZX_INFO_VCPU_FLAG_KICKED = 1 << 0;
2359]);
2360
2361#[repr(C)]
2362#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2363#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2364pub struct zx_info_interrupt_t {
2365    pub options: u32,
2366}
2367
2368multiconst!(u32, [
2369    ZX_INFO_PROCESS_FLAG_STARTED = 1 << 0;
2370    ZX_INFO_PROCESS_FLAG_EXITED = 1 << 1;
2371    ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED = 1 << 2;
2372]);
2373
2374struct_decl_macro! {
2375    #[repr(C)]
2376    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2377    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2378    pub struct <zx_info_process_t> {
2379        pub return_code: i64,
2380        pub start_time: zx_time_t,
2381        pub flags: u32,
2382        pub padding1: [PadByte; 4],
2383    }
2384}
2385
2386zx_info_process_t!(zx_info_process_t);
2387
2388struct_decl_macro! {
2389    #[repr(C)]
2390    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2391    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2392    pub struct <zx_info_job_t> {
2393        pub return_code: i64,
2394        pub exited: u8,
2395        pub kill_on_oom: u8,
2396        pub debugger_attached: u8,
2397        pub padding1: [PadByte; 5],
2398    }
2399}
2400
2401zx_info_job_t!(zx_info_job_t);
2402const_assert_eq!(core::mem::size_of::<zx_info_job_t>(), 16);
2403const_assert_eq!(core::mem::align_of::<zx_info_job_t>(), 8);
2404
2405struct_decl_macro! {
2406    #[repr(C)]
2407    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2408    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2409    pub struct <zx_info_timer_t> {
2410        pub options: u32,
2411        pub clock_id: zx_clock_t,
2412        pub deadline: zx_time_t,
2413        pub slack: zx_duration_t,
2414    }
2415}
2416
2417zx_info_timer_t!(zx_info_timer_t);
2418
2419struct_decl_macro! {
2420    #[repr(C)]
2421    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2422    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2423    pub struct <zx_info_stream_t> {
2424        pub options: u32,
2425        pub padding1: [u8; 4],
2426        pub seek: zx_off_t,
2427        pub content_size: u64,
2428    }
2429}
2430
2431zx_info_stream_t!(zx_info_stream_t);
2432
2433#[repr(C)]
2434#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2435#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2436pub struct zx_policy_basic_v1 {
2437    pub condition: u32,
2438    pub policy: u32,
2439}
2440
2441pub type zx_policy_basic_v1_t = zx_policy_basic_v1;
2442pub type zx_policy_basic = zx_policy_basic_v1;
2443pub type zx_policy_basic_t = zx_policy_basic_v1;
2444
2445#[repr(C)]
2446#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2447#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2448pub struct zx_policy_basic_v2 {
2449    pub condition: u32,
2450    pub action: u32,
2451    pub flags: u32,
2452}
2453
2454pub type zx_policy_basic_v2_t = zx_policy_basic_v2;
2455
2456#[repr(C)]
2457#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2458#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2459pub struct zx_policy_timer_slack {
2460    pub min_slack: zx_duration_t,
2461    pub default_mode: u32,
2462    pub _padding: [u8; 4],
2463}
2464
2465pub type zx_policy_timer_slack_t = zx_policy_timer_slack;
2466
2467multiconst!(u32, [
2468    // policy options
2469    ZX_JOB_POL_RELATIVE = 0;
2470    ZX_JOB_POL_ABSOLUTE = 1;
2471
2472    // policy topic
2473    ZX_JOB_POL_BASIC_V1 = 0;
2474    ZX_JOB_POL_BASIC_V2 = 0x0100_0000;
2475    ZX_JOB_POL_BASIC = 0;
2476    ZX_JOB_POL_TIMER_SLACK = 1;
2477
2478    // policy conditions
2479    ZX_POL_BAD_HANDLE            = 0;
2480    ZX_POL_WRONG_OBJECT          = 1;
2481    ZX_POL_VMAR_WX               = 2;
2482    ZX_POL_NEW_ANY               = 3;
2483    ZX_POL_NEW_VMO               = 4;
2484    ZX_POL_NEW_CHANNEL           = 5;
2485    ZX_POL_NEW_EVENT             = 6;
2486    ZX_POL_NEW_EVENTPAIR         = 7;
2487    ZX_POL_NEW_PORT              = 8;
2488    ZX_POL_NEW_SOCKET            = 9;
2489    ZX_POL_NEW_FIFO              = 10;
2490    ZX_POL_NEW_TIMER             = 11;
2491    ZX_POL_NEW_PROCESS           = 12;
2492    ZX_POL_NEW_PROFILE           = 13;
2493    ZX_POL_NEW_PAGER             = 14;
2494    ZX_POL_AMBIENT_MARK_VMO_EXEC = 15;
2495    ZX_POL_NEW_IOB               = 16;
2496    ZX_POL_NEW_SAMPLER           = 17;
2497    #[cfg(feature = "kernel")]
2498    ZX_POL_MAX                   = 18;
2499
2500    // policy actions
2501    ZX_POL_ACTION_ALLOW           = 0;
2502    ZX_POL_ACTION_DENY            = 1;
2503    ZX_POL_ACTION_ALLOW_EXCEPTION = 2;
2504    ZX_POL_ACTION_DENY_EXCEPTION  = 3;
2505    ZX_POL_ACTION_KILL            = 4;
2506    #[cfg(feature = "kernel")]
2507    ZX_POL_ACTION_MAX             = 5;
2508
2509    // policy override
2510    ZX_POL_OVERRIDE_ALLOW = 0;
2511    ZX_POL_OVERRIDE_DENY  = 1;
2512
2513    // timer slack default modes
2514    ZX_TIMER_SLACK_CENTER = 0;
2515    ZX_TIMER_SLACK_EARLY  = 1;
2516    ZX_TIMER_SLACK_LATE   = 2;
2517]);
2518
2519multiconst!(u32, [
2520    // critical options
2521    ZX_JOB_CRITICAL_PROCESS_RETCODE_NONZERO = 1 << 0;
2522]);
2523
2524// Don't use struct_decl_macro, wrapper is different.
2525#[repr(C)]
2526#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2527#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2528pub struct zx_info_vmo_t {
2529    pub koid: zx_koid_t,
2530    pub name: [u8; ZX_MAX_NAME_LEN],
2531    pub size_bytes: u64,
2532    pub parent_koid: zx_koid_t,
2533    pub num_children: usize,
2534    pub num_mappings: usize,
2535    pub share_count: usize,
2536    pub flags: u32,
2537    padding1: [PadByte; 4],
2538    pub committed_bytes: u64,
2539    pub handle_rights: zx_rights_t,
2540    pub cache_policy: u32,
2541    pub metadata_bytes: u64,
2542    pub committed_change_events: u64,
2543    pub populated_bytes: u64,
2544    pub committed_private_bytes: u64,
2545    pub populated_private_bytes: u64,
2546    pub committed_scaled_bytes: u64,
2547    pub populated_scaled_bytes: u64,
2548    pub committed_fractional_scaled_bytes: u64,
2549    pub populated_fractional_scaled_bytes: u64,
2550}
2551
2552#[repr(C)]
2553#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2554#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2555pub struct zx_info_vmo_v1_t {
2556    pub koid: zx_koid_t,
2557    pub name: [u8; ZX_MAX_NAME_LEN],
2558    pub size_bytes: u64,
2559    pub parent_koid: zx_koid_t,
2560    pub num_children: usize,
2561    pub num_mappings: usize,
2562    pub share_count: usize,
2563    pub flags: u32,
2564    pub padding1: [PadByte; 4],
2565    pub committed_bytes: u64,
2566    pub handle_rights: zx_rights_t,
2567    pub cache_policy: u32,
2568}
2569
2570const_assert_eq!(core::mem::size_of::<zx_info_vmo_v1_t>(), 104);
2571const_assert_eq!(core::mem::align_of::<zx_info_vmo_v1_t>(), 8);
2572
2573#[repr(C)]
2574#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2575#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2576pub struct zx_info_vmo_v2_t {
2577    pub koid: zx_koid_t,
2578    pub name: [u8; ZX_MAX_NAME_LEN],
2579    pub size_bytes: u64,
2580    pub parent_koid: zx_koid_t,
2581    pub num_children: usize,
2582    pub num_mappings: usize,
2583    pub share_count: usize,
2584    pub flags: u32,
2585    pub padding1: [PadByte; 4],
2586    pub committed_bytes: u64,
2587    pub handle_rights: zx_rights_t,
2588    pub cache_policy: u32,
2589    pub metadata_bytes: u64,
2590    pub committed_change_events: u64,
2591}
2592
2593const_assert_eq!(core::mem::size_of::<zx_info_vmo_v2_t>(), 120);
2594const_assert_eq!(core::mem::align_of::<zx_info_vmo_v2_t>(), 8);
2595
2596#[repr(C)]
2597#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2598#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2599pub struct zx_info_vmo_v3_t {
2600    pub koid: zx_koid_t,
2601    pub name: [u8; ZX_MAX_NAME_LEN],
2602    pub size_bytes: u64,
2603    pub parent_koid: zx_koid_t,
2604    pub num_children: usize,
2605    pub num_mappings: usize,
2606    pub share_count: usize,
2607    pub flags: u32,
2608    pub padding1: [PadByte; 4],
2609    pub committed_bytes: u64,
2610    pub handle_rights: zx_rights_t,
2611    pub cache_policy: u32,
2612    pub metadata_bytes: u64,
2613    pub committed_change_events: u64,
2614    pub populated_bytes: u64,
2615}
2616
2617const_assert_eq!(core::mem::size_of::<zx_info_vmo_v3_t>(), 128);
2618const_assert_eq!(core::mem::align_of::<zx_info_vmo_v3_t>(), 8);
2619
2620multiconst!(u32, [
2621    ZX_INFO_CPU_STATS_FLAG_ONLINE = 1 << 0;
2622]);
2623
2624struct_decl_macro! {
2625    #[repr(C)]
2626    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2627    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2628    pub struct <zx_info_cpu_stats_t> {
2629        pub cpu_number: u32,
2630        pub flags: u32,
2631        pub idle_time: zx_duration_t,
2632        pub normalized_busy_time: zx_duration_t,
2633        pub reschedules: u64,
2634        pub context_switches: u64,
2635        pub irq_preempts: u64,
2636        pub preempts: u64,
2637        pub yields: u64,
2638        pub ints: u64,
2639        pub timer_ints: u64,
2640        pub timers: u64,
2641        pub page_faults: u64,
2642        pub exceptions: u64,
2643        pub syscalls: u64,
2644        pub reschedule_ipis: u64,
2645        pub generic_ipis: u64,
2646        pub active_energy_consumption_nj: u64,
2647        pub idle_energy_consumption_nj: u64,
2648    }
2649}
2650
2651zx_info_cpu_stats_t!(zx_info_cpu_stats_t);
2652
2653#[repr(C)]
2654#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2655#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2656pub struct zx_arm64_info_guest_stats_t {
2657    pub cpu_number: u32,
2658    pub flags: u32,
2659    pub vm_entries: u64,
2660    pub vm_exits: u64,
2661    pub wfi_wfe_instructions: u64,
2662    pub instruction_aborts: u64,
2663    pub data_aborts: u64,
2664    pub system_instructions: u64,
2665    pub smc_instructions: u64,
2666    pub interrupts: u64,
2667}
2668
2669#[repr(C)]
2670#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2671#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2672pub struct zx_x86_64_info_guest_stats_t {
2673    pub cpu_number: u32,
2674    pub flags: u32,
2675    pub vm_entries: u64,
2676    pub vm_exits: u64,
2677    pub interrupts: u64,
2678    pub interrupt_windows: u64,
2679    pub cpuid_instructions: u64,
2680    pub hlt_instructions: u64,
2681    pub control_register_accesses: u64,
2682    pub io_instructions: u64,
2683    pub rdmsr_instructions: u64,
2684    pub wrmsr_instructions: u64,
2685    pub ept_violations: u64,
2686    pub xsetbv_instructions: u64,
2687    pub pause_instructions: u64,
2688    pub vmcall_instructions: u64,
2689}
2690
2691#[repr(C)]
2692#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2693#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2694pub struct zx_riscv64_info_guest_stats_t {
2695    pub cpu_number: u32,
2696    pub flags: u32,
2697    pub vm_entries: u64,
2698    pub vm_exits: u64,
2699    pub interrupts: u64,
2700}
2701
2702#[cfg(target_arch = "aarch64")]
2703pub type zx_info_guest_stats_t = zx_arm64_info_guest_stats_t;
2704#[cfg(target_arch = "x86_64")]
2705pub type zx_info_guest_stats_t = zx_x86_64_info_guest_stats_t;
2706#[cfg(target_arch = "riscv64")]
2707pub type zx_info_guest_stats_t = zx_riscv64_info_guest_stats_t;
2708
2709struct_decl_macro! {
2710    #[repr(C)]
2711    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2712    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2713    pub struct <zx_info_kmem_stats_t> {
2714        pub total_bytes: u64,
2715        pub free_bytes: u64,
2716        pub free_loaned_bytes: u64,
2717        pub wired_bytes: u64,
2718        pub total_heap_bytes: u64,
2719        pub free_heap_bytes: u64,
2720        pub vmo_bytes: u64,
2721        pub mmu_overhead_bytes: u64,
2722        pub ipc_bytes: u64,
2723        pub cache_bytes: u64,
2724        pub slab_bytes: u64,
2725        pub zram_bytes: u64,
2726        pub other_bytes: u64,
2727        pub vmo_reclaim_total_bytes: u64,
2728        pub vmo_reclaim_newest_bytes: u64,
2729        pub vmo_reclaim_oldest_bytes: u64,
2730        pub vmo_reclaim_disabled_bytes: u64,
2731        pub vmo_discardable_locked_bytes: u64,
2732        pub vmo_discardable_unlocked_bytes: u64,
2733    }
2734}
2735
2736zx_info_kmem_stats_t!(zx_info_kmem_stats_t);
2737
2738struct_decl_macro! {
2739    #[repr(C)]
2740    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2741    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2742    pub struct <zx_info_kmem_stats_v1_t> {
2743        pub total_bytes: u64,
2744        pub free_bytes: u64,
2745        pub wired_bytes: u64,
2746        pub total_heap_bytes: u64,
2747        pub free_heap_bytes: u64,
2748        pub vmo_bytes: u64,
2749        pub mmu_overhead_bytes: u64,
2750        pub ipc_bytes: u64,
2751        pub other_bytes: u64,
2752    }
2753}
2754
2755zx_info_kmem_stats_v1_t!(zx_info_kmem_stats_v1_t);
2756const_assert_eq!(core::mem::size_of::<zx_info_kmem_stats_v1_t>(), 72);
2757const_assert_eq!(core::mem::align_of::<zx_info_kmem_stats_v1_t>(), 8);
2758
2759struct_decl_macro! {
2760    #[repr(C)]
2761    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2762    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2763    pub struct <zx_info_kmem_stats_extended_t> {
2764        pub total_bytes: u64,
2765        pub free_bytes: u64,
2766        pub wired_bytes: u64,
2767        pub total_heap_bytes: u64,
2768        pub free_heap_bytes: u64,
2769        pub vmo_bytes: u64,
2770        pub vmo_pager_total_bytes: u64,
2771        pub vmo_pager_newest_bytes: u64,
2772        pub vmo_pager_oldest_bytes: u64,
2773        pub vmo_discardable_locked_bytes: u64,
2774        pub vmo_discardable_unlocked_bytes: u64,
2775        pub mmu_overhead_bytes: u64,
2776        pub ipc_bytes: u64,
2777        pub other_bytes: u64,
2778        pub vmo_reclaim_disable_bytes: u64,
2779    }
2780}
2781
2782zx_info_kmem_stats_extended_t!(zx_info_kmem_stats_extended_t);
2783
2784struct_decl_macro! {
2785    #[repr(C)]
2786    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2787    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2788    pub struct <zx_info_kmem_stats_compression_t> {
2789        pub uncompressed_storage_bytes: u64,
2790        pub compressed_storage_bytes: u64,
2791        pub compressed_fragmentation_bytes: u64,
2792        pub compression_time: zx_duration_t,
2793        pub decompression_time: zx_duration_t,
2794        pub total_page_compression_attempts: u64,
2795        pub failed_page_compression_attempts: u64,
2796        pub total_page_decompressions: u64,
2797        pub compressed_page_evictions: u64,
2798        pub eager_page_compressions: u64,
2799        pub memory_pressure_page_compressions: u64,
2800        pub critical_memory_page_compressions: u64,
2801        pub pages_decompressed_unit_ns: u64,
2802        pub pages_decompressed_within_log_time: [u64; 8],
2803    }
2804}
2805
2806zx_info_kmem_stats_compression_t!(zx_info_kmem_stats_compression_t);
2807
2808struct_decl_macro! {
2809    #[repr(C)]
2810    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2811    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2812    pub struct <zx_info_resource_t> {
2813        pub kind: u32,
2814        pub flags: u32,
2815        pub base: u64,
2816        pub size: usize,
2817        pub name: [u8; ZX_MAX_NAME_LEN],
2818    }
2819}
2820
2821const_assert_eq!(core::mem::size_of::<zx_info_resource_t>(), 56);
2822const_assert_eq!(core::mem::align_of::<zx_info_resource_t>(), 8);
2823
2824struct_decl_macro! {
2825    #[repr(C)]
2826    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2827    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2828    pub struct <zx_info_bti_t> {
2829        pub minimum_contiguity: u64,
2830        pub aspace_size: u64,
2831        pub pmo_count: u64,
2832        pub quarantine_count: u64,
2833    }
2834}
2835
2836zx_info_bti_t!(zx_info_bti_t);
2837
2838struct_decl_macro! {
2839    #[repr(C)]
2840    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2841    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2842    pub struct <zx_info_msi_t> {
2843        pub target_addr: u64,
2844        pub target_data: u32,
2845        pub base_irq_id: u32,
2846        pub num_irq: u32,
2847        pub interrupt_count: u32,
2848    }
2849}
2850
2851zx_info_msi_t!(zx_info_msi_t);
2852
2853pub type zx_thread_state_t = u32;
2854
2855multiconst!(zx_thread_state_t, [
2856    ZX_THREAD_STATE_NEW = 0x0000;
2857    ZX_THREAD_STATE_RUNNING = 0x0001;
2858    ZX_THREAD_STATE_SUSPENDED = 0x0002;
2859    ZX_THREAD_STATE_BLOCKED = 0x0003;
2860    ZX_THREAD_STATE_DYING = 0x0004;
2861    ZX_THREAD_STATE_DEAD = 0x0005;
2862    ZX_THREAD_STATE_BLOCKED_EXCEPTION = 0x0103;
2863    ZX_THREAD_STATE_BLOCKED_SLEEPING = 0x0203;
2864    ZX_THREAD_STATE_BLOCKED_FUTEX = 0x0303;
2865    ZX_THREAD_STATE_BLOCKED_PORT = 0x0403;
2866    ZX_THREAD_STATE_BLOCKED_CHANNEL = 0x0503;
2867    ZX_THREAD_STATE_BLOCKED_WAIT_ONE = 0x0603;
2868    ZX_THREAD_STATE_BLOCKED_WAIT_MANY = 0x0703;
2869    ZX_THREAD_STATE_BLOCKED_INTERRUPT = 0x0803;
2870    ZX_THREAD_STATE_BLOCKED_PAGER = 0x0903;
2871]);
2872
2873#[repr(C)]
2874#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2875#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2876pub struct zx_info_thread_t {
2877    pub state: zx_thread_state_t,
2878    pub wait_exception_channel_type: u32,
2879    pub cpu_affinity_mask: zx_cpu_set_t,
2880}
2881
2882struct_decl_macro! {
2883    #[repr(C)]
2884    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2885    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2886    pub struct <zx_info_thread_stats_t> {
2887        pub total_runtime: zx_duration_t,
2888        pub last_scheduled_cpu: u32,
2889        pub padding1: [PadByte; 4],
2890    }
2891}
2892
2893zx_info_thread_stats_t!(zx_info_thread_stats_t);
2894const_assert_eq!(core::mem::size_of::<zx_info_thread_stats_t>(), 16);
2895const_assert_eq!(core::mem::align_of::<zx_info_thread_stats_t>(), 8);
2896
2897zx_info_resource_t!(zx_info_resource_t);
2898
2899struct_decl_macro! {
2900    #[repr(C)]
2901    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2902    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2903    pub struct <zx_info_vmar_t> {
2904        pub base: usize,
2905        pub len: usize,
2906    }
2907}
2908
2909zx_info_vmar_t!(zx_info_vmar_t);
2910const_assert_eq!(core::mem::size_of::<zx_info_vmar_t>(), 16);
2911const_assert_eq!(core::mem::align_of::<zx_info_vmar_t>(), 8);
2912
2913struct_decl_macro! {
2914    #[repr(C)]
2915    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2916    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2917    pub struct <zx_info_task_stats_t> {
2918        pub mem_mapped_bytes: usize,
2919        pub mem_private_bytes: usize,
2920        pub mem_shared_bytes: usize,
2921        pub mem_scaled_shared_bytes: usize,
2922        pub mem_fractional_scaled_shared_bytes: u64,
2923    }
2924}
2925
2926zx_info_task_stats_t!(zx_info_task_stats_t);
2927const_assert_eq!(core::mem::size_of::<zx_info_task_stats_t>(), 40);
2928const_assert_eq!(core::mem::align_of::<zx_info_task_stats_t>(), 8);
2929
2930struct_decl_macro! {
2931    #[repr(C)]
2932    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2933    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2934    pub struct <zx_info_task_stats_v1_t> {
2935        pub mem_mapped_bytes: usize,
2936        pub mem_private_bytes: usize,
2937        pub mem_shared_bytes: usize,
2938        pub mem_scaled_shared_bytes: usize,
2939    }
2940}
2941
2942zx_info_task_stats_v1_t!(zx_info_task_stats_v1_t);
2943const_assert_eq!(core::mem::size_of::<zx_info_task_stats_v1_t>(), 32);
2944const_assert_eq!(core::mem::align_of::<zx_info_task_stats_v1_t>(), 8);
2945
2946struct_decl_macro! {
2947    #[repr(C)]
2948    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2949    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2950    pub struct <zx_info_task_runtime_t> {
2951        pub cpu_time: zx_duration_t,
2952        pub queue_time: zx_duration_t,
2953        pub page_fault_time: zx_duration_t,
2954        pub lock_contention_time: zx_duration_t,
2955    }
2956}
2957
2958zx_info_task_runtime_t!(zx_info_task_runtime_t);
2959const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_t>(), 32);
2960const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_t>(), 8);
2961
2962struct_decl_macro! {
2963    #[repr(C)]
2964    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2965    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2966    pub struct <zx_info_task_runtime_v1_t> {
2967        pub cpu_time: zx_duration_mono_t,
2968        pub queue_time: zx_duration_mono_t,
2969    }
2970}
2971
2972zx_info_task_runtime_v1_t!(zx_info_task_runtime_v1_t);
2973const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_v1_t>(), 16);
2974const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_v1_t>(), 8);
2975
2976multiconst!(zx_info_maps_type_t, [
2977    ZX_INFO_MAPS_TYPE_NONE    = 0;
2978    ZX_INFO_MAPS_TYPE_ASPACE  = 1;
2979    ZX_INFO_MAPS_TYPE_VMAR    = 2;
2980    ZX_INFO_MAPS_TYPE_MAPPING = 3;
2981]);
2982
2983struct_decl_macro! {
2984    #[repr(C)]
2985    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2986    #[derive(zerocopy::FromBytes, zerocopy::Immutable, IntoBytes)]
2987    pub struct <zx_info_maps_mapping_t> {
2988        pub mmu_flags: zx_vm_option_t,
2989        pub padding1: [PadByte; 4],
2990        pub vmo_koid: zx_koid_t,
2991        pub vmo_offset: u64,
2992        pub committed_bytes: usize,
2993        pub populated_bytes: usize,
2994        pub committed_private_bytes: usize,
2995        pub populated_private_bytes: usize,
2996        pub committed_scaled_bytes: usize,
2997        pub populated_scaled_bytes: usize,
2998        pub committed_fractional_scaled_bytes: u64,
2999        pub populated_fractional_scaled_bytes: u64,
3000    }
3001}
3002
3003zx_info_maps_mapping_t!(zx_info_maps_mapping_t);
3004
3005#[repr(C)]
3006#[derive(Copy, Clone)]
3007#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3008pub union InfoMapsTypeUnion {
3009    pub mapping: zx_info_maps_mapping_t,
3010}
3011
3012impl Default for InfoMapsTypeUnion {
3013    fn default() -> Self {
3014        Self { mapping: zx_info_maps_mapping_t::default() }
3015    }
3016}
3017
3018struct_decl_macro! {
3019    #[repr(C)]
3020    #[derive(Default, Copy, Clone)]
3021    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
3022    pub struct <zx_info_maps_t> {
3023        pub name: [u8; ZX_MAX_NAME_LEN],
3024        pub base: zx_vaddr_t,
3025        pub size: usize,
3026        pub depth: usize,
3027        pub r#type: zx_info_maps_type_t,
3028        pub padding1: [PadByte; 4],
3029        pub u: InfoMapsTypeUnion,
3030    }
3031}
3032
3033zx_info_maps_t!(zx_info_maps_t);
3034
3035#[repr(C)]
3036#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
3037#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3038pub struct zx_info_maps_mapping_v2_t {
3039    pub mmu_flags: zx_vm_option_t,
3040    pub padding1: [PadByte; 4],
3041    pub vmo_koid: zx_koid_t,
3042    pub vmo_offset: u64,
3043    pub committed_pages: usize,
3044    pub populated_pages: usize,
3045}
3046
3047#[repr(C)]
3048#[derive(Copy, Clone)]
3049#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3050pub union InfoMapsTypeUnionV2 {
3051    pub mapping: zx_info_maps_mapping_v2_t,
3052}
3053
3054impl Default for InfoMapsTypeUnionV2 {
3055    fn default() -> Self {
3056        Self { mapping: zx_info_maps_mapping_v2_t::default() }
3057    }
3058}
3059
3060#[repr(C)]
3061#[derive(Default, Copy, Clone)]
3062#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3063pub struct zx_info_maps_v2_t {
3064    pub name: [u8; ZX_MAX_NAME_LEN],
3065    pub base: zx_vaddr_t,
3066    pub size: usize,
3067    pub depth: usize,
3068    pub r#type: zx_info_maps_type_t,
3069    pub padding1: [PadByte; 4],
3070    pub u: InfoMapsTypeUnionV2,
3071}
3072
3073const_assert_eq!(core::mem::size_of::<zx_info_maps_v2_t>(), 104);
3074const_assert_eq!(core::mem::align_of::<zx_info_maps_v2_t>(), 8);
3075
3076#[repr(C)]
3077#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
3078#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3079pub struct zx_info_maps_mapping_v1_t {
3080    pub mmu_flags: zx_vm_option_t,
3081    pub padding1: [PadByte; 4],
3082    pub vmo_koid: zx_koid_t,
3083    pub vmo_offset: u64,
3084    pub committed_pages: usize,
3085}
3086
3087#[repr(C)]
3088#[derive(Copy, Clone)]
3089#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3090pub union InfoMapsTypeUnionV1 {
3091    pub mapping: zx_info_maps_mapping_v1_t,
3092}
3093
3094impl Default for InfoMapsTypeUnionV1 {
3095    fn default() -> Self {
3096        Self { mapping: zx_info_maps_mapping_v1_t::default() }
3097    }
3098}
3099
3100#[repr(C)]
3101#[derive(Default, Copy, Clone)]
3102#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3103pub struct zx_info_maps_v1_t {
3104    pub name: [u8; ZX_MAX_NAME_LEN],
3105    pub base: zx_vaddr_t,
3106    pub size: usize,
3107    pub depth: usize,
3108    pub r#type: zx_info_maps_type_t,
3109    pub padding1: [PadByte; 4],
3110    pub u: InfoMapsTypeUnionV1,
3111}
3112
3113const_assert_eq!(core::mem::size_of::<zx_info_maps_v1_t>(), 96);
3114const_assert_eq!(core::mem::align_of::<zx_info_maps_v1_t>(), 8);
3115
3116struct_decl_macro! {
3117    #[repr(C)]
3118    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
3119    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
3120    pub struct <zx_info_process_handle_stats_t> {
3121        pub handle_count: [u32; ZX_OBJ_TYPE_UPPER_BOUND],
3122    }
3123}
3124
3125const_assert_eq!(core::mem::size_of::<zx_info_process_handle_stats_t>(), 256);
3126const_assert_eq!(core::mem::align_of::<zx_info_process_handle_stats_t>(), 4);
3127
3128impl Default for zx_info_process_handle_stats_t {
3129    fn default() -> Self {
3130        Self { handle_count: [0; ZX_OBJ_TYPE_UPPER_BOUND] }
3131    }
3132}
3133
3134zx_info_process_handle_stats_t!(zx_info_process_handle_stats_t);
3135
3136struct_decl_macro! {
3137    #[repr(C)]
3138    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
3139    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
3140    pub struct <zx_info_memory_stall_t> {
3141        pub stall_time_some: zx_duration_mono_t,
3142        pub stall_time_full: zx_duration_mono_t,
3143    }
3144}
3145
3146zx_info_memory_stall_t!(zx_info_memory_stall_t);
3147
3148// from //zircon/system/public/zircon/syscalls/hypervisor.h
3149multiconst!(zx_guest_trap_t, [
3150    ZX_GUEST_TRAP_BELL = 0;
3151    ZX_GUEST_TRAP_MEM  = 1;
3152    ZX_GUEST_TRAP_IO   = 2;
3153]);
3154
3155pub const ZX_LOG_RECORD_MAX: usize = 256;
3156pub const ZX_LOG_RECORD_DATA_MAX: usize = 216;
3157
3158pub const DEBUGLOG_TRACE: u8 = 0x10;
3159pub const DEBUGLOG_DEBUG: u8 = 0x20;
3160pub const DEBUGLOG_INFO: u8 = 0x30;
3161pub const DEBUGLOG_WARNING: u8 = 0x40;
3162pub const DEBUGLOG_ERROR: u8 = 0x50;
3163pub const DEBUGLOG_FATAL: u8 = 0x60;
3164
3165// From //zircon/system/public/zircon/syscalls/log.h
3166// Do not forward this message via network (for logging in network core and drivers).
3167pub const ZX_LOG_LOCAL: u32 = 0x10;
3168pub const ZX_LOG_FLAGS_MASK: u32 = ZX_LOG_LOCAL;
3169
3170// From //zircon/system/public/zircon/processargs.h
3171pub const ZX_PROCARGS_PROTOCOL: u32 = 0x4150585d; // MXPA
3172pub const ZX_PROCARGS_VERSION: u32 = 0x00001000;
3173
3174#[repr(C)]
3175#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3176#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3177pub struct zx_log_record_header_t {
3178    pub sequence: u64,
3179    padding1: [PadByte; 4],
3180    pub datalen: u16,
3181    pub severity: u8,
3182    pub flags: u8,
3183    pub timestamp: zx_instant_boot_t,
3184    pub pid: u64,
3185    pub tid: u64,
3186}
3187
3188#[repr(C)]
3189#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3190#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3191pub struct zx_log_record_t {
3192    pub header: zx_log_record_header_t,
3193    pub data: [u8; ZX_LOG_RECORD_DATA_MAX],
3194}
3195
3196const_assert_eq!(core::mem::size_of::<zx_log_record_t>(), ZX_LOG_RECORD_MAX);
3197
3198impl Default for zx_log_record_t {
3199    fn default() -> Self {
3200        Self { header: zx_log_record_header_t::default(), data: [0; ZX_LOG_RECORD_DATA_MAX] }
3201    }
3202}
3203
3204multiconst!(u32, [
3205    ZX_LOG_FLAG_READABLE = 0x40000000;
3206]);
3207
3208// For C, the below types are currently forward declared for syscalls.h.
3209// We might want to investigate a better solution for Rust or removing those
3210// forward declarations.
3211//
3212// These are hand typed translations from C types into Rust structures using a C
3213// layout
3214
3215// source: zircon/system/public/zircon/syscalls/system.h
3216multiconst!(zx_system_powerctl_cmd_t, [
3217    ZX_SYSTEM_POWERCTL_REBOOT                        = 5;
3218    ZX_SYSTEM_POWERCTL_REBOOT_BOOTLOADER             = 6;
3219    ZX_SYSTEM_POWERCTL_REBOOT_RECOVERY               = 7;
3220    ZX_SYSTEM_POWERCTL_SHUTDOWN                      = 8;
3221    ZX_SYSTEM_POWERCTL_ACK_KERNEL_INITIATED_REBOOT   = 9;
3222]);
3223
3224// source: zircon/system/public/zircon/syscalls/smc.h
3225#[repr(C)]
3226#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3227#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3228pub struct zx_smc_parameters_t {
3229    pub func_id: u32,
3230    padding1: [PadByte; 4],
3231    pub arg1: u64,
3232    pub arg2: u64,
3233    pub arg3: u64,
3234    pub arg4: u64,
3235    pub arg5: u64,
3236    pub arg6: u64,
3237    pub client_id: u16,
3238    pub secure_os_id: u16,
3239    padding2: [PadByte; 4],
3240}
3241
3242#[repr(C)]
3243#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3244#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3245pub struct zx_smc_result_t {
3246    pub arg0: u64,
3247    pub arg1: u64,
3248    pub arg2: u64,
3249    pub arg3: u64,
3250    pub arg6: u64,
3251}
3252
3253#[repr(C)]
3254#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
3255#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
3256pub struct zx_vmo_lock_state_t {
3257    pub offset: u64,
3258    pub size: u64,
3259    pub discarded_offset: u64,
3260    pub discarded_size: u64,
3261}
3262
3263pub const ZX_CPU_SET_MAX_CPUS: usize = 512;
3264pub const ZX_CPU_SET_BITS_PER_WORD: usize = 64;
3265
3266#[repr(C)]
3267#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3268#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3269pub struct zx_cpu_set_t {
3270    pub mask: [u64; ZX_CPU_SET_MAX_CPUS / ZX_CPU_SET_BITS_PER_WORD],
3271}
3272
3273// source: zircon/system/public/zircon/syscalls/scheduler.h
3274#[repr(C)]
3275#[derive(Copy, Clone)]
3276#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3277pub struct zx_profile_info_t {
3278    pub flags: u32,
3279    padding1: [PadByte; 4],
3280    pub zx_profile_info_union: zx_profile_info_union,
3281    pub cpu_affinity_mask: zx_cpu_set_t,
3282}
3283
3284pub const ZX_PROFILE_INFO_FLAG_PRIORITY: u32 = 1 << 0;
3285pub const ZX_PROFILE_INFO_FLAG_CPU_MASK: u32 = 1 << 1;
3286pub const ZX_PROFILE_INFO_FLAG_DEADLINE: u32 = 1 << 2;
3287pub const ZX_PROFILE_INFO_FLAG_NO_INHERIT: u32 = 1 << 3;
3288pub const ZX_PROFILE_INFO_FLAG_MEMORY_PRIORITY: u32 = 1 << 4;
3289pub const ZX_PROFILE_INFO_FLAG_CRITICAL: u32 = 1 << 5;
3290
3291pub const ZX_PRIORITY_LOWEST: i32 = 0;
3292pub const ZX_PRIORITY_LOW: i32 = 8;
3293pub const ZX_PRIORITY_DEFAULT: i32 = 16;
3294pub const ZX_PRIORITY_HIGH: i32 = 24;
3295pub const ZX_PRIORITY_HIGHEST: i32 = 31;
3296
3297#[cfg(feature = "zerocopy")]
3298impl Default for zx_profile_info_t {
3299    fn default() -> Self {
3300        Self {
3301            flags: Default::default(),
3302            padding1: Default::default(),
3303            zx_profile_info_union: FromZeros::new_zeroed(),
3304            cpu_affinity_mask: Default::default(),
3305        }
3306    }
3307}
3308
3309#[repr(C)]
3310#[derive(Copy, Clone)]
3311#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3312pub struct priority_params {
3313    pub priority: i32,
3314    padding1: [PadByte; 20],
3315}
3316
3317#[repr(C)]
3318#[derive(Copy, Clone)]
3319#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3320pub union zx_profile_info_union {
3321    pub priority_params: priority_params,
3322    pub deadline_params: zx_sched_deadline_params_t,
3323}
3324
3325#[repr(C)]
3326#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3327#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3328pub struct zx_sched_deadline_params_t {
3329    pub capacity: zx_duration_t,
3330    pub relative_deadline: zx_duration_t,
3331    pub period: zx_duration_t,
3332}
3333
3334#[repr(C)]
3335#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3336#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3337pub struct zx_cpu_performance_scale_t {
3338    pub integer_part: u32,
3339    pub fractional_part: u32,
3340}
3341
3342#[repr(C)]
3343#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3344#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3345pub struct zx_cpu_performance_info_t {
3346    pub logical_cpu_number: u32,
3347    pub performance_scale: zx_cpu_performance_scale_t,
3348}
3349
3350#[repr(C)]
3351#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3352#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3353pub struct zx_cpu_perf_limit_t {
3354    pub logical_cpu_number: u32,
3355    pub limit_type: u32,
3356    pub min: u64,
3357    pub max: u64,
3358}
3359
3360#[repr(C)]
3361#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3362pub struct zx_iommu_desc_stub_t {
3363    padding1: PadByte,
3364}
3365
3366pub const ZX_IOMMU_MAX_DESC_LEN: usize = 4096;
3367
3368multiconst!(u32, [
3369    ZX_IOMMU_TYPE_STUB = 0;
3370    ZX_IOMMU_TYPE_INTEL = 1;
3371]);
3372
3373pub const ZX_SAMPLER_MIN_PERIOD: zx_duration_t = 10_000;
3374pub const ZX_SAMPLER_MAX_BUFFER_SIZE: usize = 1024 * 1024 * 1024;
3375
3376#[repr(C)]
3377#[derive(Debug, Copy, Clone)]
3378#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3379pub struct zx_sampler_config_t {
3380    pub period: zx_duration_t,
3381    pub buffer_size: usize,
3382    pub iobuffer_discipline: u64,
3383}
3384
3385multiconst!(zx_processor_power_level_options_t, [
3386    ZX_PROCESSOR_POWER_LEVEL_OPTIONS_DOMAIN_INDEPENDENT = 1 << 0;
3387]);
3388
3389multiconst!(zx_processor_power_control_t, [
3390    ZX_PROCESSOR_POWER_CONTROL_CPU_DRIVER = 0;
3391    ZX_PROCESSOR_POWER_CONTROL_ARM_PSCI = 1;
3392    ZX_PROCESSOR_POWER_CONTROL_ARM_WFI = 2;
3393    ZX_PROCESSOR_POWER_CONTROL_RISCV_SBI = 3;
3394    ZX_PROCESSOR_POWER_CONTROL_RISCV_WFI = 4;
3395]);
3396
3397#[repr(C)]
3398#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3399pub struct zx_processor_power_level_t {
3400    pub options: zx_processor_power_level_options_t,
3401    pub processing_rate: u64,
3402    pub power_coefficient_nw: u64,
3403    pub control_interface: zx_processor_power_control_t,
3404    pub control_argument: u64,
3405    pub diagnostic_name: [u8; ZX_MAX_NAME_LEN],
3406    padding1: [PadByte; 32],
3407}
3408
3409#[repr(C)]
3410#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3411pub struct zx_processor_power_level_transition_t {
3412    pub latency: zx_duration_t,
3413    pub energy: u64,
3414    pub from: u8,
3415    pub to: u8,
3416    padding1: [PadByte; 6],
3417}
3418
3419#[repr(C)]
3420#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3421pub struct zx_packet_processor_power_level_transition_request_t {
3422    pub domain_id: u32,
3423    pub options: u32,
3424    pub control_interface: u64,
3425    pub control_argument: u64,
3426    padding1: [PadByte; 8],
3427}
3428
3429#[repr(C)]
3430#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3431pub struct zx_processor_power_state_t {
3432    pub domain_id: u32,
3433    pub options: u32,
3434    pub control_interface: u64,
3435    pub control_argument: u64,
3436}
3437
3438#[repr(C)]
3439#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3440pub struct zx_processor_power_domain_t {
3441    pub cpus: zx_cpu_set_t,
3442    pub domain_id: u32,
3443    padding1: [PadByte; 4],
3444}
3445
3446#[repr(C)]
3447#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3448pub struct zx_power_domain_info_t {
3449    pub cpus: zx_cpu_set_t,
3450    pub domain_id: u32,
3451    pub idle_power_levels: u8,
3452    pub active_power_levels: u8,
3453    padding1: [PadByte; 2],
3454}
3455
3456multiconst!(u32, [
3457    ZX_BTI_PERM_READ = 1 << 0;
3458    ZX_BTI_PERM_WRITE = 1 << 1;
3459    ZX_BTI_PERM_EXECUTE = 1 << 2;
3460    ZX_BTI_COMPRESS = 1 << 3;
3461    ZX_BTI_CONTIGUOUS = 1 << 4;
3462]);
3463
3464// Options for zx_port_create
3465multiconst!(u32, [
3466    ZX_PORT_BIND_TO_INTERRUPT = 1 << 0;
3467]);
3468
3469// Options for zx_interrupt_create
3470multiconst!(u32, [
3471    ZX_INTERRUPT_REMAP_IRQ = 0x1;
3472    ZX_INTERRUPT_MODE_DEFAULT = 0 << 1;
3473    ZX_INTERRUPT_MODE_EDGE_LOW = 1 << 1;
3474    ZX_INTERRUPT_MODE_EDGE_HIGH = 2 << 1;
3475    ZX_INTERRUPT_MODE_LEVEL_LOW = 3 << 1;
3476    ZX_INTERRUPT_MODE_LEVEL_HIGH = 4 << 1;
3477    ZX_INTERRUPT_MODE_EDGE_BOTH = 5 << 1;
3478    ZX_INTERRUPT_MODE_MASK = 0xe;
3479    ZX_INTERRUPT_VIRTUAL = 0x10;
3480    ZX_INTERRUPT_WAKE_VECTOR = 0x20;
3481    ZX_INTERRUPT_TIMESTAMP_MONO = 1 << 6;
3482]);
3483
3484// Options for zx_msi_create
3485multiconst!(u32, [
3486    ZX_MSI_MODE_MSI_X = 0x1;
3487]);
3488
3489// Options for zx_interrupt_bind
3490multiconst!(u32, [
3491    ZX_INTERRUPT_BIND = 0;
3492    ZX_INTERRUPT_UNBIND = 1;
3493]);
3494
3495#[repr(C)]
3496#[derive(Copy, Clone)]
3497#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3498pub struct zx_iob_region_t {
3499    pub r#type: zx_iob_region_type_t,
3500    pub access: zx_iob_access_t,
3501    pub size: u64,
3502    pub discipline: zx_iob_discipline_t,
3503    pub extension: zx_iob_region_extension_t,
3504}
3505
3506multiconst!(zx_iob_region_type_t, [
3507    ZX_IOB_REGION_TYPE_PRIVATE = 0;
3508    ZX_IOB_REGION_TYPE_SHARED = 1;
3509]);
3510
3511multiconst!(zx_iob_access_t, [
3512    ZX_IOB_ACCESS_EP0_CAN_MAP_READ = 1 << 0;
3513    ZX_IOB_ACCESS_EP0_CAN_MAP_WRITE = 1 << 1;
3514    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_READ = 1 << 2;
3515    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_WRITE = 1 << 3;
3516    ZX_IOB_ACCESS_EP1_CAN_MAP_READ = 1 << 4;
3517    ZX_IOB_ACCESS_EP1_CAN_MAP_WRITE = 1 << 5;
3518    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_READ = 1 << 6;
3519    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_WRITE = 1 << 7;
3520]);
3521
3522#[repr(C)]
3523#[derive(Copy, Clone)]
3524#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3525pub struct zx_iob_discipline_t {
3526    pub r#type: zx_iob_discipline_type_t,
3527    pub extension: zx_iob_discipline_extension_t,
3528}
3529
3530#[repr(C)]
3531#[derive(Copy, Clone)]
3532#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3533pub union zx_iob_discipline_extension_t {
3534    // This is in vdso-next.
3535    pub ring_buffer: zx_iob_discipline_mediated_write_ring_buffer_t,
3536    pub reserved: [PadByte; 64],
3537}
3538
3539#[repr(C)]
3540#[derive(Debug, Copy, Clone)]
3541#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3542pub struct zx_iob_discipline_mediated_write_ring_buffer_t {
3543    pub tag: u64,
3544    pub padding: [PadByte; 56],
3545}
3546
3547multiconst!(zx_iob_discipline_type_t, [
3548    ZX_IOB_DISCIPLINE_TYPE_NONE = 0;
3549    ZX_IOB_DISCIPLINE_TYPE_ID_ALLOCATOR = 1;
3550    ZX_IOB_DISCIPLINE_TYPE_MEDIATED_WRITE_RING_BUFFER = 2;
3551]);
3552
3553pub const ZX_IOB_MAX_REGIONS: usize = 64;
3554
3555#[repr(C)]
3556#[derive(Clone, Copy, Default)]
3557#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3558pub struct zx_iob_region_private_t {
3559    pub options: u32,
3560    pub padding: [PadByte; 28],
3561}
3562
3563#[repr(C)]
3564#[derive(Clone, Copy)]
3565#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3566pub struct zx_iob_region_shared_t {
3567    pub options: u32,
3568    pub shared_region: zx_handle_t,
3569    pub padding: [PadByte; 24],
3570}
3571
3572#[repr(C)]
3573#[derive(Copy, Clone)]
3574#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3575pub union zx_iob_region_extension_t {
3576    pub private_region: zx_iob_region_private_t,
3577    pub shared_region: zx_iob_region_shared_t,
3578    pub max_extension: [u8; 32],
3579}
3580
3581#[repr(C)]
3582#[derive(Copy, Clone, Default)]
3583#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3584pub struct zx_wake_source_report_entry_t {
3585    pub koid: zx_koid_t,
3586    pub name: [u8; ZX_MAX_NAME_LEN],
3587    pub initial_signal_time: zx_instant_boot_t,
3588    pub last_signal_time: zx_instant_boot_t,
3589    pub last_ack_time: zx_instant_boot_t,
3590    pub signal_count: u32,
3591    pub flags: u32,
3592}
3593
3594#[repr(C)]
3595#[derive(Copy, Clone, Default)]
3596#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3597pub struct zx_wake_source_report_header_t {
3598    pub report_time: zx_instant_boot_t,
3599    pub suspend_start_time: zx_instant_boot_t,
3600    pub total_wake_sources: u32,
3601    pub unreported_wake_report_entries: u32,
3602}
3603
3604#[cfg(test)]
3605mod test {
3606    #[cfg(test)]
3607    extern crate alloc;
3608
3609    use super::*;
3610
3611    #[test]
3612    fn padded_struct_equality() {
3613        let test_struct = zx_clock_update_args_v1_t {
3614            rate_adjust: 222,
3615            padding1: Default::default(),
3616            value: 333,
3617            error_bound: 444,
3618        };
3619
3620        let different_data = zx_clock_update_args_v1_t { rate_adjust: 999, ..test_struct.clone() };
3621
3622        let different_padding = zx_clock_update_args_v1_t {
3623            padding1: [PadByte(0), PadByte(1), PadByte(2), PadByte(3)],
3624            ..test_struct.clone()
3625        };
3626
3627        // Structures with different data should not be equal.
3628        assert_ne!(test_struct, different_data);
3629        // Structures with only different padding should not be equal.
3630        assert_eq!(test_struct, different_padding);
3631    }
3632
3633    #[test]
3634    fn padded_struct_debug() {
3635        let test_struct = zx_clock_update_args_v1_t {
3636            rate_adjust: 222,
3637            padding1: Default::default(),
3638            value: 333,
3639            error_bound: 444,
3640        };
3641        let expectation = "zx_clock_update_args_v1_t { \
3642            rate_adjust: 222, \
3643            padding1: [-, -, -, -], \
3644            value: 333, \
3645            error_bound: 444 }";
3646        assert_eq!(alloc::format!("{:?}", test_struct), expectation);
3647    }
3648}
3649
3650#[repr(C, align(32))]
3651#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3652#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3653pub struct zx_rseq_t {
3654    pub cpu_id: u32,
3655    pub reserved: u32,
3656    pub start_ip: u64,
3657    pub post_commit_offset: u64,
3658    pub abort_ip: u64,
3659}
3660
3661pub const ZX_INFO_INVALID_CPU: u32 = 0xFFFFFFFF;