UFFDIO_REGISTER(2const)
π UFFDIO_REGISTER β the 2const girlie's guide to registering memory with your userfaultfd π
okay so bestie, this is a page from the UFFDIO_REGISTER(2const) manual β yeah, 2const, that niche little corner of the man pages where the ioctl constants live. but don't let that fool you, this one is lowkey the whole personality of userfaultfd. let's get into it π¦
β¨ NAME β¨
UFFDIO_REGISTER β register a memory address range with the userfaultfd object
π LIBRARY π
Standard C library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <linux/userfaultfd.h> /* Definition of UFFD* constants */
#include <sys/ioctl.h>
int ioctl(int fd, UFFDIO_REGISTER, struct uffdio_register *argp);
#include <linux/userfaultfd.h>
struct uffdio_range {
__u64 start; /* Start of range */
__u64 len; /* Size of range (bytes) */
};
struct uffdio_register {
struct uffdio_range range;
__u64 mode; /* Desired mode of operation (input) */
__u64 ioctls; /* Available ioctl()s (output) */
};
like. look at that struct. range, mode, ioctls. it's giving organised. it's giving input/output split done right. π
π DESCRIPTION π
so what are we actually doing here? we're registering a memory address range with the userfaultfd object. for real for real. π«Ά
here's the catch though β the pages in that range have to be "compatible". which compatibility you need depends on which register mode you're going for, and there's a whole list of modes below that spells out which memory backends play nice with each one. no cap.
The argp->range field defines a memory range starting at argp->range.start and continuing for argp->range.len bytes that should be handled by the userfaultfd.
The argp->mode field defines the mode of operation desired for this memory region. and here's where it gets cute, because the following values may be bitwise ORed to set the userfaultfd mode for the specified range:
UFFDIO_REGISTER_MODE_MISSINGTrack page faults on missing pages. Since Linux 4.3, only private anonymous ranges are compatible. Since Linux 4.11, hugetlbfs and shared memory ranges are also compatible.UFFDIO_REGISTER_MODE_WPTrack page faults on write-protected pages. Since Linux 5.7, only private anonymous ranges are compatible.UFFDIO_REGISTER_MODE_MINORTrack minor page faults. Since Linux 5.13, only hugetlbfs ranges are compatible. Since Linux 5.14, compatibility with shmem ranges was added.UFFDIO_REGISTER_MODE_RWP(since Linux 7.2) Track page faults on read-write-protected pages. Every access (read or write) to a page present within the registered range generates a notification once the range has been protected withUFFDIO_RWPROTECT(2const). This mode cannot be combined withUFFDIO_REGISTER_MODE_WP; attempting to do so fails withEINVAL. Anonymous, shmem, and hugetlbfs ranges are compatible.
π¨ bestie heads up:UFFDIO_REGISTER_MODE_RWPandUFFDIO_REGISTER_MODE_WPare not a thing you can ship together. try it and the kernel hits you withEINVAL, periodt.
π the ioctls output bits π
if the operation is successful, the kernel modifies the argp->ioctls bit-mask field to indicate which ioctl(2) operations are available for the specified range. this returned bit mask can contain the following bits:
1 << _UFFDIO_COPYTheUFFDIO_COPYoperation is supported.1 << _UFFDIO_WAKETheUFFDIO_WAKEoperation is supported.1 << _UFFDIO_WRITEPROTECTTheUFFDIO_WRITEPROTECToperation is supported.1 << _UFFDIO_ZEROPAGETheUFFDIO_ZEROPAGEoperation is supported.1 << _UFFDIO_CONTINUETheUFFDIO_CONTINUEoperation is supported.1 << _UFFDIO_POISONTheUFFDIO_POISONoperation is supported.1 << _UFFDIO_RWPROTECT(since Linux 7.2) TheUFFDIO_RWPROTECToperation is supported. This bit is reported only when the range was registered withUFFDIO_REGISTER_MODE_RWP(which itself requiresUFFD_FEATURE_RWPto have been negotiated).
β RETURN VALUE β
- on success?
0is returned. slay. - on error?
-1is returned anderrnois set to indicate the error. π
π ERRORS π
EBUSYβ A mapping in the specified range is registered with another userfaultfd object.EFAULTβargprefers to an address that is outside the calling process's accessible address space.EINVALβ An invalid or unsupported bit was specified in themodefield; or themodefield was zero.EINVALβ There is no mapping in the specified address range.EINVALβrange.startorrange.lenis not a multiple of the system page size; or,range.lenis zero; or these fields are otherwise invalid.EINVALβ There as an incompatible mapping in the specified address range.
π not the man page saying "There as an incompatible mapping"... i'm keeping it exactly as written because we do not edit the source text in this house, we only vibe it up. that EINVAL is doing the most, there's five of them, and honestly? iconic.
π STANDARDS π
Linux.
(that's it. that's the section. Linux. π)
π§ HISTORY π§
Linux 4.3.
π EXAMPLES π
See userfaultfd(2).
π₯ SEE ALSO π₯
ioctl(2)ioctl_userfaultfd(2)UFFDIO_UNREGISTER(2const)userfaultfd(2)linux.git/Documentation/admin-guide/mm/userfaultfd.rst
and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2026-06-04, and if you made it all the way through five separate EINVALs without losing it, you're genuinely built different. go forth and register your ranges responsibly πβ¨ππ¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2016, International Business Machines Corp
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms