Skip to content

Commit

Permalink
Merge pull request #51 from bytecodealliance/pch/nix_0.27
Browse files Browse the repository at this point in the history
update to nix 0.27
  • Loading branch information
Pat Hickey authored Aug 30, 2023
2 parents 33b4335 + 4e200ce commit 623c395
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "userfaultfd"
version = "0.6.0"
version = "0.6.1"
authors = ["The Wasmtime Project Developers"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -12,11 +12,14 @@ readme = "README.md"
bitflags = "2.2.1"
cfg-if = "^1.0.0"
libc = "0.2.65"
nix = "0.26"
nix = { version = "0.27", features = ["ioctl"] }
thiserror = "1.0.4"
userfaultfd-sys = { path = "userfaultfd-sys", version = "^0.4.0" }

[dev-dependencies]
nix = { version = "0.27", features = ["poll", "mman", "feature"] }

[features]
default = []
linux4_14 = ["userfaultfd-sys/linux4_14"]
linux4_14 = ["userfaultfd-sys/linux4_14", "nix/process"]
linux5_7 = ["userfaultfd-sys/linux5_7"]
7 changes: 3 additions & 4 deletions examples/manpage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use libc::{self, c_void};
use nix::poll::{poll, PollFd, PollFlags};
use nix::sys::mman::{mmap, MapFlags, ProtFlags};
use nix::unistd::{sysconf, SysconfVar};
use std::os::unix::io::AsRawFd;
use std::{convert::TryInto, env};
use userfaultfd::{Event, Uffd, UffdBuilder};

Expand All @@ -18,7 +17,7 @@ fn fault_handler_thread(uffd: Uffd) {
page_size.try_into().unwrap(),
ProtFlags::PROT_READ | ProtFlags::PROT_WRITE,
MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
-1,
None::<std::os::fd::BorrowedFd>,
0,
)
.expect("mmap")
Expand All @@ -30,7 +29,7 @@ fn fault_handler_thread(uffd: Uffd) {
loop {
// See what poll() tells us about the userfaultfd

let pollfd = PollFd::new(uffd.as_raw_fd(), PollFlags::POLLIN);
let pollfd = PollFd::new(&uffd, PollFlags::POLLIN);
let nready = poll(&mut [pollfd], -1).expect("poll");

println!("\nfault_handler_thread():");
Expand Down Expand Up @@ -101,7 +100,7 @@ fn main() {
len.try_into().unwrap(),
ProtFlags::PROT_READ | ProtFlags::PROT_WRITE,
MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
-1,
None::<std::os::fd::BorrowedFd>,
0,
)
.expect("mmap")
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use libc::{self, c_void};
use nix::errno::Errno;
use nix::unistd::read;
use std::mem;
use std::os::fd::{AsFd, BorrowedFd};
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};

/// Represents an opaque buffer where userfaultfd events are stored.
Expand Down Expand Up @@ -53,6 +54,12 @@ impl Drop for Uffd {
}
}

impl AsFd for Uffd {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
}
}

impl AsRawFd for Uffd {
fn as_raw_fd(&self) -> RawFd {
self.fd
Expand Down

0 comments on commit 623c395

Please sign in to comment.