Skip to main content

zx_types/
lib.rs

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