tools/testing/selftests/mm/mlock2-tests.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/mlock2-tests.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/mlock2-tests.c- Extension
.c- Size
- 13009 bytes
- Lines
- 523
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/mman.hlinux/mman.hstdint.hunistd.hstring.hsys/time.hsys/resource.hstdbool.hkselftest.hmlock2.h
Detected Declarations
struct vm_boundariesfunction get_vm_areafunction is_vmflag_setfunction get_value_for_namefunction is_vma_lock_on_faultfunction lock_checkfunction unlock_lock_checkfunction test_mlock_lockfunction onfault_checkfunction unlock_onfault_checkfunction test_mlock_onfaultfunction test_lock_onfault_of_presentfunction test_munlockall0function test_munlockall1function test_mlock_droppablefunction test_mlockall_future_droppablefunction test_vma_managementfunction test_mlockallfunction main
Annotated Snippet
struct vm_boundaries {
unsigned long start;
unsigned long end;
};
static int get_vm_area(unsigned long addr, struct vm_boundaries *area)
{
FILE *file;
int ret = 1;
char line[1024] = {0};
unsigned long start;
unsigned long end;
if (!area)
return ret;
file = fopen("/proc/self/maps", "r");
if (!file) {
perror("fopen");
return ret;
}
memset(area, 0, sizeof(struct vm_boundaries));
while(fgets(line, 1024, file)) {
if (sscanf(line, "%lx-%lx", &start, &end) != 2) {
ksft_print_msg("cannot parse /proc/self/maps\n");
goto out;
}
if (start <= addr && end > addr) {
area->start = start;
area->end = end;
ret = 0;
goto out;
}
}
out:
fclose(file);
return ret;
}
#define VMFLAGS "VmFlags:"
static bool is_vmflag_set(unsigned long addr, const char *vmflag)
{
char *line = NULL;
char *flags;
size_t size = 0;
bool ret = false;
FILE *smaps;
smaps = seek_to_smaps_entry(addr);
if (!smaps) {
ksft_print_msg("Unable to parse /proc/self/smaps\n");
goto out;
}
while (getline(&line, &size, smaps) > 0) {
if (!strstr(line, VMFLAGS)) {
free(line);
line = NULL;
size = 0;
continue;
}
flags = line + strlen(VMFLAGS);
ret = (strstr(flags, vmflag) != NULL);
goto out;
}
out:
free(line);
fclose(smaps);
return ret;
}
#define SIZE "Size:"
#define RSS "Rss:"
#define LOCKED "lo"
static unsigned long get_value_for_name(unsigned long addr, const char *name)
{
char *line = NULL;
size_t size = 0;
char *value_ptr;
FILE *smaps = NULL;
unsigned long value = -1UL;
smaps = seek_to_smaps_entry(addr);
Annotation
- Immediate include surface: `sys/mman.h`, `linux/mman.h`, `stdint.h`, `unistd.h`, `string.h`, `sys/time.h`, `sys/resource.h`, `stdbool.h`.
- Detected declarations: `struct vm_boundaries`, `function get_vm_area`, `function is_vmflag_set`, `function get_value_for_name`, `function is_vma_lock_on_fault`, `function lock_check`, `function unlock_lock_check`, `function test_mlock_lock`, `function onfault_check`, `function unlock_onfault_check`.
- 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.