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 const MAX_PROGRAM_INSTRUCTIONS: u32 = 4096;
13
14pub const MAX_PROGRAM_MAPS: u32 = 4096;
16
17bitflags! {
18 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
20 pub struct MapFlags: u32 {
21 const NO_PREALLOC = 1;
23 const SYSCALL_READ_ONLY = 2;
25 const SYSCALL_WRITE_ONLY = 4;
27 const MMAPABLE = 8;
29 }
30}
31
32impl MapFlags {
33 #[inline(always)]
34 pub fn from_bits_allow_unknown(bits: u32) -> Self {
35 Self::from_bits_retain(bits)
36 }
37
38 #[inline(always)]
39 pub fn has_unknown_bits(&self) -> bool {
40 self.get_unknown_bits() != 0
41 }
42
43 #[inline(always)]
44 pub fn get_unknown_bits(&self) -> u32 {
45 self.bits() & !Self::all().bits()
46 }
47}
48
49#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
51#[repr(u32)]
52pub enum MapType {
53 Array = 1,
55 HashMap = 2,
57 RingBuffer = 3,
59 PercpuArray = 4,
61 PercpuHash = 5,
63 DevmapHash = 6,
66 LpmTrie = 7,
68 LruHash = 8,
70 SkStorage = 9,
72}
73
74impl MapType {
75 #[inline]
76 pub fn from_primitive(prim: u32) -> Option<Self> {
77 match prim {
78 1 => Some(Self::Array),
79 2 => Some(Self::HashMap),
80 3 => Some(Self::RingBuffer),
81 4 => Some(Self::PercpuArray),
82 5 => Some(Self::PercpuHash),
83 6 => Some(Self::DevmapHash),
84 7 => Some(Self::LpmTrie),
85 8 => Some(Self::LruHash),
86 9 => Some(Self::SkStorage),
87 _ => None,
88 }
89 }
90
91 #[inline]
92 pub const fn into_primitive(self) -> u32 {
93 self as u32
94 }
95}
96
97#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
99pub struct MapSchema {
100 pub type_: MapType,
102 pub key_size: u32,
104 pub value_size: u32,
106 pub max_entries: u32,
108 pub flags: MapFlags,
110}
111
112impl fidl::Persistable for MapSchema {}
113
114#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
119pub struct StructAccess {
120 pub pc: u32,
122 pub struct_memory_id: u64,
124 pub field_offset: u32,
126 pub is_32_bit_ptr_load: bool,
129}
130
131impl fidl::Persistable for StructAccess {}
132
133mod internal {
134 use super::*;
135 unsafe impl fidl::encoding::TypeMarker for MapFlags {
136 type Owned = Self;
137
138 #[inline(always)]
139 fn inline_align(_context: fidl::encoding::Context) -> usize {
140 4
141 }
142
143 #[inline(always)]
144 fn inline_size(_context: fidl::encoding::Context) -> usize {
145 4
146 }
147 }
148
149 impl fidl::encoding::ValueTypeMarker for MapFlags {
150 type Borrowed<'a> = Self;
151 #[inline(always)]
152 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
153 *value
154 }
155 }
156
157 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for MapFlags {
158 #[inline]
159 unsafe fn encode(
160 self,
161 encoder: &mut fidl::encoding::Encoder<'_, D>,
162 offset: usize,
163 _depth: fidl::encoding::Depth,
164 ) -> fidl::Result<()> {
165 encoder.debug_check_bounds::<Self>(offset);
166 encoder.write_num(self.bits(), offset);
167 Ok(())
168 }
169 }
170
171 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MapFlags {
172 #[inline(always)]
173 fn new_empty() -> Self {
174 Self::empty()
175 }
176
177 #[inline]
178 unsafe fn decode(
179 &mut self,
180 decoder: &mut fidl::encoding::Decoder<'_, D>,
181 offset: usize,
182 _depth: fidl::encoding::Depth,
183 ) -> fidl::Result<()> {
184 decoder.debug_check_bounds::<Self>(offset);
185 let prim = decoder.read_num::<u32>(offset);
186 *self = Self::from_bits_allow_unknown(prim);
187 Ok(())
188 }
189 }
190 unsafe impl fidl::encoding::TypeMarker for MapType {
191 type Owned = Self;
192
193 #[inline(always)]
194 fn inline_align(_context: fidl::encoding::Context) -> usize {
195 std::mem::align_of::<u32>()
196 }
197
198 #[inline(always)]
199 fn inline_size(_context: fidl::encoding::Context) -> usize {
200 std::mem::size_of::<u32>()
201 }
202
203 #[inline(always)]
204 fn encode_is_copy() -> bool {
205 true
206 }
207
208 #[inline(always)]
209 fn decode_is_copy() -> bool {
210 false
211 }
212 }
213
214 impl fidl::encoding::ValueTypeMarker for MapType {
215 type Borrowed<'a> = Self;
216 #[inline(always)]
217 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
218 *value
219 }
220 }
221
222 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for MapType {
223 #[inline]
224 unsafe fn encode(
225 self,
226 encoder: &mut fidl::encoding::Encoder<'_, D>,
227 offset: usize,
228 _depth: fidl::encoding::Depth,
229 ) -> fidl::Result<()> {
230 encoder.debug_check_bounds::<Self>(offset);
231 encoder.write_num(self.into_primitive(), offset);
232 Ok(())
233 }
234 }
235
236 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MapType {
237 #[inline(always)]
238 fn new_empty() -> Self {
239 Self::Array
240 }
241
242 #[inline]
243 unsafe fn decode(
244 &mut self,
245 decoder: &mut fidl::encoding::Decoder<'_, D>,
246 offset: usize,
247 _depth: fidl::encoding::Depth,
248 ) -> fidl::Result<()> {
249 decoder.debug_check_bounds::<Self>(offset);
250 let prim = decoder.read_num::<u32>(offset);
251
252 *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
253 Ok(())
254 }
255 }
256
257 impl fidl::encoding::ValueTypeMarker for MapSchema {
258 type Borrowed<'a> = &'a Self;
259 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
260 value
261 }
262 }
263
264 unsafe impl fidl::encoding::TypeMarker for MapSchema {
265 type Owned = Self;
266
267 #[inline(always)]
268 fn inline_align(_context: fidl::encoding::Context) -> usize {
269 4
270 }
271
272 #[inline(always)]
273 fn inline_size(_context: fidl::encoding::Context) -> usize {
274 20
275 }
276 }
277
278 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<MapSchema, D>
279 for &MapSchema
280 {
281 #[inline]
282 unsafe fn encode(
283 self,
284 encoder: &mut fidl::encoding::Encoder<'_, D>,
285 offset: usize,
286 _depth: fidl::encoding::Depth,
287 ) -> fidl::Result<()> {
288 encoder.debug_check_bounds::<MapSchema>(offset);
289 fidl::encoding::Encode::<MapSchema, D>::encode(
291 (
292 <MapType as fidl::encoding::ValueTypeMarker>::borrow(&self.type_),
293 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.key_size),
294 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.value_size),
295 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.max_entries),
296 <MapFlags as fidl::encoding::ValueTypeMarker>::borrow(&self.flags),
297 ),
298 encoder,
299 offset,
300 _depth,
301 )
302 }
303 }
304 unsafe impl<
305 D: fidl::encoding::ResourceDialect,
306 T0: fidl::encoding::Encode<MapType, D>,
307 T1: fidl::encoding::Encode<u32, D>,
308 T2: fidl::encoding::Encode<u32, D>,
309 T3: fidl::encoding::Encode<u32, D>,
310 T4: fidl::encoding::Encode<MapFlags, D>,
311 > fidl::encoding::Encode<MapSchema, D> for (T0, T1, T2, T3, T4)
312 {
313 #[inline]
314 unsafe fn encode(
315 self,
316 encoder: &mut fidl::encoding::Encoder<'_, D>,
317 offset: usize,
318 depth: fidl::encoding::Depth,
319 ) -> fidl::Result<()> {
320 encoder.debug_check_bounds::<MapSchema>(offset);
321 self.0.encode(encoder, offset + 0, depth)?;
325 self.1.encode(encoder, offset + 4, depth)?;
326 self.2.encode(encoder, offset + 8, depth)?;
327 self.3.encode(encoder, offset + 12, depth)?;
328 self.4.encode(encoder, offset + 16, depth)?;
329 Ok(())
330 }
331 }
332
333 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MapSchema {
334 #[inline(always)]
335 fn new_empty() -> Self {
336 Self {
337 type_: fidl::new_empty!(MapType, D),
338 key_size: fidl::new_empty!(u32, D),
339 value_size: fidl::new_empty!(u32, D),
340 max_entries: fidl::new_empty!(u32, D),
341 flags: fidl::new_empty!(MapFlags, D),
342 }
343 }
344
345 #[inline]
346 unsafe fn decode(
347 &mut self,
348 decoder: &mut fidl::encoding::Decoder<'_, D>,
349 offset: usize,
350 _depth: fidl::encoding::Depth,
351 ) -> fidl::Result<()> {
352 decoder.debug_check_bounds::<Self>(offset);
353 fidl::decode!(MapType, D, &mut self.type_, decoder, offset + 0, _depth)?;
355 fidl::decode!(u32, D, &mut self.key_size, decoder, offset + 4, _depth)?;
356 fidl::decode!(u32, D, &mut self.value_size, decoder, offset + 8, _depth)?;
357 fidl::decode!(u32, D, &mut self.max_entries, decoder, offset + 12, _depth)?;
358 fidl::decode!(MapFlags, D, &mut self.flags, decoder, offset + 16, _depth)?;
359 Ok(())
360 }
361 }
362
363 impl fidl::encoding::ValueTypeMarker for StructAccess {
364 type Borrowed<'a> = &'a Self;
365 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
366 value
367 }
368 }
369
370 unsafe impl fidl::encoding::TypeMarker for StructAccess {
371 type Owned = Self;
372
373 #[inline(always)]
374 fn inline_align(_context: fidl::encoding::Context) -> usize {
375 8
376 }
377
378 #[inline(always)]
379 fn inline_size(_context: fidl::encoding::Context) -> usize {
380 24
381 }
382 }
383
384 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StructAccess, D>
385 for &StructAccess
386 {
387 #[inline]
388 unsafe fn encode(
389 self,
390 encoder: &mut fidl::encoding::Encoder<'_, D>,
391 offset: usize,
392 _depth: fidl::encoding::Depth,
393 ) -> fidl::Result<()> {
394 encoder.debug_check_bounds::<StructAccess>(offset);
395 fidl::encoding::Encode::<StructAccess, D>::encode(
397 (
398 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.pc),
399 <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.struct_memory_id),
400 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.field_offset),
401 <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.is_32_bit_ptr_load),
402 ),
403 encoder,
404 offset,
405 _depth,
406 )
407 }
408 }
409 unsafe impl<
410 D: fidl::encoding::ResourceDialect,
411 T0: fidl::encoding::Encode<u32, D>,
412 T1: fidl::encoding::Encode<u64, D>,
413 T2: fidl::encoding::Encode<u32, D>,
414 T3: fidl::encoding::Encode<bool, D>,
415 > fidl::encoding::Encode<StructAccess, D> for (T0, T1, T2, T3)
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::<StructAccess>(offset);
425 unsafe {
428 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
429 (ptr as *mut u64).write_unaligned(0);
430 }
431 unsafe {
432 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
433 (ptr as *mut u64).write_unaligned(0);
434 }
435 self.0.encode(encoder, offset + 0, depth)?;
437 self.1.encode(encoder, offset + 8, depth)?;
438 self.2.encode(encoder, offset + 16, depth)?;
439 self.3.encode(encoder, offset + 20, depth)?;
440 Ok(())
441 }
442 }
443
444 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StructAccess {
445 #[inline(always)]
446 fn new_empty() -> Self {
447 Self {
448 pc: fidl::new_empty!(u32, D),
449 struct_memory_id: fidl::new_empty!(u64, D),
450 field_offset: fidl::new_empty!(u32, D),
451 is_32_bit_ptr_load: fidl::new_empty!(bool, D),
452 }
453 }
454
455 #[inline]
456 unsafe fn decode(
457 &mut self,
458 decoder: &mut fidl::encoding::Decoder<'_, D>,
459 offset: usize,
460 _depth: fidl::encoding::Depth,
461 ) -> fidl::Result<()> {
462 decoder.debug_check_bounds::<Self>(offset);
463 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
465 let padval = unsafe { (ptr as *const u64).read_unaligned() };
466 let mask = 0xffffffff00000000u64;
467 let maskedval = padval & mask;
468 if maskedval != 0 {
469 return Err(fidl::Error::NonZeroPadding {
470 padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
471 });
472 }
473 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
474 let padval = unsafe { (ptr as *const u64).read_unaligned() };
475 let mask = 0xffffff0000000000u64;
476 let maskedval = padval & mask;
477 if maskedval != 0 {
478 return Err(fidl::Error::NonZeroPadding {
479 padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
480 });
481 }
482 fidl::decode!(u32, D, &mut self.pc, decoder, offset + 0, _depth)?;
483 fidl::decode!(u64, D, &mut self.struct_memory_id, decoder, offset + 8, _depth)?;
484 fidl::decode!(u32, D, &mut self.field_offset, decoder, offset + 16, _depth)?;
485 fidl::decode!(bool, D, &mut self.is_32_bit_ptr_load, decoder, offset + 20, _depth)?;
486 Ok(())
487 }
488 }
489}