Reformat imports
crosvm is switching the import style to use one import per line. While more verbose, this will greatly reduce the occurence of merge conflicts going forward. Note: This is using a nightly feature of rustfmt. So it's a one-off re-format only. We are considering adding a nightly toolchain to enable the feature permanently. BUG=b:239937122 TEST=CQ Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: Dennis Kempin <denniskempin@google.com> Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
parent
18d435aa17
commit
4fea399df9
620 changed files with 10150 additions and 5237 deletions
|
|
@ -6,14 +6,20 @@ use std::collections::BTreeMap;
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
use arch::fdt::{Error, FdtWriter, Result};
|
||||
use arch::fdt::Error;
|
||||
use arch::fdt::FdtWriter;
|
||||
use arch::fdt::Result;
|
||||
use arch::SERIAL_ADDR;
|
||||
use devices::{PciAddress, PciInterruptPin};
|
||||
use hypervisor::{PsciVersion, PSCI_0_2, PSCI_1_0};
|
||||
use vm_memory::{GuestAddress, GuestMemory};
|
||||
|
||||
// This is the start of DRAM in the physical address space.
|
||||
use crate::AARCH64_PHYS_MEM_START;
|
||||
// This is a Battery related constant
|
||||
use devices::bat::GOLDFISHBAT_MMIO_LEN;
|
||||
use devices::pl030::PL030_AMBA_ID;
|
||||
use devices::PciAddress;
|
||||
use devices::PciInterruptPin;
|
||||
use hypervisor::PsciVersion;
|
||||
use hypervisor::PSCI_0_2;
|
||||
use hypervisor::PSCI_1_0;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
|
||||
// These are GIC address-space location constants.
|
||||
use crate::AARCH64_GIC_CPUI_BASE;
|
||||
|
|
@ -21,24 +27,19 @@ use crate::AARCH64_GIC_CPUI_SIZE;
|
|||
use crate::AARCH64_GIC_DIST_BASE;
|
||||
use crate::AARCH64_GIC_DIST_SIZE;
|
||||
use crate::AARCH64_GIC_REDIST_SIZE;
|
||||
|
||||
// This is the start of DRAM in the physical address space.
|
||||
use crate::AARCH64_PHYS_MEM_START;
|
||||
use crate::AARCH64_PMU_IRQ;
|
||||
// These are RTC related constants
|
||||
use crate::AARCH64_RTC_ADDR;
|
||||
use crate::AARCH64_RTC_IRQ;
|
||||
use crate::AARCH64_RTC_SIZE;
|
||||
use devices::pl030::PL030_AMBA_ID;
|
||||
|
||||
// This is a Battery related constant
|
||||
use devices::bat::GOLDFISHBAT_MMIO_LEN;
|
||||
|
||||
// These are serial device related constants.
|
||||
use crate::AARCH64_SERIAL_1_3_IRQ;
|
||||
use crate::AARCH64_SERIAL_2_4_IRQ;
|
||||
use crate::AARCH64_SERIAL_SIZE;
|
||||
use crate::AARCH64_SERIAL_SPEED;
|
||||
|
||||
use crate::AARCH64_PMU_IRQ;
|
||||
|
||||
// This is an arbitrary number to specify the node for the GIC.
|
||||
// If we had a more complex interrupt architecture, then we'd need an enum for
|
||||
// these.
|
||||
|
|
|
|||
|
|
@ -10,28 +10,52 @@ use std::collections::BTreeMap;
|
|||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use arch::{
|
||||
get_serial_cmdline, GetSerialCmdlineError, MsrConfig, MsrExitHandlerError, RunnableLinuxVm,
|
||||
VmComponents, VmImage,
|
||||
};
|
||||
use base::{Event, MemoryMappingBuilder, SendTube};
|
||||
use devices::serial_device::{SerialHardware, SerialParameters};
|
||||
use devices::vmwdt::{VMWDT_DEFAULT_CLOCK_HZ, VMWDT_DEFAULT_TIMEOUT_SEC};
|
||||
use devices::{
|
||||
Bus, BusDeviceObj, BusError, IrqChip, IrqChipAArch64, IrqEventSource, PciAddress,
|
||||
PciConfigMmio, PciDevice, Serial,
|
||||
};
|
||||
use hypervisor::{
|
||||
DeviceKind, Hypervisor, HypervisorCap, ProtectionType, VcpuAArch64, VcpuFeature,
|
||||
VcpuInitAArch64, VcpuRegAArch64, Vm, VmAArch64,
|
||||
};
|
||||
use arch::get_serial_cmdline;
|
||||
use arch::GetSerialCmdlineError;
|
||||
use arch::MsrConfig;
|
||||
use arch::MsrExitHandlerError;
|
||||
use arch::RunnableLinuxVm;
|
||||
use arch::VmComponents;
|
||||
use arch::VmImage;
|
||||
use base::Event;
|
||||
use base::MemoryMappingBuilder;
|
||||
use base::SendTube;
|
||||
use devices::serial_device::SerialHardware;
|
||||
use devices::serial_device::SerialParameters;
|
||||
use devices::vmwdt::VMWDT_DEFAULT_CLOCK_HZ;
|
||||
use devices::vmwdt::VMWDT_DEFAULT_TIMEOUT_SEC;
|
||||
use devices::Bus;
|
||||
use devices::BusDeviceObj;
|
||||
use devices::BusError;
|
||||
use devices::IrqChip;
|
||||
use devices::IrqChipAArch64;
|
||||
use devices::IrqEventSource;
|
||||
use devices::PciAddress;
|
||||
use devices::PciConfigMmio;
|
||||
use devices::PciDevice;
|
||||
use devices::Serial;
|
||||
use hypervisor::DeviceKind;
|
||||
use hypervisor::Hypervisor;
|
||||
use hypervisor::HypervisorCap;
|
||||
use hypervisor::ProtectionType;
|
||||
use hypervisor::VcpuAArch64;
|
||||
use hypervisor::VcpuFeature;
|
||||
use hypervisor::VcpuInitAArch64;
|
||||
use hypervisor::VcpuRegAArch64;
|
||||
use hypervisor::Vm;
|
||||
use hypervisor::VmAArch64;
|
||||
use minijail::Minijail;
|
||||
use remain::sorted;
|
||||
use resources::{AddressRange, SystemAllocator, SystemAllocatorConfig};
|
||||
use resources::AddressRange;
|
||||
use resources::SystemAllocator;
|
||||
use resources::SystemAllocatorConfig;
|
||||
use sync::Mutex;
|
||||
use thiserror::Error;
|
||||
use vm_control::{BatControl, BatteryType};
|
||||
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
|
||||
use vm_control::BatControl;
|
||||
use vm_control::BatteryType;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
|
||||
mod fdt;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,10 @@ impl RSDP {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::RSDP;
|
||||
use data_model::DataInit;
|
||||
|
||||
use super::RSDP;
|
||||
|
||||
#[test]
|
||||
fn test_rsdp() {
|
||||
let rsdp = RSDP::new(*b"CHYPER", 0xdead_beef);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{ErrorKind, Read, Result};
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Read;
|
||||
use std::io::Result;
|
||||
use std::path::Path;
|
||||
|
||||
use data_model::DataInit;
|
||||
|
|
@ -124,10 +126,12 @@ impl SDT {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SDT;
|
||||
use std::io::Write;
|
||||
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use super::SDT;
|
||||
|
||||
#[test]
|
||||
fn test_sdt() {
|
||||
let mut sdt = SDT::new(*b"TEST", 40, 1, *b"CROSVM", *b"TESTTEST", 1);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ use std::fs::File;
|
|||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
|
||||
use crate::fdt::{Error, FdtWriter, Result};
|
||||
use crate::fdt::Error;
|
||||
use crate::fdt::FdtWriter;
|
||||
use crate::fdt::Result;
|
||||
|
||||
fn parse_fstab_line(line: &str) -> Result<Vec<String>> {
|
||||
let vec: Vec<&str> = line.split_whitespace().collect();
|
||||
|
|
|
|||
106
arch/src/lib.rs
106
arch/src/lib.rs
|
|
@ -14,60 +14,90 @@ pub mod sys;
|
|||
use std::collections::BTreeMap;
|
||||
use std::error::Error as StdError;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Seek, SeekFrom};
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::io::{self};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use acpi_tables::sdt::SDT;
|
||||
use base::syslog;
|
||||
use base::AsRawDescriptor;
|
||||
use base::AsRawDescriptors;
|
||||
use base::Event;
|
||||
use base::SendTube;
|
||||
#[cfg(all(target_arch = "x86_64", feature = "gdb"))]
|
||||
use base::Tube;
|
||||
use base::{syslog, AsRawDescriptor, AsRawDescriptors, Event, SendTube};
|
||||
use devices::virtio::VirtioDevice;
|
||||
use devices::BarRange;
|
||||
use devices::Bus;
|
||||
use devices::BusDevice;
|
||||
use devices::BusDeviceObj;
|
||||
use devices::BusError;
|
||||
use devices::BusResumeDevice;
|
||||
use devices::HotPlugBus;
|
||||
use devices::IrqChip;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use devices::IrqChipAArch64 as IrqChipArch;
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use devices::IrqChipX86_64 as IrqChipArch;
|
||||
use devices::IrqEventSource;
|
||||
#[cfg(windows)]
|
||||
use devices::Minijail;
|
||||
use devices::PciAddress;
|
||||
use devices::PciBus;
|
||||
use devices::PciDevice;
|
||||
use devices::PciDeviceError;
|
||||
use devices::PciInterruptPin;
|
||||
use devices::PciRoot;
|
||||
#[cfg(unix)]
|
||||
use devices::ProxyDevice;
|
||||
use devices::{
|
||||
BarRange, Bus, BusDevice, BusDeviceObj, BusError, BusResumeDevice, HotPlugBus, IrqChip,
|
||||
IrqEventSource, PciAddress, PciBus, PciDevice, PciDeviceError, PciInterruptPin, PciRoot,
|
||||
SerialHardware, SerialParameters,
|
||||
};
|
||||
use hypervisor::{IoEventAddress, ProtectionType, Vm};
|
||||
use devices::SerialHardware;
|
||||
use devices::SerialParameters;
|
||||
#[cfg(all(target_arch = "x86_64", feature = "gdb"))]
|
||||
use gdbstub_arch::x86::reg::X86_64CoreRegs as GdbStubRegs;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use hypervisor::Hypervisor as HypervisorArch;
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use hypervisor::HypervisorX86_64 as HypervisorArch;
|
||||
use hypervisor::IoEventAddress;
|
||||
use hypervisor::ProtectionType;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use hypervisor::VcpuAArch64 as VcpuArch;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use hypervisor::VcpuInitAArch64 as VcpuInitArch;
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use hypervisor::VcpuInitX86_64 as VcpuInitArch;
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use hypervisor::VcpuX86_64 as VcpuArch;
|
||||
use hypervisor::Vm;
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use hypervisor::VmAArch64 as VmArch;
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use hypervisor::VmX86_64 as VmArch;
|
||||
#[cfg(unix)]
|
||||
use minijail::Minijail;
|
||||
use remain::sorted;
|
||||
use resources::{SystemAllocator, SystemAllocatorConfig};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use resources::AddressRange;
|
||||
use resources::SystemAllocator;
|
||||
use resources::SystemAllocatorConfig;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
pub use serial::add_serial_devices;
|
||||
pub use serial::get_serial_cmdline;
|
||||
pub use serial::set_default_serial_parameters;
|
||||
pub use serial::GetSerialCmdlineError;
|
||||
pub use serial::SERIAL_ADDR;
|
||||
use sync::Mutex;
|
||||
use thiserror::Error;
|
||||
use vm_control::{BatControl, BatteryType, PmResource};
|
||||
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", feature = "gdb"))]
|
||||
use gdbstub_arch::x86::reg::X86_64CoreRegs as GdbStubRegs;
|
||||
|
||||
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
|
||||
use {
|
||||
devices::IrqChipAArch64 as IrqChipArch,
|
||||
hypervisor::{
|
||||
Hypervisor as HypervisorArch, VcpuAArch64 as VcpuArch, VcpuInitAArch64 as VcpuInitArch,
|
||||
VmAArch64 as VmArch,
|
||||
},
|
||||
};
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use {
|
||||
devices::IrqChipX86_64 as IrqChipArch,
|
||||
hypervisor::{
|
||||
HypervisorX86_64 as HypervisorArch, VcpuInitX86_64 as VcpuInitArch, VcpuX86_64 as VcpuArch,
|
||||
VmX86_64 as VmArch,
|
||||
},
|
||||
resources::AddressRange,
|
||||
};
|
||||
|
||||
pub use serial::{
|
||||
add_serial_devices, get_serial_cmdline, set_default_serial_parameters, GetSerialCmdlineError,
|
||||
SERIAL_ADDR,
|
||||
};
|
||||
use vm_control::BatControl;
|
||||
use vm_control::BatteryType;
|
||||
use vm_control::PmResource;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
|
||||
pub enum VmImage {
|
||||
Kernel(File),
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@
|
|||
|
||||
use std::fs::OpenOptions;
|
||||
|
||||
use crate::Pstore;
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::bail;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use base::MemoryMappingBuilder;
|
||||
use hypervisor::Vm;
|
||||
use resources::AddressRange;
|
||||
use vm_memory::GuestAddress;
|
||||
|
||||
use crate::Pstore;
|
||||
|
||||
mod sys;
|
||||
|
||||
pub struct RamoopsRegion {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::fs::OpenOptions;
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
|
||||
use winapi::um::winnt::FILE_SHARE_READ;
|
||||
|
||||
pub fn set_extra_open_opts(opts: &mut OpenOptions) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use base::Event;
|
||||
use devices::serial_device::{SerialHardware, SerialParameters, SerialType};
|
||||
use devices::serial_device::SerialHardware;
|
||||
use devices::serial_device::SerialParameters;
|
||||
use devices::serial_device::SerialType;
|
||||
use devices::Bus;
|
||||
#[cfg(windows)]
|
||||
use devices::Minijail;
|
||||
use devices::{Bus, Serial};
|
||||
use devices::Serial;
|
||||
use hypervisor::ProtectionType;
|
||||
#[cfg(unix)]
|
||||
use minijail::Minijail;
|
||||
|
|
@ -208,9 +211,10 @@ pub fn get_serial_cmdline(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use kernel_cmdline::Cmdline;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn get_serial_cmdline_default() {
|
||||
let mut cmdline = Cmdline::new(4096);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ use std::sync::Arc;
|
|||
|
||||
use base::RawDescriptor;
|
||||
use devices::serial_device::SerialParameters;
|
||||
use devices::Bus;
|
||||
use devices::BusDevice;
|
||||
use devices::{Bus, ProxyDevice, Serial};
|
||||
use devices::ProxyDevice;
|
||||
use devices::Serial;
|
||||
use minijail::Minijail;
|
||||
use sync::Mutex;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,18 @@
|
|||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use devices::serial_device::{SerialParameters, SerialType};
|
||||
use std::io::Read;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use base::{RawDescriptor, Result};
|
||||
use devices::{Bus, Minijail, Serial};
|
||||
use base::RawDescriptor;
|
||||
use base::Result;
|
||||
use devices::serial_device::SerialParameters;
|
||||
use devices::serial_device::SerialType;
|
||||
use devices::Bus;
|
||||
use devices::Minijail;
|
||||
use devices::Serial;
|
||||
use sync::Mutex;
|
||||
|
||||
use crate::serial::SERIAL_ADDR;
|
||||
|
|
|
|||
|
|
@ -2,24 +2,28 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use acpi_tables::aml::Aml;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use acpi_tables::aml::Aml;
|
||||
use base::syslog;
|
||||
use base::AsRawDescriptors;
|
||||
#[cfg(any(all(target_arch = "x86_64", feature = "gdb"), unix))]
|
||||
use base::Tube;
|
||||
use base::{syslog, AsRawDescriptors};
|
||||
use devices::{Bus, IrqChip, IrqEventSource};
|
||||
use devices::{BusDevice, ProxyDevice, VfioPlatformDevice};
|
||||
use devices::Bus;
|
||||
use devices::BusDevice;
|
||||
use devices::IrqChip;
|
||||
use devices::IrqEventSource;
|
||||
use devices::ProxyDevice;
|
||||
use devices::VfioPlatformDevice;
|
||||
use libc::sched_getcpu;
|
||||
use minijail::Minijail;
|
||||
use resources::MmioType;
|
||||
use resources::SystemAllocator;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use sync::Mutex;
|
||||
|
||||
use crate::{DeviceRegistrationError, MsrValueFrom};
|
||||
use crate::DeviceRegistrationError;
|
||||
use crate::MsrValueFrom;
|
||||
|
||||
impl MsrValueFrom {
|
||||
/// Get the physical(host) CPU id from MsrValueFrom type.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,17 @@
|
|||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro2::{Ident, TokenStream};
|
||||
use proc_macro2::Ident;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, Index, Member, Variant};
|
||||
use syn::parse_macro_input;
|
||||
use syn::Data;
|
||||
use syn::DeriveInput;
|
||||
use syn::Field;
|
||||
use syn::Fields;
|
||||
use syn::Index;
|
||||
use syn::Member;
|
||||
use syn::Variant;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use quote::quote;
|
||||
use syn::{parse_quote, DeriveInput};
|
||||
use syn::parse_quote;
|
||||
use syn::DeriveInput;
|
||||
|
||||
#[test]
|
||||
fn test_variant_bits() {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
alloc::{alloc, alloc_zeroed, dealloc, Layout},
|
||||
cmp::min,
|
||||
};
|
||||
use std::alloc::alloc;
|
||||
use std::alloc::alloc_zeroed;
|
||||
use std::alloc::dealloc;
|
||||
use std::alloc::Layout;
|
||||
use std::cmp::min;
|
||||
|
||||
/// A contiguous memory allocation with a specified size and alignment, with a
|
||||
/// Drop impl to perform the deallocation.
|
||||
|
|
@ -168,8 +169,10 @@ impl Drop for LayoutAllocation {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::mem::align_of;
|
||||
use std::mem::size_of;
|
||||
|
||||
use super::*;
|
||||
use std::mem::{align_of, size_of};
|
||||
|
||||
#[test]
|
||||
fn test_as_slice_u32() {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@
|
|||
// Utility file to provide a fake clock object representing current time, and a timer driven by
|
||||
// that time.
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::{descriptor::AsRawDescriptor, Event};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::Event;
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone)]
|
||||
pub struct Clock {}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::{EventToken, RawDescriptor};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs::File,
|
||||
mem::{self, ManuallyDrop},
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::mem::{self};
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::EventToken;
|
||||
use crate::RawDescriptor;
|
||||
|
||||
/// Wraps a RawDescriptor and safely closes it when self falls out of scope.
|
||||
#[derive(Serialize, Deserialize, Debug, Eq)]
|
||||
|
|
|
|||
|
|
@ -48,21 +48,25 @@
|
|||
//! .expect("failed to deserialize");
|
||||
//! ```
|
||||
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
convert::TryInto,
|
||||
fmt,
|
||||
fs::File,
|
||||
ops::{Deref, DerefMut},
|
||||
panic::{catch_unwind, resume_unwind, AssertUnwindSafe},
|
||||
};
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::panic::catch_unwind;
|
||||
use std::panic::resume_unwind;
|
||||
use std::panic::AssertUnwindSafe;
|
||||
|
||||
use serde::{
|
||||
de::{
|
||||
Error, Visitor, {self},
|
||||
},
|
||||
ser, Deserialize, Deserializer, Serialize, Serializer,
|
||||
};
|
||||
use serde::de::Error;
|
||||
use serde::de::Visitor;
|
||||
use serde::de::{self};
|
||||
use serde::ser;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
|
@ -340,11 +344,11 @@ where
|
|||
/// }
|
||||
/// ```
|
||||
pub mod with_raw_descriptor {
|
||||
use super::super::RawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use serde::Deserializer;
|
||||
|
||||
use super::super::RawDescriptor;
|
||||
pub use super::serialize_descriptor as serialize;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
|
||||
pub fn deserialize<'de, D>(de: D) -> std::result::Result<RawDescriptor, D::Error>
|
||||
where
|
||||
|
|
@ -371,8 +375,12 @@ pub mod with_raw_descriptor {
|
|||
/// }
|
||||
/// ```
|
||||
pub mod with_as_descriptor {
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
|
||||
use serde::{Deserializer, Serializer};
|
||||
use serde::Deserializer;
|
||||
use serde::Serializer;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
|
||||
pub fn serialize<S: Serializer>(
|
||||
rd: &dyn AsRawDescriptor,
|
||||
|
|
@ -432,16 +440,25 @@ impl DerefMut for FileSerdeWrapper {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::{
|
||||
deserialize_with_descriptors, with_as_descriptor, with_raw_descriptor, AsRawDescriptor,
|
||||
FileSerdeWrapper, FromRawDescriptor, RawDescriptor, SafeDescriptor, SerializeDescriptors,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::mem::ManuallyDrop;
|
||||
|
||||
use std::{collections::HashMap, fs::File, mem::ManuallyDrop};
|
||||
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use tempfile::tempfile;
|
||||
|
||||
use super::super::deserialize_with_descriptors;
|
||||
use super::super::with_as_descriptor;
|
||||
use super::super::with_raw_descriptor;
|
||||
use super::super::AsRawDescriptor;
|
||||
use super::super::FileSerdeWrapper;
|
||||
use super::super::FromRawDescriptor;
|
||||
use super::super::RawDescriptor;
|
||||
use super::super::SafeDescriptor;
|
||||
use super::super::SerializeDescriptors;
|
||||
|
||||
fn deserialize<T: DeserializeOwned>(json: &str, descriptors: &[RawDescriptor]) -> T {
|
||||
let mut safe_descriptors = descriptors
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
convert::{From, TryInto},
|
||||
fmt::{
|
||||
Display, {self},
|
||||
},
|
||||
io, result,
|
||||
};
|
||||
use std::convert::From;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{self};
|
||||
use std::io;
|
||||
use std::result;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
/// A system error
|
||||
|
|
|
|||
|
|
@ -4,11 +4,16 @@
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::platform::Event as PlatformEvent;
|
||||
pub use crate::platform::EventReadResult;
|
||||
use crate::{platform::Event as PlatformEvent, RawDescriptor, Result};
|
||||
use crate::RawDescriptor;
|
||||
use crate::Result;
|
||||
|
||||
/// See the [platform-specific Event struct](crate::platform::Event) for struct- and method-level
|
||||
/// documentation.
|
||||
|
|
|
|||
126
base/src/lib.rs
126
base/src/lib.rs
|
|
@ -21,27 +21,46 @@ mod wait_context;
|
|||
mod write_zeroes;
|
||||
|
||||
pub mod sys;
|
||||
pub use sys::platform;
|
||||
|
||||
pub use alloc::LayoutAllocation;
|
||||
pub use clock::{Clock, FakeClock};
|
||||
pub use errno::{errno_result, Error, Result};
|
||||
pub use event::{Event, EventReadResult};
|
||||
pub use external_mapping::{
|
||||
Error as ExternalMappingError, ExternalMapping, Result as ExternalMappingResult,
|
||||
};
|
||||
pub use mmap::{MappedRegion, MemoryMapping, MemoryMappingBuilder};
|
||||
pub use notifiers::{CloseNotifier, ReadNotifier};
|
||||
|
||||
pub use clock::Clock;
|
||||
pub use clock::FakeClock;
|
||||
pub use errno::errno_result;
|
||||
pub use errno::Error;
|
||||
pub use errno::Result;
|
||||
pub use event::Event;
|
||||
pub use event::EventReadResult;
|
||||
pub use external_mapping::Error as ExternalMappingError;
|
||||
pub use external_mapping::ExternalMapping;
|
||||
pub use external_mapping::Result as ExternalMappingResult;
|
||||
pub use mmap::MappedRegion;
|
||||
pub use mmap::MemoryMapping;
|
||||
pub use mmap::MemoryMappingBuilder;
|
||||
pub use notifiers::CloseNotifier;
|
||||
pub use notifiers::ReadNotifier;
|
||||
pub use platform::gmtime_secure;
|
||||
pub use platform::ioctl::{
|
||||
ioctl, ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref, ioctl_with_val,
|
||||
IoctlNr,
|
||||
};
|
||||
pub use platform::ioctl::ioctl;
|
||||
pub use platform::ioctl::ioctl_with_mut_ptr;
|
||||
pub use platform::ioctl::ioctl_with_mut_ref;
|
||||
pub use platform::ioctl::ioctl_with_ptr;
|
||||
pub use platform::ioctl::ioctl_with_ref;
|
||||
pub use platform::ioctl::ioctl_with_val;
|
||||
pub use platform::ioctl::IoctlNr;
|
||||
pub use shm::SharedMemory;
|
||||
pub use timer::{FakeTimer, Timer};
|
||||
pub use tube::{Error as TubeError, RecvTube, Result as TubeResult, SendTube, Tube};
|
||||
pub use wait_context::{EventToken, EventType, TriggeredEvent, WaitContext};
|
||||
pub use write_zeroes::{PunchHole, WriteZeroesAt};
|
||||
pub use sys::platform;
|
||||
pub use timer::FakeTimer;
|
||||
pub use timer::Timer;
|
||||
pub use tube::Error as TubeError;
|
||||
pub use tube::RecvTube;
|
||||
pub use tube::Result as TubeResult;
|
||||
pub use tube::SendTube;
|
||||
pub use tube::Tube;
|
||||
pub use wait_context::EventToken;
|
||||
pub use wait_context::EventType;
|
||||
pub use wait_context::TriggeredEvent;
|
||||
pub use wait_context::WaitContext;
|
||||
pub use write_zeroes::PunchHole;
|
||||
pub use write_zeroes::WriteZeroesAt;
|
||||
|
||||
// TODO(b/233233301): reorganize platform specific exports under platform
|
||||
// namespaces instead of exposing them directly in base::.
|
||||
|
|
@ -107,33 +126,51 @@ cfg_if::cfg_if! {
|
|||
}
|
||||
}
|
||||
|
||||
pub use platform::{BlockingMode, FramingMode, StreamChannel};
|
||||
|
||||
pub use platform::{
|
||||
deserialize_with_descriptors, EventContext, FileAllocate, FileGetLen, FileSerdeWrapper,
|
||||
SerializeDescriptors, UnsyncMarker,
|
||||
};
|
||||
|
||||
pub use log::debug;
|
||||
pub use log::error;
|
||||
pub use log::info;
|
||||
pub use log::trace;
|
||||
pub use log::warn;
|
||||
pub use mmap::Protection;
|
||||
pub use platform::deserialize_with_descriptors;
|
||||
pub(crate) use platform::file_punch_hole;
|
||||
pub(crate) use platform::file_write_zeroes_at;
|
||||
pub use platform::get_cpu_affinity;
|
||||
pub use platform::get_filesystem_type;
|
||||
pub use platform::getpid;
|
||||
pub use platform::number_of_logical_cores;
|
||||
pub use platform::open_file;
|
||||
pub use platform::pagesize;
|
||||
pub use platform::platform_timer_resolution::enable_high_res_timers;
|
||||
pub use platform::round_up_to_page_size;
|
||||
pub use platform::set_cpu_affinity;
|
||||
pub use platform::with_as_descriptor;
|
||||
pub use platform::with_raw_descriptor;
|
||||
pub use platform::BlockingMode;
|
||||
pub use platform::EventContext;
|
||||
pub use platform::FileAllocate;
|
||||
pub use platform::FileGetLen;
|
||||
pub use platform::FileReadWriteAtVolatile;
|
||||
pub use platform::FileReadWriteVolatile;
|
||||
pub use platform::FileSerdeWrapper;
|
||||
pub use platform::FileSetLen;
|
||||
pub use platform::FileSync;
|
||||
pub use platform::FramingMode;
|
||||
pub use platform::MemoryMappingArena;
|
||||
pub use platform::MmapError;
|
||||
pub use platform::RawDescriptor;
|
||||
pub use platform::SerializeDescriptors;
|
||||
pub use platform::StreamChannel;
|
||||
pub use platform::UnsyncMarker;
|
||||
pub use platform::INVALID_DESCRIPTOR;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub use mmap::Protection;
|
||||
pub(crate) use platform::{file_punch_hole, file_write_zeroes_at};
|
||||
pub use platform::{get_cpu_affinity, set_cpu_affinity};
|
||||
pub use platform::{with_as_descriptor, with_raw_descriptor, RawDescriptor, INVALID_DESCRIPTOR};
|
||||
|
||||
pub use crate::descriptor::{
|
||||
AsRawDescriptor, AsRawDescriptors, Descriptor, FromRawDescriptor, IntoRawDescriptor,
|
||||
SafeDescriptor,
|
||||
};
|
||||
|
||||
pub use platform::getpid;
|
||||
pub use platform::platform_timer_resolution::enable_high_res_timers;
|
||||
pub use platform::{get_filesystem_type, open_file};
|
||||
pub use platform::{number_of_logical_cores, pagesize, round_up_to_page_size};
|
||||
pub use platform::{FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen, FileSync};
|
||||
pub use platform::{MemoryMappingArena, MmapError};
|
||||
|
||||
pub use log::{debug, error, info, trace, warn};
|
||||
pub use crate::descriptor::AsRawDescriptor;
|
||||
pub use crate::descriptor::AsRawDescriptors;
|
||||
pub use crate::descriptor::Descriptor;
|
||||
pub use crate::descriptor::FromRawDescriptor;
|
||||
pub use crate::descriptor::IntoRawDescriptor;
|
||||
pub use crate::descriptor::SafeDescriptor;
|
||||
|
||||
/// An empty trait that helps reset timer resolution to its previous state.
|
||||
// TODO(b:232103460): Maybe this needs to be thought through.
|
||||
|
|
@ -148,7 +185,8 @@ pub fn generate_uuid() -> String {
|
|||
.to_owned()
|
||||
}
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub enum VmEventType {
|
||||
Exit,
|
||||
|
|
|
|||
|
|
@ -2,24 +2,30 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
cmp::min,
|
||||
fs::File,
|
||||
intrinsics::copy_nonoverlapping,
|
||||
mem::size_of,
|
||||
ptr::{read_unaligned, read_volatile, write_unaligned, write_volatile},
|
||||
sync::atomic::{fence, Ordering},
|
||||
};
|
||||
use std::cmp::min;
|
||||
use std::fs::File;
|
||||
use std::intrinsics::copy_nonoverlapping;
|
||||
use std::mem::size_of;
|
||||
use std::ptr::read_unaligned;
|
||||
use std::ptr::read_volatile;
|
||||
use std::ptr::write_unaligned;
|
||||
use std::ptr::write_volatile;
|
||||
use std::sync::atomic::fence;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use data_model::{volatile_memory::*, DataInit};
|
||||
use data_model::volatile_memory::*;
|
||||
use data_model::DataInit;
|
||||
use libc::c_int;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
descriptor::{AsRawDescriptor, SafeDescriptor},
|
||||
platform::{MemoryMapping as PlatformMmap, MmapError as Error, PROT_READ, PROT_WRITE},
|
||||
SharedMemory,
|
||||
};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::platform::MemoryMapping as PlatformMmap;
|
||||
use crate::platform::MmapError as Error;
|
||||
use crate::platform::PROT_READ;
|
||||
use crate::platform::PROT_WRITE;
|
||||
use crate::SharedMemory;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,20 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use crate::{Error, RawDescriptor, Result};
|
||||
use std::ffi::CString;
|
||||
|
||||
use libc::EINVAL;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::platform::SharedMemory as SysUtilSharedMemory;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::Error;
|
||||
use crate::RawDescriptor;
|
||||
use crate::Result;
|
||||
|
||||
/// See [SharedMemory](crate::platform::SharedMemory) for struct- and method-level
|
||||
/// documentation.
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
use std::str;
|
||||
|
||||
use super::netlink::*;
|
||||
use data_model::DataInit;
|
||||
use thiserror::Error;
|
||||
|
||||
use data_model::DataInit;
|
||||
use super::netlink::*;
|
||||
|
||||
const ACPI_EVENT_SIZE: usize = std::mem::size_of::<AcpiGenlEvent>();
|
||||
const GENL_HDRLEN: usize = std::mem::size_of::<GenlMsgHdr>();
|
||||
|
|
|
|||
|
|
@ -6,19 +6,22 @@
|
|||
|
||||
extern crate android_log_sys;
|
||||
|
||||
use android_log_sys::{
|
||||
__android_log_is_loggable, __android_log_message, __android_log_write_log_message, log_id_t,
|
||||
LogPriority,
|
||||
};
|
||||
use std::{
|
||||
ffi::{CString, NulError},
|
||||
mem::size_of,
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use std::ffi::NulError;
|
||||
use std::mem::size_of;
|
||||
|
||||
use crate::{
|
||||
syslog::{Error, Facility, Level, Log, Syslog},
|
||||
RawDescriptor,
|
||||
};
|
||||
use android_log_sys::__android_log_is_loggable;
|
||||
use android_log_sys::__android_log_message;
|
||||
use android_log_sys::__android_log_write_log_message;
|
||||
use android_log_sys::log_id_t;
|
||||
use android_log_sys::LogPriority;
|
||||
|
||||
use crate::syslog::Error;
|
||||
use crate::syslog::Facility;
|
||||
use crate::syslog::Level;
|
||||
use crate::syslog::Log;
|
||||
use crate::syslog::Syslog;
|
||||
use crate::RawDescriptor;
|
||||
|
||||
pub struct PlatformSyslog {
|
||||
proc_name: String,
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use libc::{c_int, c_void};
|
||||
use libc::c_int;
|
||||
use libc::c_void;
|
||||
|
||||
use super::{errno_result, Result};
|
||||
use super::errno_result;
|
||||
use super::Result;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
type cap_t = *mut c_void;
|
||||
|
|
|
|||
|
|
@ -2,26 +2,30 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
fs::File,
|
||||
io::{Stderr, Stdin, Stdout},
|
||||
net::UdpSocket,
|
||||
ops::Drop,
|
||||
os::unix::{
|
||||
io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
|
||||
net::{UnixDatagram, UnixListener, UnixStream},
|
||||
},
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
use std::io::Stderr;
|
||||
use std::io::Stdin;
|
||||
use std::io::Stdout;
|
||||
use std::net::UdpSocket;
|
||||
use std::ops::Drop;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
use super::{
|
||||
errno_result,
|
||||
net::{UnixSeqpacket, UnlinkUnixSeqpacketListener},
|
||||
Result,
|
||||
};
|
||||
use crate::descriptor::{
|
||||
AsRawDescriptor, Descriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor,
|
||||
};
|
||||
use super::errno_result;
|
||||
use super::net::UnixSeqpacket;
|
||||
use super::net::UnlinkUnixSeqpacketListener;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::Descriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
pub type RawDescriptor = RawFd;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,18 +2,28 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
mem,
|
||||
os::unix::io::{AsRawFd, RawFd},
|
||||
ptr,
|
||||
time::Duration,
|
||||
};
|
||||
use std::mem;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::ptr;
|
||||
use std::time::Duration;
|
||||
|
||||
use libc::{c_void, eventfd, read, write, POLLIN};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use libc::c_void;
|
||||
use libc::eventfd;
|
||||
use libc::read;
|
||||
use libc::write;
|
||||
use libc::POLLIN;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{duration_to_timespec, errno_result, RawDescriptor, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use super::duration_to_timespec;
|
||||
use super::errno_result;
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
/// A safe wrapper around a Linux eventfd (man 2 eventfd).
|
||||
///
|
||||
|
|
|
|||
|
|
@ -4,9 +4,17 @@
|
|||
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
use libc::{fcntl, EINVAL, F_GETFL, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY};
|
||||
use libc::fcntl;
|
||||
use libc::EINVAL;
|
||||
use libc::F_GETFL;
|
||||
use libc::O_ACCMODE;
|
||||
use libc::O_RDONLY;
|
||||
use libc::O_RDWR;
|
||||
use libc::O_WRONLY;
|
||||
|
||||
use super::{errno_result, Error, Result};
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum FileFlags {
|
||||
|
|
@ -35,10 +43,9 @@ impl FileFlags {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{pipe, Event},
|
||||
*,
|
||||
};
|
||||
use super::super::pipe;
|
||||
use super::super::Event;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn pipe_pair() {
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Error, ErrorKind, Result},
|
||||
os::unix::{
|
||||
io::{AsRawFd, RawFd},
|
||||
net::UnixStream,
|
||||
},
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Result;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
use data_model::VolatileSlice;
|
||||
|
||||
use super::{fallocate, FallocateMode};
|
||||
use super::fallocate;
|
||||
use super::FallocateMode;
|
||||
|
||||
/// A trait for flushing the contents of a file to disk.
|
||||
/// This is equivalent to File's `sync_all` method, but
|
||||
|
|
@ -266,12 +266,21 @@ impl<'a, T: FileReadWriteAtVolatile + ?Sized> FileReadWriteAtVolatile for &'a mu
|
|||
// This module allows the below macros to refer to $crate::platform::file_traits::lib::X and ensures other
|
||||
// crates don't need to add additional crates to their Cargo.toml.
|
||||
pub mod lib {
|
||||
pub use libc::{
|
||||
c_int, c_void, iovec, off64_t, pread64, preadv64, pwrite64, pwritev64, read, readv, size_t,
|
||||
write, writev,
|
||||
};
|
||||
|
||||
pub use data_model::{IoBufMut, VolatileSlice};
|
||||
pub use data_model::IoBufMut;
|
||||
pub use data_model::VolatileSlice;
|
||||
pub use libc::c_int;
|
||||
pub use libc::c_void;
|
||||
pub use libc::iovec;
|
||||
pub use libc::off64_t;
|
||||
pub use libc::pread64;
|
||||
pub use libc::preadv64;
|
||||
pub use libc::pwrite64;
|
||||
pub use libc::pwritev64;
|
||||
pub use libc::read;
|
||||
pub use libc::readv;
|
||||
pub use libc::size_t;
|
||||
pub use libc::write;
|
||||
pub use libc::writev;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::fs::File;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
use libc::fstatfs;
|
||||
|
||||
use super::Result;
|
||||
use crate::syscall;
|
||||
use libc::fstatfs;
|
||||
use std::{fs::File, mem::MaybeUninit, os::unix::io::AsRawFd};
|
||||
|
||||
/// Obtain file system type of the file system that the file is served from.
|
||||
pub fn get_filesystem_type(file: &File) -> Result<i64> {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use libc::{gmtime_r, time_t, tm};
|
||||
use libc::gmtime_r;
|
||||
use libc::time_t;
|
||||
use libc::tm;
|
||||
|
||||
/// # Safety
|
||||
/// safe because we are passing in the allocated tm struct
|
||||
|
|
@ -13,9 +15,10 @@ pub unsafe fn gmtime_secure(now: *const time_t, result: *mut tm) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn gmtime() {
|
||||
// Safe because struct is not used before being initialized
|
||||
|
|
|
|||
|
|
@ -171,7 +171,8 @@ macro_rules! handle_eintr_errno {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::Error as SysError, *};
|
||||
use super::super::Error as SysError;
|
||||
use super::*;
|
||||
|
||||
// Sets errno to the given error code.
|
||||
fn set_errno(e: i32) {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@
|
|||
// `libc::ioctl`. Their safety follows `libc::ioctl`'s safety.
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
use std::os::raw::c_int;
|
||||
use std::os::raw::c_uint;
|
||||
use std::os::raw::c_ulong;
|
||||
use std::os::raw::c_void;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use std::os::raw::{c_int, c_uint, c_ulong, c_void};
|
||||
|
||||
/// Raw macro to declare the expression that calculates an ioctl number
|
||||
#[macro_export]
|
||||
|
|
|
|||
|
|
@ -4,27 +4,34 @@
|
|||
|
||||
//! Implementation of the Syslog trait for Linux.
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{ErrorKind, Write},
|
||||
mem,
|
||||
os::unix::{
|
||||
io::{AsRawFd, FromRawFd},
|
||||
net::UnixDatagram,
|
||||
},
|
||||
ptr::null,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Write;
|
||||
use std::mem;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::ptr::null;
|
||||
|
||||
use libc::{
|
||||
closelog, fcntl, localtime_r, openlog, time, time_t, tm, F_GETFD, LOG_NDELAY, LOG_PERROR,
|
||||
LOG_PID, LOG_USER,
|
||||
};
|
||||
use libc::closelog;
|
||||
use libc::fcntl;
|
||||
use libc::localtime_r;
|
||||
use libc::openlog;
|
||||
use libc::time;
|
||||
use libc::time_t;
|
||||
use libc::tm;
|
||||
use libc::F_GETFD;
|
||||
use libc::LOG_NDELAY;
|
||||
use libc::LOG_PERROR;
|
||||
use libc::LOG_PID;
|
||||
use libc::LOG_USER;
|
||||
|
||||
use super::super::getpid;
|
||||
use crate::{
|
||||
syslog::{Error, Facility, Priority, Syslog},
|
||||
RawDescriptor,
|
||||
};
|
||||
use crate::syslog::Error;
|
||||
use crate::syslog::Facility;
|
||||
use crate::syslog::Priority;
|
||||
use crate::syslog::Syslog;
|
||||
use crate::RawDescriptor;
|
||||
|
||||
const SYSLOG_PATH: &str = "/dev/log";
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,28 @@
|
|||
//! The mmap module provides a safe interface to mmap memory and ensures unmap is called when the
|
||||
//! mmap object leaves scope.
|
||||
|
||||
use std::{io, ptr::null_mut};
|
||||
use std::io;
|
||||
use std::ptr::null_mut;
|
||||
|
||||
use libc::{self, c_int, c_void, read, write};
|
||||
use libc::c_int;
|
||||
use libc::c_void;
|
||||
use libc::read;
|
||||
use libc::write;
|
||||
use libc::{self};
|
||||
use log::warn;
|
||||
use remain::sorted;
|
||||
|
||||
use crate::{
|
||||
external_mapping::ExternalMapping, AsRawDescriptor, Descriptor, MappedRegion,
|
||||
MemoryMapping as CrateMemoryMapping, MemoryMappingBuilder, Protection, RawDescriptor,
|
||||
SafeDescriptor,
|
||||
};
|
||||
|
||||
use super::{pagesize, Error as ErrnoError};
|
||||
use super::pagesize;
|
||||
use super::Error as ErrnoError;
|
||||
use crate::external_mapping::ExternalMapping;
|
||||
use crate::AsRawDescriptor;
|
||||
use crate::Descriptor;
|
||||
use crate::MappedRegion;
|
||||
use crate::MemoryMapping as CrateMemoryMapping;
|
||||
use crate::MemoryMappingBuilder;
|
||||
use crate::Protection;
|
||||
use crate::RawDescriptor;
|
||||
use crate::SafeDescriptor;
|
||||
|
||||
#[sorted]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
@ -880,10 +889,12 @@ impl<'a> MemoryMappingBuilder<'a> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use data_model::VolatileMemory;
|
||||
use data_model::VolatileMemoryError;
|
||||
use tempfile::tempfile;
|
||||
|
||||
use super::*;
|
||||
use crate::descriptor::Descriptor;
|
||||
use data_model::{VolatileMemory, VolatileMemoryError};
|
||||
use tempfile::tempfile;
|
||||
|
||||
#[test]
|
||||
fn basic_map() {
|
||||
|
|
|
|||
|
|
@ -46,11 +46,23 @@ mod timer;
|
|||
pub mod vsock;
|
||||
mod write_zeroes;
|
||||
|
||||
pub use crate::descriptor_reflection::{
|
||||
deserialize_with_descriptors, with_as_descriptor, with_raw_descriptor, FileSerdeWrapper,
|
||||
SerializeDescriptors,
|
||||
};
|
||||
pub use crate::errno::{Error, Result, *};
|
||||
use std::cell::Cell;
|
||||
use std::convert::TryFrom;
|
||||
use std::ffi::CStr;
|
||||
use std::fs::remove_file;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::time::Duration;
|
||||
|
||||
pub use acpi_event::*;
|
||||
pub use capabilities::drop_capabilities;
|
||||
pub use descriptor::*;
|
||||
|
|
@ -59,54 +71,66 @@ pub use descriptor::*;
|
|||
// TODO(b:231344063): Remove EventFd.
|
||||
pub use eventfd::{EventFd as Event, EventFd, EventReadResult};
|
||||
pub use file_flags::*;
|
||||
pub use file_traits::AsRawFds;
|
||||
pub use file_traits::FileAllocate;
|
||||
pub use file_traits::FileGetLen;
|
||||
pub use file_traits::FileReadWriteAtVolatile;
|
||||
pub use file_traits::FileReadWriteVolatile;
|
||||
pub use file_traits::FileSetLen;
|
||||
pub use file_traits::FileSync;
|
||||
pub use get_filesystem_type::*;
|
||||
pub use gmtime::*;
|
||||
pub use ioctl::*;
|
||||
use libc::c_int;
|
||||
use libc::c_long;
|
||||
use libc::fcntl;
|
||||
use libc::pipe2;
|
||||
use libc::syscall;
|
||||
use libc::sysconf;
|
||||
use libc::waitpid;
|
||||
use libc::SYS_getpid;
|
||||
use libc::SYS_gettid;
|
||||
use libc::EINVAL;
|
||||
use libc::F_GETFL;
|
||||
use libc::F_SETFL;
|
||||
use libc::O_CLOEXEC;
|
||||
pub(crate) use libc::PROT_READ;
|
||||
pub(crate) use libc::PROT_WRITE;
|
||||
use libc::SIGKILL;
|
||||
use libc::WNOHANG;
|
||||
use libc::_SC_IOV_MAX;
|
||||
use libc::_SC_PAGESIZE;
|
||||
pub use mmap::Error as MmapError;
|
||||
pub use mmap::*;
|
||||
pub use netlink::*;
|
||||
pub use poll::EventContext;
|
||||
pub use priority::*;
|
||||
pub use sched::*;
|
||||
pub use scoped_signal_handler::*;
|
||||
pub use shm::{kernel_has_memfd, MemfdSeals, SharedMemory, Unix as SharedMemoryUnix};
|
||||
pub use shm::kernel_has_memfd;
|
||||
pub use shm::MemfdSeals;
|
||||
pub use shm::SharedMemory;
|
||||
pub use shm::Unix as SharedMemoryUnix;
|
||||
pub use signal::*;
|
||||
pub use signalfd::Error as SignalFdError;
|
||||
pub use signalfd::*;
|
||||
pub use sock_ctrl_msg::*;
|
||||
pub use stream_channel::*;
|
||||
pub use terminal::*;
|
||||
pub use timer::*;
|
||||
pub(crate) use write_zeroes::file_punch_hole;
|
||||
pub(crate) use write_zeroes::file_write_zeroes_at;
|
||||
|
||||
use crate::descriptor::{FromRawDescriptor, SafeDescriptor};
|
||||
pub use file_traits::{
|
||||
AsRawFds, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen,
|
||||
FileSync,
|
||||
};
|
||||
pub use mmap::Error as MmapError;
|
||||
pub use signalfd::Error as SignalFdError;
|
||||
pub(crate) use write_zeroes::{file_punch_hole, file_write_zeroes_at};
|
||||
|
||||
use std::{
|
||||
cell::Cell,
|
||||
convert::TryFrom,
|
||||
ffi::CStr,
|
||||
fs::{remove_file, File, OpenOptions},
|
||||
mem,
|
||||
ops::Deref,
|
||||
os::unix::{
|
||||
io::{AsRawFd, FromRawFd, RawFd},
|
||||
net::{UnixDatagram, UnixListener},
|
||||
},
|
||||
path::Path,
|
||||
ptr,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use libc::{
|
||||
c_int, c_long, fcntl, pipe2, syscall, sysconf, waitpid, SYS_getpid, SYS_gettid, EINVAL,
|
||||
F_GETFL, F_SETFL, O_CLOEXEC, SIGKILL, WNOHANG, _SC_IOV_MAX, _SC_PAGESIZE,
|
||||
};
|
||||
|
||||
pub(crate) use libc::{PROT_READ, PROT_WRITE};
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
pub use crate::descriptor_reflection::deserialize_with_descriptors;
|
||||
pub use crate::descriptor_reflection::with_as_descriptor;
|
||||
pub use crate::descriptor_reflection::with_raw_descriptor;
|
||||
pub use crate::descriptor_reflection::FileSerdeWrapper;
|
||||
pub use crate::descriptor_reflection::SerializeDescriptors;
|
||||
pub use crate::errno::Error;
|
||||
pub use crate::errno::Result;
|
||||
pub use crate::errno::*;
|
||||
|
||||
/// Re-export libc types that are part of the API.
|
||||
pub type Pid = libc::pid_t;
|
||||
|
|
@ -637,9 +661,10 @@ pub fn number_of_logical_cores() -> Result<usize> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use libc::EBADF;
|
||||
use std::io::Write;
|
||||
|
||||
use libc::EBADF;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -2,36 +2,58 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
convert::TryFrom,
|
||||
ffi::OsString,
|
||||
fs::remove_file,
|
||||
io,
|
||||
mem::{self, size_of},
|
||||
net::{SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener, TcpStream, ToSocketAddrs},
|
||||
ops::Deref,
|
||||
os::unix::{
|
||||
ffi::{OsStrExt, OsStringExt},
|
||||
io::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
|
||||
},
|
||||
path::{Path, PathBuf},
|
||||
ptr::null_mut,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::cmp::Ordering;
|
||||
use std::convert::TryFrom;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::remove_file;
|
||||
use std::io;
|
||||
use std::mem::size_of;
|
||||
use std::mem::{self};
|
||||
use std::net::SocketAddr;
|
||||
use std::net::SocketAddrV4;
|
||||
use std::net::SocketAddrV6;
|
||||
use std::net::TcpListener;
|
||||
use std::net::TcpStream;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::ops::Deref;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::ptr::null_mut;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use libc::{
|
||||
c_int, in6_addr, in_addr, recvfrom, sa_family_t, sockaddr, sockaddr_in, sockaddr_in6,
|
||||
socklen_t, AF_INET, AF_INET6, MSG_PEEK, MSG_TRUNC, SOCK_CLOEXEC, SOCK_STREAM,
|
||||
};
|
||||
use libc::c_int;
|
||||
use libc::in6_addr;
|
||||
use libc::in_addr;
|
||||
use libc::recvfrom;
|
||||
use libc::sa_family_t;
|
||||
use libc::sockaddr;
|
||||
use libc::sockaddr_in;
|
||||
use libc::sockaddr_in6;
|
||||
use libc::socklen_t;
|
||||
use libc::AF_INET;
|
||||
use libc::AF_INET6;
|
||||
use libc::MSG_PEEK;
|
||||
use libc::MSG_TRUNC;
|
||||
use libc::SOCK_CLOEXEC;
|
||||
use libc::SOCK_STREAM;
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{
|
||||
sock_ctrl_msg::{ScmSocket, SCM_SOCKET_MAX_FD_COUNT},
|
||||
Error, RawDescriptor,
|
||||
};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
|
||||
use super::sock_ctrl_msg::ScmSocket;
|
||||
use super::sock_ctrl_msg::SCM_SOCKET_MAX_FD_COUNT;
|
||||
use super::Error;
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
|
||||
/// Assist in handling both IP version 4 and IP version 6.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
|
|
@ -870,8 +892,11 @@ impl Drop for UnlinkUnixSeqpacketListener {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::env;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
use std::{env, io::ErrorKind, path::PathBuf};
|
||||
|
||||
fn tmpdir() -> PathBuf {
|
||||
env::temp_dir()
|
||||
|
|
|
|||
|
|
@ -2,16 +2,24 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{alloc::Layout, mem::MaybeUninit, os::unix::io::AsRawFd, str};
|
||||
use std::alloc::Layout;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::str;
|
||||
|
||||
use data_model::DataInit;
|
||||
use libc::EINVAL;
|
||||
use log::error;
|
||||
|
||||
use super::errno_result;
|
||||
use super::getpid;
|
||||
use super::Error;
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::alloc::LayoutAllocation;
|
||||
|
||||
use super::{errno_result, getpid, Error, RawDescriptor, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
macro_rules! debug_pr {
|
||||
// By default debugs are suppressed, to enabled them replace macro body with:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
use std::os::unix::net::UnixStream;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::{CloseNotifier, ReadNotifier};
|
||||
use crate::CloseNotifier;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
impl ReadNotifier for UnixStream {
|
||||
fn get_read_notifier(&self) -> &dyn AsRawDescriptor {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::{EnabledHighResTimer, Result};
|
||||
use crate::EnabledHighResTimer;
|
||||
use crate::Result;
|
||||
|
||||
/// Noop struct on unix.
|
||||
/// On windows, restores the platform timer resolution to its original value on Drop.
|
||||
|
|
|
|||
|
|
@ -2,20 +2,36 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
cmp::min, fs::File, marker::PhantomData, mem::MaybeUninit, ptr::null_mut, time::Duration,
|
||||
};
|
||||
use std::cmp::min;
|
||||
use std::fs::File;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ptr::null_mut;
|
||||
use std::time::Duration;
|
||||
|
||||
use libc::{
|
||||
c_int, epoll_create1, epoll_ctl, epoll_event, epoll_wait, EPOLLHUP, EPOLLIN, EPOLLOUT,
|
||||
EPOLLRDHUP, EPOLL_CLOEXEC, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD,
|
||||
};
|
||||
use libc::c_int;
|
||||
use libc::epoll_create1;
|
||||
use libc::epoll_ctl;
|
||||
use libc::epoll_event;
|
||||
use libc::epoll_wait;
|
||||
use libc::EPOLLHUP;
|
||||
use libc::EPOLLIN;
|
||||
use libc::EPOLLOUT;
|
||||
use libc::EPOLLRDHUP;
|
||||
use libc::EPOLL_CLOEXEC;
|
||||
use libc::EPOLL_CTL_ADD;
|
||||
use libc::EPOLL_CTL_DEL;
|
||||
use libc::EPOLL_CTL_MOD;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use super::{errno_result, Result};
|
||||
use crate::{
|
||||
AsRawDescriptor, EventToken, EventType, FromRawDescriptor, RawDescriptor, TriggeredEvent,
|
||||
};
|
||||
use super::errno_result;
|
||||
use super::Result;
|
||||
use crate::AsRawDescriptor;
|
||||
use crate::EventToken;
|
||||
use crate::EventType;
|
||||
use crate::FromRawDescriptor;
|
||||
use crate::RawDescriptor;
|
||||
use crate::TriggeredEvent;
|
||||
|
||||
const EVENT_CONTEXT_MAX_EVENTS: usize = 16;
|
||||
|
||||
|
|
@ -251,10 +267,13 @@ impl<T: EventToken> AsRawDescriptor for EventContext<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::Event, *};
|
||||
use base_event_token_derive::EventToken;
|
||||
use std::time::Instant;
|
||||
|
||||
use base_event_token_derive::EventToken;
|
||||
|
||||
use super::super::Event;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn event_context() {
|
||||
let evt1 = Event::new().unwrap();
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::{errno_result, Result};
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
use super::errno_result;
|
||||
use super::Result;
|
||||
|
||||
/// Enables real time thread priorities in the current thread up to `limit`.
|
||||
pub fn set_rt_prio_limit(limit: u64) -> Result<()> {
|
||||
let rt_limit_arg = libc::rlimit {
|
||||
|
|
|
|||
|
|
@ -4,14 +4,22 @@
|
|||
|
||||
//! Wrappers for CPU affinity functions.
|
||||
|
||||
use std::{iter::FromIterator, mem};
|
||||
use std::iter::FromIterator;
|
||||
use std::mem;
|
||||
|
||||
use libc::{
|
||||
cpu_set_t, prctl, sched_getaffinity, sched_setaffinity, CPU_ISSET, CPU_SET, CPU_SETSIZE,
|
||||
CPU_ZERO, EINVAL,
|
||||
};
|
||||
use libc::cpu_set_t;
|
||||
use libc::prctl;
|
||||
use libc::sched_getaffinity;
|
||||
use libc::sched_setaffinity;
|
||||
use libc::CPU_ISSET;
|
||||
use libc::CPU_SET;
|
||||
use libc::CPU_SETSIZE;
|
||||
use libc::CPU_ZERO;
|
||||
use libc::EINVAL;
|
||||
|
||||
use super::{errno_result, Error, Result};
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
|
||||
// This is needed because otherwise the compiler will complain that the
|
||||
// impl doesn't reference any types from inside this crate.
|
||||
|
|
|
|||
|
|
@ -4,25 +4,25 @@
|
|||
|
||||
//! Provides a struct for registering signal handlers that get cleared on drop.
|
||||
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
fmt,
|
||||
io::{Cursor, Write},
|
||||
panic::catch_unwind,
|
||||
result,
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::io::Cursor;
|
||||
use std::io::Write;
|
||||
use std::panic::catch_unwind;
|
||||
use std::result;
|
||||
|
||||
use libc::{c_int, c_void, STDERR_FILENO};
|
||||
use libc::c_int;
|
||||
use libc::c_void;
|
||||
use libc::STDERR_FILENO;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::{
|
||||
signal::{
|
||||
clear_signal_handler, has_default_signal_handler, register_signal_handler, wait_for_signal,
|
||||
Signal,
|
||||
},
|
||||
Error as ErrnoError,
|
||||
};
|
||||
use super::signal::clear_signal_handler;
|
||||
use super::signal::has_default_signal_handler;
|
||||
use super::signal::register_signal_handler;
|
||||
use super::signal::wait_for_signal;
|
||||
use super::signal::Signal;
|
||||
use super::Error as ErrnoError;
|
||||
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
|
|
@ -179,24 +179,30 @@ pub fn wait_for_interrupt() -> Result<()> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
mem::zeroed,
|
||||
ptr::{null, null_mut},
|
||||
sync::{
|
||||
atomic::{AtomicI32, AtomicUsize, Ordering},
|
||||
Arc, Mutex, MutexGuard, Once,
|
||||
},
|
||||
thread::{sleep, spawn},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::mem::zeroed;
|
||||
use std::ptr::null;
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::atomic::AtomicI32;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::MutexGuard;
|
||||
use std::sync::Once;
|
||||
use std::thread::sleep;
|
||||
use std::thread::spawn;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use libc::sigaction;
|
||||
|
||||
use super::super::{gettid, kill, Pid};
|
||||
use super::super::gettid;
|
||||
use super::super::kill;
|
||||
use super::super::Pid;
|
||||
use super::*;
|
||||
|
||||
const TEST_SIGNAL: Signal = Signal::User1;
|
||||
const TEST_SIGNALS: &[Signal] = &[Signal::User1, Signal::User2];
|
||||
|
|
|
|||
|
|
@ -2,24 +2,47 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
ffi::CStr,
|
||||
fs::{read_link, File},
|
||||
io::{
|
||||
Read, Seek, SeekFrom, Write, {self},
|
||||
},
|
||||
};
|
||||
use std::ffi::CStr;
|
||||
use std::fs::read_link;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
|
||||
use libc::{
|
||||
c_char, c_int, c_long, c_uint, close, fcntl, ftruncate64, off64_t, syscall, SYS_memfd_create,
|
||||
EINVAL, F_ADD_SEALS, F_GET_SEALS, F_SEAL_FUTURE_WRITE, F_SEAL_GROW, F_SEAL_SEAL, F_SEAL_SHRINK,
|
||||
F_SEAL_WRITE, MFD_ALLOW_SEALING, {self},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use libc::c_char;
|
||||
use libc::c_int;
|
||||
use libc::c_long;
|
||||
use libc::c_uint;
|
||||
use libc::close;
|
||||
use libc::fcntl;
|
||||
use libc::ftruncate64;
|
||||
use libc::off64_t;
|
||||
use libc::syscall;
|
||||
use libc::SYS_memfd_create;
|
||||
use libc::EINVAL;
|
||||
use libc::F_ADD_SEALS;
|
||||
use libc::F_GET_SEALS;
|
||||
use libc::F_SEAL_FUTURE_WRITE;
|
||||
use libc::F_SEAL_GROW;
|
||||
use libc::F_SEAL_SEAL;
|
||||
use libc::F_SEAL_SHRINK;
|
||||
use libc::F_SEAL_WRITE;
|
||||
use libc::MFD_ALLOW_SEALING;
|
||||
use libc::{self};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{errno_result, Error, Result};
|
||||
use crate::{AsRawDescriptor, IntoRawDescriptor, RawDescriptor, SafeDescriptor};
|
||||
use crate::{FromRawDescriptor, SharedMemory as CrateSharedMemory};
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
use crate::AsRawDescriptor;
|
||||
use crate::FromRawDescriptor;
|
||||
use crate::IntoRawDescriptor;
|
||||
use crate::RawDescriptor;
|
||||
use crate::SafeDescriptor;
|
||||
use crate::SharedMemory as CrateSharedMemory;
|
||||
|
||||
/// A shared memory file descriptor and its size.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -327,12 +350,12 @@ impl Unix for CrateSharedMemory {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{kernel_has_memfd, SharedMemory};
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use data_model::VolatileMemory;
|
||||
|
||||
use super::kernel_has_memfd;
|
||||
use super::SharedMemory;
|
||||
use crate::MemoryMappingBuilder;
|
||||
|
||||
fn create_test_shmem() -> SharedMemory {
|
||||
|
|
|
|||
|
|
@ -2,28 +2,53 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use libc::{
|
||||
c_int, pthread_kill, pthread_sigmask, pthread_t, sigaction, sigaddset, sigemptyset, siginfo_t,
|
||||
sigismember, sigpending, sigset_t, sigtimedwait, sigwait, timespec, waitpid, EAGAIN, EINTR,
|
||||
EINVAL, SA_RESTART, SIG_BLOCK, SIG_DFL, SIG_UNBLOCK, WNOHANG,
|
||||
};
|
||||
use std::cmp::Ordering;
|
||||
use std::convert::TryFrom;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::os::unix::thread::JoinHandleExt;
|
||||
use std::process::Child;
|
||||
use std::ptr::null;
|
||||
use std::ptr::null_mut;
|
||||
use std::result;
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use libc::c_int;
|
||||
use libc::pthread_kill;
|
||||
use libc::pthread_sigmask;
|
||||
use libc::pthread_t;
|
||||
use libc::sigaction;
|
||||
use libc::sigaddset;
|
||||
use libc::sigemptyset;
|
||||
use libc::siginfo_t;
|
||||
use libc::sigismember;
|
||||
use libc::sigpending;
|
||||
use libc::sigset_t;
|
||||
use libc::sigtimedwait;
|
||||
use libc::sigwait;
|
||||
use libc::timespec;
|
||||
use libc::waitpid;
|
||||
use libc::EAGAIN;
|
||||
use libc::EINTR;
|
||||
use libc::EINVAL;
|
||||
use libc::SA_RESTART;
|
||||
use libc::SIG_BLOCK;
|
||||
use libc::SIG_DFL;
|
||||
use libc::SIG_UNBLOCK;
|
||||
use libc::WNOHANG;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
convert::TryFrom,
|
||||
io, mem,
|
||||
os::unix::thread::JoinHandleExt,
|
||||
process::Child,
|
||||
ptr::{null, null_mut},
|
||||
result,
|
||||
thread::JoinHandle,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use super::{duration_to_timespec, errno_result, getsid, Error as ErrnoError, Pid, Result};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use super::duration_to_timespec;
|
||||
use super::errno_result;
|
||||
use super::getsid;
|
||||
use super::Error as ErrnoError;
|
||||
use super::Pid;
|
||||
use super::Result;
|
||||
|
||||
const POLL_RATE: Duration = Duration::from_millis(50);
|
||||
const DEFAULT_KILL_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
|
|
|||
|
|
@ -2,22 +2,28 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
mem,
|
||||
os::{
|
||||
raw::c_int,
|
||||
unix::io::{AsRawFd, FromRawFd, RawFd},
|
||||
},
|
||||
result,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::mem;
|
||||
use std::os::raw::c_int;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::result;
|
||||
|
||||
use libc::{c_void, read, signalfd, signalfd_siginfo, EAGAIN, SFD_CLOEXEC, SFD_NONBLOCK};
|
||||
use libc::c_void;
|
||||
use libc::read;
|
||||
use libc::signalfd;
|
||||
use libc::signalfd_siginfo;
|
||||
use libc::EAGAIN;
|
||||
use libc::SFD_CLOEXEC;
|
||||
use libc::SFD_NONBLOCK;
|
||||
use log::error;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::{signal, Error as ErrnoError, RawDescriptor};
|
||||
use super::signal;
|
||||
use super::Error as ErrnoError;
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
|
||||
#[sorted]
|
||||
|
|
@ -139,11 +145,16 @@ impl Drop for SignalFd {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem;
|
||||
use std::ptr::null;
|
||||
|
||||
use libc::pthread_sigmask;
|
||||
use libc::raise;
|
||||
use libc::sigismember;
|
||||
use libc::sigset_t;
|
||||
|
||||
use super::super::signal::SIGRTMIN;
|
||||
use libc::{pthread_sigmask, raise, sigismember, sigset_t};
|
||||
use std::{mem, ptr::null};
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
|
|
|
|||
|
|
@ -5,26 +5,37 @@
|
|||
//! Used to send and receive messages with file descriptors on sockets that accept control messages
|
||||
//! (e.g. Unix domain sockets).
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{IoSlice, IoSliceMut},
|
||||
mem::size_of,
|
||||
mem::MaybeUninit,
|
||||
os::unix::{
|
||||
io::{AsRawFd, FromRawFd, RawFd},
|
||||
net::{UnixDatagram, UnixStream},
|
||||
},
|
||||
ptr::{copy_nonoverlapping, null_mut, write_unaligned},
|
||||
slice,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::IoSlice;
|
||||
use std::io::IoSliceMut;
|
||||
use std::mem::size_of;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::ptr::copy_nonoverlapping;
|
||||
use std::ptr::null_mut;
|
||||
use std::ptr::write_unaligned;
|
||||
use std::slice;
|
||||
|
||||
use libc::{
|
||||
c_long, c_void, cmsghdr, iovec, msghdr, recvmsg, sendmsg, MSG_NOSIGNAL, SCM_RIGHTS, SOL_SOCKET,
|
||||
};
|
||||
use data_model::IoBufMut;
|
||||
use data_model::VolatileSlice;
|
||||
use libc::c_long;
|
||||
use libc::c_void;
|
||||
use libc::cmsghdr;
|
||||
use libc::iovec;
|
||||
use libc::msghdr;
|
||||
use libc::recvmsg;
|
||||
use libc::sendmsg;
|
||||
use libc::MSG_NOSIGNAL;
|
||||
use libc::SCM_RIGHTS;
|
||||
use libc::SOL_SOCKET;
|
||||
|
||||
use data_model::{IoBufMut, VolatileSlice};
|
||||
|
||||
use super::{net::UnixSeqpacket, Error, Result};
|
||||
use super::net::UnixSeqpacket;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
|
||||
// Each of the following macros performs the same function as their C counterparts. They are each
|
||||
// macros because they are used to size statically allocated arrays.
|
||||
|
|
@ -413,18 +424,16 @@ unsafe impl<'a> AsIobuf for VolatileSlice<'a> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::{
|
||||
io::Write,
|
||||
mem::size_of,
|
||||
os::{raw::c_long, unix::net::UnixDatagram},
|
||||
slice::from_raw_parts,
|
||||
};
|
||||
use std::io::Write;
|
||||
use std::mem::size_of;
|
||||
use std::os::raw::c_long;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::slice::from_raw_parts;
|
||||
|
||||
use libc::cmsghdr;
|
||||
|
||||
use super::super::Event;
|
||||
use super::*;
|
||||
|
||||
// Doing this as a macro makes it easier to see the line if it fails
|
||||
macro_rules! CMSG_SPACE_TEST {
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::super::{net::UnixSeqpacket, Result};
|
||||
use std::io::Read;
|
||||
use std::io::{self};
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
use libc::c_void;
|
||||
use libc::{self};
|
||||
|
||||
use super::super::net::UnixSeqpacket;
|
||||
use super::super::Result;
|
||||
use super::RawDescriptor;
|
||||
use crate::{descriptor::AsRawDescriptor, ReadNotifier};
|
||||
use libc::{
|
||||
c_void, {self},
|
||||
};
|
||||
use std::{
|
||||
io::{
|
||||
Read, {self},
|
||||
},
|
||||
os::unix::net::UnixStream,
|
||||
};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum FramingMode {
|
||||
|
|
@ -167,9 +167,13 @@ impl ReadNotifier for StreamChannel {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
use super::*;
|
||||
use crate::{EventContext, EventToken, ReadNotifier};
|
||||
use std::io::{Read, Write};
|
||||
use crate::EventContext;
|
||||
use crate::EventToken;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
#[derive(EventToken, Debug, Eq, PartialEq, Copy, Clone)]
|
||||
enum Token {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,26 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
pub use super::{target_os::syslog::PlatformSyslog, RawDescriptor};
|
||||
pub use super::target_os::syslog::PlatformSyslog;
|
||||
pub use super::RawDescriptor;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::ffi::CStr;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::os::unix::io::FromRawFd;
|
||||
|
||||
use libc::shm_open;
|
||||
use libc::shm_unlink;
|
||||
use libc::O_CREAT;
|
||||
use libc::O_EXCL;
|
||||
use libc::O_RDWR;
|
||||
|
||||
use crate::syslog::*;
|
||||
|
||||
use libc::{shm_open, shm_unlink, O_CREAT, O_EXCL, O_RDWR};
|
||||
|
||||
use std::{
|
||||
ffi::CStr,
|
||||
fs::File,
|
||||
io::{Read, Seek, SeekFrom},
|
||||
os::unix::io::FromRawFd,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn fds() {
|
||||
ensure_inited().unwrap();
|
||||
|
|
|
|||
|
|
@ -2,14 +2,26 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{io::Stdin, mem::zeroed, os::unix::io::RawFd};
|
||||
use std::io::Stdin;
|
||||
use std::mem::zeroed;
|
||||
use std::os::unix::io::RawFd;
|
||||
|
||||
use libc::{
|
||||
isatty, read, tcgetattr, tcsetattr, termios, ECHO, ICANON, ISIG, O_NONBLOCK, STDIN_FILENO,
|
||||
TCSANOW,
|
||||
};
|
||||
use libc::isatty;
|
||||
use libc::read;
|
||||
use libc::tcgetattr;
|
||||
use libc::tcsetattr;
|
||||
use libc::termios;
|
||||
use libc::ECHO;
|
||||
use libc::ICANON;
|
||||
use libc::ISIG;
|
||||
use libc::O_NONBLOCK;
|
||||
use libc::STDIN_FILENO;
|
||||
use libc::TCSANOW;
|
||||
|
||||
use super::{add_fd_flags, clear_fd_flags, errno_result, Result};
|
||||
use super::add_fd_flags;
|
||||
use super::clear_fd_flags;
|
||||
use super::errno_result;
|
||||
use super::Result;
|
||||
|
||||
fn modify_mode<F: FnOnce(&mut termios)>(fd: RawFd, f: F) -> Result<()> {
|
||||
// Safe because we check the return value of isatty.
|
||||
|
|
|
|||
|
|
@ -2,23 +2,30 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
mem,
|
||||
os::unix::io::{AsRawFd, RawFd},
|
||||
ptr,
|
||||
time::Duration,
|
||||
};
|
||||
use std::mem;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::ptr;
|
||||
use std::time::Duration;
|
||||
|
||||
use libc::{
|
||||
clock_getres, timerfd_create, timerfd_settime, CLOCK_MONOTONIC, EAGAIN, POLLIN, TFD_CLOEXEC,
|
||||
{self},
|
||||
};
|
||||
use libc::clock_getres;
|
||||
use libc::timerfd_create;
|
||||
use libc::timerfd_settime;
|
||||
use libc::CLOCK_MONOTONIC;
|
||||
use libc::EAGAIN;
|
||||
use libc::POLLIN;
|
||||
use libc::TFD_CLOEXEC;
|
||||
use libc::{self};
|
||||
|
||||
use super::super::{errno_result, Error, Result};
|
||||
use super::super::errno_result;
|
||||
use super::super::Error;
|
||||
use super::super::Result;
|
||||
use super::duration_to_timespec;
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
|
||||
use crate::timer::{Timer, WaitResult};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::timer::Timer;
|
||||
use crate::timer::WaitResult;
|
||||
|
||||
impl AsRawFd for Timer {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,30 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
io::IoSlice,
|
||||
marker::PhantomData,
|
||||
os::unix::prelude::{AsRawFd, RawFd},
|
||||
time::Duration,
|
||||
};
|
||||
use std::io::IoSlice;
|
||||
use std::marker::PhantomData;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
use std::os::unix::prelude::RawFd;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
use crate::{
|
||||
platform::{deserialize_with_descriptors, SerializeDescriptors},
|
||||
tube::{Error, RecvTube, Result, SendTube},
|
||||
RawDescriptor, ReadNotifier, ScmSocket, UnixSeqpacket, UnsyncMarker,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::platform::deserialize_with_descriptors;
|
||||
use crate::platform::SerializeDescriptors;
|
||||
use crate::tube::Error;
|
||||
use crate::tube::RecvTube;
|
||||
use crate::tube::Result;
|
||||
use crate::tube::SendTube;
|
||||
use crate::RawDescriptor;
|
||||
use crate::ReadNotifier;
|
||||
use crate::ScmSocket;
|
||||
use crate::UnixSeqpacket;
|
||||
use crate::UnsyncMarker;
|
||||
|
||||
/// Bidirectional tube that support both send and recv.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -4,24 +4,31 @@
|
|||
|
||||
/// Support for virtual sockets.
|
||||
use std::fmt;
|
||||
use std::{
|
||||
io,
|
||||
mem::{
|
||||
size_of, {self},
|
||||
},
|
||||
num::ParseIntError,
|
||||
os::{
|
||||
raw::{c_uchar, c_uint, c_ushort},
|
||||
unix::io::{AsRawFd, IntoRawFd, RawFd},
|
||||
},
|
||||
result,
|
||||
str::FromStr,
|
||||
};
|
||||
use std::io;
|
||||
use std::mem::size_of;
|
||||
use std::mem::{self};
|
||||
use std::num::ParseIntError;
|
||||
use std::os::raw::c_uchar;
|
||||
use std::os::raw::c_uint;
|
||||
use std::os::raw::c_ushort;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::result;
|
||||
use std::str::FromStr;
|
||||
|
||||
use libc::{
|
||||
c_void, sa_family_t, size_t, sockaddr, socklen_t, F_GETFL, F_SETFL, O_NONBLOCK, VMADDR_CID_ANY,
|
||||
VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, {self},
|
||||
};
|
||||
use libc::c_void;
|
||||
use libc::sa_family_t;
|
||||
use libc::size_t;
|
||||
use libc::sockaddr;
|
||||
use libc::socklen_t;
|
||||
use libc::F_GETFL;
|
||||
use libc::F_SETFL;
|
||||
use libc::O_NONBLOCK;
|
||||
use libc::VMADDR_CID_ANY;
|
||||
use libc::VMADDR_CID_HOST;
|
||||
use libc::VMADDR_CID_HYPERVISOR;
|
||||
use libc::{self};
|
||||
use thiserror::Error;
|
||||
|
||||
// The domain for vsock sockets.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{cmp::min, fs::File, io, os::unix::fs::FileExt};
|
||||
use std::cmp::min;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::unix::fs::FileExt;
|
||||
|
||||
use super::{fallocate, FallocateMode};
|
||||
use super::fallocate;
|
||||
use super::FallocateMode;
|
||||
|
||||
pub(crate) fn file_punch_hole(file: &File, offset: u64, length: u64) -> io::Result<()> {
|
||||
fallocate(file, FallocateMode::PunchHole, true, offset, length as u64)
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::io::{Error, Read, Result};
|
||||
use std::io::Error;
|
||||
use std::io::Read;
|
||||
use std::io::Result;
|
||||
|
||||
use winapi::{
|
||||
shared::{minwindef::LPVOID, ntdef::NULL},
|
||||
um::{fileapi::ReadFile, minwinbase::LPOVERLAPPED},
|
||||
};
|
||||
use winapi::shared::minwindef::LPVOID;
|
||||
use winapi::shared::ntdef::NULL;
|
||||
use winapi::um::fileapi::ReadFile;
|
||||
use winapi::um::minwinbase::LPOVERLAPPED;
|
||||
|
||||
use crate::{AsRawDescriptor, ReadNotifier};
|
||||
use crate::AsRawDescriptor;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
pub struct Console(std::io::Stdin);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,32 +2,37 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::Result;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
fs::File,
|
||||
io::{Stderr, Stdin, Stdout},
|
||||
ops::Drop,
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
use std::ffi::CString;
|
||||
use std::fs::File;
|
||||
use std::io::Stderr;
|
||||
use std::io::Stdin;
|
||||
use std::io::Stdout;
|
||||
use std::marker::Send;
|
||||
use std::marker::Sync;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ops::Drop;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::os::windows::io::FromRawHandle;
|
||||
use std::os::windows::io::IntoRawHandle;
|
||||
use std::os::windows::io::RawHandle;
|
||||
use std::sync::Once;
|
||||
|
||||
use crate::descriptor::{
|
||||
AsRawDescriptor, Descriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor,
|
||||
};
|
||||
use std::{
|
||||
ffi::CString,
|
||||
marker::{Send, Sync},
|
||||
mem::MaybeUninit,
|
||||
os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
|
||||
sync::Once,
|
||||
};
|
||||
use win_util::{duplicate_handle, win32_wide_string};
|
||||
use winapi::{
|
||||
shared::minwindef::{BOOL, HMODULE, TRUE},
|
||||
um::{
|
||||
handleapi::{CloseHandle, INVALID_HANDLE_VALUE},
|
||||
libloaderapi,
|
||||
},
|
||||
};
|
||||
use win_util::duplicate_handle;
|
||||
use win_util::win32_wide_string;
|
||||
use winapi::shared::minwindef::BOOL;
|
||||
use winapi::shared::minwindef::HMODULE;
|
||||
use winapi::shared::minwindef::TRUE;
|
||||
use winapi::um::handleapi::CloseHandle;
|
||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
||||
use winapi::um::libloaderapi;
|
||||
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::Descriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
pub type RawDescriptor = RawHandle;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,34 +2,42 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
ffi::CString,
|
||||
mem::MaybeUninit,
|
||||
os::windows::io::{AsRawHandle, RawHandle},
|
||||
ptr::null,
|
||||
time::Duration,
|
||||
};
|
||||
use win_util::{SecurityAttributes, SelfRelativeSecurityDescriptor};
|
||||
use winapi::{
|
||||
shared::{
|
||||
minwindef::{DWORD, FALSE, TRUE},
|
||||
winerror::WAIT_TIMEOUT,
|
||||
},
|
||||
um::{
|
||||
handleapi::DuplicateHandle,
|
||||
processthreadsapi::GetCurrentProcess,
|
||||
synchapi::{CreateEventA, OpenEventA, ResetEvent, SetEvent, WaitForSingleObject},
|
||||
winbase::WAIT_FAILED,
|
||||
winnt::{DUPLICATE_SAME_ACCESS, EVENT_MODIFY_STATE, HANDLE},
|
||||
},
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::os::windows::io::RawHandle;
|
||||
use std::ptr::null;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::{errno_result, Error, RawDescriptor, Result};
|
||||
use crate::{
|
||||
descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor},
|
||||
Event as CrateEvent,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use win_util::SecurityAttributes;
|
||||
use win_util::SelfRelativeSecurityDescriptor;
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::minwindef::FALSE;
|
||||
use winapi::shared::minwindef::TRUE;
|
||||
use winapi::shared::winerror::WAIT_TIMEOUT;
|
||||
use winapi::um::handleapi::DuplicateHandle;
|
||||
use winapi::um::processthreadsapi::GetCurrentProcess;
|
||||
use winapi::um::synchapi::CreateEventA;
|
||||
use winapi::um::synchapi::OpenEventA;
|
||||
use winapi::um::synchapi::ResetEvent;
|
||||
use winapi::um::synchapi::SetEvent;
|
||||
use winapi::um::synchapi::WaitForSingleObject;
|
||||
use winapi::um::winbase::WAIT_FAILED;
|
||||
use winapi::um::winnt::DUPLICATE_SAME_ACCESS;
|
||||
use winapi::um::winnt::EVENT_MODIFY_STATE;
|
||||
use winapi::um::winnt::HANDLE;
|
||||
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::Event as CrateEvent;
|
||||
|
||||
/// A safe wrapper around Windows synchapi methods used to mimic Linux eventfd (man 2 eventfd).
|
||||
/// Since the eventfd isn't using "EFD_SEMAPHORE", we don't need to keep count so we can just use
|
||||
|
|
@ -250,11 +258,11 @@ unsafe impl Sync for Event {}
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use winapi::shared::winerror::WAIT_TIMEOUT;
|
||||
use winapi::um::winbase::INFINITE;
|
||||
use winapi::um::winbase::WAIT_OBJECT_0;
|
||||
|
||||
use super::*;
|
||||
use winapi::{
|
||||
shared::winerror::WAIT_TIMEOUT,
|
||||
um::winbase::{INFINITE, WAIT_OBJECT_0},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
|
|
|
|||
|
|
@ -35,9 +35,11 @@ impl<T: EventToken> Clone for EventTrigger<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::Event, *};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::super::Event;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn event_context() {
|
||||
let evt1 = Event::new().unwrap();
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Result;
|
||||
|
||||
use data_model::VolatileSlice;
|
||||
|
||||
pub use super::win::file_traits::*;
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Error, ErrorKind, Result},
|
||||
};
|
||||
|
||||
use data_model::VolatileSlice;
|
||||
|
||||
/// A trait for flushing the contents of a file to disk.
|
||||
/// This is equivalent to File's `sync_all` method, but
|
||||
/// wrapped in a trait so that it can be implemented for
|
||||
|
|
@ -279,11 +279,14 @@ crate::volatile_at_impl!(File);
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::Read;
|
||||
use std::io::SeekFrom;
|
||||
use std::io::Write;
|
||||
|
||||
use std::io::{Read, SeekFrom, Write};
|
||||
use tempfile::tempfile;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn read_file() -> Result<()> {
|
||||
let mut f = tempfile()?;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::Result;
|
||||
use std::fs::File;
|
||||
|
||||
use super::Result;
|
||||
|
||||
pub fn get_filesystem_type(_file: &File) -> Result<i64> {
|
||||
// TODO (b/203574110): create a windows equivalent to get the filesystem type like fstatfs
|
||||
Ok(0)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use libc::{gmtime_s, time_t, tm};
|
||||
use libc::gmtime_s;
|
||||
use libc::time_t;
|
||||
use libc::tm;
|
||||
|
||||
/// # Safety
|
||||
/// safe because we are passing in the allocated tm struct
|
||||
|
|
@ -13,9 +15,10 @@ pub unsafe fn gmtime_secure(now: *const time_t, result: *mut tm) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn gmtime() {
|
||||
// Safe because struct is not used before being initialized
|
||||
|
|
|
|||
|
|
@ -4,16 +4,19 @@
|
|||
|
||||
//! Macros and wrapper functions for dealing with ioctls.
|
||||
|
||||
use std::{
|
||||
mem::size_of,
|
||||
os::raw::*,
|
||||
os::raw::{c_int, c_ulong},
|
||||
ptr::null_mut,
|
||||
};
|
||||
use std::mem::size_of;
|
||||
use std::os::raw::c_int;
|
||||
use std::os::raw::c_ulong;
|
||||
use std::os::raw::*;
|
||||
use std::ptr::null_mut;
|
||||
|
||||
use winapi::um::errhandlingapi::GetLastError;
|
||||
use winapi::um::ioapiset::DeviceIoControl;
|
||||
pub use winapi::um::winioctl::CTL_CODE;
|
||||
pub use winapi::um::winioctl::FILE_ANY_ACCESS;
|
||||
pub use winapi::um::winioctl::METHOD_BUFFERED;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
pub use winapi::um::winioctl::{CTL_CODE, FILE_ANY_ACCESS, METHOD_BUFFERED};
|
||||
use winapi::um::{errhandlingapi::GetLastError, ioapiset::DeviceIoControl};
|
||||
|
||||
/// Raw macro to declare the expression that calculates an ioctl number
|
||||
#[macro_export]
|
||||
|
|
@ -321,24 +324,27 @@ pub unsafe fn device_io_control<F: AsRawDescriptor, T, T2>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use winapi::um::winioctl::{FSCTL_GET_COMPRESSION, FSCTL_SET_COMPRESSION};
|
||||
|
||||
use winapi::um::{
|
||||
fileapi::{CreateFileW, OPEN_EXISTING},
|
||||
winbase::SECURITY_SQOS_PRESENT,
|
||||
winnt::{
|
||||
COMPRESSION_FORMAT_LZNT1, COMPRESSION_FORMAT_NONE, FILE_SHARE_READ, FILE_SHARE_WRITE,
|
||||
GENERIC_READ, GENERIC_WRITE,
|
||||
},
|
||||
};
|
||||
|
||||
use std::{fs::OpenOptions, os::raw::*, ptr::null_mut};
|
||||
|
||||
use std::{ffi::OsStr, fs::File, io::prelude::*, os::windows::ffi::OsStrExt};
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::prelude::*;
|
||||
use std::os::raw::*;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::os::windows::prelude::*;
|
||||
use std::ptr::null_mut;
|
||||
|
||||
use tempfile::tempdir;
|
||||
use winapi::um::fileapi::CreateFileW;
|
||||
use winapi::um::fileapi::OPEN_EXISTING;
|
||||
use winapi::um::winbase::SECURITY_SQOS_PRESENT;
|
||||
use winapi::um::winioctl::FSCTL_GET_COMPRESSION;
|
||||
use winapi::um::winioctl::FSCTL_SET_COMPRESSION;
|
||||
use winapi::um::winnt::COMPRESSION_FORMAT_LZNT1;
|
||||
use winapi::um::winnt::COMPRESSION_FORMAT_NONE;
|
||||
use winapi::um::winnt::FILE_SHARE_READ;
|
||||
use winapi::um::winnt::FILE_SHARE_WRITE;
|
||||
use winapi::um::winnt::GENERIC_READ;
|
||||
use winapi::um::winnt::GENERIC_WRITE;
|
||||
|
||||
// helper func, returns str as Vec<u16>
|
||||
fn to_u16s<S: AsRef<OsStr>>(s: S) -> std::io::Result<Vec<u16>> {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,29 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use libc::c_int;
|
||||
use libc::c_uint;
|
||||
use libc::c_void;
|
||||
use remain::sorted;
|
||||
use win_util::create_file_mapping;
|
||||
use win_util::duplicate_handle;
|
||||
use winapi::um::winnt::PAGE_READWRITE;
|
||||
|
||||
use crate::{
|
||||
external_mapping::ExternalMapping, AsRawDescriptor, Descriptor, FromRawDescriptor,
|
||||
MappedRegion, MemoryMapping as CrateMemoryMapping, MemoryMappingBuilder, Protection,
|
||||
RawDescriptor, SafeDescriptor,
|
||||
};
|
||||
|
||||
pub use super::mmap_platform::MemoryMappingArena;
|
||||
use crate::external_mapping::ExternalMapping;
|
||||
use crate::AsRawDescriptor;
|
||||
use crate::Descriptor;
|
||||
use crate::FromRawDescriptor;
|
||||
use crate::MappedRegion;
|
||||
use crate::MemoryMapping as CrateMemoryMapping;
|
||||
use crate::MemoryMappingBuilder;
|
||||
use crate::Protection;
|
||||
use crate::RawDescriptor;
|
||||
use crate::SafeDescriptor;
|
||||
|
||||
#[sorted]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
@ -307,10 +315,14 @@ impl<'a> MemoryMappingBuilder<'a> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::shm::SharedMemory, *};
|
||||
use data_model::{VolatileMemory, VolatileMemoryError};
|
||||
use std::ffi::CString;
|
||||
|
||||
use data_model::VolatileMemory;
|
||||
use data_model::VolatileMemoryError;
|
||||
|
||||
use super::super::shm::SharedMemory;
|
||||
use super::*;
|
||||
|
||||
// get_slice() and other methods are only available on crate::MemoryMapping.
|
||||
fn to_crate_mmap(mapping: MemoryMapping) -> crate::MemoryMapping {
|
||||
crate::MemoryMapping {
|
||||
|
|
|
|||
|
|
@ -5,20 +5,32 @@
|
|||
//! The mmap module provides a safe interface to map memory and ensures UnmapViewOfFile is called when the
|
||||
//! mmap object leaves scope.
|
||||
|
||||
use std::{
|
||||
io,
|
||||
slice::{from_raw_parts, from_raw_parts_mut},
|
||||
};
|
||||
use std::io;
|
||||
use std::slice::from_raw_parts;
|
||||
use std::slice::from_raw_parts_mut;
|
||||
|
||||
use libc::{self, c_int, c_uint, c_void};
|
||||
use libc::c_int;
|
||||
use libc::c_uint;
|
||||
use libc::c_void;
|
||||
use libc::{self};
|
||||
use win_util::allocation_granularity;
|
||||
use win_util::get_high_order;
|
||||
use win_util::get_low_order;
|
||||
use winapi::um::memoryapi::FlushViewOfFile;
|
||||
use winapi::um::memoryapi::MapViewOfFile;
|
||||
use winapi::um::memoryapi::MapViewOfFileEx;
|
||||
use winapi::um::memoryapi::UnmapViewOfFile;
|
||||
use winapi::um::memoryapi::FILE_MAP_READ;
|
||||
use winapi::um::memoryapi::FILE_MAP_WRITE;
|
||||
|
||||
use win_util::{allocation_granularity, get_high_order, get_low_order};
|
||||
use winapi::um::memoryapi::{
|
||||
FlushViewOfFile, MapViewOfFile, MapViewOfFileEx, UnmapViewOfFile, FILE_MAP_READ, FILE_MAP_WRITE,
|
||||
};
|
||||
|
||||
use super::mmap::{Error, MemoryMapping, Result};
|
||||
use crate::{descriptor::AsRawDescriptor, warn, MappedRegion, Protection, RawDescriptor};
|
||||
use super::mmap::Error;
|
||||
use super::mmap::MemoryMapping;
|
||||
use super::mmap::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::warn;
|
||||
use crate::MappedRegion;
|
||||
use crate::Protection;
|
||||
use crate::RawDescriptor;
|
||||
|
||||
pub(crate) const PROT_READ: c_int = FILE_MAP_READ as c_int;
|
||||
pub(crate) const PROT_WRITE: c_int = FILE_MAP_WRITE as c_int;
|
||||
|
|
@ -296,15 +308,18 @@ pub struct MemoryMappingArena();
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{pagesize, SharedMemory},
|
||||
Error,
|
||||
};
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::{MappedRegion, MemoryMappingBuilder};
|
||||
use std::{ffi::CString, ptr};
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
|
||||
use winapi::shared::winerror;
|
||||
|
||||
use super::super::pagesize;
|
||||
use super::super::SharedMemory;
|
||||
use super::Error;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::MappedRegion;
|
||||
use crate::MemoryMappingBuilder;
|
||||
|
||||
#[test]
|
||||
fn map_invalid_fd() {
|
||||
let descriptor = unsafe { std::fs::File::from_raw_descriptor(ptr::null_mut()) };
|
||||
|
|
|
|||
|
|
@ -39,37 +39,44 @@ pub mod thread;
|
|||
|
||||
mod write_zeroes;
|
||||
|
||||
pub use crate::descriptor_reflection::{
|
||||
deserialize_with_descriptors, with_as_descriptor, with_raw_descriptor, FileSerdeWrapper,
|
||||
SerializeDescriptors,
|
||||
};
|
||||
pub use crate::errno::{Error, Result, *};
|
||||
use std::cell::Cell;
|
||||
|
||||
pub use console::*;
|
||||
pub use descriptor::*;
|
||||
pub use event::*;
|
||||
pub use events::*;
|
||||
pub use file_traits::AsRawDescriptors;
|
||||
pub use file_traits::FileAllocate;
|
||||
pub use file_traits::FileGetLen;
|
||||
pub use file_traits::FileReadWriteAtVolatile;
|
||||
pub use file_traits::FileReadWriteVolatile;
|
||||
pub use file_traits::FileSetLen;
|
||||
pub use file_traits::FileSync;
|
||||
pub use get_filesystem_type::*;
|
||||
pub use gmtime::*;
|
||||
pub use ioctl::*;
|
||||
pub use mmap::Error as MmapError;
|
||||
pub use mmap::*;
|
||||
pub(crate) use mmap_platform::PROT_READ;
|
||||
pub(crate) use mmap_platform::PROT_WRITE;
|
||||
pub use priority::*;
|
||||
pub(crate) use punch_hole::file_punch_hole;
|
||||
pub use sched::*;
|
||||
pub use shm::*;
|
||||
pub use shm_platform::*;
|
||||
pub use stream_channel::*;
|
||||
pub use timer::*;
|
||||
pub use win::*;
|
||||
|
||||
pub use file_traits::{
|
||||
AsRawDescriptors, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile,
|
||||
FileSetLen, FileSync,
|
||||
};
|
||||
pub use mmap::Error as MmapError;
|
||||
pub(crate) use mmap_platform::{PROT_READ, PROT_WRITE};
|
||||
pub(crate) use punch_hole::file_punch_hole;
|
||||
pub(crate) use write_zeroes::file_write_zeroes_at;
|
||||
|
||||
use std::cell::Cell;
|
||||
pub use crate::descriptor_reflection::deserialize_with_descriptors;
|
||||
pub use crate::descriptor_reflection::with_as_descriptor;
|
||||
pub use crate::descriptor_reflection::with_raw_descriptor;
|
||||
pub use crate::descriptor_reflection::FileSerdeWrapper;
|
||||
pub use crate::descriptor_reflection::SerializeDescriptors;
|
||||
pub use crate::errno::Error;
|
||||
pub use crate::errno::Result;
|
||||
pub use crate::errno::*;
|
||||
|
||||
// Define libc::* types
|
||||
#[allow(non_camel_case_types)]
|
||||
|
|
|
|||
|
|
@ -2,44 +2,62 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use rand::Rng;
|
||||
use std::{
|
||||
ffi::CString,
|
||||
fs::OpenOptions,
|
||||
io,
|
||||
io::Result,
|
||||
mem,
|
||||
os::windows::fs::OpenOptionsExt,
|
||||
process, ptr,
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io;
|
||||
use std::io::Result;
|
||||
use std::mem;
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
use std::process;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use super::{Event, RawDescriptor};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use win_util::{SecurityAttributes, SelfRelativeSecurityDescriptor};
|
||||
use winapi::{
|
||||
shared::{
|
||||
minwindef::{DWORD, FALSE, LPCVOID, LPVOID, TRUE},
|
||||
winerror::{ERROR_IO_INCOMPLETE, ERROR_IO_PENDING, ERROR_NO_DATA, ERROR_PIPE_CONNECTED},
|
||||
},
|
||||
um::{
|
||||
errhandlingapi::GetLastError,
|
||||
fileapi::{FlushFileBuffers, ReadFile, WriteFile},
|
||||
handleapi::INVALID_HANDLE_VALUE,
|
||||
ioapiset::{CancelIoEx, GetOverlappedResult},
|
||||
minwinbase::OVERLAPPED,
|
||||
namedpipeapi::{
|
||||
ConnectNamedPipe, GetNamedPipeInfo, PeekNamedPipe, SetNamedPipeHandleState,
|
||||
},
|
||||
winbase::{
|
||||
CreateNamedPipeA, FILE_FLAG_FIRST_PIPE_INSTANCE, FILE_FLAG_OVERLAPPED,
|
||||
PIPE_ACCESS_DUPLEX, PIPE_NOWAIT, PIPE_READMODE_BYTE, PIPE_READMODE_MESSAGE,
|
||||
PIPE_REJECT_REMOTE_CLIENTS, PIPE_TYPE_BYTE, PIPE_TYPE_MESSAGE, PIPE_WAIT,
|
||||
SECURITY_IDENTIFICATION,
|
||||
},
|
||||
},
|
||||
};
|
||||
use rand::Rng;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use win_util::SecurityAttributes;
|
||||
use win_util::SelfRelativeSecurityDescriptor;
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::minwindef::FALSE;
|
||||
use winapi::shared::minwindef::LPCVOID;
|
||||
use winapi::shared::minwindef::LPVOID;
|
||||
use winapi::shared::minwindef::TRUE;
|
||||
use winapi::shared::winerror::ERROR_IO_INCOMPLETE;
|
||||
use winapi::shared::winerror::ERROR_IO_PENDING;
|
||||
use winapi::shared::winerror::ERROR_NO_DATA;
|
||||
use winapi::shared::winerror::ERROR_PIPE_CONNECTED;
|
||||
use winapi::um::errhandlingapi::GetLastError;
|
||||
use winapi::um::fileapi::FlushFileBuffers;
|
||||
use winapi::um::fileapi::ReadFile;
|
||||
use winapi::um::fileapi::WriteFile;
|
||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
||||
use winapi::um::ioapiset::CancelIoEx;
|
||||
use winapi::um::ioapiset::GetOverlappedResult;
|
||||
use winapi::um::minwinbase::OVERLAPPED;
|
||||
use winapi::um::namedpipeapi::ConnectNamedPipe;
|
||||
use winapi::um::namedpipeapi::GetNamedPipeInfo;
|
||||
use winapi::um::namedpipeapi::PeekNamedPipe;
|
||||
use winapi::um::namedpipeapi::SetNamedPipeHandleState;
|
||||
use winapi::um::winbase::CreateNamedPipeA;
|
||||
use winapi::um::winbase::FILE_FLAG_FIRST_PIPE_INSTANCE;
|
||||
use winapi::um::winbase::FILE_FLAG_OVERLAPPED;
|
||||
use winapi::um::winbase::PIPE_ACCESS_DUPLEX;
|
||||
use winapi::um::winbase::PIPE_NOWAIT;
|
||||
use winapi::um::winbase::PIPE_READMODE_BYTE;
|
||||
use winapi::um::winbase::PIPE_READMODE_MESSAGE;
|
||||
use winapi::um::winbase::PIPE_REJECT_REMOTE_CLIENTS;
|
||||
use winapi::um::winbase::PIPE_TYPE_BYTE;
|
||||
use winapi::um::winbase::PIPE_TYPE_MESSAGE;
|
||||
use winapi::um::winbase::PIPE_WAIT;
|
||||
use winapi::um::winbase::SECURITY_IDENTIFICATION;
|
||||
|
||||
use super::Event;
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
/// The default buffer size for all named pipes in the system. If this size is too small, writers
|
||||
/// on named pipes that expect not to block *can* block until the reading side empties the buffer.
|
||||
|
|
|
|||
|
|
@ -2,12 +2,17 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::{
|
||||
info, measure_timer_resolution, nt_query_timer_resolution, nt_set_timer_resolution,
|
||||
set_time_period, warn, EnabledHighResTimer, Result,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::info;
|
||||
use crate::measure_timer_resolution;
|
||||
use crate::nt_query_timer_resolution;
|
||||
use crate::nt_set_timer_resolution;
|
||||
use crate::set_time_period;
|
||||
use crate::warn;
|
||||
use crate::EnabledHighResTimer;
|
||||
use crate::Result;
|
||||
|
||||
/// Restores the Windows platform timer resolution to its original value on Drop.
|
||||
struct NtSetTimerResolution {
|
||||
previous_duration: Duration,
|
||||
|
|
|
|||
|
|
@ -2,17 +2,18 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::{errno_result, Result};
|
||||
use log::warn;
|
||||
use std::os::windows::raw::HANDLE;
|
||||
use winapi::{
|
||||
shared::minwindef::FALSE,
|
||||
um::{
|
||||
avrt::{AvRevertMmThreadCharacteristics, AvSetMmThreadCharacteristicsA},
|
||||
errhandlingapi::GetLastError,
|
||||
processthreadsapi::{GetCurrentThread, SetThreadPriority},
|
||||
},
|
||||
};
|
||||
|
||||
use log::warn;
|
||||
use winapi::shared::minwindef::FALSE;
|
||||
use winapi::um::avrt::AvRevertMmThreadCharacteristics;
|
||||
use winapi::um::avrt::AvSetMmThreadCharacteristicsA;
|
||||
use winapi::um::errhandlingapi::GetLastError;
|
||||
use winapi::um::processthreadsapi::GetCurrentThread;
|
||||
use winapi::um::processthreadsapi::SetThreadPriority;
|
||||
|
||||
use super::errno_result;
|
||||
use super::Result;
|
||||
|
||||
pub fn set_audio_thread_priorities() -> Result<SafeMultimediaHandle> {
|
||||
// Safe because we know Pro Audio is part of windows and we down task_index.
|
||||
|
|
@ -65,11 +66,12 @@ impl Drop for SafeMultimediaHandle {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use winapi::um::processthreadsapi::GetCurrentThread;
|
||||
use winapi::um::processthreadsapi::GetThreadPriority;
|
||||
use winapi::um::winbase::THREAD_PRIORITY_NORMAL;
|
||||
use winapi::um::winbase::THREAD_PRIORITY_TIME_CRITICAL;
|
||||
|
||||
use super::*;
|
||||
use winapi::um::{
|
||||
processthreadsapi::{GetCurrentThread, GetThreadPriority},
|
||||
winbase::{THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_TIME_CRITICAL},
|
||||
};
|
||||
|
||||
// TODO(b/223733375): Enable ignored flaky tests.
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, Error};
|
||||
use std::io::Error;
|
||||
use std::io::{self};
|
||||
|
||||
use win_util::LargeInteger;
|
||||
pub use winapi::um::winioctl::FSCTL_SET_ZERO_DATA;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use libc::EINVAL;
|
||||
use winapi::um::{processthreadsapi::GetCurrentThread, winbase::SetThreadAffinityMask};
|
||||
use winapi::um::processthreadsapi::GetCurrentThread;
|
||||
use winapi::um::winbase::SetThreadAffinityMask;
|
||||
|
||||
use super::{errno_result, Error, Result};
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
|
||||
/// Set the CPU affinity of the current thread to a given set of CPUs.
|
||||
/// The cpus must be a subset of those in the process affinity mask.
|
||||
|
|
@ -49,8 +52,10 @@ pub fn get_cpu_affinity() -> Result<Vec<usize>> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use winapi::um::processthreadsapi::GetCurrentProcess;
|
||||
use winapi::um::winbase::GetProcessAffinityMask;
|
||||
|
||||
use super::super::sched::*;
|
||||
use winapi::um::{processthreadsapi::GetCurrentProcess, winbase::GetProcessAffinityMask};
|
||||
#[test]
|
||||
fn cpu_affinity() {
|
||||
let mut process_affinity_mask: usize = 0;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,25 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use super::{RawDescriptor, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
|
||||
use serde::ser;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::MemoryMapping;
|
||||
use serde::{ser, Deserialize, Serialize, Serializer};
|
||||
use std::io::{
|
||||
Error, ErrorKind, Read, Seek, SeekFrom, Write, {self},
|
||||
};
|
||||
|
||||
/// A shared memory file descriptor and its size.
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
@ -155,9 +167,10 @@ impl Seek for SharedMemory {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::ffi::CString;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
let shm = SharedMemory::new(&CString::new("name").unwrap(), 1028)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,18 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
use win_util::create_file_mapping;
|
||||
use winapi::um::winnt::PAGE_EXECUTE_READWRITE;
|
||||
|
||||
use super::{shm::SharedMemory, MemoryMapping, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
use crate::{MemoryMapping as CrateMemoryMapping, MmapError};
|
||||
use super::shm::SharedMemory;
|
||||
use super::MemoryMapping;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::MemoryMapping as CrateMemoryMapping;
|
||||
use crate::MmapError;
|
||||
|
||||
impl SharedMemory {
|
||||
/// Creates a new shared memory file mapping with zero size.
|
||||
|
|
@ -56,10 +62,12 @@ impl SharedMemory {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::ffi::CString;
|
||||
|
||||
use winapi::shared::winerror::ERROR_NOT_ENOUGH_MEMORY;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[cfg_attr(all(target_os = "windows", target_env = "gnu"), ignore)]
|
||||
#[test]
|
||||
fn new_too_huge() {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::io;
|
||||
|
||||
pub use super::stream_channel_platform::*;
|
||||
use super::RawDescriptor;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use std::io;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum FramingMode {
|
||||
|
|
@ -39,13 +40,14 @@ impl AsRawDescriptor for StreamChannel {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{
|
||||
super::{EventContext, EventTrigger},
|
||||
*,
|
||||
};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
use crate::{EventToken, ReadNotifier};
|
||||
use std::io::{Read, Write};
|
||||
use super::super::EventContext;
|
||||
use super::super::EventTrigger;
|
||||
use super::*;
|
||||
use crate::EventToken;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
#[derive(EventToken, Debug, Eq, PartialEq, Copy, Clone)]
|
||||
enum Token {
|
||||
|
|
|
|||
|
|
@ -2,18 +2,29 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{cell::RefCell, io, sync::Arc};
|
||||
use std::cell::RefCell;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use log::{error, warn};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use log::error;
|
||||
use log::warn;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use sync::Mutex;
|
||||
|
||||
use super::{
|
||||
named_pipes::{self, PipeConnection},
|
||||
stream_channel::{BlockingMode, FramingMode},
|
||||
Event, MultiProcessMutex, RawDescriptor, Result,
|
||||
};
|
||||
use crate::{descriptor::AsRawDescriptor, CloseNotifier, ReadNotifier};
|
||||
use super::named_pipes::PipeConnection;
|
||||
use super::named_pipes::{self};
|
||||
use super::stream_channel::BlockingMode;
|
||||
use super::stream_channel::FramingMode;
|
||||
use super::Event;
|
||||
use super::MultiProcessMutex;
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::CloseNotifier;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
impl From<FramingMode> for named_pipes::FramingMode {
|
||||
fn from(framing_mode: FramingMode) -> Self {
|
||||
|
|
@ -396,15 +407,15 @@ impl CloseNotifier for StreamChannel {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{
|
||||
super::{EventContext, EventTrigger},
|
||||
*,
|
||||
};
|
||||
use crate::{EventToken, ReadNotifier};
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
time::Duration,
|
||||
};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::super::EventContext;
|
||||
use super::super::EventTrigger;
|
||||
use super::*;
|
||||
use crate::EventToken;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
#[derive(EventToken, Debug, Eq, PartialEq, Copy, Clone)]
|
||||
enum Token {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,14 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
any::Any,
|
||||
panic,
|
||||
panic::UnwindSafe,
|
||||
sync::mpsc::{channel, Receiver},
|
||||
thread,
|
||||
thread::JoinHandle,
|
||||
time::Duration,
|
||||
};
|
||||
use std::any::Any;
|
||||
use std::panic;
|
||||
use std::panic::UnwindSafe;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::sync::mpsc::Receiver;
|
||||
use std::thread;
|
||||
use std::thread::JoinHandle;
|
||||
use std::time::Duration;
|
||||
|
||||
/// Spawns a thread that can be joined with a timeout.
|
||||
pub fn spawn_with_timeout<F, T>(f: F) -> JoinHandleWithTimeout<T>
|
||||
|
|
|
|||
|
|
@ -2,26 +2,31 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
os::windows::io::{AsRawHandle, RawHandle},
|
||||
ptr,
|
||||
time::Duration,
|
||||
};
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::os::windows::io::RawHandle;
|
||||
use std::ptr;
|
||||
use std::time::Duration;
|
||||
|
||||
use win_util::{LargeInteger, SecurityAttributes, SelfRelativeSecurityDescriptor};
|
||||
use winapi::{
|
||||
shared::{minwindef::FALSE, winerror::WAIT_TIMEOUT},
|
||||
um::{
|
||||
synchapi::{CancelWaitableTimer, SetWaitableTimer, WaitForSingleObject},
|
||||
winbase::{CreateWaitableTimerA, INFINITE, WAIT_OBJECT_0},
|
||||
},
|
||||
};
|
||||
use win_util::LargeInteger;
|
||||
use win_util::SecurityAttributes;
|
||||
use win_util::SelfRelativeSecurityDescriptor;
|
||||
use winapi::shared::minwindef::FALSE;
|
||||
use winapi::shared::winerror::WAIT_TIMEOUT;
|
||||
use winapi::um::synchapi::CancelWaitableTimer;
|
||||
use winapi::um::synchapi::SetWaitableTimer;
|
||||
use winapi::um::synchapi::WaitForSingleObject;
|
||||
use winapi::um::winbase::CreateWaitableTimerA;
|
||||
use winapi::um::winbase::INFINITE;
|
||||
use winapi::um::winbase::WAIT_OBJECT_0;
|
||||
|
||||
use super::{errno_result, win::nt_query_timer_resolution, Result};
|
||||
use crate::{
|
||||
descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor},
|
||||
timer::{Timer, WaitResult},
|
||||
};
|
||||
use super::errno_result;
|
||||
use super::win::nt_query_timer_resolution;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::timer::Timer;
|
||||
use crate::timer::WaitResult;
|
||||
|
||||
impl AsRawHandle for Timer {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
|
|
|
|||
|
|
@ -2,28 +2,40 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
io::{
|
||||
Cursor, Read, Write, {self},
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
use std::mem;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::os::windows::io::RawHandle;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
use crate::{
|
||||
platform::{deserialize_with_descriptors, RawDescriptor, SerializeDescriptors},
|
||||
tube::{Error, RecvTube, Result, SendTube},
|
||||
BlockingMode, CloseNotifier, EventToken, FramingMode, ReadNotifier, StreamChannel,
|
||||
};
|
||||
use data_model::DataInit;
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize, Serializer};
|
||||
use std::{
|
||||
mem,
|
||||
os::windows::io::{AsRawHandle, RawHandle},
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use winapi::shared::winerror::ERROR_MORE_DATA;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
use crate::platform::deserialize_with_descriptors;
|
||||
use crate::platform::RawDescriptor;
|
||||
use crate::platform::SerializeDescriptors;
|
||||
use crate::tube::Error;
|
||||
use crate::tube::RecvTube;
|
||||
use crate::tube::Result;
|
||||
use crate::tube::SendTube;
|
||||
use crate::BlockingMode;
|
||||
use crate::CloseNotifier;
|
||||
use crate::EventToken;
|
||||
use crate::FramingMode;
|
||||
use crate::ReadNotifier;
|
||||
use crate::StreamChannel;
|
||||
|
||||
/// Bidirectional tube that support both send and recv.
|
||||
///
|
||||
/// NOTE: serializing this type across processes is slightly involved. Suppose there is a Tube pair
|
||||
|
|
@ -402,10 +414,14 @@ impl DuplicateHandleTube {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{EventContext, EventToken, EventTrigger, ReadNotifier};
|
||||
use std::time;
|
||||
|
||||
use super::*;
|
||||
use crate::EventContext;
|
||||
use crate::EventToken;
|
||||
use crate::EventTrigger;
|
||||
use crate::ReadNotifier;
|
||||
|
||||
const EVENT_WAIT_TIME: time::Duration = time::Duration::from_secs(10);
|
||||
|
||||
#[derive(EventToken, Debug, Eq, PartialEq, Copy, Clone)]
|
||||
|
|
|
|||
|
|
@ -2,21 +2,34 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{cmp::min, collections::HashMap, os::windows::io::RawHandle, sync::Arc, time::Duration};
|
||||
use std::cmp::min;
|
||||
use std::collections::HashMap;
|
||||
use std::os::windows::io::RawHandle;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use smallvec::SmallVec;
|
||||
use sync::Mutex;
|
||||
use winapi::{
|
||||
shared::{
|
||||
minwindef::{DWORD, FALSE},
|
||||
winerror::{ERROR_INVALID_PARAMETER, WAIT_TIMEOUT},
|
||||
},
|
||||
um::{synchapi::WaitForMultipleObjects, winbase::WAIT_OBJECT_0},
|
||||
};
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::minwindef::FALSE;
|
||||
use winapi::shared::winerror::ERROR_INVALID_PARAMETER;
|
||||
use winapi::shared::winerror::WAIT_TIMEOUT;
|
||||
use winapi::um::synchapi::WaitForMultipleObjects;
|
||||
use winapi::um::winbase::WAIT_OBJECT_0;
|
||||
|
||||
use super::{errno_result, Error, Event, EventTrigger, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, Descriptor};
|
||||
use crate::{error, EventToken, EventType, RawDescriptor, TriggeredEvent, WaitContext};
|
||||
use super::errno_result;
|
||||
use super::Error;
|
||||
use super::Event;
|
||||
use super::EventTrigger;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::Descriptor;
|
||||
use crate::error;
|
||||
use crate::EventToken;
|
||||
use crate::EventType;
|
||||
use crate::RawDescriptor;
|
||||
use crate::TriggeredEvent;
|
||||
use crate::WaitContext;
|
||||
|
||||
// MAXIMUM_WAIT_OBJECTS = 64
|
||||
pub const MAXIMUM_WAIT_OBJECTS: usize = winapi::um::winnt::MAXIMUM_WAIT_OBJECTS as usize;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::{FileAllocate, WriteZeroesAt};
|
||||
use std::{fs::File, io};
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
|
||||
use crate::FileAllocate;
|
||||
use crate::WriteZeroesAt;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! volatile_impl {
|
||||
|
|
@ -11,11 +14,12 @@ macro_rules! volatile_impl {
|
|||
// Unused imports are "unneeded" because the only usage of this macro already has those
|
||||
// names in scope.
|
||||
#[allow(unused_imports)]
|
||||
use crate::AsRawDescriptor as _;
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryInto as _;
|
||||
#[allow(unused_imports)]
|
||||
use std::io::Seek as _;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use crate::AsRawDescriptor as _;
|
||||
impl FileReadWriteVolatile for $ty {
|
||||
fn read_volatile(&mut self, slice: VolatileSlice) -> Result<usize> {
|
||||
// Safe because only bytes inside the slice are accessed and the kernel is expected
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use std::{ffi::c_void, io};
|
||||
use std::ffi::c_void;
|
||||
use std::io;
|
||||
|
||||
pub use winapi::um::winioctl::FSCTL_SET_SPARSE;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
|
||||
/// Marks the given file as sparse. Required if we want hole punching to be performant.
|
||||
/// (If a file is not marked as sparse, a hole punch will just write zeros.)
|
||||
/// # Safety
|
||||
|
|
|
|||
|
|
@ -12,26 +12,33 @@ mod platform_timer_utils;
|
|||
pub use platform_timer_utils::*;
|
||||
|
||||
mod file_util;
|
||||
pub use file_util::*;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
use std::ptr::null_mut;
|
||||
|
||||
use super::{errno_result, pid_t, Error, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs::{File, OpenOptions},
|
||||
path::Path,
|
||||
ptr::null_mut,
|
||||
};
|
||||
use winapi::{
|
||||
shared::{minwindef::DWORD, winerror::WAIT_TIMEOUT},
|
||||
um::{
|
||||
handleapi::INVALID_HANDLE_VALUE,
|
||||
processthreadsapi::GetCurrentProcessId,
|
||||
synchapi::{CreateMutexA, ReleaseMutex, WaitForSingleObject},
|
||||
winbase::{INFINITE, WAIT_ABANDONED, WAIT_OBJECT_0},
|
||||
winuser::AllowSetForegroundWindow,
|
||||
},
|
||||
};
|
||||
pub use file_util::*;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::winerror::WAIT_TIMEOUT;
|
||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
||||
use winapi::um::processthreadsapi::GetCurrentProcessId;
|
||||
use winapi::um::synchapi::CreateMutexA;
|
||||
use winapi::um::synchapi::ReleaseMutex;
|
||||
use winapi::um::synchapi::WaitForSingleObject;
|
||||
use winapi::um::winbase::INFINITE;
|
||||
use winapi::um::winbase::WAIT_ABANDONED;
|
||||
use winapi::um::winbase::WAIT_OBJECT_0;
|
||||
use winapi::um::winuser::AllowSetForegroundWindow;
|
||||
|
||||
use super::errno_result;
|
||||
use super::pid_t;
|
||||
use super::Error;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn pagesize() -> usize {
|
||||
|
|
|
|||
|
|
@ -2,33 +2,30 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
io,
|
||||
mem::MaybeUninit,
|
||||
sync::Once,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use winapi::shared::minwindef::{
|
||||
HINSTANCE, HMODULE, PULONG, {self},
|
||||
};
|
||||
|
||||
use winapi::{
|
||||
shared::{
|
||||
ntdef::{NTSTATUS, ULONG},
|
||||
ntstatus::STATUS_SUCCESS,
|
||||
},
|
||||
um::{libloaderapi, mmsystem::TIMERR_NOERROR},
|
||||
};
|
||||
|
||||
use std::io;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::sync::Once;
|
||||
use std::thread::sleep;
|
||||
use win_util::{win32_string, win32_wide_string};
|
||||
use winapi::um::{
|
||||
timeapi::{timeBeginPeriod, timeEndPeriod},
|
||||
winnt::BOOLEAN,
|
||||
};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use super::super::{Error, Result};
|
||||
use win_util::win32_string;
|
||||
use win_util::win32_wide_string;
|
||||
use winapi::shared::minwindef::HINSTANCE;
|
||||
use winapi::shared::minwindef::HMODULE;
|
||||
use winapi::shared::minwindef::PULONG;
|
||||
use winapi::shared::minwindef::{self};
|
||||
use winapi::shared::ntdef::NTSTATUS;
|
||||
use winapi::shared::ntdef::ULONG;
|
||||
use winapi::shared::ntstatus::STATUS_SUCCESS;
|
||||
use winapi::um::libloaderapi;
|
||||
use winapi::um::mmsystem::TIMERR_NOERROR;
|
||||
use winapi::um::timeapi::timeBeginPeriod;
|
||||
use winapi::um::timeapi::timeEndPeriod;
|
||||
use winapi::um::winnt::BOOLEAN;
|
||||
|
||||
use super::super::Error;
|
||||
use super::super::Result;
|
||||
use crate::warn;
|
||||
|
||||
static NT_INIT: Once = Once::new();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
//! Implementation of the Syslog trait as a wrapper around Window's events
|
||||
|
||||
use crate::syslog::{Error, Facility, Log, Syslog};
|
||||
use crate::syslog::Error;
|
||||
use crate::syslog::Facility;
|
||||
use crate::syslog::Log;
|
||||
use crate::syslog::Syslog;
|
||||
use crate::RawDescriptor;
|
||||
|
||||
pub struct PlatformSyslog {}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::cmp::min;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::windows::fs::FileExt;
|
||||
|
||||
use crate::PunchHole;
|
||||
use std::{cmp::min, fs::File, io, os::windows::fs::FileExt};
|
||||
|
||||
// TODO(b/195151495): Fix so that this will extend a file size if needed.
|
||||
pub(crate) fn file_write_zeroes_at(
|
||||
|
|
|
|||
|
|
@ -49,21 +49,23 @@
|
|||
//!
|
||||
//! [log-crate-url]: https://docs.rs/log/
|
||||
|
||||
use std::{fmt::Display, io, io::Write};
|
||||
use std::fmt::Display;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
|
||||
use chrono::Local;
|
||||
// Reexports
|
||||
pub use env_logger::{self, fmt};
|
||||
pub use log::*;
|
||||
use once_cell::sync::OnceCell;
|
||||
use remain::sorted;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
use crate::platform::syslog::PlatformSyslog;
|
||||
use crate::platform::RawDescriptor;
|
||||
|
||||
// Reexports
|
||||
pub use env_logger::{self, fmt};
|
||||
pub use log::*;
|
||||
|
||||
/// The priority (i.e. severity) of a syslog message.
|
||||
///
|
||||
/// See syslog man pages for information on their semantics.
|
||||
|
|
@ -468,16 +470,18 @@ impl io::Write for Syslogger {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::field_reassign_with_default)]
|
||||
use super::*;
|
||||
use std::io::Write;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self::new(Default::default()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
#[derive(Clone)]
|
||||
struct MockWrite {
|
||||
buffer: Arc<Mutex<Vec<u8>>>,
|
||||
|
|
|
|||
|
|
@ -2,14 +2,21 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use sync::Mutex;
|
||||
|
||||
use super::{Event, EventReadResult, FakeClock, RawDescriptor, Result};
|
||||
use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use super::Event;
|
||||
use super::EventReadResult;
|
||||
use super::FakeClock;
|
||||
use super::RawDescriptor;
|
||||
use super::Result;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
use crate::descriptor::IntoRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
||||
pub struct Timer {
|
||||
pub(crate) handle: SafeDescriptor,
|
||||
|
|
@ -182,8 +189,10 @@ impl IntoRawDescriptor for FakeTimer {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use super::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
// clock error is 2*clock_resolution + 100 microseconds to handle
|
||||
// time change from calling now() to arming timer
|
||||
|
|
|
|||
|
|
@ -2,16 +2,19 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use remain::sorted;
|
||||
use std::io;
|
||||
|
||||
use remain::sorted;
|
||||
use thiserror::Error as ThisError;
|
||||
|
||||
#[cfg_attr(windows, path = "sys/windows/tube.rs")]
|
||||
#[cfg_attr(not(windows), path = "sys/unix/tube.rs")]
|
||||
mod tube;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
pub use tube::*;
|
||||
|
||||
impl Tube {
|
||||
|
|
@ -122,17 +125,18 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Barrier;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::*;
|
||||
use crate::Event;
|
||||
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
sync::{Arc, Barrier},
|
||||
thread,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct DataStruct {
|
||||
x: u32,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::{platform::EventContext, RawDescriptor, Result};
|
||||
pub use base_event_token_derive::*;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
pub use base_event_token_derive::*;
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::platform::EventContext;
|
||||
use crate::RawDescriptor;
|
||||
use crate::Result;
|
||||
|
||||
/// Trait that can be used to associate events with arbitrary enums when using
|
||||
/// `WaitContext`.
|
||||
|
|
@ -232,9 +234,10 @@ impl<T: EventToken> AsRawDescriptor for WaitContext<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base_event_token_derive::EventToken;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[allow(dead_code)]
|
||||
fn event_token_derive() {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, Error, ErrorKind},
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::{self};
|
||||
|
||||
/// A trait for deallocating space in a file.
|
||||
pub trait PunchHole {
|
||||
|
|
@ -60,10 +60,15 @@ impl WriteZeroesAt for File {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::io::Read;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::io::Write;
|
||||
|
||||
use tempfile::tempfile;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn simple_test() {
|
||||
let mut f = tempfile().unwrap();
|
||||
|
|
|
|||
|
|
@ -6,13 +6,26 @@
|
|||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{quote, quote_spanned};
|
||||
use syn::parse::{Error, Result};
|
||||
use syn::{
|
||||
parse_macro_input, Attribute, Data, DataEnum, DeriveInput, Fields, FieldsNamed, FieldsUnnamed,
|
||||
Ident, Lit, LitInt, Meta, Type, Visibility,
|
||||
};
|
||||
use proc_macro2::Span;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use quote::quote_spanned;
|
||||
use syn::parse::Error;
|
||||
use syn::parse::Result;
|
||||
use syn::parse_macro_input;
|
||||
use syn::Attribute;
|
||||
use syn::Data;
|
||||
use syn::DataEnum;
|
||||
use syn::DeriveInput;
|
||||
use syn::Fields;
|
||||
use syn::FieldsNamed;
|
||||
use syn::FieldsUnnamed;
|
||||
use syn::Ident;
|
||||
use syn::Lit;
|
||||
use syn::LitInt;
|
||||
use syn::Meta;
|
||||
use syn::Type;
|
||||
use syn::Visibility;
|
||||
|
||||
/// The function that derives the actual implementation.
|
||||
#[proc_macro_attribute]
|
||||
|
|
@ -641,9 +654,10 @@ pub fn define_bit_field_specifiers(_input: proc_macro::TokenStream) -> proc_macr
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use syn::parse_quote;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn end_to_end() {
|
||||
let input: DeriveInput = parse_quote! {
|
||||
|
|
|
|||
|
|
@ -267,7 +267,8 @@
|
|||
//! }
|
||||
//! ```
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{self};
|
||||
|
||||
pub use bit_field_derive::bitfield;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,15 @@
|
|||
//! Generic implementation of product specific functions that are called on child process
|
||||
//! initialization.
|
||||
|
||||
use crate::{log_file_from_path, CommonChildStartupArgs};
|
||||
use base::Tube;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use base::Tube;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::log_file_from_path;
|
||||
use crate::CommonChildStartupArgs;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProductAttributes {}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,28 @@
|
|||
//! Contains shared code between the broker & its children, specifically any IPC messages or common
|
||||
//! bootstrapping code.
|
||||
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
|
||||
use anyhow::Context;
|
||||
use base::{enable_high_res_timers, syslog, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor};
|
||||
use base::{EnabledHighResTimer, Tube};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use base::enable_high_res_timers;
|
||||
use base::syslog;
|
||||
use base::EnabledHighResTimer;
|
||||
use base::FromRawDescriptor;
|
||||
use base::IntoRawDescriptor;
|
||||
use base::SafeDescriptor;
|
||||
use base::Tube;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
mod generic;
|
||||
use generic as product;
|
||||
|
||||
use product::{init_child_crash_reporting, product_child_setup, ProductAttributes};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use generic as product;
|
||||
use product::init_child_crash_reporting;
|
||||
use product::product_child_setup;
|
||||
use product::ProductAttributes;
|
||||
|
||||
/// Arguments that are common to all devices & helper processes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CommonChildStartupArgs {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@
|
|||
//!
|
||||
//! The implementation is provided in `cros_async::audio_streams_async`.
|
||||
|
||||
use std::io::Result;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::io::Result;
|
||||
use std::time::Duration;
|
||||
|
||||
#[async_trait(?Send)]
|
||||
pub trait ReadAsync {
|
||||
|
|
|
|||
|
|
@ -41,20 +41,25 @@
|
|||
//! ```
|
||||
pub mod async_api;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::cmp::min;
|
||||
use std::error;
|
||||
use std::fmt::{self, Display};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{self};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::io::RawFd as RawDescriptor;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::io::RawHandle as RawDescriptor;
|
||||
use std::result::Result;
|
||||
use std::str::FromStr;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
pub use async_api::{AsyncStream, AudioStreamsExecutor};
|
||||
pub use async_api::AsyncStream;
|
||||
pub use async_api::AudioStreamsExecutor;
|
||||
use async_trait::async_trait;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -731,10 +736,12 @@ impl StreamSourceGenerator for NoopStreamSourceGenerator {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use futures::FutureExt;
|
||||
use io::Write;
|
||||
use io::{self};
|
||||
|
||||
use super::async_api::test::TestExecutor;
|
||||
use super::*;
|
||||
use futures::FutureExt;
|
||||
use io::{self, Write};
|
||||
|
||||
#[test]
|
||||
fn invalid_buffer_length() {
|
||||
|
|
|
|||
|
|
@ -30,19 +30,24 @@
|
|||
//! # }
|
||||
//! ```
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::{
|
||||
io::{self, Read, Write},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use super::async_api::AudioStreamsExecutor;
|
||||
use super::{
|
||||
AsyncBufferCommit, AudioBuffer, BoxError, BufferCommit, NoopBufferCommit, SampleFormat,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::async_api::AudioStreamsExecutor;
|
||||
use super::AsyncBufferCommit;
|
||||
use super::AudioBuffer;
|
||||
use super::BoxError;
|
||||
use super::BufferCommit;
|
||||
use super::NoopBufferCommit;
|
||||
use super::SampleFormat;
|
||||
|
||||
/// `CaptureBufferStream` provides `CaptureBuffer`s to read with audio samples from capture.
|
||||
pub trait CaptureBufferStream: Send {
|
||||
fn next_capture_buffer<'b, 's: 'b>(&'s mut self) -> Result<CaptureBuffer<'b>, BoxError>;
|
||||
|
|
@ -308,10 +313,11 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use futures::FutureExt;
|
||||
|
||||
use super::super::async_api::test::TestExecutor;
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
use futures::FutureExt;
|
||||
|
||||
#[test]
|
||||
fn invalid_buffer_length() {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,18 @@
|
|||
#[cfg(unix)]
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::sync::Condvar;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use remain::sorted;
|
||||
use std::sync::{Condvar, Mutex};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{BoxError, SampleFormat, StreamDirection, StreamEffect};
|
||||
use crate::BoxError;
|
||||
use crate::SampleFormat;
|
||||
use crate::StreamDirection;
|
||||
use crate::StreamEffect;
|
||||
|
||||
type GenericResult<T> = std::result::Result<T, BoxError>;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
// Balloon commands that are send on the balloon command tube.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue