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 both UFFDIO_REGISTER_MODE_MISSING and UFFDIO_REGISTER_MODE_WP modes 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 the copy field) does not equal the value that was specified in the len field. she did NOT copy the full amount bestie, vibe check failed.
  • EINVAL β€” Either dst or len was not a multiple of the system page size, or the range specified by src and len or dst and len was 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 the mode field. unknown flag? absolutely not.
  • ENOENT (since Linux 4.11) β€” The faulting process has changed its virtual memory layout simultaneously with an outstanding UFFDIO_COPY operation. 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 a UFFDIO_COPY operation.
  • ESRCH (since Linux 4.13) β€” The faulting process has exited at the time of a UFFDIO_COPY operation.

(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms