mm/mincore.c
Source file repositories/reference/linux-study-clean/mm/mincore.c
File Facts
- System
- Linux kernel
- Corpus path
mm/mincore.c- Extension
.c- Size
- 8684 bytes
- Lines
- 344
- 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.
- 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/pagemap.hlinux/gfp.hlinux/pagewalk.hlinux/mman.hlinux/syscalls.hlinux/swap.hlinux/leafops.hlinux/shmem_fs.hlinux/hugetlb.hlinux/pgtable.hlinux/uaccess.hswap.hinternal.h
Detected Declarations
syscall mincorefunction Copyrightfunction mincore_swapfunction mincore_pagefunction __mincore_unmapped_rangefunction mincore_unmapped_rangefunction mincore_pte_rangefunction can_do_mincorefunction do_mincorefunction mincore
Annotated Snippet
SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len,
unsigned char __user *, vec)
{
long retval;
unsigned long pages;
unsigned char *tmp;
start = untagged_addr(start);
/* Check the start address: needs to be page-aligned.. */
if (unlikely(start & ~PAGE_MASK))
return -EINVAL;
/* ..and we need to be passed a valid user-space range */
if (!access_ok((void __user *) start, len))
return -ENOMEM;
/* This also avoids any overflows on PAGE_ALIGN */
pages = len >> PAGE_SHIFT;
pages += (offset_in_page(len)) != 0;
if (!access_ok(vec, pages))
return -EFAULT;
tmp = (void *) __get_free_page(GFP_USER);
if (!tmp)
return -EAGAIN;
retval = 0;
while (pages) {
/*
* Do at most PAGE_SIZE entries per iteration, due to
* the temporary buffer size.
*/
mmap_read_lock(current->mm);
retval = do_mincore(start, min(pages, PAGE_SIZE), tmp);
mmap_read_unlock(current->mm);
if (retval <= 0)
break;
if (copy_to_user(vec, tmp, retval)) {
retval = -EFAULT;
break;
}
pages -= retval;
vec += retval;
start += retval << PAGE_SHIFT;
retval = 0;
}
free_page((unsigned long) tmp);
return retval;
}
Annotation
- Immediate include surface: `linux/pagemap.h`, `linux/gfp.h`, `linux/pagewalk.h`, `linux/mman.h`, `linux/syscalls.h`, `linux/swap.h`, `linux/leafops.h`, `linux/shmem_fs.h`.
- Detected declarations: `syscall mincore`, `function Copyright`, `function mincore_swap`, `function mincore_page`, `function __mincore_unmapped_range`, `function mincore_unmapped_range`, `function mincore_pte_range`, `function can_do_mincore`, `function do_mincore`, `function mincore`.
- 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.
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.