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
2338#[repr(C)]
2339#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2340#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2341pub struct zx_info_interrupt_t {
2342    pub options: u32,
2343}
2344
2345multiconst!(u32, [
2346    ZX_INFO_PROCESS_FLAG_STARTED = 1 << 0;
2347    ZX_INFO_PROCESS_FLAG_EXITED = 1 << 1;
2348    ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED = 1 << 2;
2349]);
2350
2351struct_decl_macro! {
2352    #[repr(C)]
2353    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2354    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2355    pub struct <zx_info_process_t> {
2356        pub return_code: i64,
2357        pub start_time: zx_time_t,
2358        pub flags: u32,
2359        pub padding1: [PadByte; 4],
2360    }
2361}
2362
2363zx_info_process_t!(zx_info_process_t);
2364
2365struct_decl_macro! {
2366    #[repr(C)]
2367    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2368    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2369    pub struct <zx_info_job_t> {
2370        pub return_code: i64,
2371        pub exited: u8,
2372        pub kill_on_oom: u8,
2373        pub debugger_attached: u8,
2374        pub padding1: [PadByte; 5],
2375    }
2376}
2377
2378zx_info_job_t!(zx_info_job_t);
2379const_assert_eq!(core::mem::size_of::<zx_info_job_t>(), 16);
2380const_assert_eq!(core::mem::align_of::<zx_info_job_t>(), 8);
2381
2382struct_decl_macro! {
2383    #[repr(C)]
2384    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2385    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2386    pub struct <zx_info_timer_t> {
2387        pub options: u32,
2388        pub clock_id: zx_clock_t,
2389        pub deadline: zx_time_t,
2390        pub slack: zx_duration_t,
2391    }
2392}
2393
2394zx_info_timer_t!(zx_info_timer_t);
2395
2396struct_decl_macro! {
2397    #[repr(C)]
2398    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2399    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2400    pub struct <zx_info_stream_t> {
2401        pub options: u32,
2402        pub padding1: [u8; 4],
2403        pub seek: zx_off_t,
2404        pub content_size: u64,
2405    }
2406}
2407
2408zx_info_stream_t!(zx_info_stream_t);
2409
2410#[repr(C)]
2411#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2412#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2413pub struct zx_policy_basic_v1 {
2414    pub condition: u32,
2415    pub policy: u32,
2416}
2417
2418pub type zx_policy_basic_v1_t = zx_policy_basic_v1;
2419pub type zx_policy_basic = zx_policy_basic_v1;
2420pub type zx_policy_basic_t = zx_policy_basic_v1;
2421
2422#[repr(C)]
2423#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2424#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2425pub struct zx_policy_basic_v2 {
2426    pub condition: u32,
2427    pub action: u32,
2428    pub flags: u32,
2429}
2430
2431pub type zx_policy_basic_v2_t = zx_policy_basic_v2;
2432
2433#[repr(C)]
2434#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2435#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
2436pub struct zx_policy_timer_slack {
2437    pub min_slack: zx_duration_t,
2438    pub default_mode: u32,
2439    pub _padding: [u8; 4],
2440}
2441
2442pub type zx_policy_timer_slack_t = zx_policy_timer_slack;
2443
2444multiconst!(u32, [
2445    // policy options
2446    ZX_JOB_POL_RELATIVE = 0;
2447    ZX_JOB_POL_ABSOLUTE = 1;
2448
2449    // policy topic
2450    ZX_JOB_POL_BASIC_V1 = 0;
2451    ZX_JOB_POL_BASIC_V2 = 0x0100_0000;
2452    ZX_JOB_POL_BASIC = 0;
2453    ZX_JOB_POL_TIMER_SLACK = 1;
2454
2455    // policy conditions
2456    ZX_POL_BAD_HANDLE            = 0;
2457    ZX_POL_WRONG_OBJECT          = 1;
2458    ZX_POL_VMAR_WX               = 2;
2459    ZX_POL_NEW_ANY               = 3;
2460    ZX_POL_NEW_VMO               = 4;
2461    ZX_POL_NEW_CHANNEL           = 5;
2462    ZX_POL_NEW_EVENT             = 6;
2463    ZX_POL_NEW_EVENTPAIR         = 7;
2464    ZX_POL_NEW_PORT              = 8;
2465    ZX_POL_NEW_SOCKET            = 9;
2466    ZX_POL_NEW_FIFO              = 10;
2467    ZX_POL_NEW_TIMER             = 11;
2468    ZX_POL_NEW_PROCESS           = 12;
2469    ZX_POL_NEW_PROFILE           = 13;
2470    ZX_POL_NEW_PAGER             = 14;
2471    ZX_POL_AMBIENT_MARK_VMO_EXEC = 15;
2472    ZX_POL_NEW_IOB               = 16;
2473    ZX_POL_NEW_SAMPLER           = 17;
2474    #[cfg(feature = "kernel")]
2475    ZX_POL_MAX                   = 18;
2476
2477    // policy actions
2478    ZX_POL_ACTION_ALLOW           = 0;
2479    ZX_POL_ACTION_DENY            = 1;
2480    ZX_POL_ACTION_ALLOW_EXCEPTION = 2;
2481    ZX_POL_ACTION_DENY_EXCEPTION  = 3;
2482    ZX_POL_ACTION_KILL            = 4;
2483    #[cfg(feature = "kernel")]
2484    ZX_POL_ACTION_MAX             = 5;
2485
2486    // policy override
2487    ZX_POL_OVERRIDE_ALLOW = 0;
2488    ZX_POL_OVERRIDE_DENY  = 1;
2489
2490    // timer slack default modes
2491    ZX_TIMER_SLACK_CENTER = 0;
2492    ZX_TIMER_SLACK_EARLY  = 1;
2493    ZX_TIMER_SLACK_LATE   = 2;
2494]);
2495
2496multiconst!(u32, [
2497    // critical options
2498    ZX_JOB_CRITICAL_PROCESS_RETCODE_NONZERO = 1 << 0;
2499]);
2500
2501// Don't use struct_decl_macro, wrapper is different.
2502#[repr(C)]
2503#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2504#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2505pub struct zx_info_vmo_t {
2506    pub koid: zx_koid_t,
2507    pub name: [u8; ZX_MAX_NAME_LEN],
2508    pub size_bytes: u64,
2509    pub parent_koid: zx_koid_t,
2510    pub num_children: usize,
2511    pub num_mappings: usize,
2512    pub share_count: usize,
2513    pub flags: u32,
2514    padding1: [PadByte; 4],
2515    pub committed_bytes: u64,
2516    pub handle_rights: zx_rights_t,
2517    pub cache_policy: u32,
2518    pub metadata_bytes: u64,
2519    pub committed_change_events: u64,
2520    pub populated_bytes: u64,
2521    pub committed_private_bytes: u64,
2522    pub populated_private_bytes: u64,
2523    pub committed_scaled_bytes: u64,
2524    pub populated_scaled_bytes: u64,
2525    pub committed_fractional_scaled_bytes: u64,
2526    pub populated_fractional_scaled_bytes: u64,
2527}
2528
2529#[repr(C)]
2530#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2531#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2532pub struct zx_info_vmo_v1_t {
2533    pub koid: zx_koid_t,
2534    pub name: [u8; ZX_MAX_NAME_LEN],
2535    pub size_bytes: u64,
2536    pub parent_koid: zx_koid_t,
2537    pub num_children: usize,
2538    pub num_mappings: usize,
2539    pub share_count: usize,
2540    pub flags: u32,
2541    pub padding1: [PadByte; 4],
2542    pub committed_bytes: u64,
2543    pub handle_rights: zx_rights_t,
2544    pub cache_policy: u32,
2545}
2546
2547const_assert_eq!(core::mem::size_of::<zx_info_vmo_v1_t>(), 104);
2548const_assert_eq!(core::mem::align_of::<zx_info_vmo_v1_t>(), 8);
2549
2550#[repr(C)]
2551#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2552#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2553pub struct zx_info_vmo_v2_t {
2554    pub koid: zx_koid_t,
2555    pub name: [u8; ZX_MAX_NAME_LEN],
2556    pub size_bytes: u64,
2557    pub parent_koid: zx_koid_t,
2558    pub num_children: usize,
2559    pub num_mappings: usize,
2560    pub share_count: usize,
2561    pub flags: u32,
2562    pub padding1: [PadByte; 4],
2563    pub committed_bytes: u64,
2564    pub handle_rights: zx_rights_t,
2565    pub cache_policy: u32,
2566    pub metadata_bytes: u64,
2567    pub committed_change_events: u64,
2568}
2569
2570const_assert_eq!(core::mem::size_of::<zx_info_vmo_v2_t>(), 120);
2571const_assert_eq!(core::mem::align_of::<zx_info_vmo_v2_t>(), 8);
2572
2573#[repr(C)]
2574#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2575#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
2576pub struct zx_info_vmo_v3_t {
2577    pub koid: zx_koid_t,
2578    pub name: [u8; ZX_MAX_NAME_LEN],
2579    pub size_bytes: u64,
2580    pub parent_koid: zx_koid_t,
2581    pub num_children: usize,
2582    pub num_mappings: usize,
2583    pub share_count: usize,
2584    pub flags: u32,
2585    pub padding1: [PadByte; 4],
2586    pub committed_bytes: u64,
2587    pub handle_rights: zx_rights_t,
2588    pub cache_policy: u32,
2589    pub metadata_bytes: u64,
2590    pub committed_change_events: u64,
2591    pub populated_bytes: u64,
2592}
2593
2594const_assert_eq!(core::mem::size_of::<zx_info_vmo_v3_t>(), 128);
2595const_assert_eq!(core::mem::align_of::<zx_info_vmo_v3_t>(), 8);
2596
2597struct_decl_macro! {
2598    #[repr(C)]
2599    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2600    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2601    pub struct <zx_info_cpu_stats_t> {
2602        pub cpu_number: u32,
2603        pub flags: u32,
2604        pub idle_time: zx_duration_t,
2605        pub normalized_busy_time: zx_duration_t,
2606        pub reschedules: u64,
2607        pub context_switches: u64,
2608        pub irq_preempts: u64,
2609        pub preempts: u64,
2610        pub yields: u64,
2611        pub ints: u64,
2612        pub timer_ints: u64,
2613        pub timers: u64,
2614        pub page_faults: u64,
2615        pub exceptions: u64,
2616        pub syscalls: u64,
2617        pub reschedule_ipis: u64,
2618        pub generic_ipis: u64,
2619        pub active_energy_consumption_nj: u64,
2620        pub idle_energy_consumption_nj: u64,
2621    }
2622}
2623
2624zx_info_cpu_stats_t!(zx_info_cpu_stats_t);
2625
2626struct_decl_macro! {
2627    #[repr(C)]
2628    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2629    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2630    pub struct <zx_info_kmem_stats_t> {
2631        pub total_bytes: u64,
2632        pub free_bytes: u64,
2633        pub free_loaned_bytes: u64,
2634        pub wired_bytes: u64,
2635        pub total_heap_bytes: u64,
2636        pub free_heap_bytes: u64,
2637        pub vmo_bytes: u64,
2638        pub mmu_overhead_bytes: u64,
2639        pub ipc_bytes: u64,
2640        pub cache_bytes: u64,
2641        pub slab_bytes: u64,
2642        pub zram_bytes: u64,
2643        pub other_bytes: u64,
2644        pub vmo_reclaim_total_bytes: u64,
2645        pub vmo_reclaim_newest_bytes: u64,
2646        pub vmo_reclaim_oldest_bytes: u64,
2647        pub vmo_reclaim_disabled_bytes: u64,
2648        pub vmo_discardable_locked_bytes: u64,
2649        pub vmo_discardable_unlocked_bytes: u64,
2650    }
2651}
2652
2653zx_info_kmem_stats_t!(zx_info_kmem_stats_t);
2654
2655struct_decl_macro! {
2656    #[repr(C)]
2657    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2658    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2659    pub struct <zx_info_kmem_stats_v1_t> {
2660        pub total_bytes: u64,
2661        pub free_bytes: u64,
2662        pub wired_bytes: u64,
2663        pub total_heap_bytes: u64,
2664        pub free_heap_bytes: u64,
2665        pub vmo_bytes: u64,
2666        pub mmu_overhead_bytes: u64,
2667        pub ipc_bytes: u64,
2668        pub other_bytes: u64,
2669    }
2670}
2671
2672zx_info_kmem_stats_v1_t!(zx_info_kmem_stats_v1_t);
2673const_assert_eq!(core::mem::size_of::<zx_info_kmem_stats_v1_t>(), 72);
2674const_assert_eq!(core::mem::align_of::<zx_info_kmem_stats_v1_t>(), 8);
2675
2676struct_decl_macro! {
2677    #[repr(C)]
2678    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2679    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2680    pub struct <zx_info_kmem_stats_extended_t> {
2681        pub total_bytes: u64,
2682        pub free_bytes: u64,
2683        pub wired_bytes: u64,
2684        pub total_heap_bytes: u64,
2685        pub free_heap_bytes: u64,
2686        pub vmo_bytes: u64,
2687        pub vmo_pager_total_bytes: u64,
2688        pub vmo_pager_newest_bytes: u64,
2689        pub vmo_pager_oldest_bytes: u64,
2690        pub vmo_discardable_locked_bytes: u64,
2691        pub vmo_discardable_unlocked_bytes: u64,
2692        pub mmu_overhead_bytes: u64,
2693        pub ipc_bytes: u64,
2694        pub other_bytes: u64,
2695        pub vmo_reclaim_disable_bytes: u64,
2696    }
2697}
2698
2699zx_info_kmem_stats_extended_t!(zx_info_kmem_stats_extended_t);
2700
2701struct_decl_macro! {
2702    #[repr(C)]
2703    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2704    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2705    pub struct <zx_info_kmem_stats_compression_t> {
2706        pub uncompressed_storage_bytes: u64,
2707        pub compressed_storage_bytes: u64,
2708        pub compressed_fragmentation_bytes: u64,
2709        pub compression_time: zx_duration_t,
2710        pub decompression_time: zx_duration_t,
2711        pub total_page_compression_attempts: u64,
2712        pub failed_page_compression_attempts: u64,
2713        pub total_page_decompressions: u64,
2714        pub compressed_page_evictions: u64,
2715        pub eager_page_compressions: u64,
2716        pub memory_pressure_page_compressions: u64,
2717        pub critical_memory_page_compressions: u64,
2718        pub pages_decompressed_unit_ns: u64,
2719        pub pages_decompressed_within_log_time: [u64; 8],
2720    }
2721}
2722
2723zx_info_kmem_stats_compression_t!(zx_info_kmem_stats_compression_t);
2724
2725struct_decl_macro! {
2726    #[repr(C)]
2727    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2728    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2729    pub struct <zx_info_resource_t> {
2730        pub kind: u32,
2731        pub flags: u32,
2732        pub base: u64,
2733        pub size: usize,
2734        pub name: [u8; ZX_MAX_NAME_LEN],
2735    }
2736}
2737
2738const_assert_eq!(core::mem::size_of::<zx_info_resource_t>(), 56);
2739const_assert_eq!(core::mem::align_of::<zx_info_resource_t>(), 8);
2740
2741struct_decl_macro! {
2742    #[repr(C)]
2743    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2744    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2745    pub struct <zx_info_bti_t> {
2746        pub minimum_contiguity: u64,
2747        pub aspace_size: u64,
2748        pub pmo_count: u64,
2749        pub quarantine_count: u64,
2750    }
2751}
2752
2753zx_info_bti_t!(zx_info_bti_t);
2754
2755struct_decl_macro! {
2756    #[repr(C)]
2757    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2758    #[derive(zerocopy::FromBytes, zerocopy::IntoBytes, zerocopy::Immutable)]
2759    pub struct <zx_info_msi_t> {
2760        pub target_addr: u64,
2761        pub target_data: u32,
2762        pub base_irq_id: u32,
2763        pub num_irq: u32,
2764        pub interrupt_count: u32,
2765    }
2766}
2767
2768zx_info_msi_t!(zx_info_msi_t);
2769
2770pub type zx_thread_state_t = u32;
2771
2772multiconst!(zx_thread_state_t, [
2773    ZX_THREAD_STATE_NEW = 0x0000;
2774    ZX_THREAD_STATE_RUNNING = 0x0001;
2775    ZX_THREAD_STATE_SUSPENDED = 0x0002;
2776    ZX_THREAD_STATE_BLOCKED = 0x0003;
2777    ZX_THREAD_STATE_DYING = 0x0004;
2778    ZX_THREAD_STATE_DEAD = 0x0005;
2779    ZX_THREAD_STATE_BLOCKED_EXCEPTION = 0x0103;
2780    ZX_THREAD_STATE_BLOCKED_SLEEPING = 0x0203;
2781    ZX_THREAD_STATE_BLOCKED_FUTEX = 0x0303;
2782    ZX_THREAD_STATE_BLOCKED_PORT = 0x0403;
2783    ZX_THREAD_STATE_BLOCKED_CHANNEL = 0x0503;
2784    ZX_THREAD_STATE_BLOCKED_WAIT_ONE = 0x0603;
2785    ZX_THREAD_STATE_BLOCKED_WAIT_MANY = 0x0703;
2786    ZX_THREAD_STATE_BLOCKED_INTERRUPT = 0x0803;
2787    ZX_THREAD_STATE_BLOCKED_PAGER = 0x0903;
2788]);
2789
2790#[repr(C)]
2791#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2792#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
2793pub struct zx_info_thread_t {
2794    pub state: zx_thread_state_t,
2795    pub wait_exception_channel_type: u32,
2796    pub cpu_affinity_mask: zx_cpu_set_t,
2797}
2798
2799struct_decl_macro! {
2800    #[repr(C)]
2801    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2802    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2803    pub struct <zx_info_thread_stats_t> {
2804        pub total_runtime: zx_duration_t,
2805        pub last_scheduled_cpu: u32,
2806        pub padding1: [PadByte; 4],
2807    }
2808}
2809
2810zx_info_thread_stats_t!(zx_info_thread_stats_t);
2811const_assert_eq!(core::mem::size_of::<zx_info_thread_stats_t>(), 16);
2812const_assert_eq!(core::mem::align_of::<zx_info_thread_stats_t>(), 8);
2813
2814zx_info_resource_t!(zx_info_resource_t);
2815
2816struct_decl_macro! {
2817    #[repr(C)]
2818    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2819    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2820    pub struct <zx_info_vmar_t> {
2821        pub base: usize,
2822        pub len: usize,
2823    }
2824}
2825
2826zx_info_vmar_t!(zx_info_vmar_t);
2827const_assert_eq!(core::mem::size_of::<zx_info_vmar_t>(), 16);
2828const_assert_eq!(core::mem::align_of::<zx_info_vmar_t>(), 8);
2829
2830struct_decl_macro! {
2831    #[repr(C)]
2832    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2833    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2834    pub struct <zx_info_task_stats_t> {
2835        pub mem_mapped_bytes: usize,
2836        pub mem_private_bytes: usize,
2837        pub mem_shared_bytes: usize,
2838        pub mem_scaled_shared_bytes: usize,
2839        pub mem_fractional_scaled_shared_bytes: u64,
2840    }
2841}
2842
2843zx_info_task_stats_t!(zx_info_task_stats_t);
2844const_assert_eq!(core::mem::size_of::<zx_info_task_stats_t>(), 40);
2845const_assert_eq!(core::mem::align_of::<zx_info_task_stats_t>(), 8);
2846
2847struct_decl_macro! {
2848    #[repr(C)]
2849    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2850    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2851    pub struct <zx_info_task_stats_v1_t> {
2852        pub mem_mapped_bytes: usize,
2853        pub mem_private_bytes: usize,
2854        pub mem_shared_bytes: usize,
2855        pub mem_scaled_shared_bytes: usize,
2856    }
2857}
2858
2859zx_info_task_stats_v1_t!(zx_info_task_stats_v1_t);
2860const_assert_eq!(core::mem::size_of::<zx_info_task_stats_v1_t>(), 32);
2861const_assert_eq!(core::mem::align_of::<zx_info_task_stats_v1_t>(), 8);
2862
2863struct_decl_macro! {
2864    #[repr(C)]
2865    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2866    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2867    pub struct <zx_info_task_runtime_t> {
2868        pub cpu_time: zx_duration_t,
2869        pub queue_time: zx_duration_t,
2870        pub page_fault_time: zx_duration_t,
2871        pub lock_contention_time: zx_duration_t,
2872    }
2873}
2874
2875zx_info_task_runtime_t!(zx_info_task_runtime_t);
2876const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_t>(), 32);
2877const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_t>(), 8);
2878
2879struct_decl_macro! {
2880    #[repr(C)]
2881    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2882    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2883    pub struct <zx_info_task_runtime_v1_t> {
2884        pub cpu_time: zx_duration_mono_t,
2885        pub queue_time: zx_duration_mono_t,
2886    }
2887}
2888
2889zx_info_task_runtime_v1_t!(zx_info_task_runtime_v1_t);
2890const_assert_eq!(core::mem::size_of::<zx_info_task_runtime_v1_t>(), 16);
2891const_assert_eq!(core::mem::align_of::<zx_info_task_runtime_v1_t>(), 8);
2892
2893multiconst!(zx_info_maps_type_t, [
2894    ZX_INFO_MAPS_TYPE_NONE    = 0;
2895    ZX_INFO_MAPS_TYPE_ASPACE  = 1;
2896    ZX_INFO_MAPS_TYPE_VMAR    = 2;
2897    ZX_INFO_MAPS_TYPE_MAPPING = 3;
2898]);
2899
2900struct_decl_macro! {
2901    #[repr(C)]
2902    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2903    #[derive(zerocopy::FromBytes, zerocopy::Immutable, IntoBytes)]
2904    pub struct <zx_info_maps_mapping_t> {
2905        pub mmu_flags: zx_vm_option_t,
2906        pub padding1: [PadByte; 4],
2907        pub vmo_koid: zx_koid_t,
2908        pub vmo_offset: u64,
2909        pub committed_bytes: usize,
2910        pub populated_bytes: usize,
2911        pub committed_private_bytes: usize,
2912        pub populated_private_bytes: usize,
2913        pub committed_scaled_bytes: usize,
2914        pub populated_scaled_bytes: usize,
2915        pub committed_fractional_scaled_bytes: u64,
2916        pub populated_fractional_scaled_bytes: u64,
2917    }
2918}
2919
2920zx_info_maps_mapping_t!(zx_info_maps_mapping_t);
2921
2922#[repr(C)]
2923#[derive(Copy, Clone)]
2924#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, KnownLayout))]
2925pub union InfoMapsTypeUnion {
2926    pub mapping: zx_info_maps_mapping_t,
2927}
2928
2929struct_decl_macro! {
2930    #[repr(C)]
2931    #[derive(Copy, Clone)]
2932    #[derive(zerocopy::FromBytes, zerocopy::Immutable)]
2933    pub struct <zx_info_maps_t> {
2934        pub name: [u8; ZX_MAX_NAME_LEN],
2935        pub base: zx_vaddr_t,
2936        pub size: usize,
2937        pub depth: usize,
2938        pub r#type: zx_info_maps_type_t,
2939        pub u: InfoMapsTypeUnion,
2940    }
2941}
2942
2943zx_info_maps_t!(zx_info_maps_t);
2944
2945struct_decl_macro! {
2946    #[repr(C)]
2947    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
2948    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2949    pub struct <zx_info_process_handle_stats_t> {
2950        pub handle_count: [u32; ZX_OBJ_TYPE_UPPER_BOUND],
2951    }
2952}
2953
2954const_assert_eq!(core::mem::size_of::<zx_info_process_handle_stats_t>(), 256);
2955const_assert_eq!(core::mem::align_of::<zx_info_process_handle_stats_t>(), 4);
2956
2957impl Default for zx_info_process_handle_stats_t {
2958    fn default() -> Self {
2959        Self { handle_count: [0; ZX_OBJ_TYPE_UPPER_BOUND] }
2960    }
2961}
2962
2963zx_info_process_handle_stats_t!(zx_info_process_handle_stats_t);
2964
2965struct_decl_macro! {
2966    #[repr(C)]
2967    #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
2968    #[derive(zerocopy::FromBytes, zerocopy::Immutable, zerocopy::IntoBytes)]
2969    pub struct <zx_info_memory_stall_t> {
2970        pub stall_time_some: zx_duration_mono_t,
2971        pub stall_time_full: zx_duration_mono_t,
2972    }
2973}
2974
2975zx_info_memory_stall_t!(zx_info_memory_stall_t);
2976
2977// from //zircon/system/public/zircon/syscalls/hypervisor.h
2978multiconst!(zx_guest_trap_t, [
2979    ZX_GUEST_TRAP_BELL = 0;
2980    ZX_GUEST_TRAP_MEM  = 1;
2981    ZX_GUEST_TRAP_IO   = 2;
2982]);
2983
2984pub const ZX_LOG_RECORD_MAX: usize = 256;
2985pub const ZX_LOG_RECORD_DATA_MAX: usize = 216;
2986
2987pub const DEBUGLOG_TRACE: u8 = 0x10;
2988pub const DEBUGLOG_DEBUG: u8 = 0x20;
2989pub const DEBUGLOG_INFO: u8 = 0x30;
2990pub const DEBUGLOG_WARNING: u8 = 0x40;
2991pub const DEBUGLOG_ERROR: u8 = 0x50;
2992pub const DEBUGLOG_FATAL: u8 = 0x60;
2993
2994// From //zircon/system/public/zircon/syscalls/log.h
2995// Do not forward this message via network (for logging in network core and drivers).
2996pub const ZX_LOG_LOCAL: u32 = 0x10;
2997pub const ZX_LOG_FLAGS_MASK: u32 = ZX_LOG_LOCAL;
2998
2999// From //zircon/system/public/zircon/processargs.h
3000pub const ZX_PROCARGS_PROTOCOL: u32 = 0x4150585d; // MXPA
3001pub const ZX_PROCARGS_VERSION: u32 = 0x00001000;
3002
3003#[repr(C)]
3004#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3005#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3006pub struct zx_log_record_header_t {
3007    pub sequence: u64,
3008    padding1: [PadByte; 4],
3009    pub datalen: u16,
3010    pub severity: u8,
3011    pub flags: u8,
3012    pub timestamp: zx_instant_boot_t,
3013    pub pid: u64,
3014    pub tid: u64,
3015}
3016
3017#[repr(C)]
3018#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3019#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3020pub struct zx_log_record_t {
3021    pub header: zx_log_record_header_t,
3022    pub data: [u8; ZX_LOG_RECORD_DATA_MAX],
3023}
3024
3025const_assert_eq!(core::mem::size_of::<zx_log_record_t>(), ZX_LOG_RECORD_MAX);
3026
3027impl Default for zx_log_record_t {
3028    fn default() -> Self {
3029        Self { header: zx_log_record_header_t::default(), data: [0; ZX_LOG_RECORD_DATA_MAX] }
3030    }
3031}
3032
3033multiconst!(u32, [
3034    ZX_LOG_FLAG_READABLE = 0x40000000;
3035]);
3036
3037// For C, the below types are currently forward declared for syscalls.h.
3038// We might want to investigate a better solution for Rust or removing those
3039// forward declarations.
3040//
3041// These are hand typed translations from C types into Rust structures using a C
3042// layout
3043
3044// source: zircon/system/public/zircon/syscalls/system.h
3045multiconst!(zx_system_powerctl_cmd_t, [
3046    ZX_SYSTEM_POWERCTL_ENABLE_ALL_CPUS               = 1;
3047    ZX_SYSTEM_POWERCTL_DISABLE_ALL_CPUS_BUT_PRIMARY  = 2;
3048    ZX_SYSTEM_POWERCTL_ACPI_TRANSITION_S_STATE       = 3;
3049    ZX_SYSTEM_POWERCTL_X86_SET_PKG_PL1               = 4;
3050    ZX_SYSTEM_POWERCTL_REBOOT                        = 5;
3051    ZX_SYSTEM_POWERCTL_REBOOT_BOOTLOADER             = 6;
3052    ZX_SYSTEM_POWERCTL_REBOOT_RECOVERY               = 7;
3053    ZX_SYSTEM_POWERCTL_SHUTDOWN                      = 8;
3054    ZX_SYSTEM_POWERCTL_ACK_KERNEL_INITIATED_REBOOT   = 9;
3055]);
3056
3057#[repr(C)]
3058#[derive(Copy, Clone)]
3059#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3060pub struct zx_system_powerctl_arg_t {
3061    // rust can't express anonymous unions at this time
3062    // https://github.com/rust-lang/rust/issues/49804
3063    pub powerctl_internal: zx_powerctl_union,
3064}
3065
3066#[repr(C)]
3067#[derive(Copy, Clone)]
3068#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3069pub union zx_powerctl_union {
3070    acpi_transition_s_state: acpi_transition_s_state,
3071    x86_power_limit: x86_power_limit,
3072}
3073
3074#[repr(C)]
3075#[derive(Default, Debug, PartialEq, Copy, Clone)]
3076#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3077pub struct acpi_transition_s_state {
3078    target_s_state: u8, // Value between 1 and 5 indicating which S-state
3079    sleep_type_a: u8,   // Value from ACPI VM (SLP_TYPa)
3080    sleep_type_b: u8,   // Value from ACPI VM (SLP_TYPb)
3081    padding1: [PadByte; 9],
3082}
3083
3084#[repr(C)]
3085#[derive(Default, Debug, PartialEq, Copy, Clone)]
3086#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3087pub struct x86_power_limit {
3088    power_limit: u32, // PL1 value in milliwatts
3089    time_window: u32, // PL1 time window in microseconds
3090    clamp: u8,        // PL1 clamping enable
3091    enable: u8,       // PL1 enable
3092    padding1: [PadByte; 2],
3093}
3094
3095// source: zircon/system/public/zircon/syscalls/smc.h
3096#[repr(C)]
3097#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3098#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3099pub struct zx_smc_parameters_t {
3100    pub func_id: u32,
3101    padding1: [PadByte; 4],
3102    pub arg1: u64,
3103    pub arg2: u64,
3104    pub arg3: u64,
3105    pub arg4: u64,
3106    pub arg5: u64,
3107    pub arg6: u64,
3108    pub client_id: u16,
3109    pub secure_os_id: u16,
3110    padding2: [PadByte; 4],
3111}
3112
3113#[repr(C)]
3114#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3115#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3116pub struct zx_smc_result_t {
3117    pub arg0: u64,
3118    pub arg1: u64,
3119    pub arg2: u64,
3120    pub arg3: u64,
3121    pub arg6: u64,
3122}
3123
3124#[repr(C)]
3125#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
3126#[cfg_attr(feature = "zerocopy", derive(KnownLayout, FromBytes, Immutable, IntoBytes))]
3127pub struct zx_vmo_lock_state_t {
3128    pub offset: u64,
3129    pub size: u64,
3130    pub discarded_offset: u64,
3131    pub discarded_size: u64,
3132}
3133
3134pub const ZX_CPU_SET_MAX_CPUS: usize = 512;
3135pub const ZX_CPU_SET_BITS_PER_WORD: usize = 64;
3136
3137#[repr(C)]
3138#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3139#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3140pub struct zx_cpu_set_t {
3141    pub mask: [u64; ZX_CPU_SET_MAX_CPUS / ZX_CPU_SET_BITS_PER_WORD],
3142}
3143
3144// source: zircon/system/public/zircon/syscalls/scheduler.h
3145#[repr(C)]
3146#[derive(Copy, Clone)]
3147#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3148pub struct zx_profile_info_t {
3149    pub flags: u32,
3150    padding1: [PadByte; 4],
3151    pub zx_profile_info_union: zx_profile_info_union,
3152    pub cpu_affinity_mask: zx_cpu_set_t,
3153}
3154
3155pub const ZX_PROFILE_INFO_FLAG_PRIORITY: u32 = 1 << 0;
3156pub const ZX_PROFILE_INFO_FLAG_CPU_MASK: u32 = 1 << 1;
3157pub const ZX_PROFILE_INFO_FLAG_DEADLINE: u32 = 1 << 2;
3158pub const ZX_PROFILE_INFO_FLAG_NO_INHERIT: u32 = 1 << 3;
3159pub const ZX_PROFILE_INFO_FLAG_MEMORY_PRIORITY: u32 = 1 << 4;
3160pub const ZX_PROFILE_INFO_FLAG_CRITICAL: u32 = 1 << 5;
3161
3162pub const ZX_PRIORITY_LOWEST: i32 = 0;
3163pub const ZX_PRIORITY_LOW: i32 = 8;
3164pub const ZX_PRIORITY_DEFAULT: i32 = 16;
3165pub const ZX_PRIORITY_HIGH: i32 = 24;
3166pub const ZX_PRIORITY_HIGHEST: i32 = 31;
3167
3168#[cfg(feature = "zerocopy")]
3169impl Default for zx_profile_info_t {
3170    fn default() -> Self {
3171        Self {
3172            flags: Default::default(),
3173            padding1: Default::default(),
3174            zx_profile_info_union: FromZeros::new_zeroed(),
3175            cpu_affinity_mask: Default::default(),
3176        }
3177    }
3178}
3179
3180#[repr(C)]
3181#[derive(Copy, Clone)]
3182#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3183pub struct priority_params {
3184    pub priority: i32,
3185    padding1: [PadByte; 20],
3186}
3187
3188#[repr(C)]
3189#[derive(Copy, Clone)]
3190#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3191pub union zx_profile_info_union {
3192    pub priority_params: priority_params,
3193    pub deadline_params: zx_sched_deadline_params_t,
3194}
3195
3196#[repr(C)]
3197#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3198#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3199pub struct zx_sched_deadline_params_t {
3200    pub capacity: zx_duration_t,
3201    pub relative_deadline: zx_duration_t,
3202    pub period: zx_duration_t,
3203}
3204
3205#[repr(C)]
3206#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3207#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3208pub struct zx_cpu_performance_scale_t {
3209    pub integer_part: u32,
3210    pub fractional_part: u32,
3211}
3212
3213#[repr(C)]
3214#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3215#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3216pub struct zx_cpu_performance_info_t {
3217    pub logical_cpu_number: u32,
3218    pub performance_scale: zx_cpu_performance_scale_t,
3219}
3220
3221#[repr(C)]
3222#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3223#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable, KnownLayout))]
3224pub struct zx_cpu_perf_limit_t {
3225    pub logical_cpu_number: u32,
3226    pub limit_type: u32,
3227    pub min: u64,
3228    pub max: u64,
3229}
3230
3231#[repr(C)]
3232#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3233pub struct zx_iommu_desc_stub_t {
3234    padding1: PadByte,
3235}
3236
3237pub const ZX_IOMMU_MAX_DESC_LEN: usize = 4096;
3238
3239multiconst!(u32, [
3240    ZX_IOMMU_TYPE_STUB = 0;
3241    ZX_IOMMU_TYPE_INTEL = 1;
3242]);
3243
3244pub const ZX_SAMPLER_MIN_PERIOD: zx_duration_t = 10_000;
3245pub const ZX_SAMPLER_MAX_BUFFER_SIZE: usize = 1024 * 1024 * 1024;
3246
3247#[repr(C)]
3248#[derive(Debug, Copy, Clone)]
3249#[cfg_attr(feature = "zerocopy", derive(FromBytes, IntoBytes, Immutable))]
3250pub struct zx_sampler_config_t {
3251    pub period: zx_duration_t,
3252    pub buffer_size: usize,
3253    pub iobuffer_discipline: u64,
3254}
3255
3256multiconst!(zx_processor_power_level_options_t, [
3257    ZX_PROCESSOR_POWER_LEVEL_OPTIONS_DOMAIN_INDEPENDENT = 1 << 0;
3258]);
3259
3260multiconst!(zx_processor_power_control_t, [
3261    ZX_PROCESSOR_POWER_CONTROL_CPU_DRIVER = 0;
3262    ZX_PROCESSOR_POWER_CONTROL_ARM_PSCI = 1;
3263    ZX_PROCESSOR_POWER_CONTROL_ARM_WFI = 2;
3264    ZX_PROCESSOR_POWER_CONTROL_RISCV_SBI = 3;
3265    ZX_PROCESSOR_POWER_CONTROL_RISCV_WFI = 4;
3266]);
3267
3268#[repr(C)]
3269#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3270pub struct zx_processor_power_level_t {
3271    pub options: zx_processor_power_level_options_t,
3272    pub processing_rate: u64,
3273    pub power_coefficient_nw: u64,
3274    pub control_interface: zx_processor_power_control_t,
3275    pub control_argument: u64,
3276    pub diagnostic_name: [u8; ZX_MAX_NAME_LEN],
3277    padding1: [PadByte; 32],
3278}
3279
3280#[repr(C)]
3281#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3282pub struct zx_processor_power_level_transition_t {
3283    pub latency: zx_duration_t,
3284    pub energy: u64,
3285    pub from: u8,
3286    pub to: u8,
3287    padding1: [PadByte; 6],
3288}
3289
3290#[repr(C)]
3291#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3292pub struct zx_packet_processor_power_level_transition_request_t {
3293    pub domain_id: u32,
3294    pub options: u32,
3295    pub control_interface: u64,
3296    pub control_argument: u64,
3297    padding1: [PadByte; 8],
3298}
3299
3300#[repr(C)]
3301#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3302pub struct zx_processor_power_state_t {
3303    pub domain_id: u32,
3304    pub options: u32,
3305    pub control_interface: u64,
3306    pub control_argument: u64,
3307}
3308
3309#[repr(C)]
3310#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
3311pub struct zx_processor_power_domain_t {
3312    pub cpus: zx_cpu_set_t,
3313    pub domain_id: u32,
3314    padding1: [PadByte; 4],
3315}
3316
3317#[repr(C)]
3318#[derive(Debug, Copy, Clone, Eq, PartialEq)]
3319pub struct zx_power_domain_info_t {
3320    pub cpus: zx_cpu_set_t,
3321    pub domain_id: u32,
3322    pub idle_power_levels: u8,
3323    pub active_power_levels: u8,
3324    padding1: [PadByte; 2],
3325}
3326
3327multiconst!(u32, [
3328    ZX_BTI_PERM_READ = 1 << 0;
3329    ZX_BTI_PERM_WRITE = 1 << 1;
3330    ZX_BTI_PERM_EXECUTE = 1 << 2;
3331    ZX_BTI_COMPRESS = 1 << 3;
3332    ZX_BTI_CONTIGUOUS = 1 << 4;
3333]);
3334
3335// Options for zx_port_create
3336multiconst!(u32, [
3337    ZX_PORT_BIND_TO_INTERRUPT = 1 << 0;
3338]);
3339
3340// Options for zx_interrupt_create
3341multiconst!(u32, [
3342    ZX_INTERRUPT_REMAP_IRQ = 0x1;
3343    ZX_INTERRUPT_MODE_DEFAULT = 0 << 1;
3344    ZX_INTERRUPT_MODE_EDGE_LOW = 1 << 1;
3345    ZX_INTERRUPT_MODE_EDGE_HIGH = 2 << 1;
3346    ZX_INTERRUPT_MODE_LEVEL_LOW = 3 << 1;
3347    ZX_INTERRUPT_MODE_LEVEL_HIGH = 4 << 1;
3348    ZX_INTERRUPT_MODE_EDGE_BOTH = 5 << 1;
3349    ZX_INTERRUPT_MODE_MASK = 0xe;
3350    ZX_INTERRUPT_VIRTUAL = 0x10;
3351    ZX_INTERRUPT_WAKE_VECTOR = 0x20;
3352    ZX_INTERRUPT_TIMESTAMP_MONO = 1 << 6;
3353]);
3354
3355// Options for zx_msi_create
3356multiconst!(u32, [
3357    ZX_MSI_MODE_MSI_X = 0x1;
3358]);
3359
3360// Options for zx_interrupt_bind
3361multiconst!(u32, [
3362    ZX_INTERRUPT_BIND = 0;
3363    ZX_INTERRUPT_UNBIND = 1;
3364]);
3365
3366#[repr(C)]
3367#[derive(Copy, Clone)]
3368#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3369pub struct zx_iob_region_t {
3370    pub r#type: zx_iob_region_type_t,
3371    pub access: zx_iob_access_t,
3372    pub size: u64,
3373    pub discipline: zx_iob_discipline_t,
3374    pub extension: zx_iob_region_extension_t,
3375}
3376
3377multiconst!(zx_iob_region_type_t, [
3378    ZX_IOB_REGION_TYPE_PRIVATE = 0;
3379    ZX_IOB_REGION_TYPE_SHARED = 1;
3380]);
3381
3382multiconst!(zx_iob_access_t, [
3383    ZX_IOB_ACCESS_EP0_CAN_MAP_READ = 1 << 0;
3384    ZX_IOB_ACCESS_EP0_CAN_MAP_WRITE = 1 << 1;
3385    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_READ = 1 << 2;
3386    ZX_IOB_ACCESS_EP0_CAN_MEDIATED_WRITE = 1 << 3;
3387    ZX_IOB_ACCESS_EP1_CAN_MAP_READ = 1 << 4;
3388    ZX_IOB_ACCESS_EP1_CAN_MAP_WRITE = 1 << 5;
3389    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_READ = 1 << 6;
3390    ZX_IOB_ACCESS_EP1_CAN_MEDIATED_WRITE = 1 << 7;
3391]);
3392
3393#[repr(C)]
3394#[derive(Copy, Clone)]
3395#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3396pub struct zx_iob_discipline_t {
3397    pub r#type: zx_iob_discipline_type_t,
3398    pub extension: zx_iob_discipline_extension_t,
3399}
3400
3401#[repr(C)]
3402#[derive(Copy, Clone)]
3403#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3404pub union zx_iob_discipline_extension_t {
3405    // This is in vdso-next.
3406    pub ring_buffer: zx_iob_discipline_mediated_write_ring_buffer_t,
3407    pub reserved: [PadByte; 64],
3408}
3409
3410#[repr(C)]
3411#[derive(Debug, Copy, Clone)]
3412#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3413pub struct zx_iob_discipline_mediated_write_ring_buffer_t {
3414    pub tag: u64,
3415    pub padding: [PadByte; 56],
3416}
3417
3418multiconst!(zx_iob_discipline_type_t, [
3419    ZX_IOB_DISCIPLINE_TYPE_NONE = 0;
3420    ZX_IOB_DISCIPLINE_TYPE_ID_ALLOCATOR = 1;
3421    ZX_IOB_DISCIPLINE_TYPE_MEDIATED_WRITE_RING_BUFFER = 2;
3422]);
3423
3424pub const ZX_IOB_MAX_REGIONS: usize = 64;
3425
3426#[repr(C)]
3427#[derive(Clone, Copy, Default)]
3428#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3429pub struct zx_iob_region_private_t {
3430    pub options: u32,
3431    pub padding: [PadByte; 28],
3432}
3433
3434#[repr(C)]
3435#[derive(Clone, Copy)]
3436#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3437pub struct zx_iob_region_shared_t {
3438    pub options: u32,
3439    pub shared_region: zx_handle_t,
3440    pub padding: [PadByte; 24],
3441}
3442
3443#[repr(C)]
3444#[derive(Copy, Clone)]
3445#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable))]
3446pub union zx_iob_region_extension_t {
3447    pub private_region: zx_iob_region_private_t,
3448    pub shared_region: zx_iob_region_shared_t,
3449    pub max_extension: [u8; 32],
3450}
3451
3452#[repr(C)]
3453pub struct zx_wake_source_report_entry_t {
3454    pub koid: zx_koid_t,
3455    pub name: [u8; ZX_MAX_NAME_LEN],
3456    pub initial_signal_time: zx_instant_boot_t,
3457    pub last_signal_time: zx_instant_boot_t,
3458    pub last_ack_time: zx_instant_boot_t,
3459    pub signal_count: u32,
3460    pub flags: u32,
3461}
3462
3463#[repr(C)]
3464pub struct zx_wake_source_report_header_t {
3465    pub report_time: zx_instant_boot_t,
3466    pub suspend_start_time: zx_instant_boot_t,
3467    pub total_wake_sources: u32,
3468    pub unreported_wake_report_entries: u32,
3469}
3470
3471#[cfg(test)]
3472mod test {
3473    #[cfg(test)]
3474    extern crate alloc;
3475
3476    use super::*;
3477
3478    #[test]
3479    fn padded_struct_equality() {
3480        let test_struct = zx_clock_update_args_v1_t {
3481            rate_adjust: 222,
3482            padding1: Default::default(),
3483            value: 333,
3484            error_bound: 444,
3485        };
3486
3487        let different_data = zx_clock_update_args_v1_t { rate_adjust: 999, ..test_struct.clone() };
3488
3489        let different_padding = zx_clock_update_args_v1_t {
3490            padding1: [PadByte(0), PadByte(1), PadByte(2), PadByte(3)],
3491            ..test_struct.clone()
3492        };
3493
3494        // Structures with different data should not be equal.
3495        assert_ne!(test_struct, different_data);
3496        // Structures with only different padding should not be equal.
3497        assert_eq!(test_struct, different_padding);
3498    }
3499
3500    #[test]
3501    fn padded_struct_debug() {
3502        let test_struct = zx_clock_update_args_v1_t {
3503            rate_adjust: 222,
3504            padding1: Default::default(),
3505            value: 333,
3506            error_bound: 444,
3507        };
3508        let expectation = "zx_clock_update_args_v1_t { \
3509            rate_adjust: 222, \
3510            padding1: [-, -, -, -], \
3511            value: 333, \
3512            error_bound: 444 }";
3513        assert_eq!(alloc::format!("{:?}", test_struct), expectation);
3514    }
3515}
3516
3517#[repr(C, align(32))]
3518#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
3519#[cfg_attr(feature = "zerocopy", derive(FromBytes, Immutable, IntoBytes, KnownLayout))]
3520pub struct zx_rseq_t {
3521    pub cpu_id: u32,
3522    pub reserved: u32,
3523    pub start_ip: u64,
3524    pub post_commit_offset: u64,
3525    pub abort_ip: u64,
3526}
3527
3528pub const ZX_INFO_INVALID_CPU: u32 = 0xFFFFFFFF;