tools/testing/selftests/riscv/abi/pointer_masking.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/riscv/abi/pointer_masking.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/riscv/abi/pointer_masking.c- Extension
.c- Size
- 8337 bytes
- Lines
- 349
- 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
errno.hfcntl.hsetjmp.hsignal.hstdbool.hsys/prctl.hsys/wait.hunistd.hkselftest.h
Detected Declarations
function sigsegv_handlerfunction valid_pmlenfunction test_pmlenfunction set_tagged_addr_ctrlfunction test_dereference_pmlenfunction test_dereferencefunction execve_child_sigsegv_handlerfunction execve_childfunction test_fork_execfunction execvefunction pwrite_wrapperfunction test_tagged_addr_abi_sysctlfunction test_tagged_addr_abi_pmlenfunction test_tagged_addr_abifunction main
Annotated Snippet
execve("/proc/self/exe", (char *const []) { "", NULL }, NULL);
}
}
static bool pwrite_wrapper(int fd, void *buf, size_t count, const char *msg)
{
int ret = pwrite(fd, buf, count, 0);
if (ret != count) {
ksft_perror(msg);
return false;
}
return true;
}
static void test_tagged_addr_abi_sysctl(void)
{
char *err_pwrite_msg = "failed to write to /proc/sys/abi/tagged_addr_disabled\n";
char value;
int fd;
ksft_print_msg("Testing tagged address ABI sysctl\n");
fd = open("/proc/sys/abi/tagged_addr_disabled", O_WRONLY);
if (fd < 0) {
ksft_test_result_skip("failed to open sysctl file\n");
ksft_test_result_skip("failed to open sysctl file\n");
return;
}
value = '1';
if (!pwrite_wrapper(fd, &value, 1, "write '1'"))
ksft_test_result_fail(err_pwrite_msg);
else
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
"sysctl disabled\n");
value = '0';
if (!pwrite_wrapper(fd, &value, 1, "write '0'"))
ksft_test_result_fail(err_pwrite_msg);
else
ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0,
"sysctl enabled\n");
set_tagged_addr_ctrl(0, false);
close(fd);
}
static void test_tagged_addr_abi_pmlen(int pmlen)
{
int i, *p, ret;
i = ~pmlen;
if (pmlen) {
p = (int *)((uintptr_t)&i | 1UL << (__riscv_xlen - pmlen));
ret = set_tagged_addr_ctrl(pmlen, false);
if (ret)
return ksft_test_result_error("PMLEN=%d ABI disabled setup (%d)\n",
pmlen, ret);
ret = write(pipefd[1], p, sizeof(*p));
if (ret >= 0 || errno != EFAULT)
return ksft_test_result_fail("PMLEN=%d ABI disabled write\n", pmlen);
ret = read(dev_zero, p, sizeof(*p));
if (ret >= 0 || errno != EFAULT)
return ksft_test_result_fail("PMLEN=%d ABI disabled read\n", pmlen);
if (i != ~pmlen)
return ksft_test_result_fail("PMLEN=%d ABI disabled value\n", pmlen);
ret = set_tagged_addr_ctrl(pmlen, true);
if (ret)
return ksft_test_result_error("PMLEN=%d ABI enabled setup (%d)\n",
pmlen, ret);
ret = write(pipefd[1], p, sizeof(*p));
if (ret != sizeof(*p))
return ksft_test_result_fail("PMLEN=%d ABI enabled write\n", pmlen);
ret = read(dev_zero, p, sizeof(*p));
if (ret != sizeof(*p))
return ksft_test_result_fail("PMLEN=%d ABI enabled read\n", pmlen);
if (i)
return ksft_test_result_fail("PMLEN=%d ABI enabled value\n", pmlen);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `setjmp.h`, `signal.h`, `stdbool.h`, `sys/prctl.h`, `sys/wait.h`, `unistd.h`.
- Detected declarations: `function sigsegv_handler`, `function valid_pmlen`, `function test_pmlen`, `function set_tagged_addr_ctrl`, `function test_dereference_pmlen`, `function test_dereference`, `function execve_child_sigsegv_handler`, `function execve_child`, `function test_fork_exec`, `function execve`.
- 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.