]> granicus.if.org Git - strace/blob - numa.c
tests: fix format warnings on x32
[strace] / numa.c
1 /*
2  * Copyright (c) 2003-2007 Ulrich Drepper <drepper@redhat.com>
3  * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
4  * Copyright (c) 2016-2019 The strace developers.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11
12 static bool
13 print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
14 {
15         if (elem_size < sizeof(kernel_ulong_t)) {
16                 tprintf("%#0*x", (int) elem_size * 2 + 2,
17                         *(unsigned int *) elem_buf);
18         } else {
19                 tprintf("%#0*" PRI_klx, (int) elem_size * 2 + 2,
20                         *(kernel_ulong_t *) elem_buf);
21         }
22
23         return true;
24 }
25
26 static void
27 print_nodemask(struct tcb *const tcp, const kernel_ulong_t addr,
28                const kernel_ulong_t maxnodes)
29 {
30         const unsigned int bits_per_long = 8 * current_wordsize;
31         const kernel_ulong_t nmemb =
32                 (maxnodes + bits_per_long - 2) / bits_per_long;
33
34         if (nmemb < maxnodes / bits_per_long ||
35             (maxnodes && !nmemb)) {
36                 printaddr(addr);
37                 return;
38         }
39
40         kernel_ulong_t buf;
41         print_array(tcp, addr, nmemb, &buf, current_wordsize,
42                     tfetch_mem, print_node, 0);
43 }
44
45 SYS_FUNC(migrate_pages)
46 {
47         tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
48         print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
49         tprints(", ");
50         print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
51
52         return RVAL_DECODED;
53 }
54
55 #include "xlat/mpol_modes.h"
56 #include "xlat/mpol_mode_flags.h"
57 #include "xlat/mbind_flags.h"
58
59 static void
60 print_mode(struct tcb *const tcp, const kernel_ulong_t mode_arg)
61 {
62         const kernel_ulong_t flags_mask =
63                 MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES;
64         const kernel_ulong_t mode = mode_arg & ~flags_mask;
65         const unsigned int flags = mode_arg & flags_mask;
66
67         if (!flags) {
68                 printxval64(mpol_modes, mode, "MPOL_???");
69                 return;
70         }
71
72         const char *mode_str = xlookup(mpol_modes, mode);
73         if (!mode_str) {
74                 printflags64(mpol_mode_flags, mode_arg, "MPOL_???");
75                 return;
76         }
77
78         if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
79                 tprintf("%#" PRI_klx, mode_arg);
80
81         if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
82                 return;
83
84         if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
85                 tprints(" /* ");
86
87         tprints(mode_str);
88         tprints("|");
89         printflags_ex(flags, NULL, XLAT_STYLE_ABBREV, mpol_mode_flags, NULL);
90
91         if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
92                 tprints(" */");
93 }
94
95 SYS_FUNC(mbind)
96 {
97         printaddr(tcp->u_arg[0]);
98         tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
99         print_mode(tcp, tcp->u_arg[2]);
100         tprints(", ");
101         print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]);
102         tprintf(", %" PRI_klu ", ", tcp->u_arg[4]);
103         printflags(mbind_flags, tcp->u_arg[5], "MPOL_???");
104
105         return RVAL_DECODED;
106 }
107
108 SYS_FUNC(set_mempolicy)
109 {
110         print_mode(tcp, (unsigned int) tcp->u_arg[0]);
111         tprints(", ");
112         print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
113         tprintf(", %" PRI_klu, tcp->u_arg[2]);
114
115         return RVAL_DECODED;
116 }
117
118 #include "xlat/get_mempolicy_flags.h"
119
120 SYS_FUNC(get_mempolicy)
121 {
122         if (exiting(tcp)) {
123                 int pol;
124                 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) {
125                         tprints("[");
126                         printxval(mpol_modes, pol, "MPOL_???");
127                         tprints("]");
128                 }
129                 tprints(", ");
130                 print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
131                 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
132                 printaddr(tcp->u_arg[3]);
133                 tprints(", ");
134                 printflags64(get_mempolicy_flags, tcp->u_arg[4], "MPOL_???");
135         }
136         return 0;
137 }
138
139 #include "xlat/move_pages_flags.h"
140
141 static bool
142 print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
143 {
144         kernel_ulong_t addr;
145
146         if (elem_size < sizeof(addr)) {
147                 addr = *(unsigned int *) elem_buf;
148         } else {
149                 addr = *(kernel_ulong_t *) elem_buf;
150         }
151
152         printaddr(addr);
153
154         return true;
155 }
156
157 static bool
158 print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
159 {
160         const int status = *(int *) elem_buf;
161
162         print_err(status, true);
163
164         return true;
165 }
166
167 SYS_FUNC(move_pages)
168 {
169         const kernel_ulong_t npages = tcp->u_arg[1];
170         kernel_ulong_t buf;
171
172         if (entering(tcp)) {
173                 tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], npages);
174                 print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
175                             tfetch_mem, print_addr, 0);
176                 tprints(", ");
177                 print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int),
178                             tfetch_mem, print_int32_array_member, 0);
179                 tprints(", ");
180         } else {
181                 print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int),
182                             tfetch_mem, print_status, 0);
183                 tprints(", ");
184                 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
185         }
186         return 0;
187 }