File: prctl-riscv-icache-flush-ctx.c

package info (click to toggle)
strace 6.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 71,488 kB
  • sloc: ansic: 176,497; sh: 9,675; makefile: 4,133; cpp: 885; awk: 353; perl: 267; exp: 62; sed: 9
file content (65 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Check decoding of prctl PR_RISCV_V_SET_CONTROL and PR_RISCV_V_GET_CONTROL
 * operations.
 *
 * Copyright (c) 2024 Eugene Syromyatnikov <evgsyr@gmail.com>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include "scno.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/prctl.h>


int
main(void)
{
	static const struct strval_klong ctx_args[] = {
		{ 0, "PR_RISCV_CTX_SW_FENCEI_ON" },
		{ 1, "PR_RISCV_CTX_SW_FENCEI_OFF" },
		{ 2, NULL },
		{ 3, NULL },
		{ 23, NULL },
		{ 0xdeadbeef, NULL },
		{ (kernel_ulong_t) -1ULL, NULL },
	};
	static const struct strval_klong scope_args[] = {
		{ 0, "PR_RISCV_SCOPE_PER_PROCESS" },
		{ 1, "PR_RISCV_SCOPE_PER_THREAD" },
		{ 2, NULL },
		{ 3, NULL },
		{ 42, NULL },
		{ 0xcafefeed, NULL },
		{ (kernel_ulong_t) -2ULL, NULL },
	};

	prctl_marker();

	for (size_t i = 0; i < ARRAY_SIZE(ctx_args); i++) {
		for (size_t j = 0; j < ARRAY_SIZE(scope_args); j++) {
			long rc = syscall(__NR_prctl,
					  PR_RISCV_SET_ICACHE_FLUSH_CTX,
					  ctx_args[i].val, scope_args[j].val,
					  0xbadc0de, 0xbadc0ded);
			const char *errstr = sprintrc(rc);

			printf("prctl("
			       XLAT_KNOWN(0x47, "PR_RISCV_SET_ICACHE_FLUSH_CTX"));
			printf(", %s, ", sprintxlat(ctx_args[i].str,
						  ctx_args[i].val,
						  "PR_RISCV_CTX_???"));
			printf("%s) = ", sprintxlat(scope_args[j].str,
						  scope_args[j].val,
						  "PR_RISCV_SCOPE_???"));
			puts(errstr);
		}
	}

	puts("+++ exited with 0 +++");
	return 0;
}