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