2020-08-03 03:09:41 +00:00
|
|
|
// Copyright 2020 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-03-18 19:38:09 +00:00
|
|
|
pub mod common;
|
2022-03-21 18:31:38 +00:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
2022-03-18 19:38:09 +00:00
|
|
|
pub mod unix;
|
2020-08-06 01:50:47 +00:00
|
|
|
|
2022-03-21 21:44:36 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
pub mod windows;
|
|
|
|
|
2022-03-24 17:14:32 +00:00
|
|
|
mod tube;
|
|
|
|
|
|
|
|
pub use tube::{Error as TubeError, RecvTube, Result as TubeResult, SendTube, Tube};
|
|
|
|
|
2022-03-21 18:31:38 +00:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(unix)] {
|
|
|
|
mod event;
|
|
|
|
mod ioctl;
|
|
|
|
mod mmap;
|
|
|
|
mod notifiers;
|
|
|
|
mod shm;
|
|
|
|
mod timer;
|
|
|
|
mod wait_context;
|
|
|
|
|
|
|
|
pub use unix as platform;
|
|
|
|
|
|
|
|
pub use unix::net::*;
|
|
|
|
pub use unix::ioctl::*;
|
|
|
|
|
|
|
|
pub use event::{Event, EventReadResult, ScopedEvent};
|
|
|
|
pub use crate::ioctl::{
|
|
|
|
ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val,
|
|
|
|
};
|
|
|
|
pub use mmap::{
|
|
|
|
MemoryMapping, MemoryMappingBuilder, MemoryMappingBuilderUnix, Unix as MemoryMappingUnix,
|
|
|
|
};
|
|
|
|
pub use notifiers::*;
|
|
|
|
pub use shm::{SharedMemory, Unix as SharedMemoryUnix};
|
|
|
|
pub use timer::{FakeTimer, Timer};
|
|
|
|
pub use wait_context::{EventToken, EventType, TriggeredEvent, WaitContext};
|
|
|
|
} else if #[cfg(windows)] {
|
2022-03-24 17:14:32 +00:00
|
|
|
pub use windows as platform;
|
2022-03-25 20:44:28 +00:00
|
|
|
pub use tube::{set_duplicate_handle_tube, set_alias_pid, DuplicateHandleTube};
|
2022-03-21 18:31:38 +00:00
|
|
|
} else {
|
|
|
|
compile_error!("Unsupported platform");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use platform::*;
|
2020-08-06 01:50:47 +00:00
|
|
|
|
|
|
|
/// Wraps an AsRawDescriptor in the simple Descriptor struct, which
|
|
|
|
/// has AsRawFd methods for interfacing with sys_util
|
2020-10-07 10:29:24 +00:00
|
|
|
pub fn wrap_descriptor(descriptor: &dyn AsRawDescriptor) -> Descriptor {
|
2020-08-06 01:50:47 +00:00
|
|
|
Descriptor(descriptor.as_raw_descriptor())
|
|
|
|
}
|
2020-09-16 22:29:20 +00:00
|
|
|
|
2020-11-11 03:32:45 +00:00
|
|
|
/// Verifies that |raw_descriptor| is actually owned by this process and duplicates it
|
|
|
|
/// to ensure that we have a unique handle to it.
|
2022-03-21 18:31:38 +00:00
|
|
|
#[cfg(unix)]
|
2020-11-11 03:32:45 +00:00
|
|
|
pub fn validate_raw_descriptor(raw_descriptor: RawDescriptor) -> Result<RawDescriptor> {
|
|
|
|
validate_raw_fd(raw_descriptor)
|
|
|
|
}
|
|
|
|
|
2020-09-16 22:29:20 +00:00
|
|
|
/// A trait similar to `AsRawDescriptor` but supports an arbitrary number of descriptors.
|
|
|
|
pub trait AsRawDescriptors {
|
|
|
|
fn as_raw_descriptors(&self) -> Vec<RawDescriptor>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> AsRawDescriptors for T
|
|
|
|
where
|
|
|
|
T: AsRawDescriptor,
|
|
|
|
{
|
|
|
|
fn as_raw_descriptors(&self) -> Vec<RawDescriptor> {
|
|
|
|
vec![self.as_raw_descriptor()]
|
|
|
|
}
|
|
|
|
}
|