mm/secretmem.c
Source file repositories/reference/linux-study-clean/mm/secretmem.c
File Facts
- System
- Linux kernel
- Corpus path
mm/secretmem.c- Extension
.c- Size
- 6232 bytes
- Lines
- 269
- 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.
- 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/mm.hlinux/fs.hlinux/swap.hlinux/mount.hlinux/memfd.hlinux/bitops.hlinux/printk.hlinux/pagemap.hlinux/syscalls.hlinux/pseudo_fs.hlinux/secretmem.hlinux/set_memory.hlinux/sched/signal.huapi/linux/magic.hasm/tlbflush.hinternal.h
Detected Declarations
syscall memfd_secretfunction secretmem_activefunction secretmem_faultfunction secretmem_releasefunction secretmem_mmap_preparefunction vma_is_secretmemfunction secretmem_migrate_foliofunction secretmem_free_foliofunction secretmem_setattrfunction secretmem_init_fs_contextfunction secretmem_initmodule init secretmem_init
Annotated Snippet
SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)
{
/* make sure local flags do not conflict with global fcntl.h */
BUILD_BUG_ON(SECRETMEM_FLAGS_MASK & O_CLOEXEC);
if (!secretmem_enable || !can_set_direct_map())
return -ENOSYS;
if (flags & ~(SECRETMEM_FLAGS_MASK | O_CLOEXEC))
return -EINVAL;
if (atomic_read(&secretmem_users) < 0)
return -ENFILE;
return FD_ADD(flags & O_CLOEXEC, secretmem_file_create(flags));
}
static int secretmem_init_fs_context(struct fs_context *fc)
{
struct pseudo_fs_context *ctx;
ctx = init_pseudo(fc, SECRETMEM_MAGIC);
if (!ctx)
return -ENOMEM;
return 0;
}
static struct file_system_type secretmem_fs = {
.name = "secretmem",
.init_fs_context = secretmem_init_fs_context,
.kill_sb = kill_anon_super,
};
static int __init secretmem_init(void)
{
if (!secretmem_enable || !can_set_direct_map())
return 0;
secretmem_mnt = kern_mount(&secretmem_fs);
if (IS_ERR(secretmem_mnt))
return PTR_ERR(secretmem_mnt);
return 0;
}
fs_initcall(secretmem_init);
Annotation
- Immediate include surface: `linux/mm.h`, `linux/fs.h`, `linux/swap.h`, `linux/mount.h`, `linux/memfd.h`, `linux/bitops.h`, `linux/printk.h`, `linux/pagemap.h`.
- Detected declarations: `syscall memfd_secret`, `function secretmem_active`, `function secretmem_fault`, `function secretmem_release`, `function secretmem_mmap_prepare`, `function vma_is_secretmem`, `function secretmem_migrate_folio`, `function secretmem_free_folio`, `function secretmem_setattr`, `function secretmem_init_fs_context`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
- 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.