fidl_fuchsia_hardware_tee_common/
fidl_fuchsia_hardware_tee_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
11pub const MAX_NUM_OF_THREAD_POOLS: u32 = 64;
12
13pub const MAX_NUM_OF_TRUSTED_APPS: u32 = 64;
14
15/// Used to inform TEE driver about thread pool configuration
16#[derive(Clone, Debug, Default, PartialEq)]
17pub struct CustomThreadConfig {
18    /// Role name for custom thread pool.
19    pub role: Option<String>,
20    /// Number of threads in the thread pool.
21    pub count: Option<u32>,
22    /// List of TA UUIDs which should be assigned to this thread pool.
23    pub trusted_apps: Option<Vec<fidl_fuchsia_tee::Uuid>>,
24    #[doc(hidden)]
25    pub __source_breaking: fidl::marker::SourceBreaking,
26}
27
28impl fidl::Persistable for CustomThreadConfig {}
29
30/// Passed to the TEE driver in metadata as DEVICE_METADATA_TEE_THREAD_CONFIG
31#[derive(Clone, Debug, Default, PartialEq)]
32pub struct TeeMetadata {
33    /// Number of threads in the default pool.
34    pub default_thread_count: Option<u32>,
35    /// List of custom pool configurations.
36    pub custom_threads: Option<Vec<CustomThreadConfig>>,
37    #[doc(hidden)]
38    pub __source_breaking: fidl::marker::SourceBreaking,
39}
40
41impl fidl::Persistable for TeeMetadata {}
42
43mod internal {
44    use super::*;
45
46    impl CustomThreadConfig {
47        #[inline(always)]
48        fn max_ordinal_present(&self) -> u64 {
49            if let Some(_) = self.trusted_apps {
50                return 3;
51            }
52            if let Some(_) = self.count {
53                return 2;
54            }
55            if let Some(_) = self.role {
56                return 1;
57            }
58            0
59        }
60    }
61
62    impl fidl::encoding::ValueTypeMarker for CustomThreadConfig {
63        type Borrowed<'a> = &'a Self;
64        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
65            value
66        }
67    }
68
69    unsafe impl fidl::encoding::TypeMarker for CustomThreadConfig {
70        type Owned = Self;
71
72        #[inline(always)]
73        fn inline_align(_context: fidl::encoding::Context) -> usize {
74            8
75        }
76
77        #[inline(always)]
78        fn inline_size(_context: fidl::encoding::Context) -> usize {
79            16
80        }
81    }
82
83    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<CustomThreadConfig, D>
84        for &CustomThreadConfig
85    {
86        unsafe fn encode(
87            self,
88            encoder: &mut fidl::encoding::Encoder<'_, D>,
89            offset: usize,
90            mut depth: fidl::encoding::Depth,
91        ) -> fidl::Result<()> {
92            encoder.debug_check_bounds::<CustomThreadConfig>(offset);
93            // Vector header
94            let max_ordinal: u64 = self.max_ordinal_present();
95            encoder.write_num(max_ordinal, offset);
96            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
97            // Calling encoder.out_of_line_offset(0) is not allowed.
98            if max_ordinal == 0 {
99                return Ok(());
100            }
101            depth.increment()?;
102            let envelope_size = 8;
103            let bytes_len = max_ordinal as usize * envelope_size;
104            #[allow(unused_variables)]
105            let offset = encoder.out_of_line_offset(bytes_len);
106            let mut _prev_end_offset: usize = 0;
107            if 1 > max_ordinal {
108                return Ok(());
109            }
110
111            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
112            // are envelope_size bytes.
113            let cur_offset: usize = (1 - 1) * envelope_size;
114
115            // Zero reserved fields.
116            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
117
118            // Safety:
119            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
120            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
121            //   envelope_size bytes, there is always sufficient room.
122            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<2048>, D>(
123            self.role.as_ref().map(<fidl::encoding::BoundedString<2048> as fidl::encoding::ValueTypeMarker>::borrow),
124            encoder, offset + cur_offset, depth
125        )?;
126
127            _prev_end_offset = cur_offset + envelope_size;
128            if 2 > max_ordinal {
129                return Ok(());
130            }
131
132            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
133            // are envelope_size bytes.
134            let cur_offset: usize = (2 - 1) * envelope_size;
135
136            // Zero reserved fields.
137            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
138
139            // Safety:
140            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
141            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
142            //   envelope_size bytes, there is always sufficient room.
143            fidl::encoding::encode_in_envelope_optional::<u32, D>(
144                self.count.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
145                encoder,
146                offset + cur_offset,
147                depth,
148            )?;
149
150            _prev_end_offset = cur_offset + envelope_size;
151            if 3 > max_ordinal {
152                return Ok(());
153            }
154
155            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
156            // are envelope_size bytes.
157            let cur_offset: usize = (3 - 1) * envelope_size;
158
159            // Zero reserved fields.
160            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
161
162            // Safety:
163            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
164            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
165            //   envelope_size bytes, there is always sufficient room.
166            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<fidl_fuchsia_tee::Uuid, 64>, D>(
167            self.trusted_apps.as_ref().map(<fidl::encoding::Vector<fidl_fuchsia_tee::Uuid, 64> as fidl::encoding::ValueTypeMarker>::borrow),
168            encoder, offset + cur_offset, depth
169        )?;
170
171            _prev_end_offset = cur_offset + envelope_size;
172
173            Ok(())
174        }
175    }
176
177    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for CustomThreadConfig {
178        #[inline(always)]
179        fn new_empty() -> Self {
180            Self::default()
181        }
182
183        unsafe fn decode(
184            &mut self,
185            decoder: &mut fidl::encoding::Decoder<'_, D>,
186            offset: usize,
187            mut depth: fidl::encoding::Depth,
188        ) -> fidl::Result<()> {
189            decoder.debug_check_bounds::<Self>(offset);
190            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
191                None => return Err(fidl::Error::NotNullable),
192                Some(len) => len,
193            };
194            // Calling decoder.out_of_line_offset(0) is not allowed.
195            if len == 0 {
196                return Ok(());
197            };
198            depth.increment()?;
199            let envelope_size = 8;
200            let bytes_len = len * envelope_size;
201            let offset = decoder.out_of_line_offset(bytes_len)?;
202            // Decode the envelope for each type.
203            let mut _next_ordinal_to_read = 0;
204            let mut next_offset = offset;
205            let end_offset = offset + bytes_len;
206            _next_ordinal_to_read += 1;
207            if next_offset >= end_offset {
208                return Ok(());
209            }
210
211            // Decode unknown envelopes for gaps in ordinals.
212            while _next_ordinal_to_read < 1 {
213                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
214                _next_ordinal_to_read += 1;
215                next_offset += envelope_size;
216            }
217
218            let next_out_of_line = decoder.next_out_of_line();
219            let handles_before = decoder.remaining_handles();
220            if let Some((inlined, num_bytes, num_handles)) =
221                fidl::encoding::decode_envelope_header(decoder, next_offset)?
222            {
223                let member_inline_size = <fidl::encoding::BoundedString<2048> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
224                if inlined != (member_inline_size <= 4) {
225                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
226                }
227                let inner_offset;
228                let mut inner_depth = depth.clone();
229                if inlined {
230                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
231                    inner_offset = next_offset;
232                } else {
233                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
234                    inner_depth.increment()?;
235                }
236                let val_ref = self.role.get_or_insert_with(|| {
237                    fidl::new_empty!(fidl::encoding::BoundedString<2048>, D)
238                });
239                fidl::decode!(
240                    fidl::encoding::BoundedString<2048>,
241                    D,
242                    val_ref,
243                    decoder,
244                    inner_offset,
245                    inner_depth
246                )?;
247                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
248                {
249                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
250                }
251                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
252                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
253                }
254            }
255
256            next_offset += envelope_size;
257            _next_ordinal_to_read += 1;
258            if next_offset >= end_offset {
259                return Ok(());
260            }
261
262            // Decode unknown envelopes for gaps in ordinals.
263            while _next_ordinal_to_read < 2 {
264                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
265                _next_ordinal_to_read += 1;
266                next_offset += envelope_size;
267            }
268
269            let next_out_of_line = decoder.next_out_of_line();
270            let handles_before = decoder.remaining_handles();
271            if let Some((inlined, num_bytes, num_handles)) =
272                fidl::encoding::decode_envelope_header(decoder, next_offset)?
273            {
274                let member_inline_size =
275                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
276                if inlined != (member_inline_size <= 4) {
277                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
278                }
279                let inner_offset;
280                let mut inner_depth = depth.clone();
281                if inlined {
282                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
283                    inner_offset = next_offset;
284                } else {
285                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
286                    inner_depth.increment()?;
287                }
288                let val_ref = self.count.get_or_insert_with(|| fidl::new_empty!(u32, D));
289                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
290                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
291                {
292                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
293                }
294                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
295                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
296                }
297            }
298
299            next_offset += envelope_size;
300            _next_ordinal_to_read += 1;
301            if next_offset >= end_offset {
302                return Ok(());
303            }
304
305            // Decode unknown envelopes for gaps in ordinals.
306            while _next_ordinal_to_read < 3 {
307                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
308                _next_ordinal_to_read += 1;
309                next_offset += envelope_size;
310            }
311
312            let next_out_of_line = decoder.next_out_of_line();
313            let handles_before = decoder.remaining_handles();
314            if let Some((inlined, num_bytes, num_handles)) =
315                fidl::encoding::decode_envelope_header(decoder, next_offset)?
316            {
317                let member_inline_size = <fidl::encoding::Vector<fidl_fuchsia_tee::Uuid, 64> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
318                if inlined != (member_inline_size <= 4) {
319                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
320                }
321                let inner_offset;
322                let mut inner_depth = depth.clone();
323                if inlined {
324                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
325                    inner_offset = next_offset;
326                } else {
327                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
328                    inner_depth.increment()?;
329                }
330                let val_ref = self.trusted_apps.get_or_insert_with(
331                    || fidl::new_empty!(fidl::encoding::Vector<fidl_fuchsia_tee::Uuid, 64>, D),
332                );
333                fidl::decode!(fidl::encoding::Vector<fidl_fuchsia_tee::Uuid, 64>, D, val_ref, decoder, inner_offset, inner_depth)?;
334                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
335                {
336                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
337                }
338                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
339                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
340                }
341            }
342
343            next_offset += envelope_size;
344
345            // Decode the remaining unknown envelopes.
346            while next_offset < end_offset {
347                _next_ordinal_to_read += 1;
348                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
349                next_offset += envelope_size;
350            }
351
352            Ok(())
353        }
354    }
355
356    impl TeeMetadata {
357        #[inline(always)]
358        fn max_ordinal_present(&self) -> u64 {
359            if let Some(_) = self.custom_threads {
360                return 2;
361            }
362            if let Some(_) = self.default_thread_count {
363                return 1;
364            }
365            0
366        }
367    }
368
369    impl fidl::encoding::ValueTypeMarker for TeeMetadata {
370        type Borrowed<'a> = &'a Self;
371        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
372            value
373        }
374    }
375
376    unsafe impl fidl::encoding::TypeMarker for TeeMetadata {
377        type Owned = Self;
378
379        #[inline(always)]
380        fn inline_align(_context: fidl::encoding::Context) -> usize {
381            8
382        }
383
384        #[inline(always)]
385        fn inline_size(_context: fidl::encoding::Context) -> usize {
386            16
387        }
388    }
389
390    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<TeeMetadata, D>
391        for &TeeMetadata
392    {
393        unsafe fn encode(
394            self,
395            encoder: &mut fidl::encoding::Encoder<'_, D>,
396            offset: usize,
397            mut depth: fidl::encoding::Depth,
398        ) -> fidl::Result<()> {
399            encoder.debug_check_bounds::<TeeMetadata>(offset);
400            // Vector header
401            let max_ordinal: u64 = self.max_ordinal_present();
402            encoder.write_num(max_ordinal, offset);
403            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
404            // Calling encoder.out_of_line_offset(0) is not allowed.
405            if max_ordinal == 0 {
406                return Ok(());
407            }
408            depth.increment()?;
409            let envelope_size = 8;
410            let bytes_len = max_ordinal as usize * envelope_size;
411            #[allow(unused_variables)]
412            let offset = encoder.out_of_line_offset(bytes_len);
413            let mut _prev_end_offset: usize = 0;
414            if 1 > max_ordinal {
415                return Ok(());
416            }
417
418            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
419            // are envelope_size bytes.
420            let cur_offset: usize = (1 - 1) * envelope_size;
421
422            // Zero reserved fields.
423            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
424
425            // Safety:
426            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
427            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
428            //   envelope_size bytes, there is always sufficient room.
429            fidl::encoding::encode_in_envelope_optional::<u32, D>(
430                self.default_thread_count
431                    .as_ref()
432                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
433                encoder,
434                offset + cur_offset,
435                depth,
436            )?;
437
438            _prev_end_offset = cur_offset + envelope_size;
439            if 2 > max_ordinal {
440                return Ok(());
441            }
442
443            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
444            // are envelope_size bytes.
445            let cur_offset: usize = (2 - 1) * envelope_size;
446
447            // Zero reserved fields.
448            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
449
450            // Safety:
451            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
452            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
453            //   envelope_size bytes, there is always sufficient room.
454            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<CustomThreadConfig, 64>, D>(
455            self.custom_threads.as_ref().map(<fidl::encoding::Vector<CustomThreadConfig, 64> as fidl::encoding::ValueTypeMarker>::borrow),
456            encoder, offset + cur_offset, depth
457        )?;
458
459            _prev_end_offset = cur_offset + envelope_size;
460
461            Ok(())
462        }
463    }
464
465    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for TeeMetadata {
466        #[inline(always)]
467        fn new_empty() -> Self {
468            Self::default()
469        }
470
471        unsafe fn decode(
472            &mut self,
473            decoder: &mut fidl::encoding::Decoder<'_, D>,
474            offset: usize,
475            mut depth: fidl::encoding::Depth,
476        ) -> fidl::Result<()> {
477            decoder.debug_check_bounds::<Self>(offset);
478            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
479                None => return Err(fidl::Error::NotNullable),
480                Some(len) => len,
481            };
482            // Calling decoder.out_of_line_offset(0) is not allowed.
483            if len == 0 {
484                return Ok(());
485            };
486            depth.increment()?;
487            let envelope_size = 8;
488            let bytes_len = len * envelope_size;
489            let offset = decoder.out_of_line_offset(bytes_len)?;
490            // Decode the envelope for each type.
491            let mut _next_ordinal_to_read = 0;
492            let mut next_offset = offset;
493            let end_offset = offset + bytes_len;
494            _next_ordinal_to_read += 1;
495            if next_offset >= end_offset {
496                return Ok(());
497            }
498
499            // Decode unknown envelopes for gaps in ordinals.
500            while _next_ordinal_to_read < 1 {
501                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
502                _next_ordinal_to_read += 1;
503                next_offset += envelope_size;
504            }
505
506            let next_out_of_line = decoder.next_out_of_line();
507            let handles_before = decoder.remaining_handles();
508            if let Some((inlined, num_bytes, num_handles)) =
509                fidl::encoding::decode_envelope_header(decoder, next_offset)?
510            {
511                let member_inline_size =
512                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
513                if inlined != (member_inline_size <= 4) {
514                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
515                }
516                let inner_offset;
517                let mut inner_depth = depth.clone();
518                if inlined {
519                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
520                    inner_offset = next_offset;
521                } else {
522                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
523                    inner_depth.increment()?;
524                }
525                let val_ref =
526                    self.default_thread_count.get_or_insert_with(|| fidl::new_empty!(u32, D));
527                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
528                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
529                {
530                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
531                }
532                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
533                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
534                }
535            }
536
537            next_offset += envelope_size;
538            _next_ordinal_to_read += 1;
539            if next_offset >= end_offset {
540                return Ok(());
541            }
542
543            // Decode unknown envelopes for gaps in ordinals.
544            while _next_ordinal_to_read < 2 {
545                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
546                _next_ordinal_to_read += 1;
547                next_offset += envelope_size;
548            }
549
550            let next_out_of_line = decoder.next_out_of_line();
551            let handles_before = decoder.remaining_handles();
552            if let Some((inlined, num_bytes, num_handles)) =
553                fidl::encoding::decode_envelope_header(decoder, next_offset)?
554            {
555                let member_inline_size = <fidl::encoding::Vector<CustomThreadConfig, 64> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
556                if inlined != (member_inline_size <= 4) {
557                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
558                }
559                let inner_offset;
560                let mut inner_depth = depth.clone();
561                if inlined {
562                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
563                    inner_offset = next_offset;
564                } else {
565                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
566                    inner_depth.increment()?;
567                }
568                let val_ref = self.custom_threads.get_or_insert_with(
569                    || fidl::new_empty!(fidl::encoding::Vector<CustomThreadConfig, 64>, D),
570                );
571                fidl::decode!(fidl::encoding::Vector<CustomThreadConfig, 64>, D, val_ref, decoder, inner_offset, inner_depth)?;
572                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
573                {
574                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
575                }
576                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
577                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
578                }
579            }
580
581            next_offset += envelope_size;
582
583            // Decode the remaining unknown envelopes.
584            while next_offset < end_offset {
585                _next_ordinal_to_read += 1;
586                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
587                next_offset += envelope_size;
588            }
589
590            Ok(())
591        }
592    }
593}