1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11pub type Identifier = u64;
16
17pub const SELF: u64 = 0;
19
20#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
21pub enum Error {
22 Internal,
24 #[doc(hidden)]
25 __SourceBreaking { unknown_ordinal: u32 },
26}
27
28#[macro_export]
30macro_rules! ErrorUnknown {
31 () => {
32 _
33 };
34}
35
36impl Error {
37 #[inline]
38 pub fn from_primitive(prim: u32) -> Option<Self> {
39 match prim {
40 1 => Some(Self::Internal),
41 _ => None,
42 }
43 }
44
45 #[inline]
46 pub fn from_primitive_allow_unknown(prim: u32) -> Self {
47 match prim {
48 1 => Self::Internal,
49 unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
50 }
51 }
52
53 #[inline]
54 pub fn unknown() -> Self {
55 Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
56 }
57
58 #[inline]
59 pub const fn into_primitive(self) -> u32 {
60 match self {
61 Self::Internal => 1,
62 Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
63 }
64 }
65
66 #[inline]
67 pub fn is_unknown(&self) -> bool {
68 match self {
69 Self::__SourceBreaking { unknown_ordinal: _ } => true,
70 _ => false,
71 }
72 }
73}
74
75#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
76pub enum PrincipalType {
77 Runnable,
82 Part,
88 #[doc(hidden)]
89 __SourceBreaking { unknown_ordinal: u32 },
90}
91
92#[macro_export]
94macro_rules! PrincipalTypeUnknown {
95 () => {
96 _
97 };
98}
99
100impl PrincipalType {
101 #[inline]
102 pub fn from_primitive(prim: u32) -> Option<Self> {
103 match prim {
104 1 => Some(Self::Runnable),
105 2 => Some(Self::Part),
106 _ => None,
107 }
108 }
109
110 #[inline]
111 pub fn from_primitive_allow_unknown(prim: u32) -> Self {
112 match prim {
113 1 => Self::Runnable,
114 2 => Self::Part,
115 unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
116 }
117 }
118
119 #[inline]
120 pub fn unknown() -> Self {
121 Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
122 }
123
124 #[inline]
125 pub const fn into_primitive(self) -> u32 {
126 match self {
127 Self::Runnable => 1,
128 Self::Part => 2,
129 Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
130 }
131 }
132
133 #[inline]
134 pub fn is_unknown(&self) -> bool {
135 match self {
136 Self::__SourceBreaking { unknown_ordinal: _ } => true,
137 _ => false,
138 }
139 }
140}
141
142#[derive(Clone, Debug, PartialEq)]
143pub struct Data {
144 pub resources: Vec<Resource>,
145}
146
147impl fidl::Persistable for Data {}
148
149#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
150#[repr(C)]
151pub struct ProcessMapped {
152 pub process: u64,
154 pub base: u64,
156 pub len: u64,
158}
159
160impl fidl::Persistable for ProcessMapped {}
161
162#[derive(Clone, Debug)]
163pub enum Resource {
164 KernelObject(u64),
169 ProcessMapped(ProcessMapped),
178 #[doc(hidden)]
179 __SourceBreaking { unknown_ordinal: u64 },
180}
181
182#[macro_export]
184macro_rules! ResourceUnknown {
185 () => {
186 _
187 };
188}
189
190impl PartialEq for Resource {
192 fn eq(&self, other: &Self) -> bool {
193 match (self, other) {
194 (Self::KernelObject(x), Self::KernelObject(y)) => *x == *y,
195 (Self::ProcessMapped(x), Self::ProcessMapped(y)) => *x == *y,
196 _ => false,
197 }
198 }
199}
200
201impl Resource {
202 #[inline]
203 pub fn ordinal(&self) -> u64 {
204 match *self {
205 Self::KernelObject(_) => 1,
206 Self::ProcessMapped(_) => 2,
207 Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
208 }
209 }
210
211 #[inline]
212 pub fn unknown_variant_for_testing() -> Self {
213 Self::__SourceBreaking { unknown_ordinal: 0 }
214 }
215
216 #[inline]
217 pub fn is_unknown(&self) -> bool {
218 match self {
219 Self::__SourceBreaking { .. } => true,
220 _ => false,
221 }
222 }
223}
224
225impl fidl::Persistable for Resource {}
226
227mod internal {
228 use super::*;
229 unsafe impl fidl::encoding::TypeMarker for Error {
230 type Owned = Self;
231
232 #[inline(always)]
233 fn inline_align(_context: fidl::encoding::Context) -> usize {
234 std::mem::align_of::<u32>()
235 }
236
237 #[inline(always)]
238 fn inline_size(_context: fidl::encoding::Context) -> usize {
239 std::mem::size_of::<u32>()
240 }
241
242 #[inline(always)]
243 fn encode_is_copy() -> bool {
244 false
245 }
246
247 #[inline(always)]
248 fn decode_is_copy() -> bool {
249 false
250 }
251 }
252
253 impl fidl::encoding::ValueTypeMarker for Error {
254 type Borrowed<'a> = Self;
255 #[inline(always)]
256 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
257 *value
258 }
259 }
260
261 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
262 #[inline]
263 unsafe fn encode(
264 self,
265 encoder: &mut fidl::encoding::Encoder<'_, D>,
266 offset: usize,
267 _depth: fidl::encoding::Depth,
268 ) -> fidl::Result<()> {
269 encoder.debug_check_bounds::<Self>(offset);
270 encoder.write_num(self.into_primitive(), offset);
271 Ok(())
272 }
273 }
274
275 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
276 #[inline(always)]
277 fn new_empty() -> Self {
278 Self::unknown()
279 }
280
281 #[inline]
282 unsafe fn decode(
283 &mut self,
284 decoder: &mut fidl::encoding::Decoder<'_, D>,
285 offset: usize,
286 _depth: fidl::encoding::Depth,
287 ) -> fidl::Result<()> {
288 decoder.debug_check_bounds::<Self>(offset);
289 let prim = decoder.read_num::<u32>(offset);
290
291 *self = Self::from_primitive_allow_unknown(prim);
292 Ok(())
293 }
294 }
295 unsafe impl fidl::encoding::TypeMarker for PrincipalType {
296 type Owned = Self;
297
298 #[inline(always)]
299 fn inline_align(_context: fidl::encoding::Context) -> usize {
300 std::mem::align_of::<u32>()
301 }
302
303 #[inline(always)]
304 fn inline_size(_context: fidl::encoding::Context) -> usize {
305 std::mem::size_of::<u32>()
306 }
307
308 #[inline(always)]
309 fn encode_is_copy() -> bool {
310 false
311 }
312
313 #[inline(always)]
314 fn decode_is_copy() -> bool {
315 false
316 }
317 }
318
319 impl fidl::encoding::ValueTypeMarker for PrincipalType {
320 type Borrowed<'a> = Self;
321 #[inline(always)]
322 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
323 *value
324 }
325 }
326
327 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PrincipalType {
328 #[inline]
329 unsafe fn encode(
330 self,
331 encoder: &mut fidl::encoding::Encoder<'_, D>,
332 offset: usize,
333 _depth: fidl::encoding::Depth,
334 ) -> fidl::Result<()> {
335 encoder.debug_check_bounds::<Self>(offset);
336 encoder.write_num(self.into_primitive(), offset);
337 Ok(())
338 }
339 }
340
341 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PrincipalType {
342 #[inline(always)]
343 fn new_empty() -> Self {
344 Self::unknown()
345 }
346
347 #[inline]
348 unsafe fn decode(
349 &mut self,
350 decoder: &mut fidl::encoding::Decoder<'_, D>,
351 offset: usize,
352 _depth: fidl::encoding::Depth,
353 ) -> fidl::Result<()> {
354 decoder.debug_check_bounds::<Self>(offset);
355 let prim = decoder.read_num::<u32>(offset);
356
357 *self = Self::from_primitive_allow_unknown(prim);
358 Ok(())
359 }
360 }
361
362 impl fidl::encoding::ValueTypeMarker for Data {
363 type Borrowed<'a> = &'a Self;
364 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
365 value
366 }
367 }
368
369 unsafe impl fidl::encoding::TypeMarker for Data {
370 type Owned = Self;
371
372 #[inline(always)]
373 fn inline_align(_context: fidl::encoding::Context) -> usize {
374 8
375 }
376
377 #[inline(always)]
378 fn inline_size(_context: fidl::encoding::Context) -> usize {
379 16
380 }
381 }
382
383 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Data, D> for &Data {
384 #[inline]
385 unsafe fn encode(
386 self,
387 encoder: &mut fidl::encoding::Encoder<'_, D>,
388 offset: usize,
389 _depth: fidl::encoding::Depth,
390 ) -> fidl::Result<()> {
391 encoder.debug_check_bounds::<Data>(offset);
392 fidl::encoding::Encode::<Data, D>::encode(
394 (
395 <fidl::encoding::UnboundedVector<Resource> as fidl::encoding::ValueTypeMarker>::borrow(&self.resources),
396 ),
397 encoder, offset, _depth
398 )
399 }
400 }
401 unsafe impl<
402 D: fidl::encoding::ResourceDialect,
403 T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Resource>, D>,
404 > fidl::encoding::Encode<Data, D> for (T0,)
405 {
406 #[inline]
407 unsafe fn encode(
408 self,
409 encoder: &mut fidl::encoding::Encoder<'_, D>,
410 offset: usize,
411 depth: fidl::encoding::Depth,
412 ) -> fidl::Result<()> {
413 encoder.debug_check_bounds::<Data>(offset);
414 self.0.encode(encoder, offset + 0, depth)?;
418 Ok(())
419 }
420 }
421
422 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Data {
423 #[inline(always)]
424 fn new_empty() -> Self {
425 Self { resources: fidl::new_empty!(fidl::encoding::UnboundedVector<Resource>, D) }
426 }
427
428 #[inline]
429 unsafe fn decode(
430 &mut self,
431 decoder: &mut fidl::encoding::Decoder<'_, D>,
432 offset: usize,
433 _depth: fidl::encoding::Depth,
434 ) -> fidl::Result<()> {
435 decoder.debug_check_bounds::<Self>(offset);
436 fidl::decode!(
438 fidl::encoding::UnboundedVector<Resource>,
439 D,
440 &mut self.resources,
441 decoder,
442 offset + 0,
443 _depth
444 )?;
445 Ok(())
446 }
447 }
448
449 impl fidl::encoding::ValueTypeMarker for ProcessMapped {
450 type Borrowed<'a> = &'a Self;
451 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
452 value
453 }
454 }
455
456 unsafe impl fidl::encoding::TypeMarker for ProcessMapped {
457 type Owned = Self;
458
459 #[inline(always)]
460 fn inline_align(_context: fidl::encoding::Context) -> usize {
461 8
462 }
463
464 #[inline(always)]
465 fn inline_size(_context: fidl::encoding::Context) -> usize {
466 24
467 }
468 #[inline(always)]
469 fn encode_is_copy() -> bool {
470 true
471 }
472
473 #[inline(always)]
474 fn decode_is_copy() -> bool {
475 true
476 }
477 }
478
479 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ProcessMapped, D>
480 for &ProcessMapped
481 {
482 #[inline]
483 unsafe fn encode(
484 self,
485 encoder: &mut fidl::encoding::Encoder<'_, D>,
486 offset: usize,
487 _depth: fidl::encoding::Depth,
488 ) -> fidl::Result<()> {
489 encoder.debug_check_bounds::<ProcessMapped>(offset);
490 unsafe {
491 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
493 (buf_ptr as *mut ProcessMapped)
494 .write_unaligned((self as *const ProcessMapped).read());
495 }
498 Ok(())
499 }
500 }
501 unsafe impl<
502 D: fidl::encoding::ResourceDialect,
503 T0: fidl::encoding::Encode<u64, D>,
504 T1: fidl::encoding::Encode<u64, D>,
505 T2: fidl::encoding::Encode<u64, D>,
506 > fidl::encoding::Encode<ProcessMapped, D> for (T0, T1, T2)
507 {
508 #[inline]
509 unsafe fn encode(
510 self,
511 encoder: &mut fidl::encoding::Encoder<'_, D>,
512 offset: usize,
513 depth: fidl::encoding::Depth,
514 ) -> fidl::Result<()> {
515 encoder.debug_check_bounds::<ProcessMapped>(offset);
516 self.0.encode(encoder, offset + 0, depth)?;
520 self.1.encode(encoder, offset + 8, depth)?;
521 self.2.encode(encoder, offset + 16, depth)?;
522 Ok(())
523 }
524 }
525
526 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ProcessMapped {
527 #[inline(always)]
528 fn new_empty() -> Self {
529 Self {
530 process: fidl::new_empty!(u64, D),
531 base: fidl::new_empty!(u64, D),
532 len: fidl::new_empty!(u64, D),
533 }
534 }
535
536 #[inline]
537 unsafe fn decode(
538 &mut self,
539 decoder: &mut fidl::encoding::Decoder<'_, D>,
540 offset: usize,
541 _depth: fidl::encoding::Depth,
542 ) -> fidl::Result<()> {
543 decoder.debug_check_bounds::<Self>(offset);
544 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
545 unsafe {
548 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 24);
549 }
550 Ok(())
551 }
552 }
553
554 impl fidl::encoding::ValueTypeMarker for Resource {
555 type Borrowed<'a> = &'a Self;
556 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
557 value
558 }
559 }
560
561 unsafe impl fidl::encoding::TypeMarker for Resource {
562 type Owned = Self;
563
564 #[inline(always)]
565 fn inline_align(_context: fidl::encoding::Context) -> usize {
566 8
567 }
568
569 #[inline(always)]
570 fn inline_size(_context: fidl::encoding::Context) -> usize {
571 16
572 }
573 }
574
575 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Resource, D> for &Resource {
576 #[inline]
577 unsafe fn encode(
578 self,
579 encoder: &mut fidl::encoding::Encoder<'_, D>,
580 offset: usize,
581 _depth: fidl::encoding::Depth,
582 ) -> fidl::Result<()> {
583 encoder.debug_check_bounds::<Resource>(offset);
584 encoder.write_num::<u64>(self.ordinal(), offset);
585 match self {
586 Resource::KernelObject(ref val) => fidl::encoding::encode_in_envelope::<u64, D>(
587 <u64 as fidl::encoding::ValueTypeMarker>::borrow(val),
588 encoder,
589 offset + 8,
590 _depth,
591 ),
592 Resource::ProcessMapped(ref val) => {
593 fidl::encoding::encode_in_envelope::<ProcessMapped, D>(
594 <ProcessMapped as fidl::encoding::ValueTypeMarker>::borrow(val),
595 encoder,
596 offset + 8,
597 _depth,
598 )
599 }
600 Resource::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
601 }
602 }
603 }
604
605 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Resource {
606 #[inline(always)]
607 fn new_empty() -> Self {
608 Self::__SourceBreaking { unknown_ordinal: 0 }
609 }
610
611 #[inline]
612 unsafe fn decode(
613 &mut self,
614 decoder: &mut fidl::encoding::Decoder<'_, D>,
615 offset: usize,
616 mut depth: fidl::encoding::Depth,
617 ) -> fidl::Result<()> {
618 decoder.debug_check_bounds::<Self>(offset);
619 #[allow(unused_variables)]
620 let next_out_of_line = decoder.next_out_of_line();
621 let handles_before = decoder.remaining_handles();
622 let (ordinal, inlined, num_bytes, num_handles) =
623 fidl::encoding::decode_union_inline_portion(decoder, offset)?;
624
625 let member_inline_size = match ordinal {
626 1 => <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
627 2 => <ProcessMapped as fidl::encoding::TypeMarker>::inline_size(decoder.context),
628 0 => return Err(fidl::Error::UnknownUnionTag),
629 _ => num_bytes as usize,
630 };
631
632 if inlined != (member_inline_size <= 4) {
633 return Err(fidl::Error::InvalidInlineBitInEnvelope);
634 }
635 let _inner_offset;
636 if inlined {
637 decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
638 _inner_offset = offset + 8;
639 } else {
640 depth.increment()?;
641 _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
642 }
643 match ordinal {
644 1 => {
645 #[allow(irrefutable_let_patterns)]
646 if let Resource::KernelObject(_) = self {
647 } else {
649 *self = Resource::KernelObject(fidl::new_empty!(u64, D));
651 }
652 #[allow(irrefutable_let_patterns)]
653 if let Resource::KernelObject(ref mut val) = self {
654 fidl::decode!(u64, D, val, decoder, _inner_offset, depth)?;
655 } else {
656 unreachable!()
657 }
658 }
659 2 => {
660 #[allow(irrefutable_let_patterns)]
661 if let Resource::ProcessMapped(_) = self {
662 } else {
664 *self = Resource::ProcessMapped(fidl::new_empty!(ProcessMapped, D));
666 }
667 #[allow(irrefutable_let_patterns)]
668 if let Resource::ProcessMapped(ref mut val) = self {
669 fidl::decode!(ProcessMapped, D, val, decoder, _inner_offset, depth)?;
670 } else {
671 unreachable!()
672 }
673 }
674 #[allow(deprecated)]
675 ordinal => {
676 for _ in 0..num_handles {
677 decoder.drop_next_handle()?;
678 }
679 *self = Resource::__SourceBreaking { unknown_ordinal: ordinal };
680 }
681 }
682 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
683 return Err(fidl::Error::InvalidNumBytesInEnvelope);
684 }
685 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
686 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
687 }
688 Ok(())
689 }
690 }
691}