]> granicus.if.org Git - strace/blob - numa.c
fetch_seccomp_fprog: change address argument type from long to kernel_ureg_t
[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  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "defs.h"
30
31 static bool
32 print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
33 {
34         if (elem_size < sizeof(long)) {
35                 tprintf("%#0*x", (int) elem_size * 2 + 2,
36                         * (unsigned int *) elem_buf);
37         } else {
38                 tprintf("%#0*lx", (int) elem_size * 2 + 2,
39                         * (unsigned long *) elem_buf);
40         }
41
42         return true;
43 }
44
45 static void
46 print_nodemask(struct tcb *const tcp, const kernel_ureg_t addr,
47                const unsigned long maxnodes)
48 {
49         const unsigned long nmemb =
50                 (maxnodes + 8 * current_wordsize - 2) / (8 * current_wordsize);
51
52         if (nmemb < maxnodes / (8 * current_wordsize) ||
53             (maxnodes && !nmemb)) {
54                 printaddr(addr);
55                 return;
56         }
57
58         unsigned long buf;
59         print_array(tcp, addr, nmemb, &buf, current_wordsize,
60                     umoven_or_printaddr, print_node, 0);
61 }
62
63 SYS_FUNC(migrate_pages)
64 {
65         tprintf("%d, %lu, ", (int) tcp->u_arg[0], tcp->u_arg[1]);
66         print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
67         tprints(", ");
68         print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
69
70         return RVAL_DECODED;
71 }
72
73 #include "xlat/policies.h"
74 #include "xlat/mbindflags.h"
75
76 SYS_FUNC(mbind)
77 {
78         printaddr(tcp->u_arg[0]);
79         tprintf(", %lu, ", tcp->u_arg[1]);
80         printxval_long(policies, tcp->u_arg[2], "MPOL_???");
81         tprints(", ");
82         print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]);
83         tprintf(", %lu, ", tcp->u_arg[4]);
84         printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
85
86         return RVAL_DECODED;
87 }
88
89 SYS_FUNC(set_mempolicy)
90 {
91         printxval(policies, tcp->u_arg[0], "MPOL_???");
92         tprints(", ");
93         print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
94         tprintf(", %lu", tcp->u_arg[2]);
95
96         return RVAL_DECODED;
97 }
98
99 #include "xlat/mempolicyflags.h"
100
101 SYS_FUNC(get_mempolicy)
102 {
103         if (exiting(tcp)) {
104                 int pol;
105                 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) {
106                         tprints("[");
107                         printxval(policies, pol, "MPOL_???");
108                         tprints("]");
109                 }
110                 tprints(", ");
111                 print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
112                 tprintf(", %lu, ", tcp->u_arg[2]);
113                 printaddr(tcp->u_arg[3]);
114                 tprints(", ");
115                 printflags_long(mempolicyflags, tcp->u_arg[4], "MPOL_???");
116         }
117         return 0;
118 }
119
120 #include "xlat/move_pages_flags.h"
121
122 static bool
123 print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
124 {
125         unsigned long addr;
126
127         if (elem_size < sizeof(long)) {
128                 addr = * (unsigned int *) elem_buf;
129         } else {
130                 addr = * (unsigned long *) elem_buf;
131         }
132
133         printaddr(addr);
134
135         return true;
136 }
137
138 static bool
139 print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
140 {
141         const int status = * (int *) elem_buf;
142
143         if (status < 0 && (unsigned) -status < nerrnos)
144                 tprintf("%s", errnoent[-status]);
145         else
146                 tprintf("%d", status);
147
148         return true;
149 }
150
151 static bool
152 print_int(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
153 {
154         tprintf("%d", * (int *) elem_buf);
155
156         return true;
157 }
158
159 SYS_FUNC(move_pages)
160 {
161         const unsigned long npages = tcp->u_arg[1];
162         long buf;
163
164         if (entering(tcp)) {
165                 tprintf("%d, %lu, ", (int) tcp->u_arg[0], npages);
166                 print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
167                             umoven_or_printaddr, print_addr, 0);
168                 tprints(", ");
169                 print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int),
170                             umoven_or_printaddr, print_int, 0);
171                 tprints(", ");
172         } else {
173                 print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int),
174                             umoven_or_printaddr, print_status, 0);
175                 tprints(", ");
176                 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
177         }
178         return 0;
179 }