Skip to content

Commit 623c395

Browse files
author
Pat Hickey
authored
Merge pull request #51 from bytecodealliance/pch/nix_0.27
update to nix 0.27
2 parents 33b4335 + 4e200ce commit 623c395

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "userfaultfd"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
authors = ["The Wasmtime Project Developers"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"
@@ -12,11 +12,14 @@ readme = "README.md"
1212
bitflags = "2.2.1"
1313
cfg-if = "^1.0.0"
1414
libc = "0.2.65"
15-
nix = "0.26"
15+
nix = { version = "0.27", features = ["ioctl"] }
1616
thiserror = "1.0.4"
1717
userfaultfd-sys = { path = "userfaultfd-sys", version = "^0.4.0" }
1818

19+
[dev-dependencies]
20+
nix = { version = "0.27", features = ["poll", "mman", "feature"] }
21+
1922
[features]
2023
default = []
21-
linux4_14 = ["userfaultfd-sys/linux4_14"]
24+
linux4_14 = ["userfaultfd-sys/linux4_14", "nix/process"]
2225
linux5_7 = ["userfaultfd-sys/linux5_7"]

examples/manpage.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use libc::{self, c_void};
33
use nix::poll::{poll, PollFd, PollFlags};
44
use nix::sys::mman::{mmap, MapFlags, ProtFlags};
55
use nix::unistd::{sysconf, SysconfVar};
6-
use std::os::unix::io::AsRawFd;
76
use std::{convert::TryInto, env};
87
use userfaultfd::{Event, Uffd, UffdBuilder};
98

@@ -18,7 +17,7 @@ fn fault_handler_thread(uffd: Uffd) {
1817
page_size.try_into().unwrap(),
1918
ProtFlags::PROT_READ | ProtFlags::PROT_WRITE,
2019
MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
21-
-1,
20+
None::<std::os::fd::BorrowedFd>,
2221
0,
2322
)
2423
.expect("mmap")
@@ -30,7 +29,7 @@ fn fault_handler_thread(uffd: Uffd) {
3029
loop {
3130
// See what poll() tells us about the userfaultfd
3231

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

3635
println!("\nfault_handler_thread():");
@@ -101,7 +100,7 @@ fn main() {
101100
len.try_into().unwrap(),
102101
ProtFlags::PROT_READ | ProtFlags::PROT_WRITE,
103102
MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
104-
-1,
103+
None::<std::os::fd::BorrowedFd>,
105104
0,
106105
)
107106
.expect("mmap")

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use libc::{self, c_void};
2121
use nix::errno::Errno;
2222
use nix::unistd::read;
2323
use std::mem;
24+
use std::os::fd::{AsFd, BorrowedFd};
2425
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
2526

2627
/// Represents an opaque buffer where userfaultfd events are stored.
@@ -53,6 +54,12 @@ impl Drop for Uffd {
5354
}
5455
}
5556

57+
impl AsFd for Uffd {
58+
fn as_fd(&self) -> BorrowedFd<'_> {
59+
unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
60+
}
61+
}
62+
5663
impl AsRawFd for Uffd {
5764
fn as_raw_fd(&self) -> RawFd {
5865
self.fd

0 commit comments

Comments
 (0)