fidl_fuchsia_memory_attribution__common/
fidl_fuchsia_memory_attribution__common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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
11/// Unique identifier within the scope of an attribution provider, used to
12/// identify a specific principal (Component, part of a Component, etc.)
13/// in attribution updates.
14/// The `0` identifier should be used to point to the source principal itself.
15pub type Identifier = u64;
16
17/// Identifier that refers to the principal that emits the attribution.
18pub const SELF: u64 = 0;
19
20#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
21pub enum Error {
22    /// Internal error within the principal.
23    Internal,
24    #[doc(hidden)]
25    __SourceBreaking { unknown_ordinal: u32 },
26}
27
28/// Pattern that matches an unknown `Error` member.
29#[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    /// An independent unit of computation that can be described as
78    /// running, such as a component or an application.
79    ///
80    /// Runnable principals will be shown in the default memory view.
81    Runnable,
82    /// A part of another principal that isn't independent, such as a
83    /// cache.
84    ///
85    /// Part principals will be shown in the detailed memory view of the
86    /// principal they are a part of.
87    Part,
88    #[doc(hidden)]
89    __SourceBreaking { unknown_ordinal: u32 },
90}
91
92/// Pattern that matches an unknown `PrincipalType` member.
93#[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    /// The KOID of the process that this VMAR lives in.
153    pub process: u64,
154    /// Base address of the VMAR.
155    pub base: u64,
156    /// Length of the VMAR.
157    pub len: u64,
158}
159
160impl fidl::Persistable for ProcessMapped {}
161
162#[derive(Clone, Debug)]
163pub enum Resource {
164    /// Identifies a kernel object whose memory is being attributed.
165    ///
166    /// Refers to all memory held by VMOs reachable from the object
167    /// (currently a Job, Process or VMO).
168    KernelObject(u64),
169    /// Identifies a part of a process address space.
170    ///
171    /// This member can be removed if the Zircon kernel exposed KOIDs of
172    /// VMARs in memory mapping object information, in which case we
173    /// can report the VMAR using `kernel_object`.
174    ///
175    /// We should consider a generic KOID + range concept if there are
176    /// other use cases for describing ranges within a resource.
177    ProcessMapped(ProcessMapped),
178    #[doc(hidden)]
179    __SourceBreaking { unknown_ordinal: u64 },
180}
181
182/// Pattern that matches an unknown `Resource` member.
183#[macro_export]
184macro_rules! ResourceUnknown {
185    () => {
186        _
187    };
188}
189
190// Custom PartialEq so that unknown variants are not equal to themselves.
191impl 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
227pub mod provider_ordinals {
228    pub const GET: u64 = 0x7a2f2d2cdcfcc945;
229}
230
231mod internal {
232    use super::*;
233    unsafe impl fidl::encoding::TypeMarker for Error {
234        type Owned = Self;
235
236        #[inline(always)]
237        fn inline_align(_context: fidl::encoding::Context) -> usize {
238            std::mem::align_of::<u32>()
239        }
240
241        #[inline(always)]
242        fn inline_size(_context: fidl::encoding::Context) -> usize {
243            std::mem::size_of::<u32>()
244        }
245
246        #[inline(always)]
247        fn encode_is_copy() -> bool {
248            false
249        }
250
251        #[inline(always)]
252        fn decode_is_copy() -> bool {
253            false
254        }
255    }
256
257    impl fidl::encoding::ValueTypeMarker for Error {
258        type Borrowed<'a> = Self;
259        #[inline(always)]
260        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
261            *value
262        }
263    }
264
265    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
266        #[inline]
267        unsafe fn encode(
268            self,
269            encoder: &mut fidl::encoding::Encoder<'_, D>,
270            offset: usize,
271            _depth: fidl::encoding::Depth,
272        ) -> fidl::Result<()> {
273            encoder.debug_check_bounds::<Self>(offset);
274            encoder.write_num(self.into_primitive(), offset);
275            Ok(())
276        }
277    }
278
279    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
280        #[inline(always)]
281        fn new_empty() -> Self {
282            Self::unknown()
283        }
284
285        #[inline]
286        unsafe fn decode(
287            &mut self,
288            decoder: &mut fidl::encoding::Decoder<'_, D>,
289            offset: usize,
290            _depth: fidl::encoding::Depth,
291        ) -> fidl::Result<()> {
292            decoder.debug_check_bounds::<Self>(offset);
293            let prim = decoder.read_num::<u32>(offset);
294
295            *self = Self::from_primitive_allow_unknown(prim);
296            Ok(())
297        }
298    }
299    unsafe impl fidl::encoding::TypeMarker for PrincipalType {
300        type Owned = Self;
301
302        #[inline(always)]
303        fn inline_align(_context: fidl::encoding::Context) -> usize {
304            std::mem::align_of::<u32>()
305        }
306
307        #[inline(always)]
308        fn inline_size(_context: fidl::encoding::Context) -> usize {
309            std::mem::size_of::<u32>()
310        }
311
312        #[inline(always)]
313        fn encode_is_copy() -> bool {
314            false
315        }
316
317        #[inline(always)]
318        fn decode_is_copy() -> bool {
319            false
320        }
321    }
322
323    impl fidl::encoding::ValueTypeMarker for PrincipalType {
324        type Borrowed<'a> = Self;
325        #[inline(always)]
326        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
327            *value
328        }
329    }
330
331    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PrincipalType {
332        #[inline]
333        unsafe fn encode(
334            self,
335            encoder: &mut fidl::encoding::Encoder<'_, D>,
336            offset: usize,
337            _depth: fidl::encoding::Depth,
338        ) -> fidl::Result<()> {
339            encoder.debug_check_bounds::<Self>(offset);
340            encoder.write_num(self.into_primitive(), offset);
341            Ok(())
342        }
343    }
344
345    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PrincipalType {
346        #[inline(always)]
347        fn new_empty() -> Self {
348            Self::unknown()
349        }
350
351        #[inline]
352        unsafe fn decode(
353            &mut self,
354            decoder: &mut fidl::encoding::Decoder<'_, D>,
355            offset: usize,
356            _depth: fidl::encoding::Depth,
357        ) -> fidl::Result<()> {
358            decoder.debug_check_bounds::<Self>(offset);
359            let prim = decoder.read_num::<u32>(offset);
360
361            *self = Self::from_primitive_allow_unknown(prim);
362            Ok(())
363        }
364    }
365
366    impl fidl::encoding::ValueTypeMarker for Data {
367        type Borrowed<'a> = &'a Self;
368        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
369            value
370        }
371    }
372
373    unsafe impl fidl::encoding::TypeMarker for Data {
374        type Owned = Self;
375
376        #[inline(always)]
377        fn inline_align(_context: fidl::encoding::Context) -> usize {
378            8
379        }
380
381        #[inline(always)]
382        fn inline_size(_context: fidl::encoding::Context) -> usize {
383            16
384        }
385    }
386
387    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Data, D> for &Data {
388        #[inline]
389        unsafe fn encode(
390            self,
391            encoder: &mut fidl::encoding::Encoder<'_, D>,
392            offset: usize,
393            _depth: fidl::encoding::Depth,
394        ) -> fidl::Result<()> {
395            encoder.debug_check_bounds::<Data>(offset);
396            // Delegate to tuple encoding.
397            fidl::encoding::Encode::<Data, D>::encode(
398                (
399                    <fidl::encoding::UnboundedVector<Resource> as fidl::encoding::ValueTypeMarker>::borrow(&self.resources),
400                ),
401                encoder, offset, _depth
402            )
403        }
404    }
405    unsafe impl<
406            D: fidl::encoding::ResourceDialect,
407            T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Resource>, D>,
408        > fidl::encoding::Encode<Data, D> for (T0,)
409    {
410        #[inline]
411        unsafe fn encode(
412            self,
413            encoder: &mut fidl::encoding::Encoder<'_, D>,
414            offset: usize,
415            depth: fidl::encoding::Depth,
416        ) -> fidl::Result<()> {
417            encoder.debug_check_bounds::<Data>(offset);
418            // Zero out padding regions. There's no need to apply masks
419            // because the unmasked parts will be overwritten by fields.
420            // Write the fields.
421            self.0.encode(encoder, offset + 0, depth)?;
422            Ok(())
423        }
424    }
425
426    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Data {
427        #[inline(always)]
428        fn new_empty() -> Self {
429            Self { resources: fidl::new_empty!(fidl::encoding::UnboundedVector<Resource>, D) }
430        }
431
432        #[inline]
433        unsafe fn decode(
434            &mut self,
435            decoder: &mut fidl::encoding::Decoder<'_, D>,
436            offset: usize,
437            _depth: fidl::encoding::Depth,
438        ) -> fidl::Result<()> {
439            decoder.debug_check_bounds::<Self>(offset);
440            // Verify that padding bytes are zero.
441            fidl::decode!(
442                fidl::encoding::UnboundedVector<Resource>,
443                D,
444                &mut self.resources,
445                decoder,
446                offset + 0,
447                _depth
448            )?;
449            Ok(())
450        }
451    }
452
453    impl fidl::encoding::ValueTypeMarker for ProcessMapped {
454        type Borrowed<'a> = &'a Self;
455        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
456            value
457        }
458    }
459
460    unsafe impl fidl::encoding::TypeMarker for ProcessMapped {
461        type Owned = Self;
462
463        #[inline(always)]
464        fn inline_align(_context: fidl::encoding::Context) -> usize {
465            8
466        }
467
468        #[inline(always)]
469        fn inline_size(_context: fidl::encoding::Context) -> usize {
470            24
471        }
472        #[inline(always)]
473        fn encode_is_copy() -> bool {
474            true
475        }
476
477        #[inline(always)]
478        fn decode_is_copy() -> bool {
479            true
480        }
481    }
482
483    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ProcessMapped, D>
484        for &ProcessMapped
485    {
486        #[inline]
487        unsafe fn encode(
488            self,
489            encoder: &mut fidl::encoding::Encoder<'_, D>,
490            offset: usize,
491            _depth: fidl::encoding::Depth,
492        ) -> fidl::Result<()> {
493            encoder.debug_check_bounds::<ProcessMapped>(offset);
494            unsafe {
495                // Copy the object into the buffer.
496                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
497                (buf_ptr as *mut ProcessMapped)
498                    .write_unaligned((self as *const ProcessMapped).read());
499                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
500                // done second because the memcpy will write garbage to these bytes.
501            }
502            Ok(())
503        }
504    }
505    unsafe impl<
506            D: fidl::encoding::ResourceDialect,
507            T0: fidl::encoding::Encode<u64, D>,
508            T1: fidl::encoding::Encode<u64, D>,
509            T2: fidl::encoding::Encode<u64, D>,
510        > fidl::encoding::Encode<ProcessMapped, D> for (T0, T1, T2)
511    {
512        #[inline]
513        unsafe fn encode(
514            self,
515            encoder: &mut fidl::encoding::Encoder<'_, D>,
516            offset: usize,
517            depth: fidl::encoding::Depth,
518        ) -> fidl::Result<()> {
519            encoder.debug_check_bounds::<ProcessMapped>(offset);
520            // Zero out padding regions. There's no need to apply masks
521            // because the unmasked parts will be overwritten by fields.
522            // Write the fields.
523            self.0.encode(encoder, offset + 0, depth)?;
524            self.1.encode(encoder, offset + 8, depth)?;
525            self.2.encode(encoder, offset + 16, depth)?;
526            Ok(())
527        }
528    }
529
530    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ProcessMapped {
531        #[inline(always)]
532        fn new_empty() -> Self {
533            Self {
534                process: fidl::new_empty!(u64, D),
535                base: fidl::new_empty!(u64, D),
536                len: fidl::new_empty!(u64, D),
537            }
538        }
539
540        #[inline]
541        unsafe fn decode(
542            &mut self,
543            decoder: &mut fidl::encoding::Decoder<'_, D>,
544            offset: usize,
545            _depth: fidl::encoding::Depth,
546        ) -> fidl::Result<()> {
547            decoder.debug_check_bounds::<Self>(offset);
548            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
549            // Verify that padding bytes are zero.
550            // Copy from the buffer into the object.
551            unsafe {
552                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 24);
553            }
554            Ok(())
555        }
556    }
557
558    impl fidl::encoding::ValueTypeMarker for Resource {
559        type Borrowed<'a> = &'a Self;
560        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
561            value
562        }
563    }
564
565    unsafe impl fidl::encoding::TypeMarker for Resource {
566        type Owned = Self;
567
568        #[inline(always)]
569        fn inline_align(_context: fidl::encoding::Context) -> usize {
570            8
571        }
572
573        #[inline(always)]
574        fn inline_size(_context: fidl::encoding::Context) -> usize {
575            16
576        }
577    }
578
579    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Resource, D> for &Resource {
580        #[inline]
581        unsafe fn encode(
582            self,
583            encoder: &mut fidl::encoding::Encoder<'_, D>,
584            offset: usize,
585            _depth: fidl::encoding::Depth,
586        ) -> fidl::Result<()> {
587            encoder.debug_check_bounds::<Resource>(offset);
588            encoder.write_num::<u64>(self.ordinal(), offset);
589            match self {
590                Resource::KernelObject(ref val) => fidl::encoding::encode_in_envelope::<u64, D>(
591                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(val),
592                    encoder,
593                    offset + 8,
594                    _depth,
595                ),
596                Resource::ProcessMapped(ref val) => {
597                    fidl::encoding::encode_in_envelope::<ProcessMapped, D>(
598                        <ProcessMapped as fidl::encoding::ValueTypeMarker>::borrow(val),
599                        encoder,
600                        offset + 8,
601                        _depth,
602                    )
603                }
604                Resource::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
605            }
606        }
607    }
608
609    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Resource {
610        #[inline(always)]
611        fn new_empty() -> Self {
612            Self::__SourceBreaking { unknown_ordinal: 0 }
613        }
614
615        #[inline]
616        unsafe fn decode(
617            &mut self,
618            decoder: &mut fidl::encoding::Decoder<'_, D>,
619            offset: usize,
620            mut depth: fidl::encoding::Depth,
621        ) -> fidl::Result<()> {
622            decoder.debug_check_bounds::<Self>(offset);
623            #[allow(unused_variables)]
624            let next_out_of_line = decoder.next_out_of_line();
625            let handles_before = decoder.remaining_handles();
626            let (ordinal, inlined, num_bytes, num_handles) =
627                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
628
629            let member_inline_size = match ordinal {
630                1 => <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
631                2 => <ProcessMapped as fidl::encoding::TypeMarker>::inline_size(decoder.context),
632                0 => return Err(fidl::Error::UnknownUnionTag),
633                _ => num_bytes as usize,
634            };
635
636            if inlined != (member_inline_size <= 4) {
637                return Err(fidl::Error::InvalidInlineBitInEnvelope);
638            }
639            let _inner_offset;
640            if inlined {
641                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
642                _inner_offset = offset + 8;
643            } else {
644                depth.increment()?;
645                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
646            }
647            match ordinal {
648                1 => {
649                    #[allow(irrefutable_let_patterns)]
650                    if let Resource::KernelObject(_) = self {
651                        // Do nothing, read the value into the object
652                    } else {
653                        // Initialize `self` to the right variant
654                        *self = Resource::KernelObject(fidl::new_empty!(u64, D));
655                    }
656                    #[allow(irrefutable_let_patterns)]
657                    if let Resource::KernelObject(ref mut val) = self {
658                        fidl::decode!(u64, D, val, decoder, _inner_offset, depth)?;
659                    } else {
660                        unreachable!()
661                    }
662                }
663                2 => {
664                    #[allow(irrefutable_let_patterns)]
665                    if let Resource::ProcessMapped(_) = self {
666                        // Do nothing, read the value into the object
667                    } else {
668                        // Initialize `self` to the right variant
669                        *self = Resource::ProcessMapped(fidl::new_empty!(ProcessMapped, D));
670                    }
671                    #[allow(irrefutable_let_patterns)]
672                    if let Resource::ProcessMapped(ref mut val) = self {
673                        fidl::decode!(ProcessMapped, D, val, decoder, _inner_offset, depth)?;
674                    } else {
675                        unreachable!()
676                    }
677                }
678                #[allow(deprecated)]
679                ordinal => {
680                    for _ in 0..num_handles {
681                        decoder.drop_next_handle()?;
682                    }
683                    *self = Resource::__SourceBreaking { unknown_ordinal: ordinal };
684                }
685            }
686            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
687                return Err(fidl::Error::InvalidNumBytesInEnvelope);
688            }
689            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
690                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
691            }
692            Ok(())
693        }
694    }
695}