tools/testing/selftests/mm/mdwe_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/mdwe_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/mdwe_test.c- Extension
.c- Size
- 6435 bytes
- Lines
- 304
- 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
asm/hwcap.hlinux/mman.hlinux/prctl.hstdio.hstdlib.hsys/auxv.hsys/prctl.hsys/wait.hunistd.hkselftest_harness.h
Detected Declarations
function executable_map_should_failfunction ASSERT_GE
Annotated Snippet
ASSERT_GE(self->pid, 0) {
TH_LOG("fork failed\n");
}
if (self->pid > 0) {
ret = waitpid(self->pid, &status, 0);
ASSERT_TRUE(WIFEXITED(status));
exit(WEXITSTATUS(status));
}
}
}
FIXTURE_TEARDOWN(mdwe)
{
if (self->p && self->p != MAP_FAILED)
munmap(self->p, self->size);
}
TEST_F(mdwe, mmap_READ_EXEC)
{
self->p = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0);
EXPECT_NE(self->p, MAP_FAILED);
}
TEST_F(mdwe, mmap_WRITE_EXEC)
{
self->p = mmap(NULL, self->size, PROT_WRITE | PROT_EXEC, self->flags, 0, 0);
if (executable_map_should_fail(variant)) {
EXPECT_EQ(self->p, MAP_FAILED);
} else {
EXPECT_NE(self->p, MAP_FAILED);
}
}
TEST_F(mdwe, mprotect_stay_EXEC)
{
int ret;
self->p = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED);
ret = mprotect(self->p, self->size, PROT_READ | PROT_EXEC);
EXPECT_EQ(ret, 0);
}
TEST_F(mdwe, mprotect_add_EXEC)
{
int ret;
self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED);
ret = mprotect(self->p, self->size, PROT_READ | PROT_EXEC);
if (executable_map_should_fail(variant)) {
EXPECT_LT(ret, 0);
} else {
EXPECT_EQ(ret, 0);
}
}
TEST_F(mdwe, mprotect_WRITE_EXEC)
{
int ret;
self->p = mmap(NULL, self->size, PROT_WRITE, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED);
ret = mprotect(self->p, self->size, PROT_WRITE | PROT_EXEC);
if (executable_map_should_fail(variant)) {
EXPECT_LT(ret, 0);
} else {
EXPECT_EQ(ret, 0);
}
}
TEST_F(mdwe, mmap_FIXED)
{
void *p;
self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED);
/* MAP_FIXED unmaps the existing page before mapping which is allowed */
p = mmap(self->p, self->size, PROT_READ | PROT_EXEC,
self->flags | MAP_FIXED, 0, 0);
EXPECT_EQ(p, self->p);
}
TEST_F(mdwe, arm64_BTI)
{
Annotation
- Immediate include surface: `asm/hwcap.h`, `linux/mman.h`, `linux/prctl.h`, `stdio.h`, `stdlib.h`, `sys/auxv.h`, `sys/prctl.h`, `sys/wait.h`.
- Detected declarations: `function executable_map_should_fail`, `function ASSERT_GE`.
- 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.