1 // Copyright 2023 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use crate::rutabaga_os::sys::platform::MemoryMapping as PlatformMapping; 6 use crate::rutabaga_os::OwnedDescriptor; 7 use crate::rutabaga_utils::RutabagaMapping; 8 use crate::rutabaga_utils::RutabagaResult; 9 10 pub struct MemoryMapping { 11 mapping: PlatformMapping, 12 } 13 14 impl MemoryMapping { from_safe_descriptor( descriptor: OwnedDescriptor, size: usize, map_info: u32, ) -> RutabagaResult<MemoryMapping>15 pub fn from_safe_descriptor( 16 descriptor: OwnedDescriptor, 17 size: usize, 18 map_info: u32, 19 ) -> RutabagaResult<MemoryMapping> { 20 let mapping = PlatformMapping::from_safe_descriptor(descriptor, size, map_info)?; 21 Ok(MemoryMapping { mapping }) 22 } 23 as_rutabaga_mapping(&self) -> RutabagaMapping24 pub fn as_rutabaga_mapping(&self) -> RutabagaMapping { 25 RutabagaMapping { 26 ptr: self.mapping.addr.as_ptr() as u64, 27 size: self.mapping.size as u64, 28 } 29 } 30 } 31