Struct userfaultfd::UffdBuilder
source · 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
impl UffdBuilder
sourcepub fn new() -> UffdBuilder
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.
sourcepub fn close_on_exec(&mut self, close_on_exec: bool) -> &mut Self
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)).
sourcepub fn non_blocking(&mut self, non_blocking: bool) -> &mut Self
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.
sourcepub fn user_mode_only(&mut self, user_mode_only: bool) -> &mut Self
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.
sourcepub fn require_features(&mut self, feature: FeatureFlags) -> &mut Self
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.
sourcepub fn require_ioctls(&mut self, ioctls: IoctlFlags) -> &mut Self
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.