.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH USERFAULTFD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
+.TH USERFAULTFD 2 2020-02-09 "Linux" "Linux Programmer's Manual"
.SH NAME
userfaultfd \- create a file descriptor for handling page faults in user space
.SH SYNOPSIS
The application can then use the
.B UFFDIO_COPY
or
-.B UFFDIO_ZERO
+.B UFFDIO_ZEROPAGE
.BR ioctl (2)
operations to resolve the page fault.
.PP
.TP
.B ENOMEM
Insufficient kernel memory was available.
+.TP
+.BR EPERM " (since Linux 5.2)"
+.\" cefdca0a86be517bc390fc4541e3674b8e7803b0
+The caller is not privileged (does not have the
+.B CAP_SYS_PTRACE
+capability in the initial user namespace), and
+.I /proc/sys/vm/unprivileged_userfaultfd
+has the value 0.
.SH VERSIONS
The
.BR userfaultfd ()
.B UFFD_FEATURE_EVENT_FORK
is enabled and a system call from the
.BR fork (2)
-family is interrupted by a signal or failed,q a stale userfaultfd descriptor
+family is interrupted by a signal or failed, a stale userfaultfd descriptor
might be created.
-In this case a spurious
+In this case, a spurious
.B UFFD_EVENT_FORK
will be delivered to the userfaultfd monitor.
.SH EXAMPLE
#include <sys/ioctl.h>
#include <poll.h>
-#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
+#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
static int page_size;
if (nready == \-1)
errExit("poll");
- printf("\\nfault_handler_thread():\\n");
+ printf("\enfault_handler_thread():\en");
printf(" poll() returns: nready = %d; "
- "POLLIN = %d; POLLERR = %d\\n", nready,
+ "POLLIN = %d; POLLERR = %d\en", nready,
(pollfd.revents & POLLIN) != 0,
(pollfd.revents & POLLERR) != 0);
nread = read(uffd, &msg, sizeof(msg));
if (nread == 0) {
- printf("EOF on userfaultfd!\\n");
+ printf("EOF on userfaultfd!\en");
exit(EXIT_FAILURE);
}
/* We expect only one kind of event; verify that assumption */
if (msg.event != UFFD_EVENT_PAGEFAULT) {
- fprintf(stderr, "Unexpected event on userfaultfd\\n");
+ fprintf(stderr, "Unexpected event on userfaultfd\en");
exit(EXIT_FAILURE);
}
printf(" UFFD_EVENT_PAGEFAULT event: ");
printf("flags = %llx; ", msg.arg.pagefault.flags);
- printf("address = %llx\\n", msg.arg.pagefault.address);
+ printf("address = %llx\en", msg.arg.pagefault.address);
/* Copy the page pointed to by \(aqpage\(aq into the faulting
region. Vary the contents that are copied in, so that it
if (ioctl(uffd, UFFDIO_COPY, &uffdio_copy) == \-1)
errExit("ioctl\-UFFDIO_COPY");
- printf(" (uffdio_copy.copy returned %lld)\\n",
+ printf(" (uffdio_copy.copy returned %lld)\en",
uffdio_copy.copy);
}
}
int s;
if (argc != 2) {
- fprintf(stderr, "Usage: %s num\-pages\\n", argv[0]);
+ fprintf(stderr, "Usage: %s num\-pages\en", argv[0]);
exit(EXIT_FAILURE);
}
if (addr == MAP_FAILED)
errExit("mmap");
- printf("Address returned by mmap() = %p\\n", addr);
+ printf("Address returned by mmap() = %p\en", addr);
/* Register the memory range of the mapping we just created for
handling by the userfaultfd object. In mode, we request to track
while (l < len) {
char c = addr[l];
printf("Read address %p in main(): ", addr + l);
- printf("%c\\n", c);
+ printf("%c\en", c);
l += 1024;
usleep(100000); /* Slow things down a little */
}
.BR madvise (2),
.BR mmap (2)
.PP
-.IR Documentation/vm/userfaultfd.txt
+.IR Documentation/admin-guide/mm/userfaultfd.rst
in the Linux kernel source tree
.PP