tools/testing/selftests/powerpc/dexcr/chdexcr.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/dexcr/chdexcr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/dexcr/chdexcr.c- Extension
.c- Size
- 2587 bytes
- Lines
- 113
- 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.hstddef.hstdio.hstdlib.hstring.hsys/prctl.hdexcr.hutils.h
Detected Declarations
function diefunction helpfunction apply_optionfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include "dexcr.h"
#include "utils.h"
static void die(const char *msg)
{
printf("%s\n", msg);
exit(1);
}
static void help(void)
{
printf("Invoke a provided program with a custom DEXCR on-exec reset value\n"
"\n"
"usage: chdexcr [CHDEXCR OPTIONS] -- PROGRAM [ARGS...]\n"
"\n"
"Each configurable DEXCR aspect is exposed as an option.\n"
"\n"
"The normal option sets the aspect in the DEXCR. The --no- variant\n"
"clears that aspect. For example, --ibrtpd sets the IBRTPD aspect bit,\n"
"so indirect branch prediction will be disabled in the provided program.\n"
"Conversely, --no-ibrtpd clears the aspect bit, so indirect branch\n"
"prediction may occur.\n"
"\n"
"CHDEXCR OPTIONS:\n");
for (int i = 0; i < ARRAY_SIZE(aspects); i++) {
const struct dexcr_aspect *aspect = &aspects[i];
if (aspect->prctl == -1)
continue;
printf(" --%-6s / --no-%-6s : %s\n", aspect->opt, aspect->opt, aspect->desc);
}
}
static const struct dexcr_aspect *opt_to_aspect(const char *opt)
{
for (int i = 0; i < ARRAY_SIZE(aspects); i++)
if (aspects[i].prctl != -1 && !strcmp(aspects[i].opt, opt))
return &aspects[i];
return NULL;
}
static int apply_option(const char *option)
{
const struct dexcr_aspect *aspect;
const char *opt = NULL;
const char *set_prefix = "--";
const char *clear_prefix = "--no-";
unsigned long ctrl = 0;
int err;
if (!strcmp(option, "-h") || !strcmp(option, "--help")) {
help();
exit(0);
}
/* Strip out --(no-) prefix and determine ctrl value */
if (!strncmp(option, clear_prefix, strlen(clear_prefix))) {
opt = &option[strlen(clear_prefix)];
ctrl |= PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC;
} else if (!strncmp(option, set_prefix, strlen(set_prefix))) {
opt = &option[strlen(set_prefix)];
ctrl |= PR_PPC_DEXCR_CTRL_SET_ONEXEC;
}
if (!opt || !*opt)
return 1;
aspect = opt_to_aspect(opt);
if (!aspect)
die("unknown aspect");
err = pr_set_dexcr(aspect->prctl, ctrl);
if (err)
die("failed to apply option");
return 0;
}
Annotation
- Immediate include surface: `errno.h`, `stddef.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/prctl.h`, `dexcr.h`, `utils.h`.
- Detected declarations: `function die`, `function help`, `function apply_option`, `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.