UFFDIO_WRITEPROTECT(2const)

๐Ÿ’… UFFDIO_WRITEPROTECT (that's a section 2const page, bestie, from the Linux man-pages crew)

okay so picture this: you've got memory registered with userfaultfd, and you wanna toggle the write permission on it like a little light switch. That's literally this ioctl. Sit down, grab a strawberry ๐Ÿ“, and let's get into it.


โœจ NAME โœจ

UFFDIO_WRITEPROTECT โ€” write-protect or write-unprotect a userfaultfd-registered memory range

no cap, that's the whole job. protect it, unprotect it, repeat. ๐Ÿ’ซ


๐ŸŽ€ LIBRARY ๐ŸŽ€

Standard C library (libc, -lc)

yes babe, you link it the normal way, nothing fancy here.


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

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

int ioctl(int fd, UFFDIO_WRITEPROTECT, ...);

#include <linux/userfaultfd.h>

struct uffdio_writeprotect {
    struct uffdio_range  range;  /* Range to change write permission*/
    __u64                mode;   /* Mode to change write permission */
};

look at that struct. she's little but she's doing a LOT. ๐Ÿ‘‘


๐ŸŒธ DESCRIPTION ๐ŸŒธ

So the vibe is: this ioctl write-protects or write-unprotects a memory range that you already registered with userfaultfd using mode UFFDIO_REGISTER_MODE_WP. It's giving "I decide who gets to write here" energy.

There are two mode bits supported in this structure:

  • UFFDIO_WRITEPROTECT_MODE_WP โ€” when this bit is set, the ioctl is a write-protect operation on the memory range you specified in range. When it's not set? It's a write-unprotect operation on that range instead โ€” which is the move you pull to resolve a userfaultfd write-protect page fault. โœจ
  • UFFDIO_WRITEPROTECT_MODE_DONTWAKE โ€” when this bit is set, do not wake up any thread that's waiting around for page-fault resolution after the operation. ๐Ÿ›‘ Heads up though: you can only specify this one if UFFDIO_WRITEPROTECT_MODE_WP is not specified. That's the rule, bestie, no negotiating.

๐Ÿ’– RETURN VALUE ๐Ÿ’–

  • Success? 0 comes back. slay. โœจ
  • Error? -1 comes back and errno gets set to tell you what went wrong. ๐Ÿ’€

๐Ÿ˜ญ ERRORS ๐Ÿ˜ญ

  • EINVAL โ€” the start or the len field of the ufdio_range structure wasn't a multiple of the system page size; or len was zero; or the specified range was otherwise invalid. like, invalid invalid. ๐Ÿšซ
  • EAGAIN โ€” the process was interrupted; just retry this call. she's just a little sleepy, try again. ๐Ÿ˜ด
  • ENOENT โ€” the range specified in range is not valid. For example, the virtual address does not exist, or it's not registered with userfaultfd write-protect mode. ghosted, literally. ๐Ÿ‘ป
  • EFAULT โ€” encountered a generic fault during processing. generic fault, generic heartbreak. ๐Ÿฅฒ

๐Ÿ‘‘ STANDARDS ๐Ÿ‘‘

Linux. that's it, that's the standard. ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡บ๐Ÿ‡ฝ


โญ HISTORY โญ

Linux 5.7. baby era for this one, and she's been iconic ever since. ๐ŸŒˆ


๐Ÿงš EXAMPLES ๐Ÿงš

See userfaultfd(2). go read the big one, i believe in you ๐Ÿซถ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


fr fr, this is a section 2const page, so if you were looking for the full story, the userfaultfd(2) page is your main character. ๐Ÿ’…

okay that's the whole page, mwah. this was Linux man-pages 6.20, dated 2026-02-08 โ€” and yes the UFFDIO_WRITEPROTECT(2const) header is right there at the top, iykyk. bye bestie, go protect some memory ๐Ÿฆ‹โœจ๐Ÿ’œ

๐Ÿ“ฆ 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