pub struct UffdBuilder { /* private fields */ }
Expand description

A builder for initializing Uffd objects.

use userfaultfd::UffdBuilder;

let uffd = UffdBuilder::new()
    .close_on_exec(true)
    .non_blocking(true)
    .user_mode_only(true)
    .create();
assert!(uffd.is_ok());

Implementations§

source§

impl UffdBuilder

source

pub fn new() -> UffdBuilder

Create a new builder with no required features or ioctls, close_on_exec and non_blocking both set to false, and user_mode_only set to true.

source

pub fn close_on_exec(&mut self, close_on_exec: bool) -> &mut Self

Enable the close-on-exec flag for the new userfaultfd object (see the description of O_CLOEXEC in open(2)).

source

pub fn non_blocking(&mut self, non_blocking: bool) -> &mut Self

Enable non-blocking operation for the userfaultfd object.

If this is set to false, Uffd::read_event() will block until an event is available to read. Otherwise, it will immediately return None if no event is available.

source

pub fn user_mode_only(&mut self, user_mode_only: bool) -> &mut Self

Enable user-mode only flag for the userfaultfd object.

If set to false, the process must have the CAP_SYS_PTRACE capability starting with Linux 5.11 or object creation will fail with EPERM. When set to true, userfaultfd can’t be used to handle kernel-mode page faults such as when kernel tries copying data to userspace.

When used with kernels older than 5.11, this has no effect; the process doesn’t need CAP_SYS_PTRACE and can handle kernel-mode page faults.

source

pub fn require_features(&mut self, feature: FeatureFlags) -> &mut Self

Add a requirement that a particular feature or set of features is available.

If a required feature is unavailable, UffdBuilder.create() will return an error.

source

pub fn require_ioctls(&mut self, ioctls: IoctlFlags) -> &mut Self

Add a requirement that a particular ioctl or set of ioctls is available.

If a required ioctl is unavailable, UffdBuilder.create() will return an error.

source

pub fn create(&self) -> Result<Uffd>

Create a Uffd object with the current settings of this builder.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.