Skip to content

Commit

Permalink
upgrade nix to 0.29.0
Browse files Browse the repository at this point in the history
Summary:
Enable more features that are disabled by default and update call
sites.

Reviewed By: opsound, jasonwhite

Differential Revision: D66275420

fbshipit-source-id: 4969045de7751c7d16b6ed5c7411f04077eb0ddc
  • Loading branch information
chadaustin authored and facebook-github-bot committed Dec 17, 2024
1 parent d153151 commit 1a1bfa4
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion public_autocargo/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ edition = "2018"
clap = { version = "3.2.25", features = ["derive", "env", "regex", "unicode", "wrap_help"] }
goblin = "0.5.2"
libc = "0.2.139"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
scroll = { version = "0.10", features = ["derive"] }
2 changes: 1 addition & 1 deletion reverie-process/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bitflags = { version = "2.6", features = ["serde"] }
colored = "2.1.0"
futures = { version = "0.3.30", features = ["async-await", "compat"] }
libc = "0.2.139"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
serde = { version = "1.0.185", features = ["derive", "rc"] }
syscalls = { version = "0.6.7", features = ["serde"] }
thiserror = "2"
Expand Down
2 changes: 1 addition & 1 deletion reverie-ptrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ goblin = "0.5.2"
iced-x86 = "1.17.0"
lazy_static = "1.4"
libc = "0.2.139"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
num-traits = { version = "0.2.18", default-features = false }
paste = "1.0.14"
perf-event-open-sys = "4.0"
Expand Down
27 changes: 18 additions & 9 deletions reverie-ptrace/src/gdbstub/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

use std::collections::BTreeMap;
use std::os::fd::BorrowedFd;
use std::sync::Arc;

use bytes::Bytes;
Expand Down Expand Up @@ -327,7 +328,11 @@ impl Session {
Mode::from_bits_truncate(0o644),
)
.and_then(|fd| {
let nb = uio::pread(fd, &mut auxv, offset as libc::off_t)?;
let nb = uio::pread(
unsafe { BorrowedFd::borrow_raw(fd) },
&mut auxv,
offset as libc::off_t,
)?;
let _ = unistd::close(fd);
Ok(nb)
}) {
Expand Down Expand Up @@ -535,6 +540,7 @@ impl Session {
writer.put_str(unistd::close(fd).map_or("F-1", |_| "F0"));
}
vFile::Pread(fd, count, offset) => {
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
let count = std::cmp::min(count as usize, self.bufsiz);
let mut buf: Vec<u8> = vec![0; count];
match uio::pread(fd, &mut buf, offset as i64) {
Expand All @@ -549,15 +555,18 @@ impl Session {
}
}
}
vFile::Pwrite(fd, offset, data) => match uio::pwrite(fd, &data, offset as i64) {
Ok(nb) => {
writer.put_str("F");
writer.put_num(nb);
}
Err(_) => {
writer.put_str("F-1");
vFile::Pwrite(fd, offset, data) => {
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
match uio::pwrite(fd, &data, offset as i64) {
Ok(nb) => {
writer.put_str("F");
writer.put_num(nb);
}
Err(_) => {
writer.put_str("F-1");
}
}
},
}
vFile::Unlink(fname) => {
writer.put_str(unistd::unlink(&fname).map_or("F-1", |_| "F0"));
}
Expand Down
11 changes: 2 additions & 9 deletions reverie-ptrace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::io::Write;
use std::net::SocketAddr;
use std::os::fd::AsRawFd;
use std::os::fd::OwnedFd;
use std::os::fd::BorrowedFd;
use std::path::PathBuf;
use std::sync::Arc;

Expand Down Expand Up @@ -571,8 +571,6 @@ where
L: Tool + 'static,
F: FnOnce(),
{
use std::os::unix::io::FromRawFd;

// Because this ptrace backend is CENTRALIZED, it can keep all the
// tool's state here in a single address space.
let global_state = <L::GlobalState as GlobalTool>::init_global_state(&config).await;
Expand All @@ -584,11 +582,6 @@ where
let (read1, write1) = unistd::pipe().map_err(from_nix_error)?;
let (read2, write2) = unistd::pipe().map_err(from_nix_error)?;

let read1 = unsafe { OwnedFd::from_raw_fd(read1) };
let write1 = unsafe { OwnedFd::from_raw_fd(write1) };
let read2 = unsafe { OwnedFd::from_raw_fd(read2) };
let write2 = unsafe { OwnedFd::from_raw_fd(write2) };

// Disable io redirection just before forking. We want the child process to
// be able to call `println!()` and have that output go to stdout.
//
Expand Down Expand Up @@ -620,7 +613,7 @@ where
Err(e) => {
std::io::stdout().flush()?;
let _ = nix::unistd::write(
2,
unsafe { BorrowedFd::borrow_raw(2) },
format!("Forked Rust process panicked, cause: {:?}", e).as_ref(),
);
std::process::exit(1);
Expand Down
2 changes: 1 addition & 1 deletion reverie-syscalls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "BSD-2-Clause"
bitflags = { version = "2.6", features = ["serde"] }
derive_more = { version = "1.0.0", features = ["full"] }
libc = "0.2.139"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
paste = "1.0.14"
reverie-memory = { version = "0.1.0", path = "../reverie-memory" }
serde = { version = "1.0.185", features = ["derive", "rc"] }
Expand Down
2 changes: 1 addition & 1 deletion reverie-syscalls/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ macro_rules! impl_raw_bits {
($t:ty : $inner:ty) => {
impl $crate::FromToRaw for $t {
fn from_raw(raw: usize) -> Self {
unsafe { Self::from_bits_unchecked(raw as $inner) }
Self::from_bits_retain(raw as $inner)
}

fn into_raw(self) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions reverie-syscalls/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3563,7 +3563,7 @@ mod test {
assert_eq!(
format!("{}", syscall.display(&memory)),
format!(
"openat(-100, {:p} -> \"/some/file/path\", O_APPEND)",
"openat(-100, {:p} -> \"/some/file/path\", OFlag(O_APPEND))",
name.as_ptr()
)
);
Expand All @@ -3585,7 +3585,7 @@ mod test {
.with_flags(OFlag::O_APPEND)
.display(&memory)
),
"openat(-100, NULL, O_APPEND)"
"openat(-100, NULL, OFlag(O_APPEND))"
);

assert_eq!(
Expand All @@ -3598,7 +3598,7 @@ mod test {
.with_mode(Some(Mode::from_bits_truncate(0o644)))
.display(&memory)
),
"openat(-100, NULL, O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)"
"openat(-100, NULL, OFlag(O_CREAT), Mode(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))"
);

assert_eq!(
Expand All @@ -3611,7 +3611,7 @@ mod test {
.with_mode(Some(Mode::from_bits_truncate(0o600)))
.display(&memory)
),
"openat(-100, NULL, O_DIRECTORY | O_TMPFILE, S_IRUSR | S_IWUSR)"
"openat(-100, NULL, OFlag(O_DIRECTORY | O_TMPFILE), Mode(S_IRUSR | S_IWUSR))"
);

#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -3644,7 +3644,7 @@ mod test {
assert_eq!(
format!("{}", syscall.display_with_outputs(&memory)),
format!(
"stat({:p} -> \"/dev/null\", {:p} -> {{st_mode=S_IFCHR | 0666, st_size=0, ...}})",
"stat({:p} -> \"/dev/null\", {:p} -> {{st_mode=SFlag(S_IFCHR) | 0666, st_size=0, ...}})",
name.as_ptr(),
&stat as *const _
)
Expand Down
2 changes: 1 addition & 1 deletion reverie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ libc = "0.2.139"
linked-hash-map = { version = "0.5", features = ["serde_impl"] }
memmap2 = "0.5.10"
never-say-never = "6"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
object = { version = "0.29", features = ["write"] }
procfs = "0.15.1"
raw-cpuid = "10.6.0"
Expand Down
2 changes: 1 addition & 1 deletion safeptrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bitflags = { version = "2.6", features = ["serde"] }
futures = { version = "0.3.30", features = ["async-await", "compat"] }
lazy_static = "1.4"
libc = "0.2.139"
nix = "0.26.4"
nix = { version = "0.29.0", features = ["dir", "event", "hostname", "inotify", "ioctl", "mman", "mount", "net", "poll", "ptrace", "reboot", "resource", "sched", "term", "time", "user", "zerocopy"] }
parking_lot = { version = "0.12.1", features = ["send_guard"] }
reverie-memory = { version = "0.1.0", path = "../reverie-memory", optional = true }
reverie-process = { version = "0.1.0", path = "../reverie-process" }
Expand Down
3 changes: 2 additions & 1 deletion safeptrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ pub fn traceme_and_stop() -> Result<(), Errno> {
#[cfg(test)]
mod test {
use std::io;
use std::os::fd::BorrowedFd;
use std::thread;

use nix::sys::signal;
Expand Down Expand Up @@ -1305,7 +1306,7 @@ mod test {
_siginfo: *mut libc::siginfo_t,
_ucontext: *const libc::c_void,
) {
nix::unistd::write(2, b"caught SIGALRM!").unwrap();
nix::unistd::write(unsafe { BorrowedFd::borrow_raw(2) }, b"caught SIGALRM!").unwrap();
}

#[allow(dead_code)]
Expand Down
3 changes: 2 additions & 1 deletion safeptrace/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

use core::mem;
use std::ffi::c_long;
use std::io;

use nix::sys::ptrace;
Expand Down Expand Up @@ -51,7 +52,7 @@ impl Stopped {
ptrace::write(
self.0.into(),
addr.as_mut_ptr() as *mut ::core::ffi::c_void,
value as *mut ::core::ffi::c_void,
value as c_long,
)
}
.map_err(|err| Errno::new(err as i32))
Expand Down
10 changes: 6 additions & 4 deletions tests/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use std::ffi::CString;
#[allow(unused_imports)]
use std::io::Write;
#[allow(unused_imports)]
use std::os::fd::AsRawFd;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;

Expand Down Expand Up @@ -265,17 +267,17 @@ fn child_should_inherit_fds() {
let msg: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];
match unsafe { unistd::fork() } {
Ok(ForkResult::Parent { child, .. }) => {
assert!(unistd::close(fdwrite).is_ok());
drop(fdwrite);
let mut buf: [u8; 8] = [0; 8];
assert_eq!(unistd::read(fdread, &mut buf), Ok(8));
assert_eq!(unistd::read(fdread.as_raw_fd(), &mut buf), Ok(8));
assert_eq!(buf, msg);
assert_eq!(wait::waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
unsafe { libc::syscall(libc::SYS_exit_group, 0) };
unreachable!();
}
Ok(ForkResult::Child) => {
assert!(unistd::close(fdread).is_ok());
assert_eq!(unistd::write(fdwrite, &msg), Ok(8));
drop(fdread);
assert_eq!(unistd::write(&fdwrite, &msg), Ok(8));
unsafe { libc::syscall(libc::SYS_exit_group, 0) };
unreachable!();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/delay_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Tool for LocalState {
mod tests {
use std::io;
use std::mem::MaybeUninit;
use std::os::fd::BorrowedFd;
use std::sync::mpsc;
use std::thread;
use std::time;
Expand Down Expand Up @@ -217,7 +218,7 @@ mod tests {
_siginfo: *mut libc::siginfo_t,
_ucontext: *const libc::c_void,
) {
nix::unistd::write(2, b"caught SIGPROF!").unwrap();
nix::unistd::write(unsafe { BorrowedFd::borrow_raw(2) }, b"caught SIGPROF!").unwrap();
unsafe {
libc::syscall(libc::SYS_exit_group, 0);
}
Expand Down
11 changes: 7 additions & 4 deletions tests/parallelism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

//! Tests for parallelism and concurrency
use reverie::syscalls::Syscall;
use reverie::Error;
use reverie::GlobalTool;
Expand Down Expand Up @@ -75,21 +74,25 @@ impl Tool for TestTool {
#[test]
#[cfg(not(sanitized))]
pub fn delay_childprint_test() {
use std::os::fd::BorrowedFd;

use reverie::ExitStatus;
use reverie_ptrace::testing::print_tracee_output;
use reverie_ptrace::testing::test_fn;

let fd1 = unsafe { BorrowedFd::borrow_raw(1) };

let (output, _state) = test_fn::<TestTool, _>(|| {
let child = std::thread::spawn(move || {
for _ in 0..2 {
nix::unistd::write(1, b"a").unwrap();
nix::unistd::write(fd1, b"a").unwrap();
}
});
for _ in 0..100 {
nix::unistd::write(1, b"b").unwrap();
nix::unistd::write(fd1, b"b").unwrap();
}
child.join().unwrap();
nix::unistd::write(1, b"\n").unwrap();
nix::unistd::write(fd1, b"\n").unwrap();
})
.unwrap();

Expand Down

0 comments on commit 1a1bfa4

Please sign in to comment.