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