mm/mprotect.c
Source file repositories/reference/linux-study-clean/mm/mprotect.c
File Facts
- System
- Linux kernel
- Corpus path
mm/mprotect.c- Extension
.c- Size
- 28372 bytes
- Lines
- 1045
- 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.
- 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/pagewalk.hlinux/hugetlb.hlinux/shm.hlinux/mman.hlinux/fs.hlinux/highmem.hlinux/security.hlinux/mempolicy.hlinux/personality.hlinux/syscalls.hlinux/swap.hlinux/swapops.hlinux/mmu_notifier.hlinux/migrate.hlinux/perf_event.hlinux/pkeys.hlinux/ksm.hlinux/uaccess.hlinux/mm_inline.hlinux/pgtable.hlinux/userfaultfd_k.huapi/linux/mman.hasm/cacheflush.hasm/mmu_context.hasm/tlbflush.hasm/tlb.hinternal.h
Detected Declarations
syscall mprotectsyscall pkey_mprotectsyscall pkey_allocsyscall pkey_freefunction maybe_change_pte_writablefunction can_change_private_pte_writablefunction can_change_shared_pte_writablefunction can_change_pte_writablefunction mprotect_folio_pte_batchfunction prot_commit_flush_ptesfunction PageAnonExclusivefunction commit_anon_folio_batchfunction set_write_prot_commit_flush_ptesfunction change_softleaf_ptefunction change_present_ptesfunction change_pte_rangefunction pgtable_split_neededfunction pgtable_populate_neededfunction change_pmd_rangefunction change_pud_rangefunction change_p4d_rangefunction change_protection_rangefunction change_protectionfunction prot_none_pte_entryfunction prot_none_hugetlb_entryfunction prot_none_testfunction mprotect_fixupfunction vma_flags_test_anyfunction butfunction vma_is_anonymousfunction do_mprotect_pkey
Annotated Snippet
SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
unsigned long, prot)
{
return do_mprotect_pkey(start, len, prot, -1);
}
#ifdef CONFIG_ARCH_HAS_PKEYS
SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len,
unsigned long, prot, int, pkey)
{
return do_mprotect_pkey(start, len, prot, pkey);
}
SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val)
{
int pkey;
int ret;
/* No flags supported yet. */
if (flags)
return -EINVAL;
/* check for unsupported init values */
if (init_val & ~PKEY_ACCESS_MASK)
return -EINVAL;
mmap_write_lock(current->mm);
pkey = mm_pkey_alloc(current->mm);
ret = -ENOSPC;
if (pkey == -1)
goto out;
ret = arch_set_user_pkey_access(pkey, init_val);
if (ret) {
mm_pkey_free(current->mm, pkey);
goto out;
}
ret = pkey;
out:
mmap_write_unlock(current->mm);
return ret;
}
SYSCALL_DEFINE1(pkey_free, int, pkey)
{
int ret;
mmap_write_lock(current->mm);
ret = mm_pkey_free(current->mm, pkey);
mmap_write_unlock(current->mm);
/*
* We could provide warnings or errors if any VMA still
* has the pkey set here.
*/
return ret;
}
#endif /* CONFIG_ARCH_HAS_PKEYS */
Annotation
- Immediate include surface: `linux/pagewalk.h`, `linux/hugetlb.h`, `linux/shm.h`, `linux/mman.h`, `linux/fs.h`, `linux/highmem.h`, `linux/security.h`, `linux/mempolicy.h`.
- Detected declarations: `syscall mprotect`, `syscall pkey_mprotect`, `syscall pkey_alloc`, `syscall pkey_free`, `function maybe_change_pte_writable`, `function can_change_private_pte_writable`, `function can_change_shared_pte_writable`, `function can_change_pte_writable`, `function mprotect_folio_pte_batch`, `function prot_commit_flush_ptes`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
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.