• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 pub use sys_util::*;
6 
7 mod async_types;
8 mod event;
9 mod ioctl;
10 mod mmap;
11 mod shm;
12 mod timer;
13 mod tube;
14 mod wait_context;
15 
16 pub use async_types::*;
17 pub use event::{Event, EventReadResult, ScopedEvent};
18 pub use ioctl::{
19     ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val,
20 };
21 pub use mmap::Unix as MemoryMappingUnix;
22 pub use mmap::{MemoryMapping, MemoryMappingBuilder, MemoryMappingBuilderUnix};
23 pub use shm::{SharedMemory, Unix as SharedMemoryUnix};
24 pub use sys_util::ioctl::*;
25 pub use sys_util::sched::*;
26 pub use sys_util::{
27     volatile_at_impl, volatile_impl, FileAllocate, FileGetLen, FileReadWriteAtVolatile,
28     FileReadWriteVolatile, FileSetLen, FileSync,
29 };
30 pub use sys_util::{SeekHole, WriteZeroesAt};
31 pub use timer::{FakeTimer, Timer};
32 pub use tube::{AsyncTube, Error as TubeError, Result as TubeResult, Tube};
33 pub use wait_context::{EventToken, EventType, TriggeredEvent, WaitContext};
34 
35 /// Wraps an AsRawDescriptor in the simple Descriptor struct, which
36 /// has AsRawFd methods for interfacing with sys_util
wrap_descriptor(descriptor: &dyn AsRawDescriptor) -> Descriptor37 pub fn wrap_descriptor(descriptor: &dyn AsRawDescriptor) -> Descriptor {
38     Descriptor(descriptor.as_raw_descriptor())
39 }
40 
41 /// Verifies that |raw_descriptor| is actually owned by this process and duplicates it
42 /// to ensure that we have a unique handle to it.
validate_raw_descriptor(raw_descriptor: RawDescriptor) -> Result<RawDescriptor>43 pub fn validate_raw_descriptor(raw_descriptor: RawDescriptor) -> Result<RawDescriptor> {
44     validate_raw_fd(raw_descriptor)
45 }
46 
47 /// A trait similar to `AsRawDescriptor` but supports an arbitrary number of descriptors.
48 pub trait AsRawDescriptors {
as_raw_descriptors(&self) -> Vec<RawDescriptor>49     fn as_raw_descriptors(&self) -> Vec<RawDescriptor>;
50 }
51 
52 impl<T> AsRawDescriptors for T
53 where
54     T: AsRawDescriptor,
55 {
as_raw_descriptors(&self) -> Vec<RawDescriptor>56     fn as_raw_descriptors(&self) -> Vec<RawDescriptor> {
57         vec![self.as_raw_descriptor()]
58     }
59 }
60