1 /*
2 * Check decoding of ioprio_get and ioprio_set syscalls.
3 *
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2020 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13 #include "pidns.h"
14
15 #if defined(__NR_ioprio_get) && defined(__NR_ioprio_set)
16
17 # include <stdio.h>
18 # include <unistd.h>
19
20 enum {
21 IOPRIO_CLASS_NONE,
22 IOPRIO_CLASS_RT,
23 IOPRIO_CLASS_BE,
24 IOPRIO_CLASS_IDLE
25 };
26
27 # include "xlat.h"
28 # include "xlat/ioprio_class.h"
29
30 int
31 main(void)
32 {
33 PIDNS_TEST_INIT;
34
35 static const kernel_ulong_t bogus_which =
36 (kernel_ulong_t) 0xdeadfacefa57beefULL;
37 static const kernel_ulong_t bogus_who =
38 (kernel_ulong_t) 0xbadc0dedda7a1057ULL;
39 static const kernel_ulong_t bogus_ioprio =
40 (kernel_ulong_t) 0xdec0ded1facefeedULL;
41
42 const int pid = getpid();
43 const int pgid = getpgid(0);
44
45 # if !XLAT_RAW
46 static const char * const bogus_ioprio_str =
47 "IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
48 # endif
49
50 long rc;
51 const char *errstr;
52
53 rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
54 errstr = sprintrc(rc);
55 pidns_print_leader();
56 # if XLAT_RAW
57 printf("ioprio_get(%#x, %d) = %s\n",
58 (int) bogus_which, (int) bogus_who, errstr);
59 # else /* XLAT_ABBREV || XLAT_VERBOSE */
60 printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n",
61 (int) bogus_which, (int) bogus_who, errstr);
62 # endif
63
64 rc = syscall(__NR_ioprio_get, 1, pid);
65 errstr = sprintrc(rc);
66 pidns_print_leader();
67 printf("ioprio_get(");
68 # if XLAT_RAW
69 printf("0x1, ");
70 # elif XLAT_VERBOSE
71 printf("0x1 /* IOPRIO_WHO_PROCESS */, ");
72 # else /* XLAT_ABBREV */
73 printf("IOPRIO_WHO_PROCESS, ");
74 # endif
75 printf("%d%s) = %s", pid, pidns_pid2str(PT_TGID), errstr);
76 # if !XLAT_RAW
77 if (rc >= 0) {
78 printf(" (IOPRIO_PRIO_VALUE(");
79 printxval(ioprio_class, (unsigned int) rc >> 13,
80 "IOPRIO_CLASS_???");
81 printf(", %u))", (unsigned int) rc & 0x1fff);
82 }
83 # endif
84 puts("");
85
86 rc = syscall(__NR_ioprio_set, 2, pgid, 8191);
87 errstr = sprintrc(rc);
88 pidns_print_leader();
89 printf("ioprio_set(");
90 # if XLAT_RAW
91 printf("%#x", 2);
92 # elif XLAT_VERBOSE
93 printf("%#x /* IOPRIO_WHO_PGRP */", 2);
94 # else /* XLAT_ABBREV */
95 printf("IOPRIO_WHO_PGRP");
96 # endif
97 printf(", %d%s", pgid, pidns_pid2str(PT_PGID));
98 # if XLAT_RAW
99 printf(", 8191)");
100 # elif XLAT_VERBOSE
101 printf(", 8191 /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)");
102 # else /* XLAT_ABBREV */
103 printf(", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191))");
104 # endif
105 printf(" = %s\n", errstr);
106
107 rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio);
108 errstr = sprintrc(rc);
109 pidns_print_leader();
110 # if XLAT_RAW
111 printf("ioprio_set(%#x, %d, %d) = %s\n",
112 (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
113 errstr);
114 # elif XLAT_VERBOSE
115 printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %d /* %s */) = %s\n",
116 (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
117 bogus_ioprio_str, errstr);
118 # else /* XLAT_ABBREV */
119 printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %s) = %s\n",
120 (int) bogus_which, (int) bogus_who, bogus_ioprio_str,
121 errstr);
122 # endif
123
124 pidns_print_leader();
125 puts("+++ exited with 0 +++");
126
127 return 0;
128 }
129
130 #else
131
132 SKIP_MAIN_UNDEFINED("__NR_ioprio_get && __NR_ioprio_set");
133
134 #endif