mm/memfd.c
Source file repositories/reference/linux-study-clean/mm/memfd.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memfd.c- Extension
.c- Size
- 13213 bytes
- Lines
- 524
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/vfs.hlinux/pagemap.hlinux/file.hlinux/mm.hlinux/sched/signal.hlinux/khugepaged.hlinux/syscalls.hlinux/hugetlb.hlinux/shmem_fs.hlinux/memfd.hlinux/pid_namespace.huapi/linux/memfd.hswap.h
Detected Declarations
syscall memfd_createfunction memfd_folio_has_extra_refsfunction memfd_tag_pinsfunction memfd_pin_user_pagesfunction get_user_pagesfunction xas_for_each_markedfunction memfd_add_sealsfunction memfd_get_sealsfunction memfd_fcntlfunction check_sysctl_memfd_noexecfunction is_write_sealedfunction check_write_sealfunction memfd_check_seals_mmapfunction sanitize_flags
Annotated Snippet
SYSCALL_DEFINE2(memfd_create,
const char __user *, uname,
unsigned int, flags)
{
char *name __free(kfree) = NULL;
unsigned int fd_flags;
int error;
error = sanitize_flags(&flags);
if (error < 0)
return error;
name = alloc_name(uname);
if (IS_ERR(name))
return PTR_ERR(name);
fd_flags = (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0;
return FD_ADD(fd_flags, memfd_alloc_file(name, flags));
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/vfs.h`, `linux/pagemap.h`, `linux/file.h`, `linux/mm.h`, `linux/sched/signal.h`, `linux/khugepaged.h`, `linux/syscalls.h`.
- Detected declarations: `syscall memfd_create`, `function memfd_folio_has_extra_refs`, `function memfd_tag_pins`, `function memfd_pin_user_pages`, `function get_user_pages`, `function xas_for_each_marked`, `function memfd_add_seals`, `function memfd_get_seals`, `function memfd_fcntl`, `function check_sysctl_memfd_noexec`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.