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