• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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 std::ffi::CStr;
6 
7 use crate::rutabaga_os::descriptor::AsRawDescriptor;
8 use crate::rutabaga_os::descriptor::IntoRawDescriptor;
9 use crate::rutabaga_os::OwnedDescriptor;
10 use crate::rutabaga_os::RawDescriptor;
11 use crate::rutabaga_utils::RutabagaError;
12 use crate::rutabaga_utils::RutabagaResult;
13 
14 /// A shared memory file descriptor and its size.
15 pub struct SharedMemory {
16     pub descriptor: OwnedDescriptor,
17     pub size: u64,
18 }
19 
20 impl SharedMemory {
21     /// Creates a new shared memory file mapping with zero size.
new(_debug_name: &CStr, _size: u64) -> RutabagaResult<Self>22     pub fn new(_debug_name: &CStr, _size: u64) -> RutabagaResult<Self> {
23         Err(RutabagaError::Unsupported)
24     }
25 
26     /// Gets the size in bytes of the shared memory.
27     ///
28     /// The size returned here does not reflect changes by other interfaces or users of the shared
29     /// memory file descriptor.
size(&self) -> u6430     pub fn size(&self) -> u64 {
31         self.size
32     }
33 }
34 
35 /// USE THIS CAUTIOUSLY. The returned handle is not a file handle and cannot be
36 /// used as if it were one. It is a handle to a the associated file mapping object
37 /// and should only be used for memory-mapping the file view.
38 impl AsRawDescriptor for SharedMemory {
as_raw_descriptor(&self) -> RawDescriptor39     fn as_raw_descriptor(&self) -> RawDescriptor {
40         self.descriptor.as_raw_descriptor()
41     }
42 }
43 
44 impl IntoRawDescriptor for SharedMemory {
into_raw_descriptor(self) -> RawDescriptor45     fn into_raw_descriptor(self) -> RawDescriptor {
46         self.descriptor.into_raw_descriptor()
47     }
48 }
49 
round_up_to_page_size(_v: u64) -> RutabagaResult<u64>50 pub fn round_up_to_page_size(_v: u64) -> RutabagaResult<u64> {
51     Err(RutabagaError::Unsupported)
52 }
53