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