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_MISSING Track 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_WP Track page faults on write-protected pages. Since Linux 5.7, only private anonymous ranges are compatible.
  • UFFDIO_REGISTER_MODE_MINOR Track 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 with UFFDIO_RWPROTECT(2const). This mode cannot be combined with UFFDIO_REGISTER_MODE_WP; attempting to do so fails with EINVAL. Anonymous, shmem, and hugetlbfs ranges are compatible.
🚨 bestie heads up: UFFDIO_REGISTER_MODE_RWP and UFFDIO_REGISTER_MODE_WP are not a thing you can ship together. try it and the kernel hits you with EINVAL, 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_COPY The UFFDIO_COPY operation is supported.
  • 1 << _UFFDIO_WAKE The UFFDIO_WAKE operation is supported.
  • 1 << _UFFDIO_WRITEPROTECT The UFFDIO_WRITEPROTECT operation is supported.
  • 1 << _UFFDIO_ZEROPAGE The UFFDIO_ZEROPAGE operation is supported.
  • 1 << _UFFDIO_CONTINUE The UFFDIO_CONTINUE operation is supported.
  • 1 << _UFFDIO_POISON The UFFDIO_POISON operation is supported.
  • 1 << _UFFDIO_RWPROTECT (since Linux 7.2) The UFFDIO_RWPROTECT operation is supported. This bit is reported only when the range was registered with UFFDIO_REGISTER_MODE_RWP (which itself requires UFFD_FEATURE_RWP to have been negotiated).

⭐ RETURN VALUE ⭐

  • on success? 0 is returned. slay.
  • on error? -1 is returned and errno is set to indicate the error. 😭

πŸ’€ ERRORS πŸ’€

  • EBUSY β€” A mapping in the specified range is registered with another userfaultfd object.
  • EFAULT β€” argp refers to an address that is outside the calling process's accessible address space.
  • EINVAL β€” An invalid or unsupported bit was specified in the mode field; or the mode field was zero.
  • EINVAL β€” There is no mapping in the specified address range.
  • EINVAL β€” range.start or range.len is not a multiple of the system page size; or, range.len is 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 πŸ”₯


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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms