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#[cfg_attr(feature = "zerocopy", derive(Immutable, IntoBytes, KnownLayout))]
1134#[non_exhaustive]
1135pub enum zx_packet_type_t {
1136    #[default]
1137    ZX_PKT_TYPE_USER = 0,
1138    ZX_PKT_TYPE_SIGNAL_ONE = 1,
1139    ZX_PKT_TYPE_GUEST_BELL = 3,
1140    ZX_PKT_TYPE_GUEST_MEM = 4,
1141    ZX_PKT_TYPE_GUEST_IO = 5,
1142    ZX_PKT_TYPE_GUEST_VCPU = 6,
1143    ZX_PKT_TYPE_INTERRUPT = 7,
1144    ZX_PKT_TYPE_PAGE_REQUEST = 9,
1145    ZX_PKT_TYPE_PROCESSOR_POWER_LEVEL_TRANSITION_REQUEST = 10,
1146}
1147
1148#[repr(u32)]
1149#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1150#[non_exhaustive]
1151pub enum zx_packet_guest_vcpu_type_t {
1152    #[default]
1153    ZX_PKT_GUEST_VCPU_INTERRUPT = 0,
1154    ZX_PKT_GUEST_VCPU_STARTUP = 1,
1155}
1156
1157#[repr(C)]
1158#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1159pub struct zx_packet_signal_t {
1160    pub trigger: zx_signals_t,
1161    pub observed: zx_signals_t,
1162    pub count: u64,
1163    pub timestamp: zx_time_t,
1164}
1165
1166pub const ZX_WAIT_ASYNC_TIMESTAMP: u32 = 1;
1167pub const ZX_WAIT_ASYNC_EDGE: u32 = 2;
1168pub const ZX_WAIT_ASYNC_BOOT_TIMESTAMP: u32 = 4;
1169
1170// Actually a union of different integer types, but this should be good enough.
1171pub type zx_packet_user_t = [u8; 32];
1172
1173#[repr(C)]
1174#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1175#[cfg_attr(feature = "zerocopy", derive(Immutable, IntoBytes, KnownLayout))]
1176pub struct zx_port_packet_t {
1177    pub key: u64,
1178    pub packet_type: zx_packet_type_t,
1179    pub status: i32,
1180    pub union: [u8; 32],
1181}
1182
1183#[repr(C)]
1184#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1185pub struct zx_packet_guest_bell_t {
1186    pub addr: zx_gpaddr_t,
1187}
1188
1189#[repr(C)]
1190#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1191pub struct zx_packet_guest_io_t {
1192    pub port: u16,
1193    pub access_size: u8,
1194    pub input: bool,
1195    pub data: [u8; 4],
1196}
1197
1198#[repr(C)]
1199#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1200#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1201pub struct zx_packet_guest_vcpu_interrupt_t {
1202    pub mask: u64,
1203    pub vector: u8,
1204    padding1: [PadByte; 7],
1205}
1206
1207#[repr(C)]
1208#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1209#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1210pub struct zx_packet_guest_vcpu_startup_t {
1211    pub id: u64,
1212    pub entry: zx_gpaddr_t,
1213}
1214
1215#[repr(C)]
1216#[derive(Copy, Clone)]
1217#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
1218pub union zx_packet_guest_vcpu_union_t {
1219    pub interrupt: zx_packet_guest_vcpu_interrupt_t,
1220    pub startup: zx_packet_guest_vcpu_startup_t,
1221}
1222
1223#[cfg(feature = "zerocopy")]
1224impl Default for zx_packet_guest_vcpu_union_t {
1225    fn default() -> Self {
1226        Self::new_zeroed()
1227    }
1228}
1229
1230#[repr(C)]
1231#[derive(Copy, Clone, Default)]
1232pub struct zx_packet_guest_vcpu_t {
1233    pub r#type: zx_packet_guest_vcpu_type_t,
1234    padding1: [PadByte; 4],
1235    pub union: zx_packet_guest_vcpu_union_t,
1236    padding2: [PadByte; 8],
1237}
1238
1239impl PartialEq for zx_packet_guest_vcpu_t {
1240    fn eq(&self, other: &Self) -> bool {
1241        if self.r#type != other.r#type {
1242            return false;
1243        }
1244        match self.r#type {
1245            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT => unsafe {
1246                self.union.interrupt == other.union.interrupt
1247            },
1248            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP => unsafe {
1249                self.union.startup == other.union.startup
1250            },
1251        }
1252    }
1253}
1254
1255impl Eq for zx_packet_guest_vcpu_t {}
1256
1257impl Debug for zx_packet_guest_vcpu_t {
1258    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1259        match self.r#type {
1260            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_INTERRUPT => {
1261                write!(f, "type: {:?} union: {:?}", self.r#type, unsafe { self.union.interrupt })
1262            }
1263            zx_packet_guest_vcpu_type_t::ZX_PKT_GUEST_VCPU_STARTUP => {
1264                write!(f, "type: {:?} union: {:?}", self.r#type, unsafe { self.union.startup })
1265            }
1266        }
1267    }
1268}
1269
1270#[repr(C)]
1271#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1272pub struct zx_packet_page_request_t {
1273    pub command: zx_page_request_command_t,
1274    pub flags: u16,
1275    padding1: [PadByte; 4],
1276    pub offset: u64,
1277    pub length: u64,
1278    padding2: [PadByte; 8],
1279}
1280
1281#[repr(u16)]
1282#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
1283#[non_exhaustive]
1284pub enum zx_page_request_command_t {
1285    #[default]
1286    ZX_PAGER_VMO_READ = 0x0000,
1287    ZX_PAGER_VMO_COMPLETE = 0x0001,
1288    ZX_PAGER_VMO_DIRTY = 0x0002,
1289}
1290
1291multiconst!(u32, [
1292    ZX_PAGER_OP_FAIL = 1;
1293    ZX_PAGER_OP_DIRTY = 2;
1294    ZX_PAGER_OP_WRITEBACK_BEGIN = 3;
1295    ZX_PAGER_OP_WRITEBACK_END = 4;
1296]);
1297
1298pub type zx_excp_type_t = u32;
1299
1300multiconst!(zx_excp_type_t, [
1301    ZX_EXCP_GENERAL               = 0x008;
1302    ZX_EXCP_FATAL_PAGE_FAULT      = 0x108;
1303    ZX_EXCP_UNDEFINED_INSTRUCTION = 0x208;
1304    ZX_EXCP_SW_BREAKPOINT         = 0x308;
1305    ZX_EXCP_HW_BREAKPOINT         = 0x408;
1306    ZX_EXCP_UNALIGNED_ACCESS      = 0x508;
1307
1308    ZX_EXCP_SYNTH                 = 0x8000;
1309
1310    ZX_EXCP_THREAD_STARTING       = 0x008 | ZX_EXCP_SYNTH;
1311    ZX_EXCP_THREAD_EXITING        = 0x108 | ZX_EXCP_SYNTH;
1312    ZX_EXCP_POLICY_ERROR          = 0x208 | ZX_EXCP_SYNTH;
1313    ZX_EXCP_PROCESS_STARTING      = 0x308 | ZX_EXCP_SYNTH;
1314    ZX_EXCP_USER                  = 0x309 | ZX_EXCP_SYNTH;
1315]);
1316
1317multiconst!(u32, [
1318    ZX_EXCP_USER_CODE_PROCESS_NAME_CHANGED = 0x0001;
1319
1320    ZX_EXCP_USER_CODE_USER0                = 0xF000;
1321    ZX_EXCP_USER_CODE_USER1                = 0xF001;
1322    ZX_EXCP_USER_CODE_USER2                = 0xF002;
1323]);
1324
1325#[repr(C)]
1326#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1327#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes))]
1328pub struct zx_exception_info_t {
1329    pub pid: zx_koid_t,
1330    pub tid: zx_koid_t,
1331    pub type_: zx_excp_type_t,
1332    padding1: [PadByte; 4],
1333}
1334
1335#[repr(C)]
1336#[derive(Default, Copy, Clone, Eq, PartialEq)]
1337#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1338pub struct zx_x86_64_exc_data_t {
1339    pub vector: u64,
1340    pub err_code: u64,
1341    pub cr2: u64,
1342}
1343
1344impl Debug for zx_x86_64_exc_data_t {
1345    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1346        write!(f, "vector 0x{:x} err_code {} cr2 0x{:x}", self.vector, self.err_code, self.cr2)
1347    }
1348}
1349
1350#[repr(C)]
1351#[derive(Default, Copy, Clone, Eq, PartialEq)]
1352#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1353pub struct zx_arm64_exc_data_t {
1354    pub esr: u32,
1355    padding1: [PadByte; 4],
1356    pub far: u64,
1357    padding2: [PadByte; 8],
1358}
1359
1360impl Debug for zx_arm64_exc_data_t {
1361    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1362        write!(f, "esr 0x{:x} far 0x{:x}", self.esr, self.far)
1363    }
1364}
1365
1366#[repr(C)]
1367#[derive(Default, Copy, Clone, Eq, PartialEq)]
1368#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1369pub struct zx_riscv64_exc_data_t {
1370    pub cause: u64,
1371    pub tval: u64,
1372    padding1: [PadByte; 8],
1373}
1374
1375impl Debug for zx_riscv64_exc_data_t {
1376    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1377        write!(f, "cause {} tval {}", self.cause, self.tval)
1378    }
1379}
1380
1381#[repr(C)]
1382#[derive(Copy, Clone)]
1383#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable))]
1384pub union zx_exception_header_arch_t {
1385    pub x86_64: zx_x86_64_exc_data_t,
1386    pub arm_64: zx_arm64_exc_data_t,
1387    pub riscv_64: zx_riscv64_exc_data_t,
1388}
1389
1390impl Debug for zx_exception_header_arch_t {
1391    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1392        write!(f, "zx_exception_header_arch_t ")?;
1393        #[cfg(target_arch = "x86_64")]
1394        {
1395            // SAFETY: Exception reports are presumed to be from the target architecture.
1396            // Even if it was not, it's sound to treat the union as another variant as
1397            // the size and alignment are the same, there is no internal padding, and
1398            // the variants have no validity invariants.
1399            let x86_64 = unsafe { self.x86_64 };
1400            write!(f, "{x86_64:?}")
1401        }
1402        #[cfg(target_arch = "aarch64")]
1403        {
1404            // SAFETY: Exception reports are presumed to be from the target architecture.
1405            // Even if it was not, it's sound to treat the union as another variant as
1406            // the size and alignment are the same, there is no internal padding, and
1407            // the variants have no validity invariants.
1408            let arm_64 = unsafe { self.arm_64 };
1409            write!(f, "{arm_64:?}")
1410        }
1411        #[cfg(target_arch = "riscv64")]
1412        {
1413            // SAFETY: Exception reports are presumed to be from the target architecture.
1414            // Even if it was not, it's sound to treat the union as another variant as
1415            // the size and alignment are the same, there is no internal padding, and
1416            // the variants have no validity invariants.
1417            let riscv_64 = unsafe { self.riscv_64 };
1418            write!(f, "{riscv_64:?}")
1419        }
1420    }
1421}
1422
1423#[repr(C)]
1424#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1425#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1426pub struct zx_exception_header_t {
1427    pub size: u32,
1428    pub type_: zx_excp_type_t,
1429}
1430
1431pub type zx_excp_policy_code_t = u32;
1432
1433multiconst!(zx_excp_policy_code_t, [
1434    ZX_EXCP_POLICY_CODE_BAD_HANDLE              = 0;
1435    ZX_EXCP_POLICY_CODE_WRONG_OBJECT            = 1;
1436    ZX_EXCP_POLICY_CODE_VMAR_WX                 = 2;
1437    ZX_EXCP_POLICY_CODE_NEW_ANY                 = 3;
1438    ZX_EXCP_POLICY_CODE_NEW_VMO                 = 4;
1439    ZX_EXCP_POLICY_CODE_NEW_CHANNEL             = 5;
1440    ZX_EXCP_POLICY_CODE_NEW_EVENT               = 6;
1441    ZX_EXCP_POLICY_CODE_NEW_EVENTPAIR           = 7;
1442    ZX_EXCP_POLICY_CODE_NEW_PORT                = 8;
1443    ZX_EXCP_POLICY_CODE_NEW_SOCKET              = 9;
1444    ZX_EXCP_POLICY_CODE_NEW_FIFO                = 10;
1445    ZX_EXCP_POLICY_CODE_NEW_TIMER               = 11;
1446    ZX_EXCP_POLICY_CODE_NEW_PROCESS             = 12;
1447    ZX_EXCP_POLICY_CODE_NEW_PROFILE             = 13;
1448    ZX_EXCP_POLICY_CODE_NEW_PAGER               = 14;
1449    ZX_EXCP_POLICY_CODE_AMBIENT_MARK_VMO_EXEC   = 15;
1450    ZX_EXCP_POLICY_CODE_CHANNEL_FULL_WRITE      = 16;
1451    ZX_EXCP_POLICY_CODE_PORT_TOO_MANY_PACKETS   = 17;
1452    ZX_EXCP_POLICY_CODE_BAD_SYSCALL             = 18;
1453    ZX_EXCP_POLICY_CODE_PORT_TOO_MANY_OBSERVERS = 19;
1454    ZX_EXCP_POLICY_CODE_HANDLE_LEAK             = 20;
1455    ZX_EXCP_POLICY_CODE_NEW_IOB                 = 21;
1456]);
1457
1458#[repr(C)]
1459#[derive(Debug, Copy, Clone)]
1460#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable))]
1461pub struct zx_exception_context_t {
1462    pub arch: zx_exception_header_arch_t,
1463    pub synth_code: zx_excp_policy_code_t,
1464    pub synth_data: u32,
1465}
1466
1467#[repr(C)]
1468#[derive(Debug, Copy, Clone)]
1469#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable))]
1470pub struct zx_exception_report_t {
1471    pub header: zx_exception_header_t,
1472    pub context: zx_exception_context_t,
1473}
1474
1475const_assert_eq!(core::mem::size_of::<zx_exception_report_t>(), 40);
1476const_assert_eq!(core::mem::align_of::<zx_exception_report_t>(), 8);
1477
1478#[repr(C, align(8))]
1479#[derive(Debug, Copy, Clone, Eq, PartialEq)]
1480#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
1481pub struct zx_exception_report_v1_t {
1482    pub header: zx_exception_header_t,
1483    pub context: [u8; 24],
1484}
1485
1486const_assert_eq!(core::mem::size_of::<zx_exception_report_v1_t>(), 32);
1487const_assert_eq!(core::mem::align_of::<zx_exception_report_v1_t>(), 8);
1488
1489pub type zx_exception_state_t = u32;
1490
1491multiconst!(zx_exception_state_t, [
1492    ZX_EXCEPTION_STATE_TRY_NEXT    = 0;
1493    ZX_EXCEPTION_STATE_HANDLED     = 1;
1494    ZX_EXCEPTION_STATE_THREAD_EXIT = 2;
1495]);
1496
1497pub type zx_exception_strategy_t = u32;
1498
1499multiconst!(zx_exception_state_t, [
1500    ZX_EXCEPTION_STRATEGY_FIRST_CHANCE   = 0;
1501    ZX_EXCEPTION_STRATEGY_SECOND_CHANCE  = 1;
1502]);
1503
1504#[cfg(target_arch = "x86_64")]
1505#[repr(C)]
1506#[derive(Default, Copy, Clone, Eq, PartialEq)]
1507#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable))]
1508pub struct zx_thread_state_general_regs_t {
1509    pub rax: u64,
1510    pub rbx: u64,
1511    pub rcx: u64,
1512    pub rdx: u64,
1513    pub rsi: u64,
1514    pub rdi: u64,
1515    pub rbp: u64,
1516    pub rsp: u64,
1517    pub r8: u64,
1518    pub r9: u64,
1519    pub r10: u64,
1520    pub r11: u64,
1521    pub r12: u64,
1522    pub r13: u64,
1523    pub r14: u64,
1524    pub r15: u64,
1525    pub rip: u64,
1526    pub rflags: u64,
1527    pub fs_base: u64,
1528    pub gs_base: u64,
1529}
1530
1531#[cfg(target_arch = "x86_64")]
1532impl core::fmt::Debug for zx_thread_state_general_regs_t {
1533    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1534        f.debug_struct(core::any::type_name::<Self>())
1535            .field("rax", &format_args!("{:#x}", self.rax))
1536            .field("rbx", &format_args!("{:#x}", self.rbx))
1537            .field("rcx", &format_args!("{:#x}", self.rcx))
1538            .field("rdx", &format_args!("{:#x}", self.rdx))
1539            .field("rsi", &format_args!("{:#x}", self.rsi))
1540            .field("rdi", &format_args!("{:#x}", self.rdi))
1541            .field("rbp", &format_args!("{:#x}", self.rbp))
1542            .field("rsp", &format_args!("{:#x}", self.rsp))
1543            .field("r8", &format_args!("{:#x}", self.r8))
1544            .field("r9", &format_args!("{:#x}", self.r9))
1545            .field("r10", &format_args!("{:#x}", self.r10))
1546            .field("r11", &format_args!("{:#x}", self.r11))
1547            .field("r12", &format_args!("{:#x}", self.r12))
1548            .field("r13", &format_args!("{:#x}", self.r13))
1549            .field("r14", &format_args!("{:#x}", self.r14))
1550            .field("r15", &format_args!("{:#x}", self.r15))
1551            .field("rip", &format_args!("{:#x}", self.rip))
1552            .field("rflags", &format_args!("{:#x}", self.rflags))
1553            .field("fs_base", &format_args!("{:#x}", self.fs_base))
1554            .field("gs_base", &format_args!("{:#x}", self.gs_base))
1555            .finish()
1556    }
1557}
1558
1559#[cfg(target_arch = "x86_64")]
1560impl From<&zx_restricted_state_t> for zx_thread_state_general_regs_t {
1561    fn from(state: &zx_restricted_state_t) -> Self {
1562        Self {
1563            rdi: state.rdi,
1564            rsi: state.rsi,
1565            rbp: state.rbp,
1566            rbx: state.rbx,
1567            rdx: state.rdx,
1568            rcx: state.rcx,
1569            rax: state.rax,
1570            rsp: state.rsp,
1571            r8: state.r8,
1572            r9: state.r9,
1573            r10: state.r10,
1574            r11: state.r11,
1575            r12: state.r12,
1576            r13: state.r13,
1577            r14: state.r14,
1578            r15: state.r15,
1579            rip: state.ip,
1580            rflags: state.flags,
1581            fs_base: state.fs_base,
1582            gs_base: state.gs_base,
1583        }
1584    }
1585}
1586
1587#[cfg(target_arch = "aarch64")]
1588multiconst!(u64, [
1589    ZX_REG_CPSR_ARCH_32_MASK = 0x10;
1590    ZX_REG_CPSR_THUMB_MASK = 0x20;
1591]);
1592
1593#[cfg(target_arch = "aarch64")]
1594#[repr(C)]
1595#[derive(Default, Copy, Clone, Eq, PartialEq)]
1596pub struct zx_thread_state_general_regs_t {
1597    pub r: [u64; 30],
1598    pub lr: u64,
1599    pub sp: u64,
1600    pub pc: u64,
1601    pub cpsr: u64,
1602    pub tpidr: u64,
1603}
1604
1605#[cfg(target_arch = "aarch64")]
1606impl core::fmt::Debug for zx_thread_state_general_regs_t {
1607    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1608        struct RegisterAsHex(u64);
1609        impl core::fmt::Debug for RegisterAsHex {
1610            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1611                write!(f, "{:#x}", self.0)
1612            }
1613        }
1614
1615        f.debug_struct(core::any::type_name::<Self>())
1616            .field("r", &self.r.map(RegisterAsHex))
1617            .field("lr", &format_args!("{:#x}", self.lr))
1618            .field("sp", &format_args!("{:#x}", self.sp))
1619            .field("pc", &format_args!("{:#x}", self.pc))
1620            .field("cpsr", &format_args!("{:#x}", self.cpsr))
1621            .field("tpidr", &format_args!("{:#x}", self.tpidr))
1622            .finish()
1623    }
1624}
1625
1626#[cfg(target_arch = "aarch64")]
1627impl From<&zx_restricted_state_t> for zx_thread_state_general_regs_t {
1628    fn from(state: &zx_restricted_state_t) -> Self {
1629        if state.cpsr as u64 & ZX_REG_CPSR_ARCH_32_MASK == ZX_REG_CPSR_ARCH_32_MASK {
1630            // aarch32
1631            Self {
1632                r: [
1633                    state.r[0],
1634                    state.r[1],
1635                    state.r[2],
1636                    state.r[3],
1637                    state.r[4],
1638                    state.r[5],
1639                    state.r[6],
1640                    state.r[7],
1641                    state.r[8],
1642                    state.r[9],
1643                    state.r[10],
1644                    state.r[11],
1645                    state.r[12],
1646                    state.r[13],
1647                    state.r[14],
1648                    state.pc, // ELR overwrites this.
1649                    state.r[16],
1650                    state.r[17],
1651                    state.r[18],
1652                    state.r[19],
1653                    state.r[20],
1654                    state.r[21],
1655                    state.r[22],
1656                    state.r[23],
1657                    state.r[24],
1658                    state.r[25],
1659                    state.r[26],
1660                    state.r[27],
1661                    state.r[28],
1662                    state.r[29],
1663                ],
1664                lr: state.r[14], // R[14] for aarch32
1665                sp: state.r[13], // R[13] for aarch32
1666                // TODO(https://fxbug.dev/379669623) Should it be checked for thumb and make
1667                // sure it isn't over incrementing?
1668                pc: state.pc, // Zircon populated this from elr.
1669                cpsr: state.cpsr as u64,
1670                tpidr: state.tpidr_el0,
1671            }
1672        } else {
1673            Self {
1674                r: [
1675                    state.r[0],
1676                    state.r[1],
1677                    state.r[2],
1678                    state.r[3],
1679                    state.r[4],
1680                    state.r[5],
1681                    state.r[6],
1682                    state.r[7],
1683                    state.r[8],
1684                    state.r[9],
1685                    state.r[10],
1686                    state.r[11],
1687                    state.r[12],
1688                    state.r[13],
1689                    state.r[14],
1690                    state.r[15],
1691                    state.r[16],
1692                    state.r[17],
1693                    state.r[18],
1694                    state.r[19],
1695                    state.r[20],
1696                    state.r[21],
1697                    state.r[22],
1698                    state.r[23],
1699                    state.r[24],
1700                    state.r[25],
1701                    state.r[26],
1702                    state.r[27],
1703                    state.r[28],
1704                    state.r[29],
1705                ],
1706                lr: state.r[30],
1707                sp: state.sp,
1708                pc: state.pc,
1709                cpsr: state.cpsr as u64,
1710                tpidr: state.tpidr_el0,
1711            }
1712        }
1713    }
1714}
1715
1716#[cfg(target_arch = "riscv64")]
1717#[repr(C)]
1718#[derive(Default, Copy, Clone, Eq, PartialEq)]
1719pub struct zx_thread_state_general_regs_t {
1720    pub pc: u64,
1721    pub ra: u64,  // x1
1722    pub sp: u64,  // x2
1723    pub gp: u64,  // x3
1724    pub tp: u64,  // x4
1725    pub t0: u64,  // x5
1726    pub t1: u64,  // x6
1727    pub t2: u64,  // x7
1728    pub s0: u64,  // x8
1729    pub s1: u64,  // x9
1730    pub a0: u64,  // x10
1731    pub a1: u64,  // x11
1732    pub a2: u64,  // x12
1733    pub a3: u64,  // x13
1734    pub a4: u64,  // x14
1735    pub a5: u64,  // x15
1736    pub a6: u64,  // x16
1737    pub a7: u64,  // x17
1738    pub s2: u64,  // x18
1739    pub s3: u64,  // x19
1740    pub s4: u64,  // x20
1741    pub s5: u64,  // x21
1742    pub s6: u64,  // x22
1743    pub s7: u64,  // x23
1744    pub s8: u64,  // x24
1745    pub s9: u64,  // x25
1746    pub s10: u64, // x26
1747    pub s11: u64, // x27
1748    pub t3: u64,  // x28
1749    pub t4: u64,  // x29
1750    pub t5: u64,  // x30
1751    pub t6: u64,  // x31
1752}
1753
1754#[cfg(target_arch = "riscv64")]
1755impl core::fmt::Debug for zx_thread_state_general_regs_t {
1756    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1757        f.debug_struct(core::any::type_name::<Self>())
1758            .field("pc", &format_args!("{:#x}", self.pc))
1759            .field("ra", &format_args!("{:#x}", self.ra)) // x1
1760            .field("sp", &format_args!("{:#x}", self.sp)) // x2
1761            .field("gp", &format_args!("{:#x}", self.gp)) // x3
1762            .field("tp", &format_args!("{:#x}", self.tp)) // x4
1763            .field("t0", &format_args!("{:#x}", self.t0)) // x5
1764            .field("t1", &format_args!("{:#x}", self.t1)) // x6
1765            .field("t2", &format_args!("{:#x}", self.t2)) // x7
1766            .field("s0", &format_args!("{:#x}", self.s0)) // x8
1767            .field("s1", &format_args!("{:#x}", self.s1)) // x9
1768            .field("a0", &format_args!("{:#x}", self.a0)) // x10
1769            .field("a1", &format_args!("{:#x}", self.a1)) // x11
1770            .field("a2", &format_args!("{:#x}", self.a2)) // x12
1771            .field("a3", &format_args!("{:#x}", self.a3)) // x13
1772            .field("a4", &format_args!("{:#x}", self.a4)) // x14
1773            .field("a5", &format_args!("{:#x}", self.a5)) // x15
1774            .field("a6", &format_args!("{:#x}", self.a6)) // x16
1775            .field("a7", &format_args!("{:#x}", self.a7)) // x17
1776            .field("s2", &format_args!("{:#x}", self.s2)) // x18
1777            .field("s3", &format_args!("{:#x}", self.s3)) // x19
1778            .field("s4", &format_args!("{:#x}", self.s4)) // x20
1779            .field("s5", &format_args!("{:#x}", self.s5)) // x21
1780            .field("s6", &format_args!("{:#x}", self.s6)) // x22
1781            .field("s7", &format_args!("{:#x}", self.s7)) // x23
1782            .field("s8", &format_args!("{:#x}", self.s8)) // x24
1783            .field("s9", &format_args!("{:#x}", self.s9)) // x25
1784            .field("s10", &format_args!("{:#x}", self.s10)) // x26
1785            .field("s11", &format_args!("{:#x}", self.s11)) // x27
1786            .field("t3", &format_args!("{:#x}", self.t3)) // x28
1787            .field("t4", &format_args!("{:#x}", self.t4)) // x29
1788            .field("t5", &format_args!("{:#x}", self.t5)) // x30
1789            .field("t6", &format_args!("{:#x}", self.t6)) // x31
1790            .finish()
1791    }
1792}
1793
1794multiconst!(zx_restricted_reason_t, [
1795    ZX_RESTRICTED_REASON_SYSCALL = 0;
1796    ZX_RESTRICTED_REASON_EXCEPTION = 1;
1797    ZX_RESTRICTED_REASON_KICK = 2;
1798    ZX_RESTRICTED_REASON_EXCEPTION_LOST = 3;
1799]);
1800
1801#[cfg(target_arch = "x86_64")]
1802#[repr(C)]
1803#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1804pub struct zx_restricted_state_t {
1805    pub rdi: u64,
1806    pub rsi: u64,
1807    pub rbp: u64,
1808    pub rbx: u64,
1809    pub rdx: u64,
1810    pub rcx: u64,
1811    pub rax: u64,
1812    pub rsp: u64,
1813    pub r8: u64,
1814    pub r9: u64,
1815    pub r10: u64,
1816    pub r11: u64,
1817    pub r12: u64,
1818    pub r13: u64,
1819    pub r14: u64,
1820    pub r15: u64,
1821    pub ip: u64,
1822    pub flags: u64,
1823    pub fs_base: u64,
1824    pub gs_base: u64,
1825}
1826
1827#[cfg(target_arch = "x86_64")]
1828impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
1829    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
1830        Self {
1831            rdi: registers.rdi,
1832            rsi: registers.rsi,
1833            rbp: registers.rbp,
1834            rbx: registers.rbx,
1835            rdx: registers.rdx,
1836            rcx: registers.rcx,
1837            rax: registers.rax,
1838            rsp: registers.rsp,
1839            r8: registers.r8,
1840            r9: registers.r9,
1841            r10: registers.r10,
1842            r11: registers.r11,
1843            r12: registers.r12,
1844            r13: registers.r13,
1845            r14: registers.r14,
1846            r15: registers.r15,
1847            ip: registers.rip,
1848            flags: registers.rflags,
1849            fs_base: registers.fs_base,
1850            gs_base: registers.gs_base,
1851        }
1852    }
1853}
1854
1855#[cfg(target_arch = "aarch64")]
1856#[repr(C)]
1857#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1858pub struct zx_restricted_state_t {
1859    pub r: [u64; 31], // Note: r[30] is `lr` which is separated out in the general regs.
1860    pub sp: u64,
1861    pub pc: u64,
1862    pub tpidr_el0: u64,
1863    // Contains only the user-controllable upper 4-bits (NZCV).
1864    pub cpsr: u32,
1865    padding1: [PadByte; 4],
1866}
1867
1868#[cfg(target_arch = "aarch64")]
1869impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
1870    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
1871        Self {
1872            r: [
1873                registers.r[0],
1874                registers.r[1],
1875                registers.r[2],
1876                registers.r[3],
1877                registers.r[4],
1878                registers.r[5],
1879                registers.r[6],
1880                registers.r[7],
1881                registers.r[8],
1882                registers.r[9],
1883                registers.r[10],
1884                registers.r[11],
1885                registers.r[12],
1886                registers.r[13],
1887                registers.r[14],
1888                registers.r[15],
1889                registers.r[16],
1890                registers.r[17],
1891                registers.r[18],
1892                registers.r[19],
1893                registers.r[20],
1894                registers.r[21],
1895                registers.r[22],
1896                registers.r[23],
1897                registers.r[24],
1898                registers.r[25],
1899                registers.r[26],
1900                registers.r[27],
1901                registers.r[28],
1902                registers.r[29],
1903                registers.lr, // for compat this works nicely with zircon.
1904            ],
1905            pc: registers.pc,
1906            tpidr_el0: registers.tpidr,
1907            sp: registers.sp,
1908            cpsr: registers.cpsr as u32,
1909            padding1: Default::default(),
1910        }
1911    }
1912}
1913
1914#[cfg(target_arch = "riscv64")]
1915pub type zx_restricted_state_t = zx_thread_state_general_regs_t;
1916
1917#[cfg(target_arch = "riscv64")]
1918impl From<&zx_thread_state_general_regs_t> for zx_restricted_state_t {
1919    fn from(registers: &zx_thread_state_general_regs_t) -> Self {
1920        *registers
1921    }
1922}
1923
1924#[repr(C)]
1925#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1926#[cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "riscv64"))]
1927pub struct zx_restricted_syscall_t {
1928    pub state: zx_restricted_state_t,
1929}
1930
1931#[repr(C)]
1932#[derive(Copy, Clone)]
1933#[cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "riscv64"))]
1934pub struct zx_restricted_exception_t {
1935    pub state: zx_restricted_state_t,
1936    pub exception: zx_exception_report_t,
1937}
1938
1939#[cfg(target_arch = "x86_64")]
1940#[repr(C)]
1941#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1942#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1943pub struct zx_vcpu_state_t {
1944    pub rax: u64,
1945    pub rcx: u64,
1946    pub rdx: u64,
1947    pub rbx: u64,
1948    pub rsp: u64,
1949    pub rbp: u64,
1950    pub rsi: u64,
1951    pub rdi: u64,
1952    pub r8: u64,
1953    pub r9: u64,
1954    pub r10: u64,
1955    pub r11: u64,
1956    pub r12: u64,
1957    pub r13: u64,
1958    pub r14: u64,
1959    pub r15: u64,
1960    // Contains only the user-controllable lower 32-bits.
1961    pub rflags: u64,
1962}
1963
1964#[cfg(target_arch = "aarch64")]
1965#[repr(C)]
1966#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1967#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1968pub struct zx_vcpu_state_t {
1969    pub x: [u64; 31],
1970    pub sp: u64,
1971    // Contains only the user-controllable upper 4-bits (NZCV).
1972    pub cpsr: u32,
1973    padding1: [PadByte; 4],
1974}
1975
1976#[cfg(target_arch = "riscv64")]
1977#[repr(C)]
1978#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1979#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1980pub struct zx_vcpu_state_t {
1981    pub empty: u32,
1982}
1983
1984#[repr(C)]
1985#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1986#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
1987pub struct zx_vcpu_io_t {
1988    pub access_size: u8,
1989    padding1: [PadByte; 3],
1990    pub data: [u8; 4],
1991}
1992
1993#[cfg(target_arch = "aarch64")]
1994#[repr(C)]
1995#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
1996pub struct zx_packet_guest_mem_t {
1997    pub addr: zx_gpaddr_t,
1998    pub access_size: u8,
1999    pub sign_extend: bool,
2000    pub xt: u8,
2001    pub read: bool,
2002    pub data: u64,
2003}
2004
2005#[cfg(target_arch = "riscv64")]
2006#[repr(C)]
2007#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2008pub struct zx_packet_guest_mem_t {
2009    pub addr: zx_gpaddr_t,
2010    padding1: [PadByte; 24],
2011}
2012
2013pub const X86_MAX_INST_LEN: usize = 15;
2014
2015#[cfg(target_arch = "x86_64")]
2016#[repr(C)]
2017#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2018pub struct zx_packet_guest_mem_t {
2019    pub addr: zx_gpaddr_t,
2020    pub cr3: zx_gpaddr_t,
2021    pub rip: zx_vaddr_t,
2022    pub instruction_size: u8,
2023    pub default_operand_size: u8,
2024}
2025
2026#[repr(C)]
2027#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2028pub struct zx_packet_interrupt_t {
2029    pub timestamp: zx_time_t,
2030    padding1: [PadByte; 24],
2031}
2032
2033// Helper for constructing topics that have been versioned.
2034const fn info_topic(topic: u32, version: u32) -> u32 {
2035    (version << 28) | topic
2036}
2037
2038multiconst!(zx_object_info_topic_t, [
2039    ZX_INFO_NONE                       = 0;
2040    ZX_INFO_HANDLE_VALID               = 1;
2041    ZX_INFO_HANDLE_BASIC               = 2;  // zx_info_handle_basic_t[1]
2042    ZX_INFO_PROCESS                    = info_topic(3, 1);  // zx_info_process_t[1]
2043    ZX_INFO_PROCESS_THREADS            = 4;  // zx_koid_t[n]
2044    ZX_INFO_VMAR                       = 7;  // zx_info_vmar_t[1]
2045    ZX_INFO_JOB_CHILDREN               = 8;  // zx_koid_t[n]
2046    ZX_INFO_JOB_PROCESSES              = 9;  // zx_koid_t[n]
2047    ZX_INFO_THREAD                     = 10; // zx_info_thread_t[1]
2048    ZX_INFO_THREAD_EXCEPTION_REPORT_V1 = info_topic(11, 0); // zx_exception_report_v1_t[1]
2049    ZX_INFO_THREAD_EXCEPTION_REPORT    = info_topic(11, 1); // zx_exception_report_t[1]
2050    ZX_INFO_TASK_STATS_V1              = info_topic(12, 0); // zx_info_task_stats_v1_t[1]
2051    ZX_INFO_TASK_STATS                 = info_topic(12, 1); // zx_info_task_stats_t[1]
2052    ZX_INFO_PROCESS_MAPS_V1            = info_topic(13, 0); // zx_info_maps_t[n]
2053    ZX_INFO_PROCESS_MAPS_V2            = info_topic(13, 1); // zx_info_maps_t[n]
2054    ZX_INFO_PROCESS_MAPS               = info_topic(13, 2); // zx_info_maps_t[n]
2055    ZX_INFO_PROCESS_VMOS_V1            = info_topic(14, 0); // zx_info_vmo_t[n]
2056    ZX_INFO_PROCESS_VMOS_V2            = info_topic(14, 1); // zx_info_vmo_t[n]
2057    ZX_INFO_PROCESS_VMOS_V3            = info_topic(14, 2); // zx_info_vmo_t[n]
2058    ZX_INFO_PROCESS_VMOS               = info_topic(14, 3); // zx_info_vmo_t[n]
2059    ZX_INFO_THREAD_STATS               = 15; // zx_info_thread_stats_t[1]
2060    ZX_INFO_CPU_STATS                  = 16; // zx_info_cpu_stats_t[n]
2061    ZX_INFO_KMEM_STATS_V1              = info_topic(17, 0); // zx_info_kmem_stats_v1_t[1]
2062    ZX_INFO_KMEM_STATS                 = info_topic(17, 1); // zx_info_kmem_stats_t[1]
2063    ZX_INFO_RESOURCE                   = 18; // zx_info_resource_t[1]
2064    ZX_INFO_HANDLE_COUNT               = 19; // zx_info_handle_count_t[1]
2065    ZX_INFO_BTI                        = 20; // zx_info_bti_t[1]
2066    ZX_INFO_PROCESS_HANDLE_STATS       = 21; // zx_info_process_handle_stats_t[1]
2067    ZX_INFO_SOCKET                     = 22; // zx_info_socket_t[1]
2068    ZX_INFO_VMO_V1                     = info_topic(23, 0); // zx_info_vmo_v1_t[1]
2069    ZX_INFO_VMO_V2                     = info_topic(23, 1); // zx_info_vmo_v2_t[1]
2070    ZX_INFO_VMO_V3                     = info_topic(23, 2); // zx_info_vmo_v3_t[1]
2071    ZX_INFO_VMO                        = info_topic(23, 3); // zx_info_vmo_t[1]
2072    ZX_INFO_JOB                        = 24; // zx_info_job_t[1]
2073    ZX_INFO_TIMER                      = 25; // zx_info_timer_t[1]
2074    ZX_INFO_STREAM                     = 26; // zx_info_stream_t[1]
2075    ZX_INFO_HANDLE_TABLE               = 27; // zx_info_handle_extended_t[n]
2076    ZX_INFO_MSI                        = 28; // zx_info_msi_t[1]
2077    ZX_INFO_GUEST_STATS                = 29; // zx_info_guest_stats_t[1]
2078    ZX_INFO_TASK_RUNTIME_V1            = info_topic(30, 0); // zx_info_task_runtime_v1_t[1]
2079    ZX_INFO_TASK_RUNTIME               = info_topic(30, 1); // zx_info_task_runtime_t[1]
2080    ZX_INFO_KMEM_STATS_EXTENDED        = 31; // zx_info_kmem_stats_extended_t[1]
2081    ZX_INFO_VCPU                       = 32; // zx_info_vcpu_t[1]
2082    ZX_INFO_KMEM_STATS_COMPRESSION     = 33; // zx_info_kmem_stats_compression_t[1]
2083    ZX_INFO_IOB                        = 34; // zx_info_iob_t[1]
2084    ZX_INFO_IOB_REGIONS                = 35; // zx_iob_region_info_t[n]
2085    ZX_INFO_VMAR_MAPS                  = 36; // zx_info_maps_t[n]
2086    ZX_INFO_POWER_DOMAINS              = 37; // zx_info_power_domain_info_t[n]
2087    ZX_INFO_MEMORY_STALL               = 38; // zx_info_memory_stall_t[1]
2088    ZX_INFO_INTERRUPT                  = 39; // zx_info_interrupt_t[1]
2089    ZX_INFO_CLOCK_MAPPED_SIZE          = 40; // usize[1]
2090]);
2091
2092multiconst!(zx_system_memory_stall_type_t, [
2093    ZX_SYSTEM_MEMORY_STALL_SOME        = 0;
2094    ZX_SYSTEM_MEMORY_STALL_FULL        = 1;
2095]);
2096
2097// This macro takes struct-like syntax and creates another macro that can be used to create
2098// different instances of the struct with different names. This is used to keep struct definitions
2099// from drifting between this crate and the fuchsia-zircon crate where they are identical other
2100// than in name and location.
2101macro_rules! struct_decl_macro {
2102    ( $(#[$attrs:meta])* $vis:vis struct <$macro_name:ident> $($any:tt)* ) => {
2103        #[macro_export]
2104        macro_rules! $macro_name {
2105            ($name:ident) => {
2106                $(#[$attrs])* $vis struct $name $($any)*
2107            }
2108        }
2109    }
2110}
2111
2112// Don't need struct_decl_macro for this, the wrapper is different.
2113#[repr(C)]
2114#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2115#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2116pub struct zx_info_handle_basic_t {
2117    pub koid: zx_koid_t,
2118    pub rights: zx_rights_t,
2119    pub type_: zx_obj_type_t,
2120    pub related_koid: zx_koid_t,
2121    pub reserved: u32,
2122    pub padding1: [PadByte; 4],
2123}
2124
2125const_assert_eq!(core::mem::size_of::<zx_info_handle_basic_t>(), 32);
2126const_assert_eq!(core::mem::align_of::<zx_info_handle_basic_t>(), 8);
2127
2128// Don't need struct_decl_macro for this, the wrapper is different.
2129#[repr(C)]
2130#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2131#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2132pub struct zx_info_handle_extended_t {
2133    pub type_: zx_obj_type_t,
2134    pub handle_value: zx_handle_t,
2135    pub rights: zx_rights_t,
2136    pub reserved: u32,
2137    pub koid: zx_koid_t,
2138    pub related_koid: zx_koid_t,
2139    pub peer_owner_koid: zx_koid_t,
2140}
2141
2142struct_decl_macro! {
2143    #[repr(C)]
2144    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2145    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2146    pub struct <zx_info_handle_count_t> {
2147        pub handle_count: u32,
2148    }
2149}
2150
2151zx_info_handle_count_t!(zx_info_handle_count_t);
2152
2153// Don't need struct_decl_macro for this, the wrapper is different.
2154#[repr(C)]
2155#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2156#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2157pub struct zx_info_socket_t {
2158    pub options: u32,
2159    pub padding1: [PadByte; 4],
2160    pub rx_buf_max: usize,
2161    pub rx_buf_size: usize,
2162    pub rx_buf_available: usize,
2163    pub tx_buf_max: usize,
2164    pub tx_buf_size: usize,
2165}
2166
2167const_assert_eq!(core::mem::size_of::<zx_info_socket_t>(), 48);
2168const_assert_eq!(core::mem::align_of::<zx_info_socket_t>(), 8);
2169
2170#[repr(C)]
2171#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2172#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2173pub struct zx_info_iob_t {
2174    pub options: u64,
2175    pub region_count: u32,
2176    pub padding1: [PadByte; 4],
2177}
2178
2179#[repr(C)]
2180#[derive(Copy, Clone)]
2181#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2182pub struct zx_iob_region_info_t {
2183    pub region: zx_iob_region_t,
2184    pub koid: zx_koid_t,
2185}
2186
2187#[repr(C)]
2188#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2189#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2190pub struct zx_info_vcpu_t {
2191    // Bitwise OR of ZX_INFO_VCPU_FLAG_* values.
2192    pub flags: u32,
2193}
2194
2195multiconst!(u32, [
2196    ZX_INFO_VCPU_FLAG_KICKED = 1 << 0;
2197]);
2198
2199multiconst!(u32, [
2200    ZX_INFO_PROCESS_FLAG_STARTED = 1 << 0;
2201    ZX_INFO_PROCESS_FLAG_EXITED = 1 << 1;
2202    ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED = 1 << 2;
2203]);
2204
2205struct_decl_macro! {
2206    #[repr(C)]
2207    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2208    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2209    pub struct <zx_info_process_t> {
2210        pub return_code: i64,
2211        pub start_time: zx_time_t,
2212        pub flags: u32,
2213        pub padding1: [PadByte; 4],
2214    }
2215}
2216
2217zx_info_process_t!(zx_info_process_t);
2218
2219struct_decl_macro! {
2220    #[repr(C)]
2221    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2222    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2223    pub struct <zx_info_job_t> {
2224        pub return_code: i64,
2225        pub exited: u8,
2226        pub kill_on_oom: u8,
2227        pub debugger_attached: u8,
2228        pub padding1: [PadByte; 5],
2229    }
2230}
2231
2232zx_info_job_t!(zx_info_job_t);
2233const_assert_eq!(core::mem::size_of::<zx_info_job_t>(), 16);
2234const_assert_eq!(core::mem::align_of::<zx_info_job_t>(), 8);
2235
2236struct_decl_macro! {
2237    #[repr(C)]
2238    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2239    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2240    pub struct <zx_info_timer_t> {
2241        pub options: u32,
2242        pub clock_id: zx_clock_t,
2243        pub deadline: zx_time_t,
2244        pub slack: zx_duration_t,
2245    }
2246}
2247
2248zx_info_timer_t!(zx_info_timer_t);
2249
2250struct_decl_macro! {
2251    #[repr(C)]
2252    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2253    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2254    pub struct <zx_info_stream_t> {
2255        pub options: u32,
2256        pub padding1: [u8; 4],
2257        pub seek: zx_off_t,
2258        pub content_size: u64,
2259    }
2260}
2261
2262zx_info_stream_t!(zx_info_stream_t);
2263
2264#[repr(C)]
2265#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2266#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2267pub struct zx_policy_basic_v1 {
2268    pub condition: u32,
2269    pub policy: u32,
2270}
2271
2272pub type zx_policy_basic_v1_t = zx_policy_basic_v1;
2273pub type zx_policy_basic = zx_policy_basic_v1;
2274pub type zx_policy_basic_t = zx_policy_basic_v1;
2275
2276#[repr(C)]
2277#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2278#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2279pub struct zx_policy_basic_v2 {
2280    pub condition: u32,
2281    pub action: u32,
2282    pub flags: u32,
2283}
2284
2285pub type zx_policy_basic_v2_t = zx_policy_basic_v2;
2286
2287#[repr(C)]
2288#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2289#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2290pub struct zx_policy_timer_slack {
2291    pub min_slack: zx_duration_t,
2292    pub default_mode: u32,
2293    pub _padding: [u8; 4],
2294}
2295
2296pub type zx_policy_timer_slack_t = zx_policy_timer_slack;
2297
2298multiconst!(u32, [
2299    // policy options
2300    ZX_JOB_POL_RELATIVE = 0;
2301    ZX_JOB_POL_ABSOLUTE = 1;
2302
2303    // policy topic
2304    ZX_JOB_POL_BASIC_V1 = 0;
2305    ZX_JOB_POL_BASIC_V2 = 0x0100_0000;
2306    ZX_JOB_POL_BASIC = 0;
2307    ZX_JOB_POL_TIMER_SLACK = 1;
2308
2309    // policy conditions
2310    ZX_POL_BAD_HANDLE            = 0;
2311    ZX_POL_WRONG_OBJECT          = 1;
2312    ZX_POL_VMAR_WX               = 2;
2313    ZX_POL_NEW_ANY               = 3;
2314    ZX_POL_NEW_VMO               = 4;
2315    ZX_POL_NEW_CHANNEL           = 5;
2316    ZX_POL_NEW_EVENT             = 6;
2317    ZX_POL_NEW_EVENTPAIR         = 7;
2318    ZX_POL_NEW_PORT              = 8;
2319    ZX_POL_NEW_SOCKET            = 9;
2320    ZX_POL_NEW_FIFO              = 10;
2321    ZX_POL_NEW_TIMER             = 11;
2322    ZX_POL_NEW_PROCESS           = 12;
2323    ZX_POL_NEW_PROFILE           = 13;
2324    ZX_POL_NEW_PAGER             = 14;
2325    ZX_POL_AMBIENT_MARK_VMO_EXEC = 15;
2326    ZX_POL_NEW_IOB               = 16;
2327    ZX_POL_NEW_SAMPLER           = 17;
2328    #[cfg(feature = "kernel")]
2329    ZX_POL_MAX                   = 18;
2330
2331    // policy actions
2332    ZX_POL_ACTION_ALLOW           = 0;
2333    ZX_POL_ACTION_DENY            = 1;
2334    ZX_POL_ACTION_ALLOW_EXCEPTION = 2;
2335    ZX_POL_ACTION_DENY_EXCEPTION  = 3;
2336    ZX_POL_ACTION_KILL            = 4;
2337    #[cfg(feature = "kernel")]
2338    ZX_POL_ACTION_MAX             = 5;
2339
2340    // policy override
2341    ZX_POL_OVERRIDE_ALLOW = 0;
2342    ZX_POL_OVERRIDE_DENY  = 1;
2343
2344    // timer slack default modes
2345    ZX_TIMER_SLACK_CENTER = 0;
2346    ZX_TIMER_SLACK_EARLY  = 1;
2347    ZX_TIMER_SLACK_LATE   = 2;
2348]);
2349
2350multiconst!(u32, [
2351    // critical options
2352    ZX_JOB_CRITICAL_PROCESS_RETCODE_NONZERO = 1 << 0;
2353]);
2354
2355// Don't use struct_decl_macro, wrapper is different.
2356#[repr(C)]
2357#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2358#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2359pub struct zx_info_vmo_t {
2360    pub koid: zx_koid_t,
2361    pub name: [u8; ZX_MAX_NAME_LEN],
2362    pub size_bytes: u64,
2363    pub parent_koid: zx_koid_t,
2364    pub num_children: usize,
2365    pub num_mappings: usize,
2366    pub share_count: usize,
2367    pub flags: u32,
2368    padding1: [PadByte; 4],
2369    pub committed_bytes: u64,
2370    pub handle_rights: zx_rights_t,
2371    pub cache_policy: u32,
2372    pub metadata_bytes: u64,
2373    pub committed_change_events: u64,
2374    pub populated_bytes: u64,
2375    pub committed_private_bytes: u64,
2376    pub populated_private_bytes: u64,
2377    pub committed_scaled_bytes: u64,
2378    pub populated_scaled_bytes: u64,
2379    pub committed_fractional_scaled_bytes: u64,
2380    pub populated_fractional_scaled_bytes: u64,
2381}
2382
2383#[repr(C)]
2384#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2385#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2386pub struct zx_info_vmo_v1_t {
2387    pub koid: zx_koid_t,
2388    pub name: [u8; ZX_MAX_NAME_LEN],
2389    pub size_bytes: u64,
2390    pub parent_koid: zx_koid_t,
2391    pub num_children: usize,
2392    pub num_mappings: usize,
2393    pub share_count: usize,
2394    pub flags: u32,
2395    pub padding1: [PadByte; 4],
2396    pub committed_bytes: u64,
2397    pub handle_rights: zx_rights_t,
2398    pub cache_policy: u32,
2399}
2400
2401const_assert_eq!(core::mem::size_of::<zx_info_vmo_v1_t>(), 104);
2402const_assert_eq!(core::mem::align_of::<zx_info_vmo_v1_t>(), 8);
2403
2404#[repr(C)]
2405#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2406#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2407pub struct zx_info_vmo_v2_t {
2408    pub koid: zx_koid_t,
2409    pub name: [u8; ZX_MAX_NAME_LEN],
2410    pub size_bytes: u64,
2411    pub parent_koid: zx_koid_t,
2412    pub num_children: usize,
2413    pub num_mappings: usize,
2414    pub share_count: usize,
2415    pub flags: u32,
2416    pub padding1: [PadByte; 4],
2417    pub committed_bytes: u64,
2418    pub handle_rights: zx_rights_t,
2419    pub cache_policy: u32,
2420    pub metadata_bytes: u64,
2421    pub committed_change_events: u64,
2422}
2423
2424const_assert_eq!(core::mem::size_of::<zx_info_vmo_v2_t>(), 120);
2425const_assert_eq!(core::mem::align_of::<zx_info_vmo_v2_t>(), 8);
2426
2427#[repr(C)]
2428#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2429#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2430pub struct zx_info_vmo_v3_t {
2431    pub koid: zx_koid_t,
2432    pub name: [u8; ZX_MAX_NAME_LEN],
2433    pub size_bytes: u64,
2434    pub parent_koid: zx_koid_t,
2435    pub num_children: usize,
2436    pub num_mappings: usize,
2437    pub share_count: usize,
2438    pub flags: u32,
2439    pub padding1: [PadByte; 4],
2440    pub committed_bytes: u64,
2441    pub handle_rights: zx_rights_t,
2442    pub cache_policy: u32,
2443    pub metadata_bytes: u64,
2444    pub committed_change_events: u64,
2445    pub populated_bytes: u64,
2446}
2447
2448const_assert_eq!(core::mem::size_of::<zx_info_vmo_v3_t>(), 128);
2449const_assert_eq!(core::mem::align_of::<zx_info_vmo_v3_t>(), 8);
2450
2451struct_decl_macro! {
2452    #[repr(C)]
2453    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2454    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2455    pub struct <zx_info_cpu_stats_t> {
2456        pub cpu_number: u32,
2457        pub flags: u32,
2458        pub idle_time: zx_duration_t,
2459        pub normalized_busy_time: zx_duration_t,
2460        pub reschedules: u64,
2461        pub context_switches: u64,
2462        pub irq_preempts: u64,
2463        pub preempts: u64,
2464        pub yields: u64,
2465        pub ints: u64,
2466        pub timer_ints: u64,
2467        pub timers: u64,
2468        pub page_faults: u64,
2469        pub exceptions: u64,
2470        pub syscalls: u64,
2471        pub reschedule_ipis: u64,
2472        pub generic_ipis: u64,
2473        pub active_energy_consumption_nj: u64,
2474        pub idle_energy_consumption_nj: u64,
2475    }
2476}
2477
2478zx_info_cpu_stats_t!(zx_info_cpu_stats_t);
2479
2480struct_decl_macro! {
2481    #[repr(C)]
2482    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2483    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2484    pub struct <zx_info_kmem_stats_t> {
2485        pub total_bytes: u64,
2486        pub free_bytes: u64,
2487        pub free_loaned_bytes: u64,
2488        pub wired_bytes: u64,
2489        pub total_heap_bytes: u64,
2490        pub free_heap_bytes: u64,
2491        pub vmo_bytes: u64,
2492        pub mmu_overhead_bytes: u64,
2493        pub ipc_bytes: u64,
2494        pub cache_bytes: u64,
2495        pub slab_bytes: u64,
2496        pub zram_bytes: u64,
2497        pub other_bytes: u64,
2498        pub vmo_reclaim_total_bytes: u64,
2499        pub vmo_reclaim_newest_bytes: u64,
2500        pub vmo_reclaim_oldest_bytes: u64,
2501        pub vmo_reclaim_disabled_bytes: u64,
2502        pub vmo_discardable_locked_bytes: u64,
2503        pub vmo_discardable_unlocked_bytes: u64,
2504    }
2505}
2506
2507zx_info_kmem_stats_t!(zx_info_kmem_stats_t);
2508
2509struct_decl_macro! {
2510    #[repr(C)]
2511    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2512    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2513    pub struct <zx_info_kmem_stats_v1_t> {
2514        pub total_bytes: u64,
2515        pub free_bytes: u64,
2516        pub wired_bytes: u64,
2517        pub total_heap_bytes: u64,
2518        pub free_heap_bytes: u64,
2519        pub vmo_bytes: u64,
2520        pub mmu_overhead_bytes: u64,
2521        pub ipc_bytes: u64,
2522        pub other_bytes: u64,
2523    }
2524}
2525
2526zx_info_kmem_stats_v1_t!(zx_info_kmem_stats_v1_t);
2527const_assert_eq!(core::mem::size_of::<zx_info_kmem_stats_v1_t>(), 72);
2528const_assert_eq!(core::mem::align_of::<zx_info_kmem_stats_v1_t>(), 8);
2529
2530struct_decl_macro! {
2531    #[repr(C)]
2532    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2533    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2534    pub struct <zx_info_kmem_stats_extended_t> {
2535        pub total_bytes: u64,
2536        pub free_bytes: u64,
2537        pub wired_bytes: u64,
2538        pub total_heap_bytes: u64,
2539        pub free_heap_bytes: u64,
2540        pub vmo_bytes: u64,
2541        pub vmo_pager_total_bytes: u64,
2542        pub vmo_pager_newest_bytes: u64,
2543        pub vmo_pager_oldest_bytes: u64,
2544        pub vmo_discardable_locked_bytes: u64,
2545        pub vmo_discardable_unlocked_bytes: u64,
2546        pub mmu_overhead_bytes: u64,
2547        pub ipc_bytes: u64,
2548        pub other_bytes: u64,
2549        pub vmo_reclaim_disable_bytes: u64,
2550    }
2551}
2552
2553zx_info_kmem_stats_extended_t!(zx_info_kmem_stats_extended_t);
2554
2555struct_decl_macro! {
2556    #[repr(C)]
2557    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2558    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2559    pub struct <zx_info_kmem_stats_compression_t> {
2560        pub uncompressed_storage_bytes: u64,
2561        pub compressed_storage_bytes: u64,
2562        pub compressed_fragmentation_bytes: u64,
2563        pub compression_time: zx_duration_t,
2564        pub decompression_time: zx_duration_t,
2565        pub total_page_compression_attempts: u64,
2566        pub failed_page_compression_attempts: u64,
2567        pub total_page_decompressions: u64,
2568        pub compressed_page_evictions: u64,
2569        pub eager_page_compressions: u64,
2570        pub memory_pressure_page_compressions: u64,
2571        pub critical_memory_page_compressions: u64,
2572        pub pages_decompressed_unit_ns: u64,
2573        pub pages_decompressed_within_log_time: [u64; 8],
2574    }
2575}
2576
2577zx_info_kmem_stats_compression_t!(zx_info_kmem_stats_compression_t);
2578
2579struct_decl_macro! {
2580    #[repr(C)]
2581    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2582    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2583    pub struct <zx_info_resource_t> {
2584        pub kind: u32,
2585        pub flags: u32,
2586        pub base: u64,
2587        pub size: usize,
2588        pub name: [u8; ZX_MAX_NAME_LEN],
2589    }
2590}
2591
2592const_assert_eq!(core::mem::size_of::<zx_info_resource_t>(), 56);
2593const_assert_eq!(core::mem::align_of::<zx_info_resource_t>(), 8);
2594
2595struct_decl_macro! {
2596    #[repr(C)]
2597    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2598    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2599    pub struct <zx_info_bti_t> {
2600        pub minimum_contiguity: u64,
2601        pub aspace_size: u64,
2602        pub pmo_count: u64,
2603        pub quarantine_count: u64,
2604    }
2605}
2606
2607zx_info_bti_t!(zx_info_bti_t);
2608
2609struct_decl_macro! {
2610    #[repr(C)]
2611    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2612    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2613    pub struct <zx_info_msi_t> {
2614        pub target_addr: u64,
2615        pub target_data: u32,
2616        pub base_irq_id: u32,
2617        pub num_irq: u32,
2618        pub interrupt_count: u32,
2619    }
2620}
2621
2622zx_info_msi_t!(zx_info_msi_t);
2623
2624pub type zx_thread_state_t = u32;
2625
2626multiconst!(zx_thread_state_t, [
2627    ZX_THREAD_STATE_NEW = 0x0000;
2628    ZX_THREAD_STATE_RUNNING = 0x0001;
2629    ZX_THREAD_STATE_SUSPENDED = 0x0002;
2630    ZX_THREAD_STATE_BLOCKED = 0x0003;
2631    ZX_THREAD_STATE_DYING = 0x0004;
2632    ZX_THREAD_STATE_DEAD = 0x0005;
2633    ZX_THREAD_STATE_BLOCKED_EXCEPTION = 0x0103;
2634    ZX_THREAD_STATE_BLOCKED_SLEEPING = 0x0203;
2635    ZX_THREAD_STATE_BLOCKED_FUTEX = 0x0303;
2636    ZX_THREAD_STATE_BLOCKED_PORT = 0x0403;
2637    ZX_THREAD_STATE_BLOCKED_CHANNEL = 0x0503;
2638    ZX_THREAD_STATE_BLOCKED_WAIT_ONE = 0x0603;
2639    ZX_THREAD_STATE_BLOCKED_WAIT_MANY = 0x0703;
2640    ZX_THREAD_STATE_BLOCKED_INTERRUPT = 0x0803;
2641    ZX_THREAD_STATE_BLOCKED_PAGER = 0x0903;
2642]);
2643
2644#[repr(C)]
2645#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2646#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2647pub struct zx_info_thread_t {
2648    pub state: zx_thread_state_t,
2649    pub wait_exception_channel_type: u32,
2650    pub cpu_affinity_mask: zx_cpu_set_t,
2651}
2652
2653struct_decl_macro! {
2654    #[repr(C)]
2655    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2656    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2657    pub struct <zx_info_thread_stats_t> {
2658        pub total_runtime: zx_duration_t,
2659        pub last_scheduled_cpu: u32,
2660        pub padding1: [PadByte; 4],
2661    }
2662}
2663
2664zx_info_thread_stats_t!(zx_info_thread_stats_t);
2665const_assert_eq!(core::mem::size_of::<zx_info_thread_stats_t>(), 16);
2666const_assert_eq!(core::mem::align_of::<zx_info_thread_stats_t>(), 8);
2667
2668zx_info_resource_t!(zx_info_resource_t);
2669
2670struct_decl_macro! {
2671    #[repr(C)]
2672    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2673    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2674    pub struct <zx_info_vmar_t> {
2675        pub base: usize,
2676        pub len: usize,
2677    }
2678}
2679
2680zx_info_vmar_t!(zx_info_vmar_t);
2681const_assert_eq!(core::mem::size_of::<zx_info_vmar_t>(), 16);
2682const_assert_eq!(core::mem::align_of::<zx_info_vmar_t>(), 8);
2683
2684struct_decl_macro! {
2685    #[repr(C)]
2686    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2687    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2688    pub struct <zx_info_task_stats_t> {
2689        pub mem_mapped_bytes: usize,
2690        pub mem_private_bytes: usize,
2691        pub mem_shared_bytes: usize,
2692        pub mem_scaled_shared_bytes: usize,
2693        pub mem_fractional_scaled_shared_bytes: u64,
2694    }
2695}
2696
2697zx_info_task_stats_t!(zx_info_task_stats_t);
2698const_assert_eq!(core::mem::size_of::<zx_info_task_stats_t>(), 40);
2699const_assert_eq!(core::mem::align_of::<zx_info_task_stats_t>(), 8);
2700
2701struct_decl_macro! {
2702    #[repr(C)]
2703    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2704    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2705    pub struct <zx_info_task_stats_v1_t> {
2706        pub mem_mapped_bytes: usize,
2707        pub mem_private_bytes: usize,
2708        pub mem_shared_bytes: usize,
2709        pub mem_scaled_shared_bytes: usize,
2710    }
2711}
2712
2713zx_info_task_stats_v1_t!(zx_info_task_stats_v1_t);
2714const_assert_eq!(core::mem::size_of::<zx_info_task_stats_v1_t>(), 32);
2715const_assert_eq!(core::mem::align_of::<zx_info_task_stats_v1_t>(), 8);
2716
2717struct_decl_macro! {
2718    #[repr(C)]
2719    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2720    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2721    pub struct <zx_info_task_runtime_t> {
2722        pub cpu_time: zx_duration_t,
2723        pub queue_time: zx_duration_t,
2724        pub page_fault_time: zx_duration_t,
2725        pub lock_contention_time: zx_duration_t,
2726    }
2727}
2728
2729zx_info_task_runtime_t!(zx_info_task_runtime_t);
2730const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_t>(), 32);
2731const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_t>(), 8);
2732
2733struct_decl_macro! {
2734    #[repr(C)]
2735    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2736    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2737    pub struct <zx_info_task_runtime_v1_t> {
2738        pub cpu_time: zx_duration_mono_t,
2739        pub queue_time: zx_duration_mono_t,
2740    }
2741}
2742
2743zx_info_task_runtime_v1_t!(zx_info_task_runtime_v1_t);
2744const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_v1_t>(), 16);
2745const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_v1_t>(), 8);
2746
2747multiconst!(zx_info_maps_type_t, [
2748    ZX_INFO_MAPS_TYPE_NONE    = 0;
2749    ZX_INFO_MAPS_TYPE_ASPACE  = 1;
2750    ZX_INFO_MAPS_TYPE_VMAR    = 2;
2751    ZX_INFO_MAPS_TYPE_MAPPING = 3;
2752]);
2753
2754struct_decl_macro! {
2755    #[repr(C)]
2756    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2757    #[derive(zerocopy::FromBytes, zerocopy::Immutable, IntoBytes)]
2758    pub struct <zx_info_maps_mapping_t> {
2759        pub mmu_flags: zx_vm_option_t,
2760        pub padding1: [PadByte; 4],
2761        pub vmo_koid: zx_koid_t,
2762        pub vmo_offset: u64,
2763        pub committed_bytes: usize,
2764        pub populated_bytes: usize,
2765        pub committed_private_bytes: usize,
2766        pub populated_private_bytes: usize,
2767        pub committed_scaled_bytes: usize,
2768        pub populated_scaled_bytes: usize,
2769        pub committed_fractional_scaled_bytes: u64,
2770        pub populated_fractional_scaled_bytes: u64,
2771    }
2772}
2773
2774zx_info_maps_mapping_t!(zx_info_maps_mapping_t);
2775
2776#[repr(C)]
2777#[derive(Copy, Clone)]
2778#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, KnownLayout))]
2779pub union InfoMapsTypeUnion {
2780    pub mapping: zx_info_maps_mapping_t,
2781}
2782
2783struct_decl_macro! {
2784    #[repr(C)]
2785    #[derive(Copy, Clone)]
2786    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2787    pub struct <zx_info_maps_t> {
2788        pub name: [u8; ZX_MAX_NAME_LEN],
2789        pub base: zx_vaddr_t,
2790        pub size: usize,
2791        pub depth: usize,
2792        pub r#type: zx_info_maps_type_t,
2793        pub u: InfoMapsTypeUnion,
2794    }
2795}
2796
2797zx_info_maps_t!(zx_info_maps_t);
2798
2799struct_decl_macro! {
2800    #[repr(C)]
2801    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
2802    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2803    pub struct <zx_info_process_handle_stats_t> {
2804        pub handle_count: [u32; ZX_OBJ_TYPE_UPPER_BOUND],
2805    }
2806}
2807
2808const_assert_eq!(core::mem::size_of::<zx_info_process_handle_stats_t>(), 256);
2809const_assert_eq!(core::mem::align_of::<zx_info_process_handle_stats_t>(), 4);
2810
2811impl Default for zx_info_process_handle_stats_t {
2812    fn default() -> Self {
2813        Self { handle_count: [0; ZX_OBJ_TYPE_UPPER_BOUND] }
2814    }
2815}
2816
2817zx_info_process_handle_stats_t!(zx_info_process_handle_stats_t);
2818
2819struct_decl_macro! {
2820    #[repr(C)]
2821    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2822    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2823    pub struct <zx_info_memory_stall_t> {
2824        pub stall_time_some: zx_duration_mono_t,
2825        pub stall_time_full: zx_duration_mono_t,
2826    }
2827}
2828
2829zx_info_memory_stall_t!(zx_info_memory_stall_t);
2830
2831// from //zircon/system/public/zircon/syscalls/hypervisor.h
2832multiconst!(zx_guest_trap_t, [
2833    ZX_GUEST_TRAP_BELL = 0;
2834    ZX_GUEST_TRAP_MEM  = 1;
2835    ZX_GUEST_TRAP_IO   = 2;
2836]);
2837
2838pub const ZX_LOG_RECORD_MAX: usize = 256;
2839pub const ZX_LOG_RECORD_DATA_MAX: usize = 216;
2840
2841pub const DEBUGLOG_TRACE: u8 = 0x10;
2842pub const DEBUGLOG_DEBUG: u8 = 0x20;
2843pub const DEBUGLOG_INFO: u8 = 0x30;
2844pub const DEBUGLOG_WARNING: u8 = 0x40;
2845pub const DEBUGLOG_ERROR: u8 = 0x50;
2846pub const DEBUGLOG_FATAL: u8 = 0x60;
2847
2848#[repr(C)]
2849#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2850#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
2851pub struct zx_log_record_header_t {
2852    pub sequence: u64,
2853    padding1: [PadByte; 4],
2854    pub datalen: u16,
2855    pub severity: u8,
2856    pub flags: u8,
2857    pub timestamp: zx_instant_boot_t,
2858    pub pid: u64,
2859    pub tid: u64,
2860}
2861
2862#[repr(C)]
2863#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2864#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
2865pub struct zx_log_record_t {
2866    pub header: zx_log_record_header_t,
2867    pub data: [u8; ZX_LOG_RECORD_DATA_MAX],
2868}
2869
2870const_assert_eq!(core::mem::size_of::<zx_log_record_t>(), ZX_LOG_RECORD_MAX);
2871
2872impl Default for zx_log_record_t {
2873    fn default() -> Self {
2874        Self { header: zx_log_record_header_t::default(), data: [0; ZX_LOG_RECORD_DATA_MAX] }
2875    }
2876}
2877
2878multiconst!(u32, [
2879    ZX_LOG_FLAG_READABLE = 0x40000000;
2880]);
2881
2882// For C, the below types are currently forward declared for syscalls.h.
2883// We might want to investigate a better solution for Rust or removing those
2884// forward declarations.
2885//
2886// These are hand typed translations from C types into Rust structures using a C
2887// layout
2888
2889// source: zircon/system/public/zircon/syscalls/system.h
2890multiconst!(zx_system_powerctl_cmd_t, [
2891    ZX_SYSTEM_POWERCTL_ENABLE_ALL_CPUS               = 1;
2892    ZX_SYSTEM_POWERCTL_DISABLE_ALL_CPUS_BUT_PRIMARY  = 2;
2893    ZX_SYSTEM_POWERCTL_ACPI_TRANSITION_S_STATE       = 3;
2894    ZX_SYSTEM_POWERCTL_X86_SET_PKG_PL1               = 4;
2895    ZX_SYSTEM_POWERCTL_REBOOT                        = 5;
2896    ZX_SYSTEM_POWERCTL_REBOOT_BOOTLOADER             = 6;
2897    ZX_SYSTEM_POWERCTL_REBOOT_RECOVERY               = 7;
2898    ZX_SYSTEM_POWERCTL_SHUTDOWN                      = 8;
2899    ZX_SYSTEM_POWERCTL_ACK_KERNEL_INITIATED_REBOOT   = 9;
2900]);
2901
2902#[repr(C)]
2903#[derive(Copy, Clone)]
2904#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2905pub struct zx_system_powerctl_arg_t {
2906    // rust can't express anonymous unions at this time
2907    // https://github.com/rust-lang/rust/issues/49804
2908    pub powerctl_internal: zx_powerctl_union,
2909}
2910
2911#[repr(C)]
2912#[derive(Copy, Clone)]
2913#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2914pub union zx_powerctl_union {
2915    acpi_transition_s_state: acpi_transition_s_state,
2916    x86_power_limit: x86_power_limit,
2917}
2918
2919#[repr(C)]
2920#[derive(Default, Debug, PartialEq, Copy, Clone)]
2921#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2922pub struct acpi_transition_s_state {
2923    target_s_state: u8, // Value between 1 and 5 indicating which S-state
2924    sleep_type_a: u8,   // Value from ACPI VM (SLP_TYPa)
2925    sleep_type_b: u8,   // Value from ACPI VM (SLP_TYPb)
2926    padding1: [PadByte; 9],
2927}
2928
2929#[repr(C)]
2930#[derive(Default, Debug, PartialEq, Copy, Clone)]
2931#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2932pub struct x86_power_limit {
2933    power_limit: u32, // PL1 value in milliwatts
2934    time_window: u32, // PL1 time window in microseconds
2935    clamp: u8,        // PL1 clamping enable
2936    enable: u8,       // PL1 enable
2937    padding1: [PadByte; 2],
2938}
2939
2940// source: zircon/system/public/zircon/syscalls/smc.h
2941#[repr(C)]
2942#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
2943#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2944pub struct zx_smc_parameters_t {
2945    pub func_id: u32,
2946    padding1: [PadByte; 4],
2947    pub arg1: u64,
2948    pub arg2: u64,
2949    pub arg3: u64,
2950    pub arg4: u64,
2951    pub arg5: u64,
2952    pub arg6: u64,
2953    pub client_id: u16,
2954    pub secure_os_id: u16,
2955    padding2: [PadByte; 4],
2956}
2957
2958#[repr(C)]
2959#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
2960#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2961pub struct zx_smc_result_t {
2962    pub arg0: u64,
2963    pub arg1: u64,
2964    pub arg2: u64,
2965    pub arg3: u64,
2966    pub arg6: u64,
2967}
2968
2969#[repr(C)]
2970#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2971#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2972pub struct zx_vmo_lock_state_t {
2973    pub offset: u64,
2974    pub size: u64,
2975    pub discarded_offset: u64,
2976    pub discarded_size: u64,
2977}
2978
2979pub const ZX_CPU_SET_MAX_CPUS: usize = 512;
2980pub const ZX_CPU_SET_BITS_PER_WORD: usize = 64;
2981
2982#[repr(C)]
2983#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
2984#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2985pub struct zx_cpu_set_t {
2986    pub mask: [u64; ZX_CPU_SET_MAX_CPUS / ZX_CPU_SET_BITS_PER_WORD],
2987}
2988
2989// source: zircon/system/public/zircon/syscalls/scheduler.h
2990#[repr(C)]
2991#[derive(Copy, Clone)]
2992#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
2993pub struct zx_profile_info_t {
2994    pub flags: u32,
2995    padding1: [PadByte; 4],
2996    pub zx_profile_info_union: zx_profile_info_union,
2997    pub cpu_affinity_mask: zx_cpu_set_t,
2998}
2999
3000pub const ZX_PROFILE_INFO_FLAG_PRIORITY: u32 = 1 << 0;
3001pub const ZX_PROFILE_INFO_FLAG_CPU_MASK: u32 = 1 << 1;
3002pub const ZX_PROFILE_INFO_FLAG_DEADLINE: u32 = 1 << 2;
3003pub const ZX_PROFILE_INFO_FLAG_NO_INHERIT: u32 = 1 << 3;
3004pub const ZX_PROFILE_INFO_FLAG_MEMORY_PRIORITY: u32 = 1 << 4;
3005pub const ZX_PROFILE_INFO_FLAG_CRITICAL: u32 = 1 << 5;
3006
3007pub const ZX_PRIORITY_LOWEST: i32 = 0;
3008pub const ZX_PRIORITY_LOW: i32 = 8;
3009pub const ZX_PRIORITY_DEFAULT: i32 = 16;
3010pub const ZX_PRIORITY_HIGH: i32 = 24;
3011pub const ZX_PRIORITY_HIGHEST: i32 = 31;
3012
3013#[cfg(feature = "zerocopy")]
3014impl Default for zx_profile_info_t {
3015    fn default() -> Self {
3016        Self {
3017            flags: Default::default(),
3018            padding1: Default::default(),
3019            zx_profile_info_union: FromZeros::new_zeroed(),
3020            cpu_affinity_mask: Default::default(),
3021        }
3022    }
3023}
3024
3025#[repr(C)]
3026#[derive(Copy, Clone)]
3027#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3028pub struct priority_params {
3029    pub priority: i32,
3030    padding1: [PadByte; 20],
3031}
3032
3033#[repr(C)]
3034#[derive(Copy, Clone)]
3035#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3036pub union zx_profile_info_union {
3037    pub priority_params: priority_params,
3038    pub deadline_params: zx_sched_deadline_params_t,
3039}
3040
3041#[repr(C)]
3042#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3043#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3044pub struct zx_sched_deadline_params_t {
3045    pub capacity: zx_duration_t,
3046    pub relative_deadline: zx_duration_t,
3047    pub period: zx_duration_t,
3048}
3049
3050#[repr(C)]
3051#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3052#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3053pub struct zx_cpu_performance_scale_t {
3054    pub integer_part: u32,
3055    pub fractional_part: u32,
3056}
3057
3058#[repr(C)]
3059#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3060#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3061pub struct zx_cpu_performance_info_t {
3062    pub logical_cpu_number: u32,
3063    pub performance_scale: zx_cpu_performance_scale_t,
3064}
3065
3066#[repr(C)]
3067#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3068#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3069pub struct zx_cpu_perf_limit_t {
3070    pub logical_cpu_number: u32,
3071    pub limit_type: u32,
3072    pub min: u64,
3073    pub max: u64,
3074}
3075
3076#[repr(C)]
3077#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3078pub struct zx_iommu_desc_stub_t {
3079    padding1: PadByte,
3080}
3081
3082pub const ZX_IOMMU_MAX_DESC_LEN: usize = 4096;
3083
3084multiconst!(u32, [
3085    ZX_IOMMU_TYPE_STUB = 0;
3086    ZX_IOMMU_TYPE_INTEL = 1;
3087]);
3088
3089pub const ZX_SAMPLER_MIN_PERIOD: zx_duration_t = 10_000;
3090pub const ZX_SAMPLER_MAX_BUFFER_SIZE: usize = 1024 * 1024 * 1024;
3091
3092#[repr(C)]
3093#[derive(Debug, Copy, Clone)]
3094#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3095pub struct zx_sampler_config_t {
3096    pub period: zx_duration_t,
3097    pub buffer_size: usize,
3098    pub iobuffer_discipline: u64,
3099}
3100
3101multiconst!(zx_processor_power_level_options_t, [
3102    ZX_PROCESSOR_POWER_LEVEL_OPTIONS_DOMAIN_INDEPENDENT = 1 << 0;
3103]);
3104
3105multiconst!(zx_processor_power_control_t, [
3106    ZX_PROCESSOR_POWER_CONTROL_CPU_DRIVER = 0;
3107    ZX_PROCESSOR_POWER_CONTROL_ARM_PSCI = 1;
3108    ZX_PROCESSOR_POWER_CONTROL_ARM_WFI = 2;
3109    ZX_PROCESSOR_POWER_CONTROL_RISCV_SBI = 3;
3110    ZX_PROCESSOR_POWER_CONTROL_RISCV_WFI = 4;
3111]);
3112
3113#[repr(C)]
3114#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3115pub struct zx_processor_power_level_t {
3116    pub options: zx_processor_power_level_options_t,
3117    pub processing_rate: u64,
3118    pub power_coefficient_nw: u64,
3119    pub control_interface: zx_processor_power_control_t,
3120    pub control_argument: u64,
3121    pub diagnostic_name: [u8; ZX_MAX_NAME_LEN],
3122    padding1: [PadByte; 32],
3123}
3124
3125#[repr(C)]
3126#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3127pub struct zx_processor_power_level_transition_t {
3128    pub latency: zx_duration_t,
3129    pub energy: u64,
3130    pub from: u8,
3131    pub to: u8,
3132    padding1: [PadByte; 6],
3133}
3134
3135#[repr(C)]
3136#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3137pub struct zx_packet_processor_power_level_transition_request_t {
3138    pub domain_id: u32,
3139    pub options: u32,
3140    pub control_interface: u64,
3141    pub control_argument: u64,
3142    padding1: [PadByte; 8],
3143}
3144
3145#[repr(C)]
3146#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3147pub struct zx_processor_power_state_t {
3148    pub domain_id: u32,
3149    pub options: u32,
3150    pub control_interface: u64,
3151    pub control_argument: u64,
3152}
3153
3154#[repr(C)]
3155#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3156pub struct zx_processor_power_domain_t {
3157    pub cpus: zx_cpu_set_t,
3158    pub domain_id: u32,
3159    padding1: [PadByte; 4],
3160}
3161
3162#[repr(C)]
3163#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3164pub struct zx_power_domain_info_t {
3165    pub cpus: zx_cpu_set_t,
3166    pub domain_id: u32,
3167    pub idle_power_levels: u8,
3168    pub active_power_levels: u8,
3169    padding1: [PadByte; 2],
3170}
3171
3172multiconst!(u32, [
3173    ZX_BTI_PERM_READ = 1 << 0;
3174    ZX_BTI_PERM_WRITE = 1 << 1;
3175    ZX_BTI_PERM_EXECUTE = 1 << 2;
3176    ZX_BTI_COMPRESS = 1 << 3;
3177    ZX_BTI_CONTIGUOUS = 1 << 4;
3178]);
3179
3180// Options for zx_port_create
3181multiconst!(u32, [
3182    ZX_PORT_BIND_TO_INTERRUPT = 1 << 0;
3183]);
3184
3185// Options for zx_interrupt_create
3186multiconst!(u32, [
3187    ZX_INTERRUPT_VIRTUAL = 0x10;
3188    ZX_INTERRUPT_TIMESTAMP_MONO = 1 << 6;
3189]);
3190
3191// Options for zx_msi_create
3192multiconst!(u32, [
3193    ZX_MSI_MODE_MSI_X = 0x1;
3194]);
3195
3196// Options for zx_interrupt_bind
3197multiconst!(u32, [
3198    ZX_INTERRUPT_BIND = 0;
3199    ZX_INTERRUPT_UNBIND = 1;
3200]);
3201
3202#[repr(C)]
3203#[derive(Copy, Clone)]
3204#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3205pub struct zx_iob_region_t {
3206    pub r#type: zx_iob_region_type_t,
3207    pub access: zx_iob_access_t,
3208    pub size: u64,
3209    pub discipline: zx_iob_discipline_t,
3210    pub extension: zx_iob_region_extension_t,
3211}
3212
3213multiconst!(zx_iob_region_type_t, [
3214    ZX_IOB_REGION_TYPE_PRIVATE = 0;
3215    ZX_IOB_REGION_TYPE_SHARED = 1;
3216]);
3217
3218multiconst!(zx_iob_access_t, [
3219    ZX_IOB_ACCESS_EP0_CAN_MAP_READ = 1 << 0;
3220    ZX_IOB_ACCESS_EP0_CAN_MAP_WRITE = 1 << 1;
3221    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_READ = 1 << 2;
3222    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_WRITE = 1 << 3;
3223    ZX_IOB_ACCESS_EP1_CAN_MAP_READ = 1 << 4;
3224    ZX_IOB_ACCESS_EP1_CAN_MAP_WRITE = 1 << 5;
3225    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_READ = 1 << 6;
3226    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_WRITE = 1 << 7;
3227]);
3228
3229#[repr(C)]
3230#[derive(Copy, Clone)]
3231#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3232pub struct zx_iob_discipline_t {
3233    pub r#type: zx_iob_discipline_type_t,
3234    pub extension: zx_iob_discipline_extension_t,
3235}
3236
3237#[repr(C)]
3238#[derive(Copy, Clone)]
3239#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3240pub union zx_iob_discipline_extension_t {
3241    // This is in vdso-next.
3242    pub ring_buffer: zx_iob_discipline_mediated_write_ring_buffer_t,
3243    pub reserved: [PadByte; 64],
3244}
3245
3246#[repr(C)]
3247#[derive(Debug, Copy, Clone)]
3248#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3249pub struct zx_iob_discipline_mediated_write_ring_buffer_t {
3250    pub tag: u64,
3251    pub padding: [PadByte; 56],
3252}
3253
3254multiconst!(zx_iob_discipline_type_t, [
3255    ZX_IOB_DISCIPLINE_TYPE_NONE = 0;
3256    ZX_IOB_DISCIPLINE_TYPE_ID_ALLOCATOR = 1;
3257    ZX_IOB_DISCIPLINE_TYPE_MEDIATED_WRITE_RING_BUFFER = 2;
3258]);
3259
3260pub const ZX_IOB_MAX_REGIONS: usize = 64;
3261
3262#[repr(C)]
3263#[derive(Clone, Copy, Default)]
3264#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3265pub struct zx_iob_region_private_t {
3266    pub options: u32,
3267    pub padding: [PadByte; 28],
3268}
3269
3270#[repr(C)]
3271#[derive(Clone, Copy)]
3272#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3273pub struct zx_iob_region_shared_t {
3274    pub options: u32,
3275    pub shared_region: zx_handle_t,
3276    pub padding: [PadByte; 24],
3277}
3278
3279#[repr(C)]
3280#[derive(Copy, Clone)]
3281#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3282pub union zx_iob_region_extension_t {
3283    pub private_region: zx_iob_region_private_t,
3284    pub shared_region: zx_iob_region_shared_t,
3285    pub max_extension: [u8; 32],
3286}
3287
3288#[repr(C)]
3289pub struct zx_wake_source_report_entry_t {
3290    pub koid: zx_koid_t,
3291    pub name: [u8; ZX_MAX_NAME_LEN],
3292    pub initial_signal_time: zx_instant_boot_t,
3293    pub last_signal_time: zx_instant_boot_t,
3294    pub last_ack_time: zx_instant_boot_t,
3295    pub signal_count: u32,
3296    pub flags: u32,
3297}
3298
3299#[repr(C)]
3300pub struct zx_wake_source_report_header_t {
3301    pub report_time: zx_instant_boot_t,
3302    pub suspend_start_time: zx_instant_boot_t,
3303    pub total_wake_sources: u32,
3304    pub unreported_wake_report_entries: u32,
3305}
3306
3307#[cfg(test)]
3308mod test {
3309    #[cfg(test)]
3310    extern crate alloc;
3311
3312    use super::*;
3313
3314    #[test]
3315    fn padded_struct_equality() {
3316        let test_struct = zx_clock_update_args_v1_t {
3317            rate_adjust: 222,
3318            padding1: Default::default(),
3319            value: 333,
3320            error_bound: 444,
3321        };
3322
3323        let different_data = zx_clock_update_args_v1_t { rate_adjust: 999, ..test_struct.clone() };
3324
3325        let different_padding = zx_clock_update_args_v1_t {
3326            padding1: [PadByte(0), PadByte(1), PadByte(2), PadByte(3)],
3327            ..test_struct.clone()
3328        };
3329
3330        // Structures with different data should not be equal.
3331        assert_ne!(test_struct, different_data);
3332        // Structures with only different padding should not be equal.
3333        assert_eq!(test_struct, different_padding);
3334    }
3335
3336    #[test]
3337    fn padded_struct_debug() {
3338        let test_struct = zx_clock_update_args_v1_t {
3339            rate_adjust: 222,
3340            padding1: Default::default(),
3341            value: 333,
3342            error_bound: 444,
3343        };
3344        let expectation = "zx_clock_update_args_v1_t { \
3345            rate_adjust: 222, \
3346            padding1: [-, -, -, -], \
3347            value: 333, \
3348            error_bound: 444 }";
3349        assert_eq!(alloc::format!("{:?}", test_struct), expectation);
3350    }
3351}
3352
3353#[repr(C, align(32))]
3354#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3355#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3356pub struct zx_rseq_t {
3357    pub cpu_id: u32,
3358    pub reserved: u32,
3359    pub start_ip: u64,
3360    pub post_commit_offset: u64,
3361    pub abort_ip: u64,
3362}
3363
3364pub const ZX_INFO_INVALID_CPU: u32 = 0xFFFFFFFF;