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 inrange. 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 ifUFFDIO_WRITEPROTECT_MODE_WPis not specified. That's the rule, bestie, no negotiating.
๐ RETURN VALUE ๐
- Success?
0comes back. slay. โจ - Error?
-1comes back anderrnogets set to tell you what went wrong. ๐
๐ญ ERRORS ๐ญ
EINVALโ thestartor thelenfield of theufdio_rangestructure wasn't a multiple of the system page size; orlenwas 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 inrangeis 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 ๐ฅ
ioctl(2)ioctl_userfaultfd(2)userfaultfd(2)Documentation/admin-guide/mm/userfaultfd.rstin the Linux kernel source tree
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
- 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