UFFDIO_RWPROTECT(2const)

πŸ“¦
version 6.20 Β· 2 versions
, in arch rolling, nixpkgs unstable

πŸ’– UFFDIO_RWPROTECT πŸ’–

okay bestie, gather round, because we're talking about a 2const man page today β€” that's right, a constant, not a whole function, and she is serving. This one lives in the Linux userfaultfd cinematic universe and her whole job is: read-write-protect or un-protect a userfaultfd-registered memory range. ✨


πŸ“š LIBRARY

Standard C library (libc, -lc) β€” the usual queen.


🧚 SYNOPSIS

#include <linux/userfaultfd.h>  /* Definition of UFFD* constants */
#include <sys/ioctl.h>

int ioctl(int fd, UFFDIO_RWPROTECT, struct uffdio_rwprotect *argp);

#include <linux/userfaultfd.h>

struct uffdio_rwprotect {
    struct uffdio_range  range;  /* Range to change RWP on */
    __u64                mode;   /* Mode flags */
};

like, two fields. that's it. she's minimal, she's clean, she's iconic. πŸ’…


🌸 DESCRIPTION

So basically: you use this to read-write-protect (or un-protect) a memory range that you already registered with the mode UFFDIO_REGISTER_MODE_RWP. RWP stands for read-write-protect, iykyk. πŸŽ€

The following mode bits are supported:

  • UFFDIO_RWPROTECT_MODE_RWP β€” when this mode bit is set, the ioctl installs read-write protection on every page present in the range you specified with .range. If it's not set, the ioctl instead removes read-write protection from the range β€” which is also literally how a fault handler resolves an UFFD_PAGEFAULT_FLAG_RWP notification. no cap. πŸ”₯
  • UFFDIO_RWPROTECT_MODE_DONTWAKE β€” when this mode bit is set, do not wake up any thread that's waiting for page-fault resolution after the operation. careful though bestie β€” you can only specify this if UFFDIO_RWPROTECT_MODE_RWP is not specified.

Now for the lore that actually matters. Read-write protection only affects pages that are currently populated in the range β€” unmapped addresses are left untouched, she simply does not perceive them. πŸ’€

For anonymous mappings, protection is preserved across page reclaim (the marker rides on the swap entry, cute) and migration. For shmem and file-backed mappings, protection is dropped when the backing page is reclaimed β€” yeah, she ghosts you, it's giving tragic. 😭

⚠️ Also: callers must re-arm a range with UFFDIO_RWPROTECT after any operation that explicitly drops the underlying page: - MADV_DONTNEED on anonymous memory - hole-punch on shmem - truncation of a file mapping

don't forget to re-arm, or you will be sad. πŸ™ˆ


πŸ‘‘ RETURN VALUE

On success, 0 is returned. On error, -1 is returned and errno is set to indicate the error. classic. periodt. ✨


πŸ’€ ERRORS

  • EINVAL β€” the start or the len field of the uffdio_range structure was not a multiple of the system page size, or len was zero, or the specified range was otherwise invalid, or an invalid mode bit was specified, or UFFDIO_RWPROTECT_MODE_DONTWAKE was specified together with UFFDIO_RWPROTECT_MODE_RWP. yeah that's a lot of ways to be wrong, we don't judge. 🌸
  • EAGAIN β€” the process was interrupted; retry this call. just run it back bestie. πŸ¦‹
  • ENOENT β€” the range specified in .range is not valid; for example, the virtual address does not exist, or part of the range is not registered with UFFDIO_REGISTER_MODE_RWP. she's looking for something that isn't there, it's giving searching-for-your-ex's-instagram. πŸ“±
  • EFAULT β€” encountered a generic fault during processing. generic. no notes. πŸ’…

🌈 STANDARDS

Linux. (that's the whole vibe check, she passes.) ⭐


πŸŽ€ HISTORY

Linux 7.2. baby of the family, freshly minted. πŸ‘‘


πŸ“ EXAMPLES

See userfaultfd(2). we're not doing the whole routine here, the main character page handles it. ✨


πŸ”₯ SEE ALSO


mwah πŸ’– that's the whole page. This lil UFFDIO_RWPROTECT(2const) beauty lives in Linux man-pages 6.20, dated 2026-05-28. go protect some pages responsibly, bestie β€” and remember to re-arm. πŸ«ΆπŸŒΈπŸ’œ

πŸ“¦ 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