tools/testing/selftests/mm/pfnmap.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/pfnmap.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/pfnmap.c- Extension
.c- Size
- 6357 bytes
- Lines
- 289
- 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
stdlib.hstring.hstdint.hunistd.herrno.hstdio.hctype.hfcntl.hsignal.hsetjmp.hlinux/mman.hsys/mman.hsys/wait.hkselftest_harness.hvm_util.h
Detected Declarations
function signal_handlerfunction test_read_accessfunction find_ram_targetfunction pfnmap_initfunction main
Annotated Snippet
if (end > start + DEV_MEM_NPAGES * pagesize) {
fclose(file);
*offset = start;
return 0;
}
}
return -ENOENT;
}
static void pfnmap_init(void)
{
size_t pagesize = getpagesize();
size_t size = DEV_MEM_NPAGES * pagesize;
void *addr;
if (strncmp(file, "/dev/mem", strlen("/dev/mem")) == 0) {
int err = find_ram_target(&file_offset, pagesize);
if (err)
ksft_exit_skip("Cannot find ram target in '/proc/iomem': %s\n",
strerror(-err));
} else {
file_offset = 0;
}
fd = open(file, O_RDONLY);
if (fd < 0)
ksft_exit_skip("Cannot open '%s': %s\n", file, strerror(errno));
/*
* Make sure we can map the file, and perform some basic checks; skip
* the whole suite if anything goes wrong.
* A fresh mapping is then created for every test case by
* FIXTURE_SETUP(pfnmap).
*/
addr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, file_offset);
if (addr == MAP_FAILED)
ksft_exit_skip("Cannot mmap '%s': %s\n", file, strerror(errno));
if (!check_vmflag_pfnmap(addr))
ksft_exit_skip("Invalid file: '%s'. Not pfnmap'ed\n", file);
if (test_read_access(addr, size, pagesize))
ksft_exit_skip("Cannot read-access mmap'ed '%s'\n", file);
munmap(addr, size);
}
FIXTURE(pfnmap)
{
size_t pagesize;
char *addr1;
size_t size1;
char *addr2;
size_t size2;
};
FIXTURE_SETUP(pfnmap)
{
self->pagesize = getpagesize();
self->size1 = DEV_MEM_NPAGES * self->pagesize;
self->addr1 = mmap(NULL, self->size1, PROT_READ, MAP_SHARED,
fd, file_offset);
ASSERT_NE(self->addr1, MAP_FAILED);
self->size2 = 0;
self->addr2 = MAP_FAILED;
}
FIXTURE_TEARDOWN(pfnmap)
{
if (self->addr2 != MAP_FAILED)
munmap(self->addr2, self->size2);
if (self->addr1 != MAP_FAILED)
munmap(self->addr1, self->size1);
}
TEST_F(pfnmap, madvise_disallowed)
{
int advices[] = {
MADV_DONTNEED,
MADV_DONTNEED_LOCKED,
MADV_FREE,
MADV_WIPEONFORK,
MADV_COLD,
MADV_PAGEOUT,
MADV_POPULATE_READ,
MADV_POPULATE_WRITE,
};
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `stdint.h`, `unistd.h`, `errno.h`, `stdio.h`, `ctype.h`, `fcntl.h`.
- Detected declarations: `function signal_handler`, `function test_read_access`, `function find_ram_target`, `function pfnmap_init`, `function main`.
- 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.