Refactoring: Use super:: instead of crate:: in win_sys_util

This applies the script in https://crrev.com/c/3530119

BUG=b:22320646
TEST=presubmit

Change-Id: I0ebe218a2220f1449af9d5796207a8f8a0b92bdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530120
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Dennis Kempin 2022-03-16 16:54:09 -07:00
parent 99e336b688
commit 925e7b54d8
35 changed files with 380 additions and 297 deletions

View file

@ -7,7 +7,7 @@
use std::time::{Duration, Instant};
use crate::{AsRawDescriptor, Event};
use super::{AsRawDescriptor, Event};
#[derive(Debug, Copy, Clone)]
pub struct Clock(Instant);

View file

@ -2,28 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::{PollToken, Result};
use std::convert::TryFrom;
use std::fs::File;
use std::io::{Stderr, Stdin, Stdout};
use std::mem;
use std::ops::Drop;
use super::{PollToken, Result};
use std::{
convert::TryFrom,
fs::File,
io::{Stderr, Stdin, Stdout},
mem,
ops::Drop,
};
use serde::{Deserialize, Serialize};
// Windows imports
use std::ffi::CString;
use std::marker::{Send, Sync};
use std::mem::ManuallyDrop;
use std::mem::MaybeUninit;
use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
use std::sync::Once;
use win_util::duplicate_handle;
use win_util::win32_wide_string;
use winapi::shared::minwindef::{BOOL, HMODULE, TRUE};
use winapi::um::handleapi::CloseHandle;
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
use winapi::um::libloaderapi;
use std::{
ffi::CString,
marker::{Send, Sync},
mem::{ManuallyDrop, 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,
},
};
pub type RawDescriptor = RawHandle;
@ -51,7 +56,7 @@ pub trait FromRawDescriptor {
#[derive(Serialize, Deserialize, Debug, Eq)]
#[serde(transparent)]
pub struct SafeDescriptor {
#[serde(with = "crate::with_raw_descriptor")]
#[serde(with = "super::with_raw_descriptor")]
descriptor: RawDescriptor,
}
@ -262,7 +267,7 @@ AsRawDescriptor!(Stderr);
#[test]
#[allow(clippy::eq_op)]
fn clone_equality() {
use crate::{Event, IntoRawDescriptor};
use super::{Event, IntoRawDescriptor};
let evt = Event::new().unwrap();
let descriptor = unsafe { SafeDescriptor::from_raw_descriptor(evt.into_raw_descriptor()) };

View file

@ -48,18 +48,23 @@
//! .expect("failed to deserialize");
//! ```
use std::cell::{Cell, RefCell};
use std::convert::TryInto;
use std::fmt;
use std::fs::File;
use std::ops::{Deref, DerefMut};
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
use std::{
cell::{Cell, RefCell},
convert::TryInto,
fmt,
fs::File,
ops::{Deref, DerefMut},
panic::{catch_unwind, resume_unwind, AssertUnwindSafe},
};
use serde::de::{self, Error, Visitor};
use serde::ser;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{
de::{
Error, Visitor, {self},
},
ser, Deserialize, Deserializer, Serialize, Serializer,
};
use crate::{RawDescriptor, SafeDescriptor};
use super::{RawDescriptor, SafeDescriptor};
thread_local! {
static DESCRIPTOR_DST: RefCell<Option<Vec<RawDescriptor>>> = Default::default();
@ -334,7 +339,7 @@ where
/// }
/// ```
pub mod with_raw_descriptor {
use crate::{IntoRawDescriptor, RawDescriptor};
use super::super::{IntoRawDescriptor, RawDescriptor};
use serde::Deserializer;
pub use super::serialize_descriptor as serialize;
@ -364,7 +369,7 @@ pub mod with_raw_descriptor {
/// }
/// ```
pub mod with_as_descriptor {
use crate::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
use super::super::{AsRawDescriptor, FromRawDescriptor, IntoRawDescriptor};
use serde::{Deserializer, Serializer};
pub fn serialize<S: Serializer>(
@ -425,14 +430,12 @@ impl DerefMut for FileSerdeWrapper {
#[cfg(test)]
mod tests {
use crate::{
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 tempfile::tempfile;

View file

@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::clone::Clone;
use std::default::Default;
use std::marker::Copy;
use std::{clone::Clone, default::Default, marker::Copy};
use crate::{AsRawDescriptor, PollToken, RawDescriptor};
use super::{AsRawDescriptor, PollToken, RawDescriptor};
#[path = "win/wait.rs"]
mod wait;
@ -73,8 +71,7 @@ pub enum EventType {
#[cfg(test)]
mod tests {
use super::*;
use crate::Event;
use super::{super::Event, *};
use std::time::Duration;
#[test]

View file

@ -3,10 +3,12 @@
// found in the LICENSE file.
pub use super::win::file_traits::*;
use crate::{AsRawDescriptor, RawDescriptor};
use super::{AsRawDescriptor, RawDescriptor};
use std::fs::File;
use std::io::{Error, ErrorKind, Result};
use std::{
fs::File,
io::{Error, ErrorKind, Result},
};
use data_model::VolatileSlice;
@ -271,8 +273,8 @@ where
}
}
crate::volatile_impl!(File);
crate::volatile_at_impl!(File);
super::volatile_impl!(File);
super::volatile_at_impl!(File);
#[cfg(test)]
mod tests {

View file

@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use libc::gmtime_s;
use libc::{time_t, tm};
use libc::{gmtime_s, time_t, tm};
/// # Safety
/// safe because we are passing in the allocated tm struct

View file

@ -6,7 +6,7 @@
use std::os::raw::*;
use crate::AsRawDescriptor;
use super::AsRawDescriptor;
/// Raw macro to declare the expression that calculates an ioctl number
#[macro_export]

View file

@ -44,36 +44,36 @@ pub mod thread;
mod write_zeroes;
pub use crate::clock::{Clock, FakeClock};
pub use crate::console::*;
pub use crate::descriptor::*;
pub use crate::event::*;
pub use crate::events::*;
pub use crate::get_filesystem_type::*;
pub use crate::gmtime::*;
pub use crate::ioctl::*;
pub use crate::mmap::*;
pub use crate::notifiers::*;
pub use crate::poll::*;
pub use crate::priority::*;
pub use crate::sched::*;
pub use crate::shm::*;
pub use crate::stream_channel::*;
pub use crate::timer::*;
pub use crate::win::*;
pub use clock::{Clock, FakeClock};
pub use console::*;
pub use descriptor::*;
pub use descriptor_reflection::{
deserialize_with_descriptors, with_as_descriptor, with_raw_descriptor, FileSerdeWrapper,
SerializeDescriptors,
};
pub use event::*;
pub use events::*;
pub use get_filesystem_type::*;
pub use gmtime::*;
pub use ioctl::*;
pub use mmap::*;
pub use notifiers::*;
pub use poll::*;
pub use poll_token_derive::*;
pub use priority::*;
pub use sched::*;
pub use shm::*;
pub use stream_channel::*;
pub use sys_util_core::{Error, Result, *};
pub use timer::*;
pub use win::*;
pub use crate::file_traits::{
pub use file_traits::{
AsRawDescriptors, FileAllocate, FileGetLen, FileReadWriteAtVolatile, FileReadWriteVolatile,
FileSetLen, FileSync,
};
pub use crate::mmap::Error as MmapError;
pub use crate::write_zeroes::{PunchHole, WriteZeroes, WriteZeroesAt};
pub use mmap::Error as MmapError;
pub use write_zeroes::{PunchHole, WriteZeroes, WriteZeroesAt};
use std::cell::Cell;

View file

@ -3,17 +3,18 @@
// found in the LICENSE file.
use remain::sorted;
use std::cmp::min;
use std::io;
use std::mem::size_of;
use std::ptr::{copy_nonoverlapping, read_unaligned, write_unaligned};
use std::{
cmp::min,
io,
mem::size_of,
ptr::{copy_nonoverlapping, read_unaligned, write_unaligned},
};
use data_model::volatile_memory::*;
use data_model::DataInit;
use data_model::{volatile_memory::*, DataInit};
use libc::{c_int, c_uint, c_void};
use crate::{AsRawDescriptor, Descriptor, ExternalMapping, RawDescriptor};
use super::{AsRawDescriptor, Descriptor, ExternalMapping, RawDescriptor};
#[path = "win/mmap.rs"]
mod mmap_platform;
@ -41,7 +42,7 @@ pub enum Error {
#[error("system call failed while creating the mapping: {0}")]
StdSyscallFailed(io::Error),
#[error("mmap related system call failed: {0}")]
SystemCallFailed(#[source] crate::Error),
SystemCallFailed(#[source] super::Error),
#[error("failed to write from memory to file: {0}")]
WriteFromMemory(#[source] io::Error),
}
@ -183,7 +184,7 @@ impl dyn MappedRegion {
if ret != -1 {
Ok(())
} else {
Err(Error::SystemCallFailed(crate::Error::last()))
Err(Error::SystemCallFailed(super::Error::last()))
}
}
}
@ -421,8 +422,7 @@ impl VolatileMemory for MemoryMapping {
#[cfg(test)]
mod tests {
use super::*;
use crate::shm::SharedMemory;
use super::{super::shm::SharedMemory, *};
use data_model::{VolatileMemory, VolatileMemoryError};
#[test]

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::AsRawDescriptor;
use super::AsRawDescriptor;
pub trait ReadNotifier {
/// Gets a descriptor that can be used in EventContext to wait for events to be available (e.g.

View file

@ -4,11 +4,13 @@
use std::ffi::CString;
use crate::{
use super::{
AsRawDescriptor, IntoRawDescriptor, MemoryMapping, RawDescriptor, Result, SafeDescriptor,
};
use libc::EINVAL;
use std::io::{self, Error, ErrorKind, Read, Seek, SeekFrom, Write};
use std::io::{
Error, ErrorKind, Read, Seek, SeekFrom, Write, {self},
};
#[path = "win/shm.rs"]
mod shm_platform;
@ -32,7 +34,7 @@ impl SharedMemory {
/// error.
pub fn named<T: Into<Vec<u8>>>(name: T, size: u64) -> Result<SharedMemory> {
SharedMemory::new(
Some(&CString::new(name).map_err(|_| crate::Error::new(EINVAL))?),
Some(&CString::new(name).map_err(|_| super::Error::new(EINVAL))?),
size,
)
}

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::{AsRawDescriptor, RawDescriptor};
use super::{AsRawDescriptor, RawDescriptor};
use std::io;
#[path = "win/stream_channel.rs"]
mod stream_channel;
@ -40,8 +40,10 @@ impl AsRawDescriptor for StreamChannel {
#[cfg(test)]
mod test {
use super::*;
use crate::{EventContext, EventTrigger, PollToken, ReadNotifier};
use super::{
super::{EventContext, EventTrigger, PollToken, ReadNotifier},
*,
};
use std::io::{Read, Write};
#[derive(PollToken, Debug, Eq, PartialEq, Copy, Clone)]

View file

@ -21,17 +21,21 @@
//! ```
pub use super::win::syslog::PlatformSyslog;
use crate::{syslog_lock, AsRawDescriptor, RawDescriptor, CHRONO_TIMESTAMP_FIXED_FMT};
use super::{syslog_lock, AsRawDescriptor, RawDescriptor, CHRONO_TIMESTAMP_FIXED_FMT};
use serde::{Deserialize, Serialize};
use std::convert::{From, Into, TryFrom};
use std::env;
use std::ffi::{OsStr, OsString};
use std::fmt::{self, Display};
use std::fs::File;
use std::io;
use std::io::{stderr, Cursor, Write};
use std::path::{Path, PathBuf};
use std::sync::{MutexGuard, Once};
use std::{
convert::{From, Into, TryFrom},
env,
ffi::{OsStr, OsString},
fmt::{
Display, {self},
},
fs::File,
io,
io::{stderr, Cursor, Write},
path::{Path, PathBuf},
sync::{MutexGuard, Once},
};
use remain::sorted;
use sync::Mutex;
@ -586,11 +590,9 @@ impl io::Write for Syslogger {
mod tests {
use super::*;
use crate::{BlockingMode, FramingMode, StreamChannel};
use super::super::{BlockingMode, FramingMode, StreamChannel};
use regex::Regex;
use std::convert::TryInto;
use std::io::Read;
use std::os::windows::io::FromRawHandle;
use std::{convert::TryInto, io::Read, os::windows::io::FromRawHandle};
#[test]
#[ignore]

View file

@ -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 std::any::Any;
use std::panic::UnwindSafe;
use std::sync::mpsc::{channel, Receiver};
use std::thread::JoinHandle;
use std::time::Duration;
use std::{panic, thread};
use std::{
any::Any,
panic,
panic::UnwindSafe,
sync::mpsc::{channel, Receiver},
thread,
thread::JoinHandle,
time::Duration,
};
/// Spawns a thread that can be joined with a timeout.
pub fn spawn_with_timeout<F, T>(f: F) -> JoinHandleWithTimeout<T>

View file

@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::{
sync::Arc,
time::{Duration, Instant},
};
use sync::Mutex;
use crate::{
use super::{
AsRawDescriptor, Event, EventReadResult, FakeClock, FromRawDescriptor, IntoRawDescriptor,
RawDescriptor, Result, SafeDescriptor,
};

View file

@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::AsRawDescriptor;
use std::io::Error;
use std::io::{stdin, Read, Result};
use winapi::shared::minwindef::LPVOID;
use winapi::shared::ntdef::NULL;
use winapi::um::fileapi::ReadFile;
use winapi::um::minwinbase::LPOVERLAPPED;
use super::AsRawDescriptor;
use std::io::{stdin, Error, Read, Result};
use winapi::{
shared::{minwindef::LPVOID, ntdef::NULL},
um::{fileapi::ReadFile, minwinbase::LPOVERLAPPED},
};
pub struct Console;

View file

@ -3,25 +3,33 @@
// found in the LICENSE file.
use serde::{Deserialize, Serialize};
use std::ffi::CString;
use std::mem;
use std::mem::MaybeUninit;
use std::ops::Deref;
use std::os::windows::io::{AsRawHandle, RawHandle};
use std::ptr;
use std::ptr::null;
use std::time::Duration;
use std::{
ffi::CString,
mem,
mem::MaybeUninit,
ops::Deref,
os::windows::io::{AsRawHandle, RawHandle},
ptr,
ptr::null,
time::Duration,
};
use sys_util_core::generate_scoped_event;
use win_util::{SecurityAttributes, SelfRelativeSecurityDescriptor};
use winapi::shared::minwindef::{DWORD, FALSE, TRUE};
use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::handleapi::DuplicateHandle;
use winapi::um::processthreadsapi::GetCurrentProcess;
use winapi::um::synchapi::{CreateEventA, OpenEventA, ResetEvent, SetEvent, WaitForSingleObject};
use winapi::um::winbase::WAIT_FAILED;
use winapi::um::winnt::{DUPLICATE_SAME_ACCESS, EVENT_MODIFY_STATE, HANDLE};
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 crate::{
use super::{
errno_result, AsRawDescriptor, Error, FromRawDescriptor, IntoRawDescriptor, RawDescriptor,
Result, SafeDescriptor,
};
@ -218,8 +226,10 @@ generate_scoped_event!(Event);
#[cfg(test)]
mod tests {
use super::*;
use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::winbase::{INFINITE, WAIT_OBJECT_0};
use winapi::{
shared::winerror::WAIT_TIMEOUT,
um::winbase::{INFINITE, WAIT_OBJECT_0},
};
#[test]
fn new() {

View file

@ -2,9 +2,8 @@
// 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;
use std::io;
use super::super::{FileAllocate, WriteZeroesAt};
use std::{fs::File, io};
#[macro_export]
macro_rules! volatile_impl {

View file

@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::AsRawDescriptor;
use std::ffi::c_void;
use std::io;
use super::super::AsRawDescriptor;
use std::{ffi::c_void, io};
pub use winapi::um::winioctl::FSCTL_SET_SPARSE;
/// Marks the given file as sparse. Required if we want hole punching to be performant.
@ -15,7 +14,7 @@ pub fn set_sparse_file<T: AsRawDescriptor>(handle: &T) -> io::Result<()> {
// Safe because we check the return value and handle is guaranteed to be a
// valid file handle by the caller.
let result = unsafe {
crate::ioctl::ioctl_with_ptr(
super::super::ioctl::ioctl_with_ptr(
handle,
FSCTL_SET_SPARSE,
std::ptr::null_mut() as *mut c_void,

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::Result;
use super::Result;
use std::fs::File;
pub fn get_filesystem_type(_file: &File) -> Result<i64> {

View file

@ -4,14 +4,11 @@
//! Macros and wrapper functions for dealing with ioctls.
use std::mem::size_of;
use std::os::raw::*;
use std::ptr::null_mut;
use std::{mem::size_of, os::raw::*, ptr::null_mut};
use crate::AsRawDescriptor;
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::ioapiset::DeviceIoControl;
use super::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]
@ -307,21 +304,18 @@ mod tests {
use winapi::um::winioctl::{FSCTL_GET_COMPRESSION, FSCTL_SET_COMPRESSION};
use winapi::um::fileapi::{CreateFileW, OPEN_EXISTING};
use winapi::um::winbase::SECURITY_SQOS_PRESENT;
use winapi::um::winnt::{
COMPRESSION_FORMAT_LZNT1, COMPRESSION_FORMAT_NONE, FILE_SHARE_READ, FILE_SHARE_WRITE,
GENERIC_READ, GENERIC_WRITE,
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;
use std::os::raw::*;
use std::ptr::null_mut;
use std::{fs::OpenOptions, os::raw::*, ptr::null_mut};
use std::ffi::OsStr;
use std::fs::File;
use std::io::prelude::*;
use std::os::windows::ffi::OsStrExt;
use std::{ffi::OsStr, fs::File, io::prelude::*, os::windows::ffi::OsStrExt};
use std::os::windows::prelude::*;
@ -351,8 +345,9 @@ mod tests {
f.sync_all().expect("Failed to sync all.");
// read the compression status
let ecode =
unsafe { crate::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed) };
let ecode = unsafe {
super::super::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed)
};
// shouldn't error
assert_eq!(ecode, 0);
@ -387,7 +382,8 @@ mod tests {
))
};
let ecode = unsafe { crate::ioctl::ioctl_with_ref(&f, FSCTL_SET_COMPRESSION, &compressed) };
let ecode =
unsafe { super::super::ioctl::ioctl_with_ref(&f, FSCTL_SET_COMPRESSION, &compressed) };
assert_eq!(ecode, 0);
// set compressed short back to 0 for reading purposes,
@ -395,8 +391,9 @@ mod tests {
// is writing anything to the compressed pointer.
compressed = 0;
let ecode =
unsafe { crate::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed) };
let ecode = unsafe {
super::super::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed)
};
// now should be compressed
assert_eq!(ecode, 0);
@ -454,8 +451,9 @@ mod tests {
// now we call ioctl_with_val, which isn't particularly any more helpful than
// ioctl_with_ref except for the cases where the input is only a word long
let ecode =
unsafe { crate::ioctl::ioctl_with_val(&f, FSCTL_SET_COMPRESSION, compressed.into()) };
let ecode = unsafe {
super::super::ioctl::ioctl_with_val(&f, FSCTL_SET_COMPRESSION, compressed.into())
};
assert_eq!(ecode, 0);
// set compressed short back to 0 for reading purposes,
@ -463,8 +461,9 @@ mod tests {
// is writing anything to the compressed pointer.
compressed = 0;
let ecode =
unsafe { crate::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed) };
let ecode = unsafe {
super::super::ioctl::ioctl_with_mut_ref(&f, FSCTL_GET_COMPRESSION, &mut compressed)
};
// now should be compressed
assert_eq!(ecode, 0);

View file

@ -5,18 +5,24 @@
//! The mmap module provides a safe interface to map memory and ensures UnmapViewOfFile is called when the
//! mmap object leaves scope.
use std::io;
use std::slice::{from_raw_parts, from_raw_parts_mut};
use std::{
io,
slice::{from_raw_parts, from_raw_parts_mut},
};
use libc::{self, c_uint, c_void};
use libc::{
c_uint, c_void, {self},
};
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::{Error, MappedRegion, MemoryMapping, Protection, Result};
use crate::{warn, AsRawDescriptor, RawDescriptor};
use super::{
super::{warn, AsRawDescriptor, RawDescriptor},
Error, MappedRegion, MemoryMapping, Protection, Result,
};
pub(super) const PROT_NONE: c_uint = 0;
pub(super) const PROT_READ: c_uint = FILE_MAP_READ;
@ -169,7 +175,7 @@ impl MemoryMapping {
};
if created_address.is_null() {
return Err(Error::SystemCallFailed(crate::Error::last()));
return Err(Error::SystemCallFailed(super::super::Error::last()));
}
Ok(MemoryMapping {
@ -184,7 +190,7 @@ impl MemoryMapping {
// Safe because self can only be created as a successful memory mapping
unsafe {
if FlushViewOfFile(self.addr, self.size) == 0 {
return Err(Error::SystemCallFailed(crate::Error::last()));
return Err(Error::SystemCallFailed(super::super::Error::last()));
}
};
Ok(())
@ -280,7 +286,10 @@ impl Drop for MemoryMapping {
// else is holding a reference to it.
unsafe {
if UnmapViewOfFile(self.addr) == 0 {
warn!("Unsuccessful unmap of file: {}", crate::Error::last());
warn!(
"Unsuccessful unmap of file: {}",
super::super::Error::last()
);
}
}
}
@ -293,8 +302,10 @@ pub struct MemoryMappingArena();
#[cfg(test)]
mod tests {
use super::*;
use crate::{pagesize, FromRawDescriptor, SharedMemory};
use super::{
super::super::{pagesize, FromRawDescriptor, SharedMemory},
*,
};
use data_model::{VolatileMemory, VolatileMemoryError};
use std::ptr;
use winapi::shared::winerror;

View file

@ -14,22 +14,26 @@ pub use platform_timer_utils::*;
mod file_util;
pub use file_util::*;
use crate::{
use super::{
errno_result, pid_t, AsRawDescriptor, Error, FromRawDescriptor, Result, SafeDescriptor,
};
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::path::Path;
use std::ptr::null_mut;
use std::sync::Once;
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, ReleaseMutex, WaitForSingleObject};
use winapi::um::winbase::WAIT_ABANDONED;
use winapi::um::winbase::{INFINITE, WAIT_OBJECT_0};
use winapi::um::winuser::AllowSetForegroundWindow;
use std::{
fs::{File, OpenOptions},
path::Path,
ptr::null_mut,
sync::Once,
};
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,
},
};
#[inline(always)]
pub fn pagesize() -> usize {

View file

@ -3,35 +3,43 @@
// found in the LICENSE file.
use rand::Rng;
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, Ordering};
use std::{
ffi::CString,
fs::OpenOptions,
io,
io::Result,
mem,
os::windows::fs::OpenOptionsExt,
process, ptr,
sync::atomic::{AtomicUsize, Ordering},
};
use crate::{
use super::{
AsRawDescriptor, Event, FromRawDescriptor, IntoRawDescriptor, RawDescriptor, SafeDescriptor,
};
use serde::{Deserialize, Serialize};
use win_util::{SecurityAttributes, SelfRelativeSecurityDescriptor};
use winapi::shared::minwindef::{DWORD, LPCVOID, LPVOID, TRUE};
use winapi::shared::winerror::{ERROR_IO_PENDING, ERROR_NO_DATA, ERROR_PIPE_CONNECTED};
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::fileapi::{FlushFileBuffers, ReadFile, WriteFile};
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
use winapi::um::ioapiset::{CancelIoEx, GetOverlappedResult};
use winapi::um::minwinbase::OVERLAPPED;
use winapi::um::namedpipeapi::{
ConnectNamedPipe, GetNamedPipeInfo, PeekNamedPipe, SetNamedPipeHandleState,
};
use winapi::um::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 winapi::{
shared::{
minwindef::{DWORD, LPCVOID, LPVOID, TRUE},
winerror::{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,
},
},
};
/// The default buffer size for all named pipes in the system. If this size is too small, writers

View file

@ -2,24 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::io;
use std::mem::MaybeUninit;
use std::sync::Once;
use std::time::{Duration, Instant};
use std::{
io,
mem::MaybeUninit,
sync::Once,
time::{Duration, Instant},
};
use winapi::shared::minwindef::{self, HINSTANCE, HMODULE, PULONG};
use winapi::shared::minwindef::{
HINSTANCE, HMODULE, PULONG, {self},
};
use winapi::shared::ntdef::{NTSTATUS, ULONG};
use winapi::shared::ntstatus::STATUS_SUCCESS;
use winapi::um::libloaderapi;
use winapi::um::mmsystem::TIMERR_NOERROR;
use winapi::{
shared::{
ntdef::{NTSTATUS, ULONG},
ntstatus::STATUS_SUCCESS,
},
um::{libloaderapi, mmsystem::TIMERR_NOERROR},
};
use std::thread::sleep;
use win_util::{win32_string, win32_wide_string};
use winapi::um::timeapi::{timeBeginPeriod, timeEndPeriod};
use winapi::um::winnt::BOOLEAN;
use winapi::um::{
timeapi::{timeBeginPeriod, timeEndPeriod},
winnt::BOOLEAN,
};
use crate::{warn, Error, Result};
use super::super::{warn, Error, Result};
static NT_INIT: Once = Once::new();
static mut NT_LIBRARY: MaybeUninit<HMODULE> = MaybeUninit::uninit();

View file

@ -2,12 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::{errno_result, Result};
use super::{errno_result, Result};
use std::os::windows::raw::HANDLE;
use winapi::shared::minwindef::FALSE;
use winapi::um::avrt::{AvRevertMmThreadCharacteristics, AvSetMmThreadCharacteristicsA};
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::processthreadsapi::{GetCurrentThread, SetThreadPriority};
use winapi::{
shared::minwindef::FALSE,
um::{
avrt::{AvRevertMmThreadCharacteristics, AvSetMmThreadCharacteristicsA},
errhandlingapi::GetLastError,
processthreadsapi::{GetCurrentThread, SetThreadPriority},
},
};
pub fn set_audio_thread_priorities() -> Result<SafeMultimediaHandle> {
// Safe because we know Pro Audio is part of windows and we down task_index.
@ -61,10 +65,10 @@ impl Drop for SafeMultimediaHandle {
#[cfg(test)]
mod test {
use super::*;
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 winapi::um::{
processthreadsapi::{GetCurrentThread, GetThreadPriority},
winbase::{THREAD_PRIORITY_NORMAL, THREAD_PRIORITY_TIME_CRITICAL},
};
// TODO(b/223733375): Enable ignored flaky tests.
#[test]

View file

@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::AsRawDescriptor;
use std::io::{self, Error};
use super::super::AsRawDescriptor;
use std::io::{
Error, {self},
};
use win_util::LargeInteger;
pub use winapi::um::winioctl::FSCTL_SET_ZERO_DATA;
use winapi::um::winnt::LARGE_INTEGER;
@ -40,7 +42,8 @@ pub fn execute_punch_hole<T: AsRawDescriptor>(
};
// Safe because we check the return value and all values should be set
let result = unsafe { crate::ioctl::ioctl_with_ref(handle, FSCTL_SET_ZERO_DATA, &zero_data) };
let result =
unsafe { super::super::ioctl::ioctl_with_ref(handle, FSCTL_SET_ZERO_DATA, &zero_data) };
if result != 0 {
return Err(Error::from_raw_os_error(result));

View file

@ -3,8 +3,7 @@
// found in the LICENSE file.
use libc::EINVAL;
use winapi::um::processthreadsapi::GetCurrentThread;
use winapi::um::winbase::SetThreadAffinityMask;
use winapi::um::{processthreadsapi::GetCurrentThread, winbase::SetThreadAffinityMask};
use super::{errno_result, Error, Result};
@ -50,9 +49,8 @@ pub fn get_cpu_affinity() -> Result<Vec<usize>> {
#[cfg(test)]
mod tests {
use crate::sched::*;
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;

View file

@ -6,8 +6,10 @@ use std::ffi::CStr;
use win_util::create_file_mapping;
use winapi::um::winnt::PAGE_EXECUTE_READWRITE;
use crate::shm::SharedMemory;
use crate::{AsRawDescriptor, FromRawDescriptor, MemoryMapping, MmapError, Result, SafeDescriptor};
use super::super::{
shm::SharedMemory, AsRawDescriptor, FromRawDescriptor, MemoryMapping, MmapError, Result,
SafeDescriptor,
};
impl SharedMemory {
/// Creates a new shared memory file mapping with zero size.
@ -21,7 +23,7 @@ impl SharedMemory {
name.map(|s| s.to_str().unwrap()),
)
}
.map_err(crate::Error::from)?;
.map_err(super::super::Error::from)?;
// Safe because we have exclusive ownership of mapping_handle & it is valid.
Self::from_safe_descriptor(
@ -41,7 +43,7 @@ impl SharedMemory {
MmapError::SystemCallFailed(e) => Err(e),
// TODO(b/150414994): This error lacks meaning. Consider adding custom errors to
// shm
_ => Err(crate::Error::new(0)),
_ => Err(super::super::Error::new(0)),
};
}
};

View file

@ -2,16 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use crate::named_pipes::{self, PipeConnection};
use crate::stream_channel::{BlockingMode, FramingMode};
use crate::{
use super::super::{
named_pipes::{
PipeConnection, {self},
},
stream_channel::{BlockingMode, FramingMode},
AsRawDescriptor, CloseNotifier, Event, MultiProcessMutex, RawDescriptor, ReadNotifier, Result,
};
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize, Serializer};
use std::cell::RefCell;
use std::io;
use std::sync::Arc;
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
use std::{cell::RefCell, io, sync::Arc};
use sync::Mutex;
impl From<FramingMode> for named_pipes::FramingMode {
@ -366,10 +365,14 @@ impl CloseNotifier for StreamChannel {
#[cfg(test)]
mod test {
use super::*;
use crate::{EventContext, EventTrigger, PollToken, ReadNotifier};
use std::io::{Read, Write};
use std::time::Duration;
use super::{
super::super::{EventContext, EventTrigger, PollToken, ReadNotifier},
*,
};
use std::{
io::{Read, Write},
time::Duration,
};
#[derive(PollToken, Debug, Eq, PartialEq, Copy, Clone)]
enum Token {

View file

@ -4,8 +4,10 @@
//! Implementation of the Syslog trait as a wrapper around Window's events
use crate::syslog::{Error, Facility, Priority, Syslog};
use crate::RawDescriptor;
use super::super::{
syslog::{Error, Facility, Priority, Syslog},
RawDescriptor,
};
pub struct PlatformSyslog {
enabled: bool,

View file

@ -2,19 +2,28 @@
// 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};
use std::ptr;
use std::time::Duration;
use std::{
os::windows::io::{AsRawHandle, RawHandle},
ptr,
time::Duration,
};
use win_util::{LargeInteger, SecurityAttributes, SelfRelativeSecurityDescriptor};
use winapi::shared::minwindef::FALSE;
use winapi::shared::winerror::WAIT_TIMEOUT;
use winapi::um::synchapi::{CancelWaitableTimer, SetWaitableTimer, WaitForSingleObject};
use winapi::um::winbase::{CreateWaitableTimerA, INFINITE, WAIT_OBJECT_0};
use winapi::{
shared::{minwindef::FALSE, winerror::WAIT_TIMEOUT},
um::{
synchapi::{CancelWaitableTimer, SetWaitableTimer, WaitForSingleObject},
winbase::{CreateWaitableTimerA, INFINITE, WAIT_OBJECT_0},
},
};
use super::{Timer, WaitResult};
use crate::win::nt_query_timer_resolution;
use crate::{errno_result, AsRawDescriptor, FromRawDescriptor, Result, SafeDescriptor};
use super::{
super::{
errno_result, win::nt_query_timer_resolution, AsRawDescriptor, FromRawDescriptor, Result,
SafeDescriptor,
},
Timer, WaitResult,
};
impl AsRawHandle for Timer {
fn as_raw_handle(&self) -> RawHandle {

View file

@ -2,18 +2,23 @@
// 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::collections::HashMap;
use std::os::windows::io::RawHandle;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::{
cmp::min,
collections::HashMap,
os::windows::io::RawHandle,
sync::{Arc, Mutex},
time::Duration,
};
use winapi::shared::minwindef::{DWORD, FALSE};
use winapi::shared::winerror::{ERROR_INVALID_PARAMETER, WAIT_TIMEOUT};
use winapi::um::synchapi::WaitForMultipleObjects;
use winapi::um::winbase::WAIT_OBJECT_0;
use winapi::{
shared::{
minwindef::{DWORD, FALSE},
winerror::{ERROR_INVALID_PARAMETER, WAIT_TIMEOUT},
},
um::{synchapi::WaitForMultipleObjects, winbase::WAIT_OBJECT_0},
};
use crate::{
use super::super::{
errno_result, error, AsRawDescriptor, Descriptor, Error, Event, EventTrigger, EventType,
PollToken, Result, TriggeredEvent,
};

View file

@ -2,12 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use super::PunchHole;
use super::WriteZeroesAt;
use std::cmp::min;
use std::fs::File;
use std::io;
use std::os::windows::fs::FileExt;
use super::{PunchHole, WriteZeroesAt};
use std::{cmp::min, fs::File, io, os::windows::fs::FileExt};
impl WriteZeroesAt for File {
// TODO(b/195151495): Fix so that this will extend a file size if needed.

View file

@ -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::fs::File;
use std::io::{self, Error, ErrorKind, Seek, SeekFrom};
use std::{
fs::File,
io::{
Error, ErrorKind, Seek, SeekFrom, {self},
},
};
#[path = "win/punch_hole.rs"]
mod punch_hole;
@ -11,7 +15,7 @@ mod punch_hole;
#[path = "win/write_zeros.rs"]
mod write_zeros;
use crate::write_zeroes::punch_hole::execute_punch_hole;
use super::write_zeroes::punch_hole::execute_punch_hole;
/// A trait for deallocating space in a file.
pub trait PunchHole {
@ -100,8 +104,10 @@ impl<T: WriteZeroesAt + Seek> WriteZeroes for T {
#[cfg(test)]
mod tests {
use super::*;
use std::fs::OpenOptions;
use std::io::{Read, Seek, SeekFrom, Write};
use std::{
fs::OpenOptions,
io::{Read, Seek, SeekFrom, Write},
};
use tempfile::TempDir;
#[test]