UFFDIO_COPY(2const)
π UFFDIO_COPY β the userfaultfd copy-paste glow-up π
okay bestie so you're reading the UFFDIO_COPY(2const) page from the Linux crew's section 2 constants, and honestly? it's giving "atomic memory chunk delivery service" and I'm obsessed. let's get into it π«Ά
β¨ NAME β¨
UFFDIO_COPY β atomically copy a continuous memory chunk into the userfault registered range
like, it moves a whole continuous chunk of memory into your userfault-registered zone, all atomically, no half-copies, no drama π
π LIBRARY π
Standard C library (libc, -lc)
π SYNOPSIS π
#include <linux/userfaultfd.h> /* Definition of UFFD* constants */
#include <sys/ioctl.h>
int ioctl(int fd, UFFDIO_COPY, struct uffdio_copy *argp);
#include <linux/userfaultfd.h>
struct uffdio_copy {
__u64 dst; /* Destination of copy */
__u64 src; /* Source of copy */
__u64 len; /* Number of bytes to copy */
__u64 mode; /* Flags controlling behavior of copy */
__s64 copy; /* Number of bytes copied, or negated error */
};
not me showing you the whole struct because every field MATTERS π§
π DESCRIPTION π
Atomically copy a continuous memory chunk into the userfault registered range and optionally wake up the blocked thread. yes, the blocked thread. she's been waiting. you can free her or let her nap, your call π
The following value may be bitwise ORed in mode to change the behavior of the UFFDIO_COPY operation:
UFFDIO_COPY_MODE_DONTWAKEβ Do not wake up the thread that waits for page-fault resolution. let her sleep, she earned it π΄UFFDIO_COPY_MODE_WPβ Copy the page with read-only permission. This allows the user to trap the next write to the page, which will block and generate another write-protect userfault message. This is used only when bothUFFDIO_REGISTER_MODE_MISSINGandUFFDIO_REGISTER_MODE_WPmodes are enabled for the registered range. read-only permission is literally the "look but don't touch" of memory π«£
The copy field is used by the kernel to return the number of bytes that was actually copied, or an error (a negated errno-style value). The copy field is output-only; it is not read by the UFFDIO_COPY operation. so don't go writing into it and expecting the kernel to care, she's not reading it, periodt π
β RETURN VALUE β
On success, 0 is returned. In this case, the entire area was copied. the whole thing. all of it. ate and left no crumbs π
On error, -1 is returned and errno is set to indicate the error. classic π
π₯ ERRORS π₯
EAGAINβ The number of bytes copied (i.e., the value returned in thecopyfield) does not equal the value that was specified in thelenfield. she did NOT copy the full amount bestie, vibe check failed.EINVALβ Eitherdstorlenwas not a multiple of the system page size, or the range specified bysrcandlenordstandlenwas invalid. page size multiples only, we don't do chaos here (well, we do, but not this kind).EINVALβ An invalid bit was specified in themodefield. unknown flag? absolutely not.ENOENT(since Linux 4.11) β The faulting process has changed its virtual memory layout simultaneously with an outstandingUFFDIO_COPYoperation. she moved while you were mid-copy, rude tbh.ENOSPC(from Linux 4.11 until Linux 4.13) β The faulting process has exited at the time of aUFFDIO_COPYoperation.ESRCH(since Linux 4.13) β The faulting process has exited at the time of aUFFDIO_COPYoperation.
(girl left the chat mid-operation, it happens π)
π STANDARDS π
Linux. that's it, that's the standard. slay.
π°οΈ HISTORY π°οΈ
Linux 4.3. vintage but make it iconic β¨
πΈ EXAMPLES πΈ
See userfaultfd(2). the examples live over there, go visit her π
π¦ SEE ALSO π¦
linux.git/Documentation/admin-guide/mm/userfaultfd.rst
okay that's the whole page bestie, you're officially a userfaultfd girlie now π
this was Linux man-pages 6.20, dated 2026-02-08, and it's the UFFDIO_COPY(2const) manual page β go forth and atomically copy, ily π«Άπβ¨
π¦ 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