UFFDIO_RWPROTECT(2const)
π 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 anUFFD_PAGEFAULT_FLAG_RWPnotification. 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 ifUFFDIO_RWPROTECT_MODE_RWPis 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 withUFFDIO_RWPROTECTafter any operation that explicitly drops the underlying page: -MADV_DONTNEEDon 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β thestartor thelenfield of theuffdio_rangestructure was not a multiple of the system page size, orlenwas zero, or the specified range was otherwise invalid, or an invalid mode bit was specified, orUFFDIO_RWPROTECT_MODE_DONTWAKEwas specified together withUFFDIO_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.rangeis not valid; for example, the virtual address does not exist, or part of the range is not registered withUFFDIO_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
ioctl(2)ioctl_userfaultfd(2)userfaultfd(2)linux.git/Documentation/admin-guide/mm/userfaultfd.rst
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