From e53c5ef36286202a14267a690db3b094c89442ea Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Sat, 6 Aug 2022 08:21:44 -0700 Subject: [PATCH] Apply rustfmt Reviewed By: zertosh Differential Revision: D38485027 fbshipit-source-id: 0f5e5b743e002045c95aca427b76e969d6bce347 --- reverie-examples/chaos.rs | 6 +- reverie-examples/chrome-trace/global_state.rs | 15 ++-- reverie-examples/chrome-trace/main.rs | 12 ++- reverie-examples/chrome-trace/tool.rs | 16 ++-- reverie-examples/chunky_print.rs | 13 +-- reverie-examples/counter1.rs | 5 +- reverie-examples/counter2.rs | 10 +-- reverie-examples/strace/config.rs | 4 +- reverie-examples/strace/filter.rs | 1 - reverie-examples/strace/main.rs | 6 +- reverie-examples/strace/tool.rs | 7 +- reverie-process/src/child.rs | 27 +++---- reverie-process/src/container.rs | 38 ++++----- reverie-process/src/exit_status.rs | 3 +- reverie-process/src/fd.rs | 11 +-- reverie-process/src/lib.rs | 25 +++--- reverie-process/src/mount.rs | 12 ++- reverie-process/src/namespace.rs | 3 +- reverie-process/src/net.rs | 7 +- reverie-process/src/pid.rs | 1 + reverie-process/src/pty.rs | 21 +++-- reverie-process/src/seccomp/bpf.rs | 4 +- reverie-process/src/seccomp/mod.rs | 10 +-- reverie-process/src/seccomp/notif.rs | 8 +- reverie-process/src/spawn.rs | 9 +-- reverie-process/src/stdio.rs | 8 +- reverie-ptrace/src/cp/mmap.rs | 3 +- .../gdbstub/commands/base/_QStartNoAckMode.rs | 3 +- .../gdbstub/commands/base/_QThreadEvents.rs | 3 +- .../gdbstub/commands/base/_QuestionMark.rs | 3 +- .../src/gdbstub/commands/base/_g.rs | 3 +- .../src/gdbstub/commands/base/_g_upper.rs | 3 +- .../src/gdbstub/commands/base/_h_upper.rs | 3 +- .../src/gdbstub/commands/base/_p_upper.rs | 3 +- .../src/gdbstub/commands/base/_qAttached.rs | 3 +- .../src/gdbstub/commands/base/_qC.rs | 3 +- .../src/gdbstub/commands/base/_qSupported.rs | 5 +- .../gdbstub/commands/base/_qfThreadInfo.rs | 3 +- .../gdbstub/commands/base/_qsThreadInfo.rs | 3 +- .../src/gdbstub/commands/base/_s.rs | 3 +- .../src/gdbstub/commands/base/_t_upper.rs | 3 +- .../src/gdbstub/commands/base/_vCont.rs | 1 - .../src/gdbstub/commands/base/_vFile.rs | 6 +- .../src/gdbstub/commands/base/_vKill.rs | 2 +- .../src/gdbstub/commands/base/mod.rs | 8 +- .../extended_mode/_ExclamationMark.rs | 3 +- .../extended_mode/_QEnvironmentHexEncoded.rs | 3 +- .../extended_mode/_QEnvironmentUnset.rs | 3 +- .../commands/extended_mode/_QSetWorkingDir.rs | 3 +- .../extended_mode/_QStartupWithShell.rs | 3 +- .../commands/extended_mode/_r_upper.rs | 5 +- .../commands/extended_mode/_vAttach.rs | 5 +- .../gdbstub/commands/extended_mode/_vRun.rs | 3 +- reverie-ptrace/src/gdbstub/commands/mod.rs | 27 ++++--- .../gdbstub/commands/monitor_cmd/_qRcmd.rs | 5 +- .../commands/section_offsets/_qOffsets.rs | 3 +- reverie-ptrace/src/gdbstub/error.rs | 7 +- reverie-ptrace/src/gdbstub/inferior.rs | 6 +- reverie-ptrace/src/gdbstub/packet.rs | 5 +- reverie-ptrace/src/gdbstub/regs.rs | 6 +- reverie-ptrace/src/gdbstub/request.rs | 3 +- reverie-ptrace/src/gdbstub/response.rs | 1 - reverie-ptrace/src/gdbstub/server.rs | 5 +- reverie-ptrace/src/gdbstub/session.rs | 9 +-- reverie-ptrace/src/perf.rs | 15 ++-- reverie-ptrace/src/stack.rs | 11 +-- reverie-ptrace/src/task.rs | 80 +++++++++---------- reverie-ptrace/src/testing.rs | 4 +- reverie-ptrace/src/timer.rs | 11 +-- reverie-ptrace/src/trace/memory.rs | 14 ++-- reverie-ptrace/src/trace/mod.rs | 26 +++--- reverie-ptrace/src/trace/notifier.rs | 3 +- reverie-ptrace/src/trace/waitid.rs | 10 ++- reverie-ptrace/src/tracer.rs | 31 ++++--- reverie-ptrace/src/validation.rs | 12 +-- reverie-ptrace/src/vdso.rs | 4 +- reverie-syscalls/src/args/clone.rs | 9 ++- reverie-syscalls/src/args/ioctl.rs | 6 +- reverie-syscalls/src/args/mod.rs | 9 +-- reverie-syscalls/src/args/poll.rs | 9 ++- reverie-syscalls/src/args/stat.rs | 3 +- reverie-syscalls/src/display.rs | 10 +-- reverie-syscalls/src/lib.rs | 10 +-- reverie-syscalls/src/memory/addr.rs | 4 +- reverie-syscalls/src/memory/mod.rs | 1 - reverie-syscalls/src/raw.rs | 3 +- reverie-syscalls/src/syscalls/family.rs | 5 +- reverie-syscalls/src/syscalls/mod.rs | 49 ++++++------ reverie-util/src/commandline.rs | 6 +- reverie-util/src/pedigree.rs | 5 +- reverie/src/auxv.rs | 10 +-- reverie/src/backtrace/library.rs | 7 +- reverie/src/backtrace/mod.rs | 6 +- reverie/src/error.rs | 3 +- reverie/src/lib.rs | 24 +++--- reverie/src/rdtsc.rs | 1 + reverie/src/subscription.rs | 3 +- reverie/src/tool.rs | 13 +-- tests/backtrace.rs | 1 - tests/basics.rs | 18 +++-- tests/busywait.rs | 14 ++-- tests/convert.rs | 3 +- tests/cpuid.rs | 10 +-- tests/delay_signal.rs | 10 ++- tests/exit.rs | 3 +- .../gdbserver-helper/src/main.rs | 15 ++-- .../gdbserver-helper/src/server.rs | 3 +- tests/rdtsc.rs | 8 +- tests/signal.rs | 8 +- tests/signalfd.rs | 8 +- tests/spinlock.rs | 6 +- tests/stack.rs | 8 +- tests/standalone/at_random.rs | 3 +- tests/standalone/inject_then_tail_inject.rs | 7 +- tests/standalone/parallel_tasks.rs | 9 ++- tests/stat.rs | 6 +- tests/state.rs | 5 +- tests/timer_semantics.rs | 14 ++-- tests/vdso.rs | 6 +- tests/vfork.rs | 6 +- 120 files changed, 542 insertions(+), 497 deletions(-) diff --git a/reverie-examples/chaos.rs b/reverie-examples/chaos.rs index 4442c50..74ca9d2 100644 --- a/reverie-examples/chaos.rs +++ b/reverie-examples/chaos.rs @@ -6,11 +6,8 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use serde::Deserialize; -use serde::Serialize; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use structopt::StructOpt; use reverie::syscalls::Displayable; use reverie::syscalls::Errno; @@ -21,6 +18,9 @@ use reverie::Guest; use reverie::Pid; use reverie::Tool; use reverie_util::CommonToolArguments; +use serde::Deserialize; +use serde::Serialize; +use structopt::StructOpt; /// A tool to introduce inject "chaos" into a running process. A pathological /// kernel is simulated by forcing reads to only return one byte a time. diff --git a/reverie-examples/chrome-trace/global_state.rs b/reverie-examples/chrome-trace/global_state.rs index 05d9e61..b52b849 100644 --- a/reverie-examples/chrome-trace/global_state.rs +++ b/reverie-examples/chrome-trace/global_state.rs @@ -6,19 +6,18 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use reverie::GlobalTool; -use reverie::Pid; - -use serde::Deserialize; -use serde::Serialize; - -use crate::event::ThreadExit; - use std::io; use std::path::PathBuf; use std::sync::Mutex; use std::time::SystemTime; +use reverie::GlobalTool; +use reverie::Pid; +use serde::Deserialize; +use serde::Serialize; + +use crate::event::ThreadExit; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Program { /// The path to the program. diff --git a/reverie-examples/chrome-trace/main.rs b/reverie-examples/chrome-trace/main.rs index f033c90..9b00394 100644 --- a/reverie-examples/chrome-trace/main.rs +++ b/reverie-examples/chrome-trace/main.rs @@ -14,17 +14,15 @@ mod event; mod global_state; mod tool; -use tool::ChromeTrace; - -use structopt::StructOpt; +use std::fs; +use std::io; +use std::path::PathBuf; use anyhow::Context; use reverie::Error; use reverie_util::CommonToolArguments; - -use std::fs; -use std::io; -use std::path::PathBuf; +use structopt::StructOpt; +use tool::ChromeTrace; /// A tool to render a summary of the process tree. #[derive(Debug, StructOpt)] diff --git a/reverie-examples/chrome-trace/tool.rs b/reverie-examples/chrome-trace/tool.rs index 5e6ca28..2db490c 100644 --- a/reverie-examples/chrome-trace/tool.rs +++ b/reverie-examples/chrome-trace/tool.rs @@ -7,10 +7,10 @@ * LICENSE file in the root directory of this source tree. */ -use crate::event::Event; -use crate::event::Program; -use crate::event::ThreadExit; -use crate::global_state::GlobalState; +use std::borrow::Cow; +use std::fs; +use std::str; +use std::time::SystemTime; use reverie::syscalls::Displayable; use reverie::syscalls::Syscall; @@ -28,10 +28,10 @@ use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::borrow::Cow; -use std::fs; -use std::str; -use std::time::SystemTime; +use crate::event::Event; +use crate::event::Program; +use crate::event::ThreadExit; +use crate::global_state::GlobalState; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ChromeTrace(Pid); diff --git a/reverie-examples/chunky_print.rs b/reverie-examples/chunky_print.rs index 970530a..6102051 100644 --- a/reverie-examples/chunky_print.rs +++ b/reverie-examples/chunky_print.rs @@ -10,6 +10,13 @@ //! This tool will chunk together printed output from each thread, over fixed //! time intervals. +use std::collections::HashMap; +use std::fmt::Write; +use std::io; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; +use std::sync::Mutex; + use reverie::syscalls::Addr; use reverie::syscalls::MemoryAccess; use reverie::syscalls::Syscall; @@ -21,12 +28,6 @@ use reverie::Tool; use reverie_util::CommonToolArguments; use serde::Deserialize; use serde::Serialize; -use std::collections::HashMap; -use std::fmt::Write; -use std::io; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::sync::Mutex; use structopt::StructOpt; use tracing::debug; use tracing::info; diff --git a/reverie-examples/counter1.rs b/reverie-examples/counter1.rs index 2c2a4cd..0a62807 100644 --- a/reverie-examples/counter1.rs +++ b/reverie-examples/counter1.rs @@ -9,6 +9,9 @@ //! An example that counts system calls using a simple, global state. +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; + use reverie::syscalls::Syscall; use reverie::syscalls::SyscallInfo; use reverie::syscalls::Sysno; @@ -20,8 +23,6 @@ use reverie::Tool; use reverie_util::CommonToolArguments; use serde::Deserialize; use serde::Serialize; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; use structopt::StructOpt; #[derive(Debug, Serialize, Deserialize, Default)] diff --git a/reverie-examples/counter2.rs b/reverie-examples/counter2.rs index a07aafc..1bde11d 100644 --- a/reverie-examples/counter2.rs +++ b/reverie-examples/counter2.rs @@ -9,6 +9,10 @@ //! An example that counts system calls using a simple, global state. +use core::sync::atomic::AtomicU64; +use core::sync::atomic::Ordering; +use std::sync::Mutex; + use reverie::syscalls::Syscall; use reverie::syscalls::SyscallInfo; use reverie::Error; @@ -20,13 +24,9 @@ use reverie::Pid; use reverie::Tid; use reverie::Tool; use reverie_util::CommonToolArguments; -use structopt::StructOpt; - -use core::sync::atomic::AtomicU64; -use core::sync::atomic::Ordering; use serde::Deserialize; use serde::Serialize; -use std::sync::Mutex; +use structopt::StructOpt; use tracing::debug; /// Global state for the tool. diff --git a/reverie-examples/strace/config.rs b/reverie-examples/strace/config.rs index cbfcb58..d3cfa15 100644 --- a/reverie-examples/strace/config.rs +++ b/reverie-examples/strace/config.rs @@ -7,11 +7,11 @@ * LICENSE file in the root directory of this source tree. */ -use crate::filter::Filter; - use serde::Deserialize; use serde::Serialize; +use crate::filter::Filter; + #[derive(Clone, Default, Serialize, Deserialize)] pub struct Config { pub filters: Vec, diff --git a/reverie-examples/strace/filter.rs b/reverie-examples/strace/filter.rs index f380e2e..afc889e 100644 --- a/reverie-examples/strace/filter.rs +++ b/reverie-examples/strace/filter.rs @@ -7,7 +7,6 @@ * LICENSE file in the root directory of this source tree. */ use reverie::syscalls::Sysno; - use serde::Deserialize; use serde::Serialize; diff --git a/reverie-examples/strace/main.rs b/reverie-examples/strace/main.rs index 380f385..1fff8d0 100644 --- a/reverie-examples/strace/main.rs +++ b/reverie-examples/strace/main.rs @@ -18,12 +18,10 @@ mod tool; use config::Config; use filter::Filter; -use tool::Strace; - -use structopt::StructOpt; - use reverie::Error; use reverie_util::CommonToolArguments; +use structopt::StructOpt; +use tool::Strace; /// A tool to trace system calls. #[derive(StructOpt, Debug)] diff --git a/reverie-examples/strace/tool.rs b/reverie-examples/strace/tool.rs index 1462616..ea96bc7 100644 --- a/reverie-examples/strace/tool.rs +++ b/reverie-examples/strace/tool.rs @@ -7,9 +7,6 @@ * LICENSE file in the root directory of this source tree. */ -use crate::config::Config; -use crate::global_state::GlobalState; - use reverie::syscalls::Displayable; use reverie::syscalls::Errno; use reverie::syscalls::Syscall; @@ -23,10 +20,12 @@ use reverie::Signal; use reverie::Subscription; use reverie::Tid; use reverie::Tool; - use serde::Deserialize; use serde::Serialize; +use crate::config::Config; +use crate::global_state::GlobalState; + // Strace has no need for process-level state, so this is a unit struct. #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Strace; diff --git a/reverie-process/src/child.rs b/reverie-process/src/child.rs index e3275d2..a2f96c8 100644 --- a/reverie-process/src/child.rs +++ b/reverie-process/src/child.rs @@ -6,8 +6,17 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use super::ExitStatus; -use super::Pid; +use core::fmt; +use core::future::Future; +use core::pin::Pin; +use core::task::Context; +use core::task::Poll; +use std::io; + +use nix::sys::signal::Signal; +use serde::Deserialize; +use serde::Serialize; +use syscalls::Errno; use super::seccomp::SeccompNotif; use super::stdio::ChildStderr; @@ -15,18 +24,8 @@ use super::stdio::ChildStdin; use super::stdio::ChildStdout; use super::stdio::Stdio; use super::Command; - -use core::fmt; -use core::future::Future; -use core::pin::Pin; -use core::task::Context; -use core::task::Poll; - -use nix::sys::signal::Signal; -use serde::Deserialize; -use serde::Serialize; -use std::io; -use syscalls::Errno; +use super::ExitStatus; +use super::Pid; /// Represents a child process. /// diff --git a/reverie-process/src/container.rs b/reverie-process/src/container.rs index 07598d8..56cb0dd 100644 --- a/reverie-process/src/container.rs +++ b/reverie-process/src/container.rs @@ -6,6 +6,22 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ +use std::borrow::Cow; +use std::collections::BTreeMap; +use std::ffi::CString; +use std::ffi::OsStr; +use std::ffi::OsString; +use std::io::Read; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::io::AsRawFd; +use std::path::Path; + +use nix::sched::sched_setaffinity; +use nix::sched::CpuSet; +use serde::de::DeserializeOwned; +use serde::Serialize; +use syscalls::Errno; + use super::clone::clone_with_stack; use super::env::Env; use super::error::AddContext; @@ -26,22 +42,6 @@ use super::stdio::Stdio; use super::util::reset_signal_handling; use super::util::to_cstring; -use nix::sched::sched_setaffinity; -use nix::sched::CpuSet; -use serde::de::DeserializeOwned; -use serde::Serialize; -use syscalls::Errno; - -use std::borrow::Cow; -use std::collections::BTreeMap; -use std::ffi::CString; -use std::ffi::OsStr; -use std::ffi::OsString; -use std::io::Read; -use std::os::unix::ffi::OsStrExt; -use std::os::unix::io::AsRawFd; -use std::path::Path; - /// A `Container` is a configuration of how a process shall be spawned. It can, /// but doesn't have to, include Linux namespace configuration. /// @@ -923,9 +923,10 @@ impl Drop for WaitGuard { #[cfg(test)] mod tests { - use super::*; use nix::sys::signal::Signal; + use super::*; + #[test] fn can_panic() { assert_eq!( @@ -1009,9 +1010,10 @@ mod tests { #[test] pub fn pin_affinity_to_all_cores() -> Result<(), Error> { - use raw_cpuid::CpuId; use std::collections::HashMap; + use raw_cpuid::CpuId; + let cpus = num_cpus::get(); println!("Total cpus {}", cpus); diff --git a/reverie-process/src/exit_status.rs b/reverie-process/src/exit_status.rs index c8a39f6..b2322c6 100644 --- a/reverie-process/src/exit_status.rs +++ b/reverie-process/src/exit_status.rs @@ -150,7 +150,6 @@ impl<'de> serde::Deserialize<'de> for ExitStatus { #[cfg(all(test, not(sanitized)))] mod tests_non_sanitized { - use super::*; use nix::sys::signal; use nix::sys::signal::Signal; use nix::sys::wait::waitpid; @@ -158,6 +157,8 @@ mod tests_non_sanitized { use nix::unistd::fork; use nix::unistd::ForkResult; + use super::*; + // Runs a closure in a forked process and reports the exit status. fn run_forked(f: F) -> nix::Result where diff --git a/reverie-process/src/fd.rs b/reverie-process/src/fd.rs index 64e0f3a..61e1821 100644 --- a/reverie-process/src/fd.rs +++ b/reverie-process/src/fd.rs @@ -7,12 +7,9 @@ * LICENSE file in the root directory of this source tree. */ -use super::util; - use core::pin::Pin; use core::task::Context; use core::task::Poll; - use std::ffi::CStr; use std::ffi::CString; use std::io; @@ -31,6 +28,8 @@ use tokio::io::AsyncWrite; use tokio::io::Interest; use tokio::io::ReadBuf; +use super::util; + #[derive(Debug)] // From `std/src/sys/unix/fd.rs`. Mark `-1` as an invalid file descriptor so it // can be reused to in `Option`. @@ -498,10 +497,12 @@ where #[cfg(test)] mod tests { - use super::*; - use const_cstr::const_cstr; use std::os::unix::ffi::OsStrExt; + use const_cstr::const_cstr; + + use super::*; + #[test] fn test_is_dir() { assert!(is_dir(const_cstr!("/").as_ptr())); diff --git a/reverie-process/src/lib.rs b/reverie-process/src/lib.rs index a0fc1e1..0b166cb 100644 --- a/reverie-process/src/lib.rs +++ b/reverie-process/src/lib.rs @@ -35,6 +35,8 @@ mod spawn; mod stdio; mod util; +use std::ffi::CString; + pub use child::Child; pub use child::Output; pub use container::Container; @@ -47,6 +49,8 @@ pub use mount::Mount; pub use mount::MountFlags; pub use mount::MountParseError; pub use namespace::Namespace; +// Re-export Signal since it is used by `Child::signal`. +pub use nix::sys::signal::Signal; pub use pid::Pid; pub use pty::Pty; pub use pty::PtyChild; @@ -54,12 +58,6 @@ pub use stdio::ChildStderr; pub use stdio::ChildStdin; pub use stdio::ChildStdout; pub use stdio::Stdio; - -// Re-export Signal since it is used by `Child::signal`. -pub use nix::sys::signal::Signal; - -use std::ffi::CString; - use syscalls::Errno; /// A builder for spawning a process. @@ -155,14 +153,14 @@ impl Command { #[cfg(test)] mod tests { - use super::*; - use crate::ExitStatus; - use std::collections::BTreeMap; use std::fs; use std::path::Path; use std::str::from_utf8; + use super::*; + use crate::ExitStatus; + #[tokio::test] async fn spawn() { assert_eq!( @@ -610,9 +608,10 @@ mod tests { #[tokio::test] async fn seccomp() { - use super::seccomp::*; use syscalls::Sysno; + use super::seccomp::*; + let filter = FilterBuilder::new() .default_action(Action::Allow) .syscalls([(Sysno::brk, Action::KillProcess)]) @@ -634,13 +633,15 @@ mod tests { #[tokio::test] async fn seccomp_notify() { - use super::seccomp::*; + use std::collections::HashMap; + use futures::future::select; use futures::future::Either; use futures::stream::TryStreamExt; - use std::collections::HashMap; use syscalls::Sysno; + use super::seccomp::*; + let filter = FilterBuilder::new() .default_action(Action::Notify) .syscalls([ diff --git a/reverie-process/src/mount.rs b/reverie-process/src/mount.rs index 38c029f..ff41d7d 100644 --- a/reverie-process/src/mount.rs +++ b/reverie-process/src/mount.rs @@ -6,25 +6,23 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use super::fd::create_dir_all; -use super::fd::touch_path; -use super::fd::FileType; -use super::util; - use core::convert::Infallible; use core::fmt; use core::ptr; use core::str::FromStr; - use std::collections::HashMap; use std::ffi::CString; use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; use std::path::Path; +pub use nix::mount::MsFlags as MountFlags; use syscalls::Errno; -pub use nix::mount::MsFlags as MountFlags; +use super::fd::create_dir_all; +use super::fd::touch_path; +use super::fd::FileType; +use super::util; /// A mount. #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/reverie-process/src/namespace.rs b/reverie-process/src/namespace.rs index 0f79a20..5c30a79 100644 --- a/reverie-process/src/namespace.rs +++ b/reverie-process/src/namespace.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use std::str::FromStr; + use serde::Deserialize; use serde::Serialize; -use std::str::FromStr; bitflags::bitflags! { /// A namespace that may be unshared with [`Command::unshare`]. diff --git a/reverie-process/src/net.rs b/reverie-process/src/net.rs index 78410a9..2f2bbcf 100644 --- a/reverie-process/src/net.rs +++ b/reverie-process/src/net.rs @@ -7,8 +7,6 @@ * LICENSE file in the root directory of this source tree. */ -use super::fd::Fd; - use std::ffi::CStr; use std::ffi::OsStr; use std::mem::MaybeUninit; @@ -16,6 +14,8 @@ use std::os::unix::io::AsRawFd; use syscalls::Errno; +use super::fd::Fd; + /// Interface name. #[derive(Default, Debug, Copy, Clone, Eq, PartialEq)] #[repr(C)] @@ -193,9 +193,10 @@ impl IfReq { #[cfg(test)] mod tests { - use super::*; use nix::net::if_::InterfaceFlags; + use super::*; + #[test] fn ifname() { assert_eq!(IfName::new("lo"), Ok(IfName::LOOPBACK)); diff --git a/reverie-process/src/pid.rs b/reverie-process/src/pid.rs index 69cff1d..609ebde 100644 --- a/reverie-process/src/pid.rs +++ b/reverie-process/src/pid.rs @@ -8,6 +8,7 @@ */ use core::fmt; use core::hash::Hash; + use serde::Deserialize; use serde::Serialize; diff --git a/reverie-process/src/pty.rs b/reverie-process/src/pty.rs index f4e75f0..62eb28f 100644 --- a/reverie-process/src/pty.rs +++ b/reverie-process/src/pty.rs @@ -6,23 +6,22 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use super::fd::AsyncFd; -use super::fd::Fd; +use core::mem::MaybeUninit; +use core::pin::Pin; +use core::task::Context; +use core::task::Poll; +use std::io; +use std::os::unix::io::AsRawFd; +use std::os::unix::io::IntoRawFd; +use std::os::unix::io::RawFd; use syscalls::Errno; use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::ReadBuf; -use core::mem::MaybeUninit; -use core::pin::Pin; -use core::task::Context; -use core::task::Poll; - -use std::io; -use std::os::unix::io::AsRawFd; -use std::os::unix::io::IntoRawFd; -use std::os::unix::io::RawFd; +use super::fd::AsyncFd; +use super::fd::Fd; /// Represents a pseudo-TTY "master". #[derive(Debug)] diff --git a/reverie-process/src/seccomp/bpf.rs b/reverie-process/src/seccomp/bpf.rs index 3904f0d..af66eb8 100644 --- a/reverie-process/src/seccomp/bpf.rs +++ b/reverie-process/src/seccomp/bpf.rs @@ -9,11 +9,11 @@ #![allow(non_snake_case)] -use crate::fd::Fd; +pub use libc::sock_filter; use syscalls::Errno; use syscalls::Sysno; -pub use libc::sock_filter; +use crate::fd::Fd; // See: /include/uapi/linux/bpf_common.h diff --git a/reverie-process/src/seccomp/mod.rs b/reverie-process/src/seccomp/mod.rs index c90bc0b..c30c497 100644 --- a/reverie-process/src/seccomp/mod.rs +++ b/reverie-process/src/seccomp/mod.rs @@ -74,15 +74,13 @@ mod bpf; #[allow(unused)] mod notif; -use bpf::*; - -use syscalls::Errno; -use syscalls::Sysno; +use std::collections::BTreeMap; pub use bpf::Filter; +use bpf::*; pub use notif::*; - -use std::collections::BTreeMap; +use syscalls::Errno; +use syscalls::Sysno; /// Builder for creating seccomp filters. #[derive(Clone)] diff --git a/reverie-process/src/seccomp/notif.rs b/reverie-process/src/seccomp/notif.rs index ba3a847..1a47b6f 100644 --- a/reverie-process/src/seccomp/notif.rs +++ b/reverie-process/src/seccomp/notif.rs @@ -9,18 +9,18 @@ #![allow(missing_docs)] -use syscalls::Errno; - -use crate::fd::Fd; - use core::pin::Pin; use core::task::Context; use core::task::Poll; use std::io; use std::os::unix::io::AsRawFd; + +use syscalls::Errno; use tokio::io::unix::AsyncFd; use tokio::io::Interest; +use crate::fd::Fd; + /// The format the BPF program executes over. #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[repr(C)] diff --git a/reverie-process/src/spawn.rs b/reverie-process/src/spawn.rs index 90af8d4..fad8816 100644 --- a/reverie-process/src/spawn.rs +++ b/reverie-process/src/spawn.rs @@ -6,7 +6,11 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ +use std::io; +use std::io::Write; + use super::clone::clone; +use super::container::ChildContext; use super::error::Context; use super::error::Error; use super::fd::pipe; @@ -21,11 +25,6 @@ use super::util::SharedValue; use super::Child; use super::Command; -use super::container::ChildContext; - -use std::io; -use std::io::Write; - impl Command { /// Executes the command as a child process, returning a handle to it. /// diff --git a/reverie-process/src/stdio.rs b/reverie-process/src/stdio.rs index 676a936..233f433 100644 --- a/reverie-process/src/stdio.rs +++ b/reverie-process/src/stdio.rs @@ -6,10 +6,6 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use super::fd::pipe; -use super::fd::AsyncFd; -use super::fd::Fd; - use core::pin::Pin; use core::task::Context; use core::task::Poll; @@ -23,6 +19,10 @@ use tokio::io::AsyncRead; use tokio::io::AsyncWrite; use tokio::io::ReadBuf; +use super::fd::pipe; +use super::fd::AsyncFd; +use super::fd::Fd; + /// Describes what to do with a standard I/O stream for a child process when /// passed to the [`stdin`], [`stdout`], and [`stderr`] methods of [`Command`]. /// diff --git a/reverie-ptrace/src/cp/mmap.rs b/reverie-ptrace/src/cp/mmap.rs index 0cdbe64..2fc0d29 100644 --- a/reverie-ptrace/src/cp/mmap.rs +++ b/reverie-ptrace/src/cp/mmap.rs @@ -7,12 +7,13 @@ * LICENSE file in the root directory of this source tree. */ -use super::consts::*; use nix::sys::uio; use nix::sys::uio::IoVec; use nix::sys::uio::RemoteIoVec; use nix::unistd::Pid; +use super::consts::*; + /// generate syscall instructions at injected page /// the page address should be 0x7000_0000 (PRIVATE_PAGE_OFFSET) /// the byte code can be confirmed by running objcopy diff --git a/reverie-ptrace/src/gdbstub/commands/base/_QStartNoAckMode.rs b/reverie-ptrace/src/gdbstub/commands/base/_QStartNoAckMode.rs index e0c5856..dc8fc6d 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_QStartNoAckMode.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_QStartNoAckMode.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct QStartNoAckMode; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_QThreadEvents.rs b/reverie-ptrace/src/gdbstub/commands/base/_QThreadEvents.rs index 4bd30bf..59acc11 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_QThreadEvents.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_QThreadEvents.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct QThreadEvents { diff --git a/reverie-ptrace/src/gdbstub/commands/base/_QuestionMark.rs b/reverie-ptrace/src/gdbstub/commands/base/_QuestionMark.rs index 02a75f6..f5d318f 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_QuestionMark.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_QuestionMark.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct QuestionMark; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_g.rs b/reverie-ptrace/src/gdbstub/commands/base/_g.rs index 3337424..a5bd151 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_g.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_g.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct g; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_g_upper.rs b/reverie-ptrace/src/gdbstub/commands/base/_g_upper.rs index 83299d6..c1238be 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_g_upper.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_g_upper.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct G { diff --git a/reverie-ptrace/src/gdbstub/commands/base/_h_upper.rs b/reverie-ptrace/src/gdbstub/commands/base/_h_upper.rs index 7666a8e..cfc3f15 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_h_upper.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_h_upper.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct H { diff --git a/reverie-ptrace/src/gdbstub/commands/base/_p_upper.rs b/reverie-ptrace/src/gdbstub/commands/base/_p_upper.rs index f94acaf..a61df32 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_p_upper.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_p_upper.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::Bytes; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::Bytes; pub struct P { pub reg_id: usize, diff --git a/reverie-ptrace/src/gdbstub/commands/base/_qAttached.rs b/reverie-ptrace/src/gdbstub/commands/base/_qAttached.rs index 21ee055..058f3f7 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_qAttached.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_qAttached.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct qAttached { diff --git a/reverie-ptrace/src/gdbstub/commands/base/_qC.rs b/reverie-ptrace/src/gdbstub/commands/base/_qC.rs index 591912e..a6ccdfc 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_qC.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_qC.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ -use crate::gdbstub::commands::*; use bytes::BytesMut; +use crate::gdbstub::commands::*; + #[derive(PartialEq, Debug)] pub struct qC {} diff --git a/reverie-ptrace/src/gdbstub/commands/base/_qSupported.rs b/reverie-ptrace/src/gdbstub/commands/base/_qSupported.rs index d273776..5fe7346 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_qSupported.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_qSupported.rs @@ -7,11 +7,12 @@ * LICENSE file in the root directory of this source tree. */ -use crate::gdbstub::commands::*; -use crate::gdbstub::hex::*; use bytes::Bytes; use bytes::BytesMut; +use crate::gdbstub::commands::*; +use crate::gdbstub::hex::*; + #[derive(PartialEq, Debug)] pub struct qSupported { pub features: Bytes, // use Features type here! diff --git a/reverie-ptrace/src/gdbstub/commands/base/_qfThreadInfo.rs b/reverie-ptrace/src/gdbstub/commands/base/_qfThreadInfo.rs index 77690fc..d051851 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_qfThreadInfo.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_qfThreadInfo.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct qfThreadInfo; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_qsThreadInfo.rs b/reverie-ptrace/src/gdbstub/commands/base/_qsThreadInfo.rs index c0c7a99..df7e3ef 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_qsThreadInfo.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_qsThreadInfo.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct qsThreadInfo; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_s.rs b/reverie-ptrace/src/gdbstub/commands/base/_s.rs index d19bdb1..0a99fb7 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_s.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_s.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; pub struct s { pub addr: Option, diff --git a/reverie-ptrace/src/gdbstub/commands/base/_t_upper.rs b/reverie-ptrace/src/gdbstub/commands/base/_t_upper.rs index 86ae7e6..aa1bfba 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_t_upper.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_t_upper.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; pub struct T { pub thread: ThreadId, diff --git a/reverie-ptrace/src/gdbstub/commands/base/_vCont.rs b/reverie-ptrace/src/gdbstub/commands/base/_vCont.rs index 0983cb6..9e1fcf5 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_vCont.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_vCont.rs @@ -8,7 +8,6 @@ */ use bytes::BytesMut; - use nix::sys::signal::Signal; use crate::gdbstub::commands::*; diff --git a/reverie-ptrace/src/gdbstub/commands/base/_vFile.rs b/reverie-ptrace/src/gdbstub/commands/base/_vFile.rs index 4c40ffd..47c5c1e 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_vFile.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_vFile.rs @@ -7,13 +7,12 @@ * LICENSE file in the root directory of this source tree. */ -use bytes::BytesMut; use std::ffi::OsString; use std::os::unix::ffi::OsStringExt; use std::path::PathBuf; +use bytes::BytesMut; use nix::sys::stat::FileStat; - use reverie::Pid; use crate::gdbstub::commands::*; @@ -120,9 +119,10 @@ impl ParseCommand for vFile { #[cfg(test)] mod test { - use super::*; use std::mem; + use super::*; + #[test] fn hostio_stat_size_check() { assert_eq!(mem::size_of::(), 0x40); diff --git a/reverie-ptrace/src/gdbstub/commands/base/_vKill.rs b/reverie-ptrace/src/gdbstub/commands/base/_vKill.rs index 8ca6267..5943a81 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/_vKill.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/_vKill.rs @@ -8,10 +8,10 @@ */ use bytes::BytesMut; +use reverie::Pid; use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use reverie::Pid; #[derive(PartialEq, Debug)] pub struct vKill { diff --git a/reverie-ptrace/src/gdbstub/commands/base/mod.rs b/reverie-ptrace/src/gdbstub/commands/base/mod.rs index 7ed544d..3735db5 100644 --- a/reverie-ptrace/src/gdbstub/commands/base/mod.rs +++ b/reverie-ptrace/src/gdbstub/commands/base/mod.rs @@ -35,6 +35,10 @@ mod _x_upper; mod _z; mod _z_upper; +//pub use _p::*; +//pub use _p_upper::*; +pub use _QStartNoAckMode::*; +pub use _QThreadEvents::*; pub use _QuestionMark::*; //pub use _c::*; pub use _d_upper::*; @@ -44,10 +48,6 @@ pub use _h_upper::*; //pub use _k::*; pub use _m::*; pub use _m_upper::*; -//pub use _p::*; -//pub use _p_upper::*; -pub use _QStartNoAckMode::*; -pub use _QThreadEvents::*; pub use _qAttached::*; pub use _qC::*; pub use _qSupported::*; diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_ExclamationMark.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_ExclamationMark.rs index 64dd0e3..aaf9c93 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_ExclamationMark.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_ExclamationMark.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct ExclamationMark; diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentHexEncoded.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentHexEncoded.rs index 2621bb9..271d1b4 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentHexEncoded.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentHexEncoded.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::Bytes; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::Bytes; pub struct QEnvironmentHexEncoded { pub key: Bytes, diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentUnset.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentUnset.rs index c53a07b..2549081 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentUnset.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QEnvironmentUnset.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::Bytes; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::Bytes; pub struct QEnvironmentUnset { pub key: Bytes, diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QSetWorkingDir.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QSetWorkingDir.rs index 06d4d14..287fdfe 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QSetWorkingDir.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QSetWorkingDir.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::Bytes; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::Bytes; pub struct QSetWorkingDir { pub dir: Option, diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QStartupWithShell.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QStartupWithShell.rs index f5d36e3..067cc63 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_QStartupWithShell.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_QStartupWithShell.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; pub struct QStartupWithShell { pub val: bool, diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_r_upper.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_r_upper.rs index 42878b9..54b7de7 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_r_upper.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_r_upper.rs @@ -7,8 +7,9 @@ * LICENSE file in the root directory of this source tree. */ -use crate::gdbstub::commands::*; -use crate::gdbstub::hex::*; use bytes::BytesMut; +use crate::gdbstub::commands::*; +use crate::gdbstub::hex::*; + pub struct R; diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_vAttach.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_vAttach.rs index 7f8a493..b9fddfe 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_vAttach.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_vAttach.rs @@ -7,11 +7,12 @@ * LICENSE file in the root directory of this source tree. */ -use crate::gdbstub::commands::*; -use crate::gdbstub::hex::*; use bytes::BytesMut; use reverie::Pid; +use crate::gdbstub::commands::*; +use crate::gdbstub::hex::*; + pub struct vAttach { pub pid: Pid, } diff --git a/reverie-ptrace/src/gdbstub/commands/extended_mode/_vRun.rs b/reverie-ptrace/src/gdbstub/commands/extended_mode/_vRun.rs index 3806386..c519a99 100644 --- a/reverie-ptrace/src/gdbstub/commands/extended_mode/_vRun.rs +++ b/reverie-ptrace/src/gdbstub/commands/extended_mode/_vRun.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::Bytes; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::Bytes; pub struct vRun { pub filename: Option, diff --git a/reverie-ptrace/src/gdbstub/commands/mod.rs b/reverie-ptrace/src/gdbstub/commands/mod.rs index 137ef31..0ca682a 100644 --- a/reverie-ptrace/src/gdbstub/commands/mod.rs +++ b/reverie-ptrace/src/gdbstub/commands/mod.rs @@ -33,6 +33,20 @@ #![allow(non_snake_case, non_camel_case_types, dead_code, unused_imports)] +use std::collections::BTreeMap; +use std::path::PathBuf; + +use bytes::Bytes; +use bytes::BytesMut; +use paste::paste; +use reverie::ExitStatus; +use reverie::Pid; +use reverie::Signal; +use thiserror::Error; +use tokio::sync::broadcast; +use tokio::sync::mpsc; +use tokio::sync::oneshot; + use crate::gdbstub::hex::*; use crate::gdbstub::request::*; use crate::gdbstub::response::*; @@ -43,19 +57,6 @@ use crate::gdbstub::ResumeInferior; use crate::gdbstub::StoppedInferior; use crate::trace::ChildOp; use crate::trace::Stopped; -use bytes::Bytes; -use bytes::BytesMut; -use paste::paste; -use std::collections::BTreeMap; -use std::path::PathBuf; -use thiserror::Error; -use tokio::sync::broadcast; -use tokio::sync::mpsc; -use tokio::sync::oneshot; - -use reverie::ExitStatus; -use reverie::Pid; -use reverie::Signal; mod base; mod extended_mode; diff --git a/reverie-ptrace/src/gdbstub/commands/monitor_cmd/_qRcmd.rs b/reverie-ptrace/src/gdbstub/commands/monitor_cmd/_qRcmd.rs index a07978c..c36ef50 100644 --- a/reverie-ptrace/src/gdbstub/commands/monitor_cmd/_qRcmd.rs +++ b/reverie-ptrace/src/gdbstub/commands/monitor_cmd/_qRcmd.rs @@ -7,11 +7,12 @@ * LICENSE file in the root directory of this source tree. */ -use crate::gdbstub::commands::*; -use crate::gdbstub::hex::*; use bytes::Bytes; use bytes::BytesMut; +use crate::gdbstub::commands::*; +use crate::gdbstub::hex::*; + #[derive(PartialEq, Debug)] pub struct qRcmd { pub cmd: Bytes, diff --git a/reverie-ptrace/src/gdbstub/commands/section_offsets/_qOffsets.rs b/reverie-ptrace/src/gdbstub/commands/section_offsets/_qOffsets.rs index 229682a..61c2725 100644 --- a/reverie-ptrace/src/gdbstub/commands/section_offsets/_qOffsets.rs +++ b/reverie-ptrace/src/gdbstub/commands/section_offsets/_qOffsets.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use bytes::BytesMut; + use crate::gdbstub::commands::*; use crate::gdbstub::hex::*; -use bytes::BytesMut; #[derive(PartialEq, Debug)] pub struct qOffsets; diff --git a/reverie-ptrace/src/gdbstub/error.rs b/reverie-ptrace/src/gdbstub/error.rs index e3db026..b0366d0 100644 --- a/reverie-ptrace/src/gdbstub/error.rs +++ b/reverie-ptrace/src/gdbstub/error.rs @@ -7,17 +7,16 @@ * LICENSE file in the root directory of this source tree. */ +use std::io; + +use reverie::Pid; use thiserror::Error; use super::commands::CommandParseError; use super::hex::GdbHexError; use super::packet::PacketParseError; - use crate::trace::Error as TraceError; -use reverie::Pid; -use std::io; - #[derive(Error, Debug)] #[allow(clippy::enum_variant_names)] pub enum Error { diff --git a/reverie-ptrace/src/gdbstub/inferior.rs b/reverie-ptrace/src/gdbstub/inferior.rs index 3ed23ae..e35a93b 100644 --- a/reverie-ptrace/src/gdbstub/inferior.rs +++ b/reverie-ptrace/src/gdbstub/inferior.rs @@ -7,13 +7,13 @@ * LICENSE file in the root directory of this source tree. */ +use reverie::Pid; +use tokio::sync::mpsc; + use super::commands::*; use super::Error; use super::GdbRequest; -use reverie::Pid; -use tokio::sync::mpsc; - /// Thread id and Pid use to uniquely indentify an inferior. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct InferiorThreadId { diff --git a/reverie-ptrace/src/gdbstub/packet.rs b/reverie-ptrace/src/gdbstub/packet.rs index 93498f1..3eaf4cf 100644 --- a/reverie-ptrace/src/gdbstub/packet.rs +++ b/reverie-ptrace/src/gdbstub/packet.rs @@ -31,12 +31,13 @@ * SOFTWARE. */ +use bytes::BytesMut; +use thiserror::Error; + use super::commands::Command; use super::commands::CommandParseError; use super::hex::*; use super::PacketLogger; -use bytes::BytesMut; -use thiserror::Error; /// Packet parse error. #[derive(PartialEq, Debug, Error)] diff --git a/reverie-ptrace/src/gdbstub/regs.rs b/reverie-ptrace/src/gdbstub/regs.rs index 3365557..5401376 100644 --- a/reverie-ptrace/src/gdbstub/regs.rs +++ b/reverie-ptrace/src/gdbstub/regs.rs @@ -7,9 +7,10 @@ * LICENSE file in the root directory of this source tree. */ +use std::fmt; + use serde::Deserialize; use serde::Serialize; -use std::fmt; use super::response::*; @@ -392,9 +393,10 @@ pub struct Amd64ExtraRegs { #[cfg(test)] mod test { - use super::*; use std::mem; + use super::*; + #[test] fn fp80_sanity() { assert_eq!(mem::size_of::(), 10); diff --git a/reverie-ptrace/src/gdbstub/request.rs b/reverie-ptrace/src/gdbstub/request.rs index a718e71..bdef96d 100644 --- a/reverie-ptrace/src/gdbstub/request.rs +++ b/reverie-ptrace/src/gdbstub/request.rs @@ -7,10 +7,11 @@ * LICENSE file in the root directory of this source tree. */ +use tokio::sync::oneshot; + use super::Amd64CoreRegs; use super::Breakpoint; use crate::trace::Error as TraceError; -use tokio::sync::oneshot; /// gdb request send to reverie. #[derive(Debug)] diff --git a/reverie-ptrace/src/gdbstub/response.rs b/reverie-ptrace/src/gdbstub/response.rs index 2decc81..8e9ef5c 100644 --- a/reverie-ptrace/src/gdbstub/response.rs +++ b/reverie-ptrace/src/gdbstub/response.rs @@ -36,7 +36,6 @@ use bytes::Bytes; use bytes::BytesMut; use num_traits::AsPrimitive; use num_traits::PrimInt; - use reverie::Errno; use super::Error; diff --git a/reverie-ptrace/src/gdbstub/server.rs b/reverie-ptrace/src/gdbstub/server.rs index 6ecc279..9e5539d 100644 --- a/reverie-ptrace/src/gdbstub/server.rs +++ b/reverie-ptrace/src/gdbstub/server.rs @@ -7,11 +7,12 @@ * LICENSE file in the root directory of this source tree. */ -use bytes::BytesMut; -use futures::future; use std::io; use std::net::SocketAddr; use std::path::Path; + +use bytes::BytesMut; +use futures::future; use tokio::io::AsyncRead; use tokio::io::AsyncReadExt; use tokio::net::TcpListener; diff --git a/reverie-ptrace/src/gdbstub/session.rs b/reverie-ptrace/src/gdbstub/session.rs index e44b581..f76e21f 100644 --- a/reverie-ptrace/src/gdbstub/session.rs +++ b/reverie-ptrace/src/gdbstub/session.rs @@ -7,6 +7,9 @@ * LICENSE file in the root directory of this source tree. */ +use std::collections::BTreeMap; +use std::sync::Arc; + use bytes::Bytes; use bytes::BytesMut; use futures::future::Future; @@ -20,7 +23,6 @@ use nix::sys::stat::Mode; use nix::sys::uio; use nix::unistd; use reverie::Pid; -use std::sync::Arc; use tokio::io::AsyncWrite; use tokio::io::AsyncWriteExt; use tokio::sync::mpsc; @@ -29,8 +31,6 @@ use tokio::sync::MappedMutexGuard; use tokio::sync::Mutex; use tokio::sync::MutexGuard; -use crate::trace::ChildOp; - use super::commands; use super::commands::*; use super::regs::Amd64CoreRegs; @@ -44,8 +44,7 @@ use super::InferiorThreadId; use super::Packet; use super::ResumeInferior; use super::StoppedInferior; - -use std::collections::BTreeMap; +use crate::trace::ChildOp; type BoxWriter = Box; diff --git a/reverie-ptrace/src/perf.rs b/reverie-ptrace/src/perf.rs index f10f8a6..38434df 100644 --- a/reverie-ptrace/src/perf.rs +++ b/reverie-ptrace/src/perf.rs @@ -23,13 +23,15 @@ //! [`PerfCounter::DISABLE_SAMPLE_PERIOD`] can be used to avoid this for sampling. //! events. -use crate::validation::check_for_pmu_bugs; -use crate::validation::PmuValidationError; use core::ptr::NonNull; +#[allow(unused_imports)] // only used if we have an error +use std::compile_error; + use lazy_static::lazy_static; use nix::sys::signal::Signal; use nix::unistd::sysconf; use nix::unistd::SysconfVar; +pub use perf::perf_event_header; use perf_event_open_sys::bindings as perf; use perf_event_open_sys::ioctls; use reverie::Errno; @@ -37,10 +39,8 @@ use reverie::Tid; use tracing::info; use tracing::warn; -#[allow(unused_imports)] // only used if we have an error -use std::compile_error; - -pub use perf::perf_event_header; +use crate::validation::check_for_pmu_bugs; +use crate::validation::PmuValidationError; lazy_static! { static ref PMU_BUG: Result<(), PmuValidationError> = check_for_pmu_bugs(); @@ -615,9 +615,10 @@ pub fn do_branches(count: u64) { #[cfg(test)] mod test { - use super::*; use nix::unistd::gettid; + use super::*; + #[test] fn trace_self() { ret_without_perf!(); diff --git a/reverie-ptrace/src/stack.rs b/reverie-ptrace/src/stack.rs index e9a3841..c7e4bf4 100644 --- a/reverie-ptrace/src/stack.rs +++ b/reverie-ptrace/src/stack.rs @@ -6,8 +6,9 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use crate::trace::Error as TraceError; -use crate::trace::Stopped; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; +use std::sync::Arc; use reverie::syscalls::Addr; use reverie::syscalls::AddrMut; @@ -15,9 +16,9 @@ use reverie::syscalls::MemoryAccess; use reverie::Errno; use reverie::Pid; use reverie::Stack; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::sync::Arc; + +use crate::trace::Error as TraceError; +use crate::trace::Stopped; // NB: leaf function can use redzone without explicit stack allocation, as // a result it is not safe to just adjust stack pointer. 128B of stack diff --git a/reverie-ptrace/src/task.rs b/reverie-ptrace/src/task.rs index 00c7427..04a7d55 100644 --- a/reverie-ptrace/src/task.rs +++ b/reverie-ptrace/src/task.rs @@ -9,29 +9,17 @@ //! `TracedTask` and its methods. -use crate::children; -use crate::cp; -use crate::error::Error; -use crate::gdbstub::Amd64CoreRegs; -use crate::gdbstub::BreakpointType; -use crate::gdbstub::GdbRequest; -use crate::gdbstub::GdbServer; -use crate::gdbstub::ResumeAction; -use crate::gdbstub::ResumeInferior; -use crate::gdbstub::StopEvent; -use crate::gdbstub::StopReason; -use crate::gdbstub::StoppedInferior; -use crate::stack::GuestStack; -use crate::timer::HandleFailure; -use crate::timer::Timer; -use crate::timer::TimerEventRequest; -use crate::trace::ChildOp; -use crate::trace::Error as TraceError; -use crate::trace::Event; -use crate::trace::Running; -use crate::trace::Stopped; -use crate::trace::Wait; -use crate::vdso; +use std::collections::BTreeMap; +use std::collections::HashMap; +use std::fmt; +use std::ops::DerefMut; +use std::pin::Pin; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; +use std::task::Context; +use std::task::Poll; use async_trait::async_trait; use futures::future; @@ -39,6 +27,7 @@ use futures::future::Either; use futures::future::Future; use futures::future::FutureExt; use futures::future::TryFutureExt; +use libc::user_regs_struct; use nix::sys::mman::ProtFlags; use nix::sys::signal::Signal; use reverie::syscalls::Addr; @@ -65,23 +54,6 @@ use reverie::Symbol; use reverie::Tid; use reverie::TimerSchedule; use reverie::Tool; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::fmt; -use std::ops::DerefMut; -use std::pin::Pin; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::task::Context; -use std::task::Poll; -use tracing::debug; -use tracing::info; -use tracing::trace; -use tracing::warn; - -use libc::user_regs_struct; use tokio::sync::broadcast; use tokio::sync::mpsc; use tokio::sync::oneshot; @@ -89,6 +61,34 @@ use tokio::sync::Mutex; use tokio::sync::Notify; use tokio::task::JoinError; use tokio::task::JoinHandle; +use tracing::debug; +use tracing::info; +use tracing::trace; +use tracing::warn; + +use crate::children; +use crate::cp; +use crate::error::Error; +use crate::gdbstub::Amd64CoreRegs; +use crate::gdbstub::BreakpointType; +use crate::gdbstub::GdbRequest; +use crate::gdbstub::GdbServer; +use crate::gdbstub::ResumeAction; +use crate::gdbstub::ResumeInferior; +use crate::gdbstub::StopEvent; +use crate::gdbstub::StopReason; +use crate::gdbstub::StoppedInferior; +use crate::stack::GuestStack; +use crate::timer::HandleFailure; +use crate::timer::Timer; +use crate::timer::TimerEventRequest; +use crate::trace::ChildOp; +use crate::trace::Error as TraceError; +use crate::trace::Event; +use crate::trace::Running; +use crate::trace::Stopped; +use crate::trace::Wait; +use crate::vdso; #[derive(Debug)] struct Suspended { diff --git a/reverie-ptrace/src/testing.rs b/reverie-ptrace/src/testing.rs index d4af4e8..643497c 100644 --- a/reverie-ptrace/src/testing.rs +++ b/reverie-ptrace/src/testing.rs @@ -9,8 +9,6 @@ //! Utilities that support constructing tests for Reverie Tools. -use crate::spawn_fn_with_config; -use crate::TracerBuilder; use futures::Future; use reverie::process::Command; use reverie::process::Output; @@ -21,6 +19,8 @@ use reverie::GlobalTool; use reverie::Tool; pub use crate::perf::do_branches; +use crate::spawn_fn_with_config; +use crate::TracerBuilder; /// For some tests, its nice to show what was printed. pub fn print_tracee_output(output: &Output) { diff --git a/reverie-ptrace/src/timer.rs b/reverie-ptrace/src/timer.rs index 133f68f..f032b77 100644 --- a/reverie-ptrace/src/timer.rs +++ b/reverie-ptrace/src/timer.rs @@ -30,11 +30,6 @@ //! - before resumption of the guest, //! which _usually_ means immediately after the tool callback returns. -use crate::perf::*; -use crate::trace::Error as TraceError; -use crate::trace::Event as TraceEvent; -use crate::trace::Stopped; -use crate::trace::Wait; use raw_cpuid::CpuId; use reverie::Errno; use reverie::Pid; @@ -44,6 +39,12 @@ use thiserror::Error; use tracing::debug; use tracing::warn; +use crate::perf::*; +use crate::trace::Error as TraceError; +use crate::trace::Event as TraceEvent; +use crate::trace::Stopped; +use crate::trace::Wait; + // This signal is unused, in that the kernel will never send it to a process. const MARKER_SIGNAL: Signal = reverie::PERF_EVENT_SIGNAL; diff --git a/reverie-ptrace/src/trace/memory.rs b/reverie-ptrace/src/trace/memory.rs index bea5373..588ee25 100644 --- a/reverie-ptrace/src/trace/memory.rs +++ b/reverie-ptrace/src/trace/memory.rs @@ -7,12 +7,9 @@ * LICENSE file in the root directory of this source tree. */ use core::mem; - -use nix::sys::ptrace; - use std::io; -use super::Stopped; +use nix::sys::ptrace; use reverie::syscalls::Addr; use reverie::syscalls::AddrMut; use reverie::syscalls::AddrSlice; @@ -20,6 +17,8 @@ use reverie::syscalls::AddrSliceMut; use reverie::syscalls::Errno; use reverie::syscalls::MemoryAccess; +use super::Stopped; + impl Stopped { /// Does a read that is already page-aligned. fn read_aligned(&self, addr: Addr, buf: &mut [u8]) -> Result { @@ -196,10 +195,6 @@ impl MemoryAccess for Stopped { #[cfg(test)] mod test { - use super::*; - - use reverie::Pid; - use std::ffi::CString; use nix::sys::ptrace; @@ -211,6 +206,9 @@ mod test { use nix::unistd::ForkResult; use quickcheck::QuickCheck; use quickcheck_macros::quickcheck; + use reverie::Pid; + + use super::*; // Helper function for spawning a child process in a stopped state. The // value `T` will be in the child's address space allowing us to read or diff --git a/reverie-ptrace/src/trace/mod.rs b/reverie-ptrace/src/trace/mod.rs index c3b9957..ce3def4 100644 --- a/reverie-ptrace/src/trace/mod.rs +++ b/reverie-ptrace/src/trace/mod.rs @@ -19,19 +19,17 @@ use std::mem; use std::ptr; use nix::sys::ptrace; -use nix::sys::wait::WaitPidFlag; -use nix::sys::wait::WaitStatus; -use thiserror::Error; - -pub use reverie::Errno; -pub use reverie::ExitStatus; -pub use reverie::Pid; -use waitid::waitid; -use waitid::IdType; - // Re-exports so that nothing else needs to depend on `nix`. pub use nix::sys::ptrace::Options; pub use nix::sys::signal::Signal; +use nix::sys::wait::WaitPidFlag; +use nix::sys::wait::WaitStatus; +pub use reverie::Errno; +pub use reverie::ExitStatus; +pub use reverie::Pid; +use thiserror::Error; +use waitid::waitid; +use waitid::IdType; /// An error that occurred during tracing. #[derive(Error, Debug, Eq, PartialEq)] @@ -967,16 +965,16 @@ pub fn traceme_and_stop() -> Result<(), Errno> { /// These tests are meant to test this API but also to show how ptrace works. #[cfg(test)] mod test { - use super::*; + use std::io; + use std::mem; + use std::thread; use nix::sys::signal; use nix::sys::signal::Signal; use nix::unistd::fork; use nix::unistd::ForkResult; - use std::io; - use std::mem; - use std::thread; + use super::*; // Traces a closure in a forked process. The forked process starts in a // stopped state so that ptrace options may be set. diff --git a/reverie-ptrace/src/trace/notifier.rs b/reverie-ptrace/src/trace/notifier.rs index ac30dad..31cd6a5 100644 --- a/reverie-ptrace/src/trace/notifier.rs +++ b/reverie-ptrace/src/trace/notifier.rs @@ -357,11 +357,12 @@ impl Future for ExitFuture { #[cfg(test)] mod test { - use super::*; use nix::sys::signal::Signal; use nix::sys::wait::WaitStatus; use nix::unistd::Pid; + use super::*; + #[test] fn exit_event_code() { assert_eq!( diff --git a/reverie-ptrace/src/trace/waitid.rs b/reverie-ptrace/src/trace/waitid.rs index 26f2217..00cab26 100644 --- a/reverie-ptrace/src/trace/waitid.rs +++ b/reverie-ptrace/src/trace/waitid.rs @@ -14,14 +14,15 @@ //! `WCONTINUED`, `WNOHANG` and `WNOWAIT`. see `waitid(2)` for more details. //! NB: `waitid` here provide a similar interface as `nix`'s `waitpid`. -use super::Errno; +use std::mem::MaybeUninit; +use std::os::unix::io::RawFd; + use nix::sys::signal::Signal; use nix::sys::wait::WaitPidFlag; use nix::sys::wait::WaitStatus; use nix::unistd::Pid; -use std::mem::MaybeUninit; -use std::os::unix::io::RawFd; +use super::Errno; #[derive(Clone, Copy, PartialEq, Eq)] pub enum IdType { @@ -146,12 +147,13 @@ pub fn waitid(waitid_type: IdType, flags: WaitPidFlag) -> Result for StatxBuf { #[cfg(test)] mod tests { - use super::*; use core::mem::align_of; use core::mem::size_of; + use super::*; + #[test] fn sizes() { assert_eq!(size_of::(), size_of::()); diff --git a/reverie-syscalls/src/display.rs b/reverie-syscalls/src/display.rs index b9a7487..7050703 100644 --- a/reverie-syscalls/src/display.rs +++ b/reverie-syscalls/src/display.rs @@ -8,11 +8,6 @@ */ use core::fmt; -use crate::memory::Addr; -use crate::memory::AddrMut; -use crate::memory::MemoryAccess; -use crate::Errno; - use nix::fcntl::AtFlags; use nix::fcntl::OFlag; use nix::sched::CloneFlags; @@ -31,6 +26,11 @@ use nix::sys::timerfd::TimerFlags; use nix::sys::wait::WaitPidFlag; use nix::unistd::Pid; +use crate::memory::Addr; +use crate::memory::AddrMut; +use crate::memory::MemoryAccess; +use crate::Errno; + /// A wrapper that combines an address space and a syscall. This is useful for /// displaying the contents of syscall pointer inputs. pub struct Display<'a, M, T> { diff --git a/reverie-syscalls/src/lib.rs b/reverie-syscalls/src/lib.rs index abe9c86..dc3579d 100644 --- a/reverie-syscalls/src/lib.rs +++ b/reverie-syscalls/src/lib.rs @@ -27,13 +27,13 @@ mod memory; mod raw; mod syscalls; +// Re-export the only things that might be needed from the syscalls crate +pub use ::syscalls::Errno; +pub use ::syscalls::SyscallArgs; +pub use ::syscalls::Sysno; + pub use crate::args::*; pub use crate::display::*; pub use crate::memory::*; pub use crate::raw::*; pub use crate::syscalls::*; - -// Re-export the only things that might be needed from the syscalls crate -pub use ::syscalls::Errno; -pub use ::syscalls::SyscallArgs; -pub use ::syscalls::Sysno; diff --git a/reverie-syscalls/src/memory/addr.rs b/reverie-syscalls/src/memory/addr.rs index c4d469b..35e3c23 100644 --- a/reverie-syscalls/src/memory/addr.rs +++ b/reverie-syscalls/src/memory/addr.rs @@ -9,7 +9,6 @@ use core::fmt; use core::marker::PhantomData; use core::ptr::NonNull; - // Only used for `IoSlice`. To be fully no_std, this should get replaced with a // custom `IoSlice` type. use std::io; @@ -438,10 +437,11 @@ fn next_page(addr: usize) -> usize { #[cfg(test)] mod test { - use super::*; use core::mem::align_of; use core::mem::size_of; + use super::*; + #[test] fn test_next_page() { assert_eq!(next_page(0x1000), 0x2000); diff --git a/reverie-syscalls/src/memory/mod.rs b/reverie-syscalls/src/memory/mod.rs index cf0735a..d5eb63d 100644 --- a/reverie-syscalls/src/memory/mod.rs +++ b/reverie-syscalls/src/memory/mod.rs @@ -10,7 +10,6 @@ mod addr; mod local; use core::mem; - use std::ffi::CString; use std::io; diff --git a/reverie-syscalls/src/raw.rs b/reverie-syscalls/src/raw.rs index f1a01d0..3af4ca3 100644 --- a/reverie-syscalls/src/raw.rs +++ b/reverie-syscalls/src/raw.rs @@ -190,9 +190,10 @@ where #[cfg(test)] mod test { - use super::*; use nix::unistd::Pid; + use super::*; + #[test] fn test_results() { assert_eq!( diff --git a/reverie-syscalls/src/syscalls/family.rs b/reverie-syscalls/src/syscalls/family.rs index 2f599c7..0a173f5 100644 --- a/reverie-syscalls/src/syscalls/family.rs +++ b/reverie-syscalls/src/syscalls/family.rs @@ -11,8 +11,9 @@ //! "families"). These are useful when needing to handle families in very similar //! ways. -use super::Syscall; +use derive_more::From; +use super::Syscall; use crate::args::ClockId; use crate::args::CloneFlags; use crate::args::StatPtr; @@ -21,8 +22,6 @@ use crate::memory::Addr; use crate::memory::AddrMut; use crate::memory::MemoryAccess; -use derive_more::From; - /// Represents the `[p]write{64,v,v2}` family of syscalls. All of these syscalls /// have an associated file descriptor. #[derive(From, Debug, Copy, Clone, Eq, PartialEq)] diff --git a/reverie-syscalls/src/syscalls/mod.rs b/reverie-syscalls/src/syscalls/mod.rs index 441bb94..2ef32df 100644 --- a/reverie-syscalls/src/syscalls/mod.rs +++ b/reverie-syscalls/src/syscalls/mod.rs @@ -9,6 +9,25 @@ pub mod family; +use ::syscalls::SyscallArgs; +use ::syscalls::Sysno; +// Re-export flags that used by syscalls from the `nix` crate so downstream +// projects don't need to add another dependency on it. +pub use nix::fcntl::AtFlags; +pub use nix::fcntl::OFlag; +// FIXME: Switch everything over to `crate::args::CloneFlags`. +use nix::sched::CloneFlags; +pub use nix::sys::epoll::EpollCreateFlags; +pub use nix::sys::eventfd::EfdFlags; +pub use nix::sys::inotify::InitFlags; +pub use nix::sys::mman::MapFlags; +pub use nix::sys::mman::ProtFlags; +pub use nix::sys::signalfd::SfdFlags; +pub use nix::sys::socket::SockFlag; +pub use nix::sys::stat::Mode; +pub use nix::sys::timerfd::TimerFlags; +pub use nix::sys::wait::WaitPidFlag; + use crate::args::ioctl; use crate::args::ArchPrctlCmd; use crate::args::CArrayPtr; @@ -29,26 +48,6 @@ use crate::display::Displayable; use crate::memory::Addr; use crate::memory::AddrMut; use crate::raw::FromToRaw; -use ::syscalls::SyscallArgs; -use ::syscalls::Sysno; - -// FIXME: Switch everything over to `crate::args::CloneFlags`. -use nix::sched::CloneFlags; - -// Re-export flags that used by syscalls from the `nix` crate so downstream -// projects don't need to add another dependency on it. -pub use nix::fcntl::AtFlags; -pub use nix::fcntl::OFlag; -pub use nix::sys::epoll::EpollCreateFlags; -pub use nix::sys::eventfd::EfdFlags; -pub use nix::sys::inotify::InitFlags; -pub use nix::sys::mman::MapFlags; -pub use nix::sys::mman::ProtFlags; -pub use nix::sys::signalfd::SfdFlags; -pub use nix::sys::socket::SockFlag; -pub use nix::sys::stat::Mode; -pub use nix::sys::timerfd::TimerFlags; -pub use nix::sys::wait::WaitPidFlag; /// A trait that all syscalls implement. pub trait SyscallInfo: Displayable + Copy + Send { @@ -3284,17 +3283,17 @@ typed_syscall! { #[cfg(test)] mod test { - use super::*; - use crate::Displayable; - use crate::LocalMemory; - use crate::ReadAddr; - use std::ffi::CString; use std::path::Path; use syscalls::SyscallArgs; use syscalls::Sysno; + use super::*; + use crate::Displayable; + use crate::LocalMemory; + use crate::ReadAddr; + #[test] fn test_syscall_open() { assert_eq!(Open::NAME, "open"); diff --git a/reverie-util/src/commandline.rs b/reverie-util/src/commandline.rs index f5408b7..0617ac6 100644 --- a/reverie-util/src/commandline.rs +++ b/reverie-util/src/commandline.rs @@ -11,7 +11,6 @@ //! Each tool with this backend is a standalone executable, and thus //! needs its own CLI. -use chrono::Local; use std::error::Error; use std::ffi::OsStr; use std::fmt::Display; @@ -19,13 +18,14 @@ use std::io; use std::path::Path; use std::path::PathBuf; use std::str::FromStr; + +use chrono::Local; +use reverie::process::Command; use structopt::StructOpt; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::fmt::MakeWriter; use tracing_subscriber::EnvFilter; -use reverie::process::Command; - /// Parses an environment variable command-line argument. pub fn parse_env(s: &str) -> Result<(T, U), Box> where diff --git a/reverie-util/src/pedigree.rs b/reverie-util/src/pedigree.rs index 69d26b4..af98288 100644 --- a/reverie-util/src/pedigree.rs +++ b/reverie-util/src/pedigree.rs @@ -9,6 +9,9 @@ //! An example that tracks thread pedigree using local state. +use std::io; +use std::mem; + use bitvec::bitvec; use bitvec::order::Msb0; use bitvec::vec::BitVec; @@ -16,8 +19,6 @@ use libc::pid_t; use nix::unistd::Pid; use serde::Deserialize; use serde::Serialize; -use std::io; -use std::mem; /// Helper function that finds the longest run of repeating bits in a bitvec fn longest_run(sequence: &BitVec) -> (usize, usize) { diff --git a/reverie/src/auxv.rs b/reverie/src/auxv.rs index 756d455..8ce654b 100644 --- a/reverie/src/auxv.rs +++ b/reverie/src/auxv.rs @@ -6,15 +6,15 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use crate::syscalls::Addr; -use crate::Pid; +use std::collections::BTreeMap; +use std::fs; +use std::io; use byteorder::NativeEndian; use byteorder::ReadBytesExt; -use std::collections::BTreeMap; -use std::fs; -use std::io; +use crate::syscalls::Addr; +use crate::Pid; /// Represents the auxv table of a process. /// diff --git a/reverie/src/backtrace/library.rs b/reverie/src/backtrace/library.rs index f81b11d..39ce35a 100644 --- a/reverie/src/backtrace/library.rs +++ b/reverie/src/backtrace/library.rs @@ -6,10 +6,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use super::Pid; - use std::path::PathBuf; +use super::Pid; + /// A segment of a memory map for a loaded library. #[derive(Debug, Copy, Clone)] pub struct LibrarySegment { @@ -59,9 +59,10 @@ pub struct Libraries { impl Libraries { /// Loads the list of libraries that have been mapped by the given process. pub fn new(pid: Pid) -> Result { - use procfs::process::MMapPath; use std::collections::BTreeMap; + use procfs::process::MMapPath; + let process = procfs::process::Process::new(pid.as_raw())?; let maps = process.maps()?; diff --git a/reverie/src/backtrace/mod.rs b/reverie/src/backtrace/mod.rs index ec874dd..bf704fc 100644 --- a/reverie/src/backtrace/mod.rs +++ b/reverie/src/backtrace/mod.rs @@ -11,18 +11,18 @@ mod library; mod symbols; use core::fmt; -use serde::Deserialize; -use serde::Serialize; use std::borrow::Cow; use std::fs::File; use std::io; use std::io::Read; use std::path::PathBuf; -use super::Pid; +use serde::Deserialize; +use serde::Serialize; use self::cache::cache; use self::library::Libraries; +use super::Pid; /// A backtrace is a list of stack frames. These stack frames may have originated /// from a remote process. diff --git a/reverie/src/error.rs b/reverie/src/error.rs index 27bd5a5..123372c 100644 --- a/reverie/src/error.rs +++ b/reverie/src/error.rs @@ -9,9 +9,8 @@ //! Error handling. -use thiserror::Error; - pub use reverie_syscalls::Errno; +use thiserror::Error; /// A general error. #[derive(Error, Debug)] diff --git a/reverie/src/lib.rs b/reverie/src/lib.rs index 0d81f21..db1da4b 100644 --- a/reverie/src/lib.rs +++ b/reverie/src/lib.rs @@ -31,17 +31,15 @@ pub use auxv::*; pub use backtrace::*; pub use error::*; pub use guest::*; +pub use process::ExitStatus; +pub use process::Pid; pub use rdtsc::*; +pub use reverie_process as process; pub use stack::*; pub use subscription::*; pub use timer::*; pub use tool::*; -pub use reverie_process as process; - -pub use process::ExitStatus; -pub use process::Pid; - /// The identifier for a specific thread, corresponding to the output of gettid. /// In many cases, Linux blurs the Pid/Tid distinction, but Reverie should /// consistently use TIDs when referring to threads, and Pids when referring to @@ -51,24 +49,20 @@ pub use process::Pid; /// is deprecated. `Tid` may be a distinct newtype in the future. pub type Tid = Pid; -/// typed syscalls. -pub use reverie_syscalls as syscalls; - -/// CPUID result. -pub use raw_cpuid::CpuIdResult; - -// Reexport nix Signal type. -pub use nix::sys::signal::Signal; - /// Required for `impl Tool for MyTool` blocks. /// /// NOTE: This is just an alias for `async_trait` for now, but may be extended in /// the future to do more things (like derive syscall subscriptions). pub use async_trait::async_trait as tool; - /// Required for `impl GlobalTool for MyGlobalTool` blocks. /// /// NOTE: This is just an alias for `async_trait` for now, but may be extended in /// the future to do more things (like deriving Request/Response types from /// method names). pub use async_trait::async_trait as global_tool; +// Reexport nix Signal type. +pub use nix::sys::signal::Signal; +/// CPUID result. +pub use raw_cpuid::CpuIdResult; +/// typed syscalls. +pub use reverie_syscalls as syscalls; diff --git a/reverie/src/rdtsc.rs b/reverie/src/rdtsc.rs index 9ff907d..cf69bba 100644 --- a/reverie/src/rdtsc.rs +++ b/reverie/src/rdtsc.rs @@ -12,6 +12,7 @@ use core::arch::x86_64::__rdtscp; use core::arch::x86_64::_rdtsc; use core::mem::MaybeUninit; + use serde::Deserialize; use serde::Serialize; diff --git a/reverie/src/subscription.rs b/reverie/src/subscription.rs index 56df68a..1369aa0 100644 --- a/reverie/src/subscription.rs +++ b/reverie/src/subscription.rs @@ -6,9 +6,8 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -use reverie_syscalls::Sysno; - use bitflags::bitflags; +use reverie_syscalls::Sysno; use syscalls::SysnoSet; bitflags! { diff --git a/reverie/src/tool.rs b/reverie/src/tool.rs index 42b97ec..37e7b59 100644 --- a/reverie/src/tool.rs +++ b/reverie/src/tool.rs @@ -13,6 +13,13 @@ //! thread) instrumentation, though in some backends these will execute in the //! same process. +use async_trait::async_trait; +use raw_cpuid::cpuid; +use raw_cpuid::CpuIdResult; +use reverie_syscalls::Syscall; +use serde::de::DeserializeOwned; +use serde::Serialize; + use crate::error::Errno; use crate::error::Error; use crate::guest::Guest; @@ -23,12 +30,6 @@ use crate::Pid; use crate::Signal; use crate::Subscription; use crate::Tid; -use async_trait::async_trait; -use raw_cpuid::cpuid; -use raw_cpuid::CpuIdResult; -use reverie_syscalls::Syscall; -use serde::de::DeserializeOwned; -use serde::Serialize; /// The global half of a complete Reverie tool. /// diff --git a/tests/backtrace.rs b/tests/backtrace.rs index 3403d70..c7d42d3 100644 --- a/tests/backtrace.rs +++ b/tests/backtrace.rs @@ -16,7 +16,6 @@ use reverie::Error; use reverie::ExitStatus; use reverie::Guest; use reverie::Tool; - use serde::Deserialize; use serde::Serialize; diff --git a/tests/basics.rs b/tests/basics.rs index abd7cbb..9080cd5 100644 --- a/tests/basics.rs +++ b/tests/basics.rs @@ -10,6 +10,13 @@ //! Basic tests that don't fall into some other category. +#[allow(unused_imports)] +use std::ffi::CString; +#[allow(unused_imports)] +use std::io::Write; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; + #[allow(unused_imports)] use nix::sys::wait; #[allow(unused_imports)] @@ -35,12 +42,6 @@ use reverie_ptrace::testing::test_cmd; use reverie_ptrace::testing::test_fn; use serde::Deserialize; use serde::Serialize; -#[allow(unused_imports)] -use std::ffi::CString; -#[allow(unused_imports)] -use std::io::Write; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; #[derive(Debug, serde::Serialize, serde::Deserialize, Default)] struct NoopTool; @@ -182,11 +183,12 @@ fn run_guest_func_print_test() { #[cfg(not(sanitized))] #[test] fn orphans() { - use nix::unistd::fork; - use nix::unistd::ForkResult; use std::thread; use std::time::Duration; + use nix::unistd::fork; + use nix::unistd::ForkResult; + let (output, _state) = test_fn::(|| { // Spawn a child process and make sure the parent exits before the child // process. diff --git a/tests/busywait.rs b/tests/busywait.rs index 805c2a4..97f3f5d 100644 --- a/tests/busywait.rs +++ b/tests/busywait.rs @@ -14,6 +14,10 @@ //! This verifies that timer events, if requested, are delivered during busywaits and are not delivered //! if not requested. +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; + use raw_cpuid::cpuid; use reverie::syscalls::Syscall; use reverie::CpuIdResult; @@ -32,9 +36,6 @@ use reverie::TimerSchedule; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; #[derive(Debug, Serialize, Deserialize, Default)] struct GlobalState { @@ -188,12 +189,13 @@ fn do_marker_syscall() { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; + use std::time::Duration; + use std::time::Instant; + use reverie_ptrace::testing::check_fn_with_config; use reverie_ptrace::testing::do_branches; - use std::time::Duration; - use std::time::Instant; + use super::*; #[test] fn guest_busywait_no_timer() { diff --git a/tests/convert.rs b/tests/convert.rs index 078181d..7ad6913 100644 --- a/tests/convert.rs +++ b/tests/convert.rs @@ -60,10 +60,11 @@ impl Tool for LocalStateInject { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; use nix::unistd; use reverie_ptrace::testing::check_fn; + use super::*; + #[cfg(target_arch = "x86_64")] #[cfg(not(feature = "llvm_asm"))] #[allow(unused_mut)] diff --git a/tests/cpuid.rs b/tests/cpuid.rs index 1957114..40bdbca 100644 --- a/tests/cpuid.rs +++ b/tests/cpuid.rs @@ -10,16 +10,14 @@ //! Tests cpuid interception use raw_cpuid::CpuIdResult; - -use serde::Deserialize; -use serde::Serialize; - use reverie::Errno; use reverie::GlobalTool; use reverie::Guest; use reverie::Pid; use reverie::Subscription; use reverie::Tool; +use serde::Deserialize; +use serde::Serialize; #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct GlobalState { @@ -137,10 +135,10 @@ fn cpuid_leaf_count() { #[cfg(not(sanitized))] #[cfg(test)] mod tests { - use super::*; - use reverie_ptrace::testing::check_fn; + use super::*; + #[test] fn run_guest_func_cpuid_intercepted_test() { check_fn::(|| { diff --git a/tests/delay_signal.rs b/tests/delay_signal.rs index ac5590a..d399d52 100644 --- a/tests/delay_signal.rs +++ b/tests/delay_signal.rs @@ -139,16 +139,18 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use reverie::ExitStatus; - use reverie_ptrace::testing::check_fn; - use reverie_ptrace::testing::test_fn; use std::io; use std::mem::MaybeUninit; use std::sync::mpsc; use std::thread; use std::time; + use reverie::ExitStatus; + use reverie_ptrace::testing::check_fn; + use reverie_ptrace::testing::test_fn; + + use super::*; + // kernel_sigset_t used by naked syscall #[derive(Clone, Copy, PartialEq, Eq, Debug)] struct KernelSigset(u64); diff --git a/tests/exit.rs b/tests/exit.rs index be927ce..2013cf2 100644 --- a/tests/exit.rs +++ b/tests/exit.rs @@ -9,6 +9,8 @@ //! Tests surrounding exit logic. +use std::sync::Mutex; + use reverie::syscalls; use reverie::syscalls::Syscall; use reverie::syscalls::SyscallInfo; @@ -22,7 +24,6 @@ use reverie::Pid; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::sync::Mutex; #[derive(Debug, Serialize, Deserialize, Default)] struct GlobalState { diff --git a/tests/gdbserver-integration/gdbserver-helper/src/main.rs b/tests/gdbserver-integration/gdbserver-helper/src/main.rs index c45c4fe..8885f18 100644 --- a/tests/gdbserver-integration/gdbserver-helper/src/main.rs +++ b/tests/gdbserver-integration/gdbserver-helper/src/main.rs @@ -7,14 +7,6 @@ * LICENSE file in the root directory of this source tree. */ -use anyhow::bail; -use anyhow::Error; -use futures::future; -use structopt::StructOpt; -use tempfile::TempDir; - -use reverie::process::Output; - use std::fs; use std::io; use std::io::BufRead; @@ -23,6 +15,13 @@ use std::path::Path; use std::path::PathBuf; use std::process::ExitStatus; +use anyhow::bail; +use anyhow::Error; +use futures::future; +use reverie::process::Output; +use structopt::StructOpt; +use tempfile::TempDir; + mod client; mod server; diff --git a/tests/gdbserver-integration/gdbserver-helper/src/server.rs b/tests/gdbserver-integration/gdbserver-helper/src/server.rs index 8a0563d..e22de7a 100644 --- a/tests/gdbserver-integration/gdbserver-helper/src/server.rs +++ b/tests/gdbserver-integration/gdbserver-helper/src/server.rs @@ -7,6 +7,8 @@ * LICENSE file in the root directory of this source tree. */ +use std::path::PathBuf; + use anyhow::Error; use reverie::process::Command; use reverie::process::Mount; @@ -18,7 +20,6 @@ use reverie::Tool; use reverie_ptrace::GdbConnection; use serde::Deserialize; use serde::Serialize; -use std::path::PathBuf; pub struct GdbServerCommand { // NB: ideally we could also attach to a existing pid, but this is not diff --git a/tests/rdtsc.rs b/tests/rdtsc.rs index db53df7..9d28aac 100644 --- a/tests/rdtsc.rs +++ b/tests/rdtsc.rs @@ -7,6 +7,9 @@ * LICENSE file in the root directory of this source tree. */ +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; + use reverie::Errno; use reverie::GlobalTool; use reverie::Guest; @@ -17,8 +20,6 @@ use reverie::Tid; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; #[derive(Debug, Serialize, Deserialize, Default)] struct GlobalState { @@ -78,9 +79,10 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; use reverie_ptrace::testing::check_fn; + use super::*; + #[allow(unused_mut)] #[inline(never)] unsafe fn rdtscp() -> (u64, u32) { diff --git a/tests/signal.rs b/tests/signal.rs index 93a8fbb..f51a48d 100644 --- a/tests/signal.rs +++ b/tests/signal.rs @@ -65,12 +65,14 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use nix::sys::signal; - use reverie_ptrace::testing::check_fn; use std::io; use std::mem::MaybeUninit; + use nix::sys::signal; + use reverie_ptrace::testing::check_fn; + + use super::*; + // kernel_sigset_t used by naked syscall #[derive(Clone, Copy, PartialEq, Eq, Debug)] struct KernelSigset(u64); diff --git a/tests/signalfd.rs b/tests/signalfd.rs index 2b4a3e2..3b382f8 100644 --- a/tests/signalfd.rs +++ b/tests/signalfd.rs @@ -50,9 +50,6 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use nix::sys::signal::Signal; - use reverie_ptrace::testing::check_fn; use std::fs::File; use std::io; use std::io::Read; @@ -60,6 +57,11 @@ mod tests { use std::mem::MaybeUninit; use std::os::unix::io::FromRawFd; + use nix::sys::signal::Signal; + use reverie_ptrace::testing::check_fn; + + use super::*; + // kernel_sigset_t used by naked syscall #[derive(Clone, Copy, PartialEq, Eq, Debug)] struct KernelSigset(u64); diff --git a/tests/spinlock.rs b/tests/spinlock.rs index 41f587f..27fb211 100644 --- a/tests/spinlock.rs +++ b/tests/spinlock.rs @@ -19,14 +19,16 @@ impl Tool for LocalState {} #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use reverie_ptrace::testing::check_fn; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; use std::time; + use reverie_ptrace::testing::check_fn; + + use super::*; + #[test] fn run_guest_spinlock_test() { check_fn::(move || { diff --git a/tests/stack.rs b/tests/stack.rs index 3c586b4..edba39e 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -9,9 +9,6 @@ //! Tests for process and thread state. -use serde::Deserialize; -use serde::Serialize; - use reverie::syscalls::Addr; use reverie::syscalls::AddrMut; use reverie::syscalls::ExitGroup; @@ -26,6 +23,8 @@ use reverie::Error; use reverie::Guest; use reverie::Stack; use reverie::Tool; +use serde::Deserialize; +use serde::Serialize; #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct LocalState; @@ -169,9 +168,10 @@ impl Tool for LocalState3 { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; use reverie_ptrace::testing::check_fn; + use super::*; + #[test] fn stack_allocator_should_work() { check_fn::(|| { diff --git a/tests/standalone/at_random.rs b/tests/standalone/at_random.rs index dccb199..d153894 100644 --- a/tests/standalone/at_random.rs +++ b/tests/standalone/at_random.rs @@ -6,6 +6,8 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ +use std::env; + use reverie::syscalls::MemoryAccess; use reverie::Errno; use reverie::Error; @@ -14,7 +16,6 @@ use reverie::Guest; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::env; #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct TestTool {} diff --git a/tests/standalone/inject_then_tail_inject.rs b/tests/standalone/inject_then_tail_inject.rs index 0b19025..9da3626 100644 --- a/tests/standalone/inject_then_tail_inject.rs +++ b/tests/standalone/inject_then_tail_inject.rs @@ -6,6 +6,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ +use std::alloc; +use std::env; +use std::mem; + use nix::unistd; use reverie::syscalls::Displayable; use reverie::syscalls::MemoryAccess; @@ -18,9 +22,6 @@ use reverie::Pid; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::alloc; -use std::env; -use std::mem; use tracing::warn; #[derive(Debug, Serialize, Deserialize, Default, Clone)] diff --git a/tests/standalone/parallel_tasks.rs b/tests/standalone/parallel_tasks.rs index c22dd65..06c0f35 100644 --- a/tests/standalone/parallel_tasks.rs +++ b/tests/standalone/parallel_tasks.rs @@ -8,16 +8,17 @@ */ #![feature(get_mut_unchecked)] #![feature(thread_id_value)] -use reverie::Error; -use reverie::Tool; -use serde::Deserialize; -use serde::Serialize; use std::env; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; +use reverie::Error; +use reverie::Tool; +use serde::Deserialize; +use serde::Serialize; + #[derive(Debug, Serialize, Deserialize, Default, Clone)] struct TestTool {} diff --git a/tests/stat.rs b/tests/stat.rs index fd6da11..b189aa0 100644 --- a/tests/stat.rs +++ b/tests/stat.rs @@ -49,10 +49,12 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use reverie_ptrace::testing::check_fn; use std::mem::MaybeUninit; + use reverie_ptrace::testing::check_fn; + + use super::*; + #[test] fn stat_can_be_reinjected() { check_fn::(|| { diff --git a/tests/state.rs b/tests/state.rs index 78dcd01..4a51808 100644 --- a/tests/state.rs +++ b/tests/state.rs @@ -13,9 +13,6 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Mutex; -use serde::Deserialize; -use serde::Serialize; - use reverie::syscalls::Syscall; use reverie::Error; use reverie::ExitStatus; @@ -24,6 +21,8 @@ use reverie::GlobalTool; use reverie::Guest; use reverie::Pid; use reverie::Tool; +use serde::Deserialize; +use serde::Serialize; #[derive(Debug, Serialize, Deserialize, Default)] struct GlobalState { diff --git a/tests/timer_semantics.rs b/tests/timer_semantics.rs index d8ded6d..9e3fe0e 100644 --- a/tests/timer_semantics.rs +++ b/tests/timer_semantics.rs @@ -16,6 +16,9 @@ use core::arch::x86_64::__cpuid; use core::arch::x86_64::__rdtscp; use core::arch::x86_64::_rdtsc; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; + use reverie::syscalls::Getpid; use reverie::syscalls::Gettid; use reverie::syscalls::Syscall; @@ -33,8 +36,6 @@ use reverie::TimerSchedule; use reverie::Tool; use serde::Deserialize; use serde::Serialize; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; #[derive(Debug, Serialize, Deserialize, Default)] struct GlobalState { @@ -329,12 +330,13 @@ mod timer_tests { //! into the tracee, otherwise underflow or overflow checks will break the //! tests. - use super::*; use reverie_ptrace::ret_without_perf; use reverie_ptrace::testing::check_fn_with_config; use reverie_ptrace::testing::do_branches; use test_case::test_case; + use super::*; + #[test_case(MANY_RCBS, sched_precise)] #[test_case(MANY_RCBS, sched_imprecise)] #[test_case(LESS_RCBS, sched_precise)] @@ -644,12 +646,13 @@ mod timer_tests { #[cfg(all(not(sanitized), test))] mod clock_tests { - use super::*; use reverie_ptrace::ret_without_perf; use reverie_ptrace::testing::check_fn; use reverie_ptrace::testing::do_branches; use test_case::test_case; + use super::*; + #[test] fn clock_accuracy() { ret_without_perf!(); @@ -724,10 +727,11 @@ mod clock_tests { #[cfg(all(not(sanitized), test))] mod general { - use super::*; use reverie_ptrace::ret_without_perf; use reverie_ptrace::testing::check_fn_with_config; + use super::*; + #[test] fn basic() { ret_without_perf!(); diff --git a/tests/vdso.rs b/tests/vdso.rs index b45b4cc..17155a5 100644 --- a/tests/vdso.rs +++ b/tests/vdso.rs @@ -65,11 +65,13 @@ impl Tool for LocalState { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; - use reverie_ptrace::testing::check_fn; use std::mem::MaybeUninit; use std::time; + use reverie_ptrace::testing::check_fn; + + use super::*; + #[test] #[should_panic] fn run_guest_vdso_tod_test() { diff --git a/tests/vfork.rs b/tests/vfork.rs index d4dd192..9603dec 100644 --- a/tests/vfork.rs +++ b/tests/vfork.rs @@ -82,12 +82,14 @@ impl Tool for LocalStateVforkClone { #[cfg(all(not(sanitized), test))] mod tests { - use super::*; + use std::ffi::CString; + use nix::sys::wait; use nix::sys::wait::WaitStatus; use nix::unistd::Pid; use reverie_ptrace::testing::check_fn; - use std::ffi::CString; + + use super::*; #[derive(Clone, Copy)] enum VforkTestFlag {