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