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/// Rights to map a VMO in read-only mode and read its "content size" property.
21pub const VMO_MAP_READONLY_RIGHTS: fidl::Rights = fidl::Rights::from_bits_truncate(49255);
22
23#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
24pub enum Error {
25    /// Internal error within the principal.
26    Internal,
27    #[doc(hidden)]
28    __SourceBreaking { unknown_ordinal: u32 },
29}
30
31/// Pattern that matches an unknown `Error` member.
32#[macro_export]
33macro_rules! ErrorUnknown {
34    () => {
35        _
36    };
37}
38
39impl Error {
40    #[inline]
41    pub fn from_primitive(prim: u32) -> Option<Self> {
42        match prim {
43            1 => Some(Self::Internal),
44            _ => None,
45        }
46    }
47
48    #[inline]
49    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
50        match prim {
51            1 => Self::Internal,
52            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
53        }
54    }
55
56    #[inline]
57    pub fn unknown() -> Self {
58        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
59    }
60
61    #[inline]
62    pub const fn into_primitive(self) -> u32 {
63        match self {
64            Self::Internal => 1,
65            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
66        }
67    }
68
69    #[inline]
70    pub fn is_unknown(&self) -> bool {
71        match self {
72            Self::__SourceBreaking { unknown_ordinal: _ } => true,
73            _ => false,
74        }
75    }
76}
77
78#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
79pub enum PrincipalType {
80    /// An independent unit of computation that can be described as
81    /// running, such as a component or an application.
82    ///
83    /// Runnable principals will be shown in the default memory view.
84    Runnable,
85    /// A part of another principal that isn't independent, such as a
86    /// cache.
87    ///
88    /// Part principals will be shown in the detailed memory view of the
89    /// principal they are a part of.
90    Part,
91    #[doc(hidden)]
92    __SourceBreaking { unknown_ordinal: u32 },
93}
94
95/// Pattern that matches an unknown `PrincipalType` member.
96#[macro_export]
97macro_rules! PrincipalTypeUnknown {
98    () => {
99        _
100    };
101}
102
103impl PrincipalType {
104    #[inline]
105    pub fn from_primitive(prim: u32) -> Option<Self> {
106        match prim {
107            1 => Some(Self::Runnable),
108            2 => Some(Self::Part),
109            _ => None,
110        }
111    }
112
113    #[inline]
114    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
115        match prim {
116            1 => Self::Runnable,
117            2 => Self::Part,
118            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
119        }
120    }
121
122    #[inline]
123    pub fn unknown() -> Self {
124        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
125    }
126
127    #[inline]
128    pub const fn into_primitive(self) -> u32 {
129        match self {
130            Self::Runnable => 1,
131            Self::Part => 2,
132            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
133        }
134    }
135
136    #[inline]
137    pub fn is_unknown(&self) -> bool {
138        match self {
139            Self::__SourceBreaking { unknown_ordinal: _ } => true,
140            _ => false,
141        }
142    }
143}
144
145#[derive(Clone, Debug, PartialEq)]
146pub struct Data {
147    pub resources: Vec<Resource>,
148}
149
150impl fidl::Persistable for Data {}
151
152#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
153#[repr(C)]
154pub struct ProcessMapped {
155    /// The KOID of the process that this VMAR lives in.
156    pub process: u64,
157    /// Base address of the VMAR.
158    pub base: u64,
159    /// Length of the VMAR.
160    pub len: u64,
161}
162
163impl fidl::Persistable for ProcessMapped {}
164
165#[derive(Clone, Debug)]
166pub enum Resource {
167    /// Identifies a kernel object whose memory is being attributed.
168    ///
169    /// Refers to all memory held by VMOs reachable from the object
170    /// (currently a Job, Process or VMO).
171    KernelObject(u64),
172    /// Identifies a part of a process address space.
173    ///
174    /// This member can be removed if the Zircon kernel exposed KOIDs of
175    /// VMARs in memory mapping object information, in which case we
176    /// can report the VMAR using `kernel_object`.
177    ///
178    /// We should consider a generic KOID + range concept if there are
179    /// other use cases for describing ranges within a resource.
180    ProcessMapped(ProcessMapped),
181    #[doc(hidden)]
182    __SourceBreaking { unknown_ordinal: u64 },
183}
184
185/// Pattern that matches an unknown `Resource` member.
186#[macro_export]
187macro_rules! ResourceUnknown {
188    () => {
189        _
190    };
191}
192
193// Custom PartialEq so that unknown variants are not equal to themselves.
194impl PartialEq for Resource {
195    fn eq(&self, other: &Self) -> bool {
196        match (self, other) {
197            (Self::KernelObject(x), Self::KernelObject(y)) => *x == *y,
198            (Self::ProcessMapped(x), Self::ProcessMapped(y)) => *x == *y,
199            _ => false,
200        }
201    }
202}
203
204impl Resource {
205    #[inline]
206    pub fn ordinal(&self) -> u64 {
207        match *self {
208            Self::KernelObject(_) => 1,
209            Self::ProcessMapped(_) => 2,
210            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
211        }
212    }
213
214    #[inline]
215    pub fn unknown_variant_for_testing() -> Self {
216        Self::__SourceBreaking { unknown_ordinal: 0 }
217    }
218
219    #[inline]
220    pub fn is_unknown(&self) -> bool {
221        match self {
222            Self::__SourceBreaking { .. } => true,
223            _ => false,
224        }
225    }
226}
227
228impl fidl::Persistable for Resource {}
229
230pub mod page_refault_sink_ordinals {
231    pub const SEND_PAGE_REFAULT_COUNT: u64 = 0x1d4f9f7efbb957e3;
232}
233
234pub mod provider_ordinals {
235    pub const GET: u64 = 0x7a2f2d2cdcfcc945;
236}
237
238mod internal {
239    use super::*;
240    unsafe impl fidl::encoding::TypeMarker for Error {
241        type Owned = Self;
242
243        #[inline(always)]
244        fn inline_align(_context: fidl::encoding::Context) -> usize {
245            std::mem::align_of::<u32>()
246        }
247
248        #[inline(always)]
249        fn inline_size(_context: fidl::encoding::Context) -> usize {
250            std::mem::size_of::<u32>()
251        }
252
253        #[inline(always)]
254        fn encode_is_copy() -> bool {
255            false
256        }
257
258        #[inline(always)]
259        fn decode_is_copy() -> bool {
260            false
261        }
262    }
263
264    impl fidl::encoding::ValueTypeMarker for Error {
265        type Borrowed<'a> = Self;
266        #[inline(always)]
267        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
268            *value
269        }
270    }
271
272    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
273        #[inline]
274        unsafe fn encode(
275            self,
276            encoder: &mut fidl::encoding::Encoder<'_, D>,
277            offset: usize,
278            _depth: fidl::encoding::Depth,
279        ) -> fidl::Result<()> {
280            encoder.debug_check_bounds::<Self>(offset);
281            encoder.write_num(self.into_primitive(), offset);
282            Ok(())
283        }
284    }
285
286    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
287        #[inline(always)]
288        fn new_empty() -> Self {
289            Self::unknown()
290        }
291
292        #[inline]
293        unsafe fn decode(
294            &mut self,
295            decoder: &mut fidl::encoding::Decoder<'_, D>,
296            offset: usize,
297            _depth: fidl::encoding::Depth,
298        ) -> fidl::Result<()> {
299            decoder.debug_check_bounds::<Self>(offset);
300            let prim = decoder.read_num::<u32>(offset);
301
302            *self = Self::from_primitive_allow_unknown(prim);
303            Ok(())
304        }
305    }
306    unsafe impl fidl::encoding::TypeMarker for PrincipalType {
307        type Owned = Self;
308
309        #[inline(always)]
310        fn inline_align(_context: fidl::encoding::Context) -> usize {
311            std::mem::align_of::<u32>()
312        }
313
314        #[inline(always)]
315        fn inline_size(_context: fidl::encoding::Context) -> usize {
316            std::mem::size_of::<u32>()
317        }
318
319        #[inline(always)]
320        fn encode_is_copy() -> bool {
321            false
322        }
323
324        #[inline(always)]
325        fn decode_is_copy() -> bool {
326            false
327        }
328    }
329
330    impl fidl::encoding::ValueTypeMarker for PrincipalType {
331        type Borrowed<'a> = Self;
332        #[inline(always)]
333        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
334            *value
335        }
336    }
337
338    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PrincipalType {
339        #[inline]
340        unsafe fn encode(
341            self,
342            encoder: &mut fidl::encoding::Encoder<'_, D>,
343            offset: usize,
344            _depth: fidl::encoding::Depth,
345        ) -> fidl::Result<()> {
346            encoder.debug_check_bounds::<Self>(offset);
347            encoder.write_num(self.into_primitive(), offset);
348            Ok(())
349        }
350    }
351
352    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PrincipalType {
353        #[inline(always)]
354        fn new_empty() -> Self {
355            Self::unknown()
356        }
357
358        #[inline]
359        unsafe fn decode(
360            &mut self,
361            decoder: &mut fidl::encoding::Decoder<'_, D>,
362            offset: usize,
363            _depth: fidl::encoding::Depth,
364        ) -> fidl::Result<()> {
365            decoder.debug_check_bounds::<Self>(offset);
366            let prim = decoder.read_num::<u32>(offset);
367
368            *self = Self::from_primitive_allow_unknown(prim);
369            Ok(())
370        }
371    }
372
373    impl fidl::encoding::ValueTypeMarker for Data {
374        type Borrowed<'a> = &'a Self;
375        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
376            value
377        }
378    }
379
380    unsafe impl fidl::encoding::TypeMarker for Data {
381        type Owned = Self;
382
383        #[inline(always)]
384        fn inline_align(_context: fidl::encoding::Context) -> usize {
385            8
386        }
387
388        #[inline(always)]
389        fn inline_size(_context: fidl::encoding::Context) -> usize {
390            16
391        }
392    }
393
394    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Data, D> for &Data {
395        #[inline]
396        unsafe fn encode(
397            self,
398            encoder: &mut fidl::encoding::Encoder<'_, D>,
399            offset: usize,
400            _depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            encoder.debug_check_bounds::<Data>(offset);
403            // Delegate to tuple encoding.
404            fidl::encoding::Encode::<Data, D>::encode(
405                (
406                    <fidl::encoding::UnboundedVector<Resource> as fidl::encoding::ValueTypeMarker>::borrow(&self.resources),
407                ),
408                encoder, offset, _depth
409            )
410        }
411    }
412    unsafe impl<
413        D: fidl::encoding::ResourceDialect,
414        T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Resource>, D>,
415    > fidl::encoding::Encode<Data, D> for (T0,)
416    {
417        #[inline]
418        unsafe fn encode(
419            self,
420            encoder: &mut fidl::encoding::Encoder<'_, D>,
421            offset: usize,
422            depth: fidl::encoding::Depth,
423        ) -> fidl::Result<()> {
424            encoder.debug_check_bounds::<Data>(offset);
425            // Zero out padding regions. There's no need to apply masks
426            // because the unmasked parts will be overwritten by fields.
427            // Write the fields.
428            self.0.encode(encoder, offset + 0, depth)?;
429            Ok(())
430        }
431    }
432
433    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Data {
434        #[inline(always)]
435        fn new_empty() -> Self {
436            Self { resources: fidl::new_empty!(fidl::encoding::UnboundedVector<Resource>, D) }
437        }
438
439        #[inline]
440        unsafe fn decode(
441            &mut self,
442            decoder: &mut fidl::encoding::Decoder<'_, D>,
443            offset: usize,
444            _depth: fidl::encoding::Depth,
445        ) -> fidl::Result<()> {
446            decoder.debug_check_bounds::<Self>(offset);
447            // Verify that padding bytes are zero.
448            fidl::decode!(
449                fidl::encoding::UnboundedVector<Resource>,
450                D,
451                &mut self.resources,
452                decoder,
453                offset + 0,
454                _depth
455            )?;
456            Ok(())
457        }
458    }
459
460    impl fidl::encoding::ValueTypeMarker for ProcessMapped {
461        type Borrowed<'a> = &'a Self;
462        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
463            value
464        }
465    }
466
467    unsafe impl fidl::encoding::TypeMarker for ProcessMapped {
468        type Owned = Self;
469
470        #[inline(always)]
471        fn inline_align(_context: fidl::encoding::Context) -> usize {
472            8
473        }
474
475        #[inline(always)]
476        fn inline_size(_context: fidl::encoding::Context) -> usize {
477            24
478        }
479        #[inline(always)]
480        fn encode_is_copy() -> bool {
481            true
482        }
483
484        #[inline(always)]
485        fn decode_is_copy() -> bool {
486            true
487        }
488    }
489
490    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ProcessMapped, D>
491        for &ProcessMapped
492    {
493        #[inline]
494        unsafe fn encode(
495            self,
496            encoder: &mut fidl::encoding::Encoder<'_, D>,
497            offset: usize,
498            _depth: fidl::encoding::Depth,
499        ) -> fidl::Result<()> {
500            encoder.debug_check_bounds::<ProcessMapped>(offset);
501            unsafe {
502                // Copy the object into the buffer.
503                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
504                (buf_ptr as *mut ProcessMapped)
505                    .write_unaligned((self as *const ProcessMapped).read());
506                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
507                // done second because the memcpy will write garbage to these bytes.
508            }
509            Ok(())
510        }
511    }
512    unsafe impl<
513        D: fidl::encoding::ResourceDialect,
514        T0: fidl::encoding::Encode<u64, D>,
515        T1: fidl::encoding::Encode<u64, D>,
516        T2: fidl::encoding::Encode<u64, D>,
517    > fidl::encoding::Encode<ProcessMapped, D> for (T0, T1, T2)
518    {
519        #[inline]
520        unsafe fn encode(
521            self,
522            encoder: &mut fidl::encoding::Encoder<'_, D>,
523            offset: usize,
524            depth: fidl::encoding::Depth,
525        ) -> fidl::Result<()> {
526            encoder.debug_check_bounds::<ProcessMapped>(offset);
527            // Zero out padding regions. There's no need to apply masks
528            // because the unmasked parts will be overwritten by fields.
529            // Write the fields.
530            self.0.encode(encoder, offset + 0, depth)?;
531            self.1.encode(encoder, offset + 8, depth)?;
532            self.2.encode(encoder, offset + 16, depth)?;
533            Ok(())
534        }
535    }
536
537    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ProcessMapped {
538        #[inline(always)]
539        fn new_empty() -> Self {
540            Self {
541                process: fidl::new_empty!(u64, D),
542                base: fidl::new_empty!(u64, D),
543                len: fidl::new_empty!(u64, D),
544            }
545        }
546
547        #[inline]
548        unsafe fn decode(
549            &mut self,
550            decoder: &mut fidl::encoding::Decoder<'_, D>,
551            offset: usize,
552            _depth: fidl::encoding::Depth,
553        ) -> fidl::Result<()> {
554            decoder.debug_check_bounds::<Self>(offset);
555            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
556            // Verify that padding bytes are zero.
557            // Copy from the buffer into the object.
558            unsafe {
559                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 24);
560            }
561            Ok(())
562        }
563    }
564
565    impl fidl::encoding::ValueTypeMarker for Resource {
566        type Borrowed<'a> = &'a Self;
567        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
568            value
569        }
570    }
571
572    unsafe impl fidl::encoding::TypeMarker for Resource {
573        type Owned = Self;
574
575        #[inline(always)]
576        fn inline_align(_context: fidl::encoding::Context) -> usize {
577            8
578        }
579
580        #[inline(always)]
581        fn inline_size(_context: fidl::encoding::Context) -> usize {
582            16
583        }
584    }
585
586    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Resource, D> for &Resource {
587        #[inline]
588        unsafe fn encode(
589            self,
590            encoder: &mut fidl::encoding::Encoder<'_, D>,
591            offset: usize,
592            _depth: fidl::encoding::Depth,
593        ) -> fidl::Result<()> {
594            encoder.debug_check_bounds::<Resource>(offset);
595            encoder.write_num::<u64>(self.ordinal(), offset);
596            match self {
597                Resource::KernelObject(ref val) => fidl::encoding::encode_in_envelope::<u64, D>(
598                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(val),
599                    encoder,
600                    offset + 8,
601                    _depth,
602                ),
603                Resource::ProcessMapped(ref val) => {
604                    fidl::encoding::encode_in_envelope::<ProcessMapped, D>(
605                        <ProcessMapped as fidl::encoding::ValueTypeMarker>::borrow(val),
606                        encoder,
607                        offset + 8,
608                        _depth,
609                    )
610                }
611                Resource::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
612            }
613        }
614    }
615
616    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Resource {
617        #[inline(always)]
618        fn new_empty() -> Self {
619            Self::__SourceBreaking { unknown_ordinal: 0 }
620        }
621
622        #[inline]
623        unsafe fn decode(
624            &mut self,
625            decoder: &mut fidl::encoding::Decoder<'_, D>,
626            offset: usize,
627            mut depth: fidl::encoding::Depth,
628        ) -> fidl::Result<()> {
629            decoder.debug_check_bounds::<Self>(offset);
630            #[allow(unused_variables)]
631            let next_out_of_line = decoder.next_out_of_line();
632            let handles_before = decoder.remaining_handles();
633            let (ordinal, inlined, num_bytes, num_handles) =
634                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
635
636            let member_inline_size = match ordinal {
637                1 => <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
638                2 => <ProcessMapped as fidl::encoding::TypeMarker>::inline_size(decoder.context),
639                0 => return Err(fidl::Error::UnknownUnionTag),
640                _ => num_bytes as usize,
641            };
642
643            if inlined != (member_inline_size <= 4) {
644                return Err(fidl::Error::InvalidInlineBitInEnvelope);
645            }
646            let _inner_offset;
647            if inlined {
648                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
649                _inner_offset = offset + 8;
650            } else {
651                depth.increment()?;
652                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
653            }
654            match ordinal {
655                1 => {
656                    #[allow(irrefutable_let_patterns)]
657                    if let Resource::KernelObject(_) = self {
658                        // Do nothing, read the value into the object
659                    } else {
660                        // Initialize `self` to the right variant
661                        *self = Resource::KernelObject(fidl::new_empty!(u64, D));
662                    }
663                    #[allow(irrefutable_let_patterns)]
664                    if let Resource::KernelObject(ref mut val) = self {
665                        fidl::decode!(u64, D, val, decoder, _inner_offset, depth)?;
666                    } else {
667                        unreachable!()
668                    }
669                }
670                2 => {
671                    #[allow(irrefutable_let_patterns)]
672                    if let Resource::ProcessMapped(_) = self {
673                        // Do nothing, read the value into the object
674                    } else {
675                        // Initialize `self` to the right variant
676                        *self = Resource::ProcessMapped(fidl::new_empty!(ProcessMapped, D));
677                    }
678                    #[allow(irrefutable_let_patterns)]
679                    if let Resource::ProcessMapped(ref mut val) = self {
680                        fidl::decode!(ProcessMapped, D, val, decoder, _inner_offset, depth)?;
681                    } else {
682                        unreachable!()
683                    }
684                }
685                #[allow(deprecated)]
686                ordinal => {
687                    for _ in 0..num_handles {
688                        decoder.drop_next_handle()?;
689                    }
690                    *self = Resource::__SourceBreaking { unknown_ordinal: ordinal };
691                }
692            }
693            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
694                return Err(fidl::Error::InvalidNumBytesInEnvelope);
695            }
696            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
697                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
698            }
699            Ok(())
700        }
701    }
702}