tools/testing/selftests/mm/mseal_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/mseal_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/mseal_test.c- Extension
.c- Size
- 45686 bytes
- Lines
- 1990
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
linux/mman.hsys/mman.hstdint.hasm-generic/unistd.hstring.hsys/time.hsys/resource.hstdbool.hkselftest.hsyscall.herrno.hstdio.hstdlib.hfcntl.hsys/ioctl.hsys/vfs.hsys/stat.hmseal_helpers.h
Detected Declarations
function get_vma_sizefunction sys_msealfunction sys_mprotectfunction sys_mprotect_pkeyfunction sys_munmapfunction sys_madvisefunction sys_pkey_allocfunction __read_pkey_regfunction __write_pkey_regfunction pkey_bit_positionfunction set_pkey_bitsfunction set_pkeyfunction setup_single_addressfunction setup_single_address_rwfunction clean_single_addressfunction seal_single_addressfunction seal_supportfunction pkey_supportedfunction test_seal_addsealfunction test_seal_unmapped_startfunction test_seal_unmapped_middlefunction test_seal_unmapped_endfunction test_seal_multiple_vmasfunction test_seal_split_startfunction test_seal_split_endfunction test_seal_invalid_inputfunction test_seal_zero_lengthfunction test_seal_zero_addressfunction test_seal_twicefunction test_seal_mprotectfunction test_seal_start_mprotectfunction test_seal_end_mprotectfunction test_seal_mprotect_unalign_lenfunction test_seal_mprotect_unalign_len_variant_2function test_seal_mprotect_two_vmafunction test_seal_mprotect_two_vma_with_splitfunction test_seal_mprotect_partial_mprotectfunction test_seal_mprotect_partial_mprotect_tailfunction test_seal_mprotect_two_vma_with_gapfunction test_seal_mprotect_splitfunction test_seal_mprotect_mergefunction test_seal_munmapfunction test_seal_munmap_two_vmafunction test_seal_munmap_vma_with_gapfunction test_seal_munmap_partial_across_vmasfunction test_munmap_start_freedfunction test_munmap_end_freedfunction test_munmap_middle_freed
Annotated Snippet
if (sscanf(line, "%lx-%lx %4s", &addr_start, &addr_end, protstr) == 3) {
if (addr_start == (uintptr_t) addr) {
size = addr_end - addr_start;
if (protstr[0] == 'r')
*prot |= 0x4;
if (protstr[1] == 'w')
*prot |= 0x2;
if (protstr[2] == 'x')
*prot |= 0x1;
break;
}
}
}
fclose(maps);
return size;
}
/*
* define sys_xyx to call syscall directly.
*/
static int sys_mseal(void *start, size_t len)
{
int sret;
errno = 0;
sret = syscall(__NR_mseal, start, len, 0);
return sret;
}
static int sys_mprotect(void *ptr, size_t size, unsigned long prot)
{
int sret;
errno = 0;
sret = syscall(__NR_mprotect, ptr, size, prot);
return sret;
}
static int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
unsigned long pkey)
{
int sret;
errno = 0;
sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey);
return sret;
}
static int sys_munmap(void *ptr, size_t size)
{
int sret;
errno = 0;
sret = syscall(__NR_munmap, ptr, size);
return sret;
}
static int sys_madvise(void *start, size_t len, int types)
{
int sret;
errno = 0;
sret = syscall(__NR_madvise, start, len, types);
return sret;
}
static void *sys_mremap(void *addr, size_t old_len, size_t new_len,
unsigned long flags, void *new_addr)
{
void *sret;
errno = 0;
sret = (void *) syscall(__NR_mremap, addr, old_len, new_len, flags, new_addr);
return sret;
}
static int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
{
int ret = syscall(__NR_pkey_alloc, flags, init_val);
return ret;
}
static unsigned int __read_pkey_reg(void)
{
unsigned int pkey_reg = 0;
#if defined(__i386__) || defined(__x86_64__) /* arch */
unsigned int eax, edx;
unsigned int ecx = 0;
Annotation
- Immediate include surface: `linux/mman.h`, `sys/mman.h`, `stdint.h`, `asm-generic/unistd.h`, `string.h`, `sys/time.h`, `sys/resource.h`, `stdbool.h`.
- Detected declarations: `function get_vma_size`, `function sys_mseal`, `function sys_mprotect`, `function sys_mprotect_pkey`, `function sys_munmap`, `function sys_madvise`, `function sys_pkey_alloc`, `function __read_pkey_reg`, `function __write_pkey_reg`, `function pkey_bit_position`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.