]> granicus.if.org Git - strace/blob - ioprio.c
Fix decoding of arm struct stat64 by aarch64 strace.
[strace] / ioprio.c
1 #include "defs.h"
2
3 enum {
4         IOPRIO_WHO_PROCESS = 1,
5         IOPRIO_WHO_PGRP,
6         IOPRIO_WHO_USER
7 };
8
9 static const struct xlat ioprio_who[] = {
10         XLAT(IOPRIO_WHO_PROCESS),
11         XLAT(IOPRIO_WHO_PGRP),
12         XLAT(IOPRIO_WHO_USER),
13         XLAT_END
14 };
15
16 enum {
17         IOPRIO_CLASS_NONE,
18         IOPRIO_CLASS_RT,
19         IOPRIO_CLASS_BE,
20         IOPRIO_CLASS_IDLE
21 };
22
23 static const struct xlat ioprio_class[] = {
24         XLAT(IOPRIO_CLASS_NONE),
25         XLAT(IOPRIO_CLASS_RT),
26         XLAT(IOPRIO_CLASS_BE),
27         XLAT(IOPRIO_CLASS_IDLE),
28         XLAT_END
29 };
30
31 #define IOPRIO_CLASS_SHIFT      (13)
32 #define IOPRIO_PRIO_MASK        ((1ul << IOPRIO_CLASS_SHIFT) - 1)
33
34 #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
35 #define IOPRIO_PRIO_DATA(mask)  ((mask) & IOPRIO_PRIO_MASK)
36
37 static const char *
38 sprint_ioprio(int ioprio)
39 {
40         static char outstr[256];
41         const char *str;
42         int class, data;
43
44         class = IOPRIO_PRIO_CLASS(ioprio);
45         data = IOPRIO_PRIO_DATA(ioprio);
46         str = xlookup(ioprio_class, class);
47         if (str)
48                 sprintf(outstr, "IOPRIO_PRIO_VALUE(%s,%d)", str, data);
49         else
50                 sprintf(outstr, "IOPRIO_PRIO_VALUE(%#x /* %s */,%d)",
51                         class, "IOPRIO_CLASS_???", data);
52
53         return outstr;
54 }
55
56 int
57 sys_ioprio_get(struct tcb *tcp)
58 {
59         if (entering(tcp)) {
60                 /* int which */
61                 printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
62                 /* int who */
63                 tprintf(", %d", (int) tcp->u_arg[1]);
64                 return 0;
65         } else {
66                 if (syserror(tcp))
67                         return 0;
68
69                 tcp->auxstr = sprint_ioprio(tcp->u_rval);
70                 return RVAL_STR;
71         }
72 }
73
74 int
75 sys_ioprio_set(struct tcb *tcp)
76 {
77         if (entering(tcp)) {
78                 /* int which */
79                 printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
80                 /* int who */
81                 tprintf(", %d, ", (int) tcp->u_arg[1]);
82                 /* int ioprio */
83                 tprints(sprint_ioprio(tcp->u_arg[2]));
84         }
85         return 0;
86 }