UFFDIO_API(2const)
โจ UFFDIO_API โ the userfaultfd glow-up ritual ๐
okay so bestie, this is the manual page for UFFDIO_API(2const), and it lives in section 2const of the Linux manual pages, which is a whole vibe. it's giving "enable operation of the userfaultfd and perform API handshake." and honestly? it ate. let's get into it ๐ซถ
๐ LIBRARY
Standard C library (libc, -lc). the usual. she's classic, she's reliable ๐
๐ธ SYNOPSIS
#include <linux/userfaultfd.h> /* Definition of UFFD* constants */
#include <sys/ioctl.h>
int ioctl(int fd, UFFDIO_API, struct uffdio_api *argp);
#include <linux/userfaultfd.h>
struct uffdio_api {
__u64 api; /* Requested API version (input) */
__u64 features; /* Requested features (input/output) */
__u64 ioctls; /* Available ioctl() operations (output) */
};
not me obsessing over a struct with exactly three fields. it's minimal, it's iconic, it's doing the most with the least ๐
๐ซ DESCRIPTION
Enable operation of the userfaultfd and perform API handshake. yes bestie, that's the whole job. this is the "hi hello are we compatible ๐" conversation between your app and the kernel.
the api field is the API version your application is requesting. the kernel checks it can actually support that requested API version, and then sets the features and ioctls fields to bit masks representing all the available features and the generic ioctl(2) operations available. it's like a vibe check but for syscalls โจ
Before Linux 4.11, the features field must be initialized to zero before the call to UFFDIO_API, and zero (i.e., no feature bits) is placed in the features field by the kernel upon return from ioctl(2). so basically the kernel was like "no thoughts, head empty, zero anyway" ๐
Since Linux 4.11, userfaultfd supports features that need to be enabled explicitly. to enable any of the features, one needs to set the corresponding feature bits in features when issuing the UFFDIO_API ioctl. no passive vibes here, you gotta ask for what you want, bestie.
For historical reasons, a temporary userfaultfd is needed to probe what userfaultfd features the kernel supports. the application needs to create a temporary userfaultfd, issue an UFFDIO_API ioctl with features set to zero. after the UFFDIO_API ioctl returns successfully, features should contain all the userfaultfd features that the kernel supports. the temporary userfaultfd can be safely closed after the probe. it's giving "trial run", it's giving "test the waters", it's giving "make a fake account to check the app out" ๐ญ
โ ๏ธ If the application sets unsupported feature bits, the kernel will zero out the returneduffdio_apistructure and returnEINVAL. she said "nope, not on my watch" and wiped the whole board. rude but fair ๐
The following feature bits may be set:
UFFD_FEATURE_EVENT_FORK(since Linux 4.11) โ When this feature is enabled, the userfaultfd objects associated with a parent process are duplicated into the child process duringfork(2)and aUFFD_EVENT_FORKevent is delivered to the userfaultfd monitor. family tree but make it syscalls ๐UFFD_FEATURE_EVENT_REMAP(since Linux 4.11) โ If this feature is enabled, when the faulting process invokesmremap(2), the userfaultfd monitor will receive an event of typeUFFD_EVENT_REMAP.UFFD_FEATURE_EVENT_REMOVE(since Linux 4.11) โ If this feature is enabled, when the faulting process callsmadvise(2)with theMADV_DONTNEEDorMADV_REMOVEadvice value to free a virtual memory area the userfaultfd monitor will receive an event of typeUFFD_EVENT_REMOVE.UFFD_FEATURE_EVENT_UNMAP(since Linux 4.11) โ If this feature is enabled, when the faulting process unmaps virtual memory either explicitly withmunmap(2), or implicitly during eithermmap(2)ormremap(2), the userfaultfd monitor will receive an event of typeUFFD_EVENT_UNMAP.UFFD_FEATURE_MISSING_HUGETLBFS(since Linux 4.11) โ If this feature bit is set, the kernel supports registering userfaultfd ranges on hugetlbfs virtual memory areas.UFFD_FEATURE_MISSING_SHMEM(since Linux 4.11) โ If this feature bit is set, the kernel supports registering userfaultfd ranges on shared memory areas. This includes all kernel shared memory APIs: System V shared memory,tmpfs(5), shared mappings of/dev/zero,mmap(2)with theMAP_SHAREDflag set,memfd_create(2), and so on. she's inclusive, she contains multitudes ๐UFFD_FEATURE_SIGBUS(since Linux 4.14) โ If this feature bit is set, no page-fault events (UFFD_EVENT_PAGEFAULT) will be delivered. Instead, aSIGBUSsignal will be sent to the faulting process. Applications using this feature will not require the use of a userfaultfd monitor for processing memory accesses to the regions registered with userfaultfd.UFFD_FEATURE_THREAD_ID(since Linux 4.14) โ If this feature bit is set,uffd_msg.pagefault.feat.ptidwill be set to the faulted thread ID for each page-fault message. we love knowing exactly which thread did the thing ๐ซถUFFD_FEATURE_PAGEFAULT_FLAG_WP(since Linux 5.10) โ If this feature bit is set, userfaultfd supports write-protect faults for anonymous memory. (Note that shmem / hugetlbfs support is indicated by a separate feature.) note bestie, separate feature, don't get it twisted โจUFFD_FEATURE_MINOR_HUGETLBFS(since Linux 5.13) โ If this feature bit is set, the kernel supports registering userfaultfd ranges in minor mode on hugetlbfs-backed memory areas.UFFD_FEATURE_MINOR_SHMEM(since Linux 5.14) โ If this feature bit is set, the kernel supports registering userfaultfd ranges in minor mode on shmem-backed memory areas.UFFD_FEATURE_EXACT_ADDRESS(since Linux 5.18) โ If this feature bit is set,uffd_msg.pagefault.addresswill be set to the exact page-fault address that was reported by the hardware, and will not mask the offset within the page. Note that old Linux versions might indicate the exact address as well, even though the feature bit is not set. so she might already be doing it and just not telling you ๐UFFD_FEATURE_WP_HUGETLBFS_SHMEM(since Linux 5.19) โ If this feature bit is set, userfaultfd supports write-protect faults for hugetlbfs and shmem / tmpfs memory.UFFD_FEATURE_WP_UNPOPULATED(since Linux 6.4) โ If this feature bit is set, the kernel will handle anonymous memory the same way as file memory, by allowing the user to write-protect unpopulated page table entries.UFFD_FEATURE_POISON(since Linux 6.6) โ If this feature bit is set, the kernel supports resolving faults with theUFFDIO_POISONioctl.UFFD_FEATURE_WP_ASYNC(since Linux 6.7) โ If this feature bit is set, the write protection faults would be asynchronously resolved by the kernel.UFFD_FEATURE_MOVE(since Linux 6.8) โ If this feature bit is set, the kernel supports resolving faults with theUFFDIO_MOVEioctl.UFFD_FEATURE_RWP(since Linux 7.2) โ If this feature bit is set, the kernel supports read-write-protection tracking, and theUFFDIO_REGISTER_MODE_RWPregistration mode and theUFFDIO_RWPROTECTioctl become available.UFFD_FEATURE_RWP_ASYNC(since Linux 7.2) โ If this feature bit is set, the kernel will resolve read-write-protect faults in place without delivering a notification, automatically restoring page permissions and letting the faulted thread continue. This bit requiresUFFD_FEATURE_RWPto be set in the sameUFFDIO_APIcall. The async mode can also be toggled at runtime using theUFFDIO_SET_MODE(2const)ioctl. package deal bestie, you can't just take the async one and dip ๐ธ
The returned argp->ioctls field can contain the following bits:
1 << _UFFDIO_APIโ TheUFFDIO_APIoperation is supported.1 << _UFFDIO_REGISTERโ TheUFFDIO_REGISTERoperation is supported.1 << _UFFDIO_UNREGISTERโ TheUFFDIO_UNREGISTERoperation is supported.1 << _UFFDIO_SET_MODE(since Linux 7.2) โ TheUFFDIO_SET_MODEoperation is supported. This is a file-descriptor-level ioctl and is reported once per userfaultfd, independent of any registered range. one per userfaultfd and she means it ๐
๐ฏ RETURN VALUE
On success, 0 is returned. slay. โ
On error, -1 is returned and errno is set to indicate the error. we love a dramatic entrance ๐ญ
๐จ ERRORS
EFAULTโargprefers to an address that is outside the calling process's accessible address space. you pointed at the void bestie, the void pointed back ๐EINVALโ The API version requested in theapifield is not supported by this kernel, or thefeaturesfield passed to the kernel includes feature bits that are not supported by the current kernel version.EINVALโ A previousUFFDIO_APIcall already enabled one or more features for this userfaultfd. CallingUFFDIO_APItwice, the first time with no features set, is explicitly allowed as per the two-step feature detection handshake. okay so this one is the allowed double-dip, do not panic โจEPERMโ TheUFFD_FEATURE_EVENT_FORKfeature was enabled, but the calling process doesn't have theCAP_SYS_PTRACEcapability. no cap, literally, you need the cap ๐งข
๐ STANDARDS
Linux. that's it. that's the standard. ๐ฑ๐ฎ๐ณ๐บ๐ฝ
๐ฐ๏ธ HISTORY
Linux 4.3. she's been around, she's a little vintage, she's an icon ๐
โ ๏ธ CAVEATS
If an error occurs, the kernel may zero the provided uffdio_api structure. The caller should treat its contents as unspecified, and reinitialize it before re-attempting another UFFDIO_API call.
bestie please. treat it as unspecified. do not read the vibes off a zeroed struct. reinitialize it, it's not that deep, but it IS that important ๐ซถ
๐ BUGS
In order to detect available userfault features and enable some subset of those features the userfaultfd file descriptor must be closed after the first UFFDIO_API operation that queries features availability and reopened before the second UFFDIO_API operation that actually enables the desired features.
so yeah, close it, reopen it, close it, reopen it. it's giving getting back together with your ex, except this time it's a file descriptor and it actually works ๐ญ
๐ EXAMPLES
See userfaultfd(2). the homework is over there, bestie, I'm not doing it for you ๐โจ
๐ SEE ALSO
ioctl(2)ioctl_userfaultfd(2)mmap(2)userfaultfd(2)linux.git/Documentation/admin-guide/mm/userfaultfd.rst
and that's the page ๐ this was Linux man-pages 6.20, dated 2026-06-04, and honestly? iconic. periodt. go forth and handshake with your kernel, bestie, you've got this ๐ฆโจ๐
๐ฆ 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