]> granicus.if.org Git - strace/blob - numa.c
Move parsers of NUMA related syscalls to numa.c
[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 void
32 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
33 {
34         unsigned long nlongs, size, end;
35
36         nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
37         size = nlongs * sizeof(long);
38         end = ptr + size;
39         if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
40                             && (end > ptr))) {
41                 unsigned long n, cur, abbrev_end;
42                 int failed = 0;
43
44                 if (abbrev(tcp)) {
45                         abbrev_end = ptr + max_strlen * sizeof(long);
46                         if (abbrev_end < ptr)
47                                 abbrev_end = end;
48                 } else {
49                         abbrev_end = end;
50                 }
51                 tprints(", {");
52                 for (cur = ptr; cur < end; cur += sizeof(long)) {
53                         if (cur > ptr)
54                                 tprints(", ");
55                         if (cur >= abbrev_end) {
56                                 tprints("...");
57                                 break;
58                         }
59                         if (umoven(tcp, cur, sizeof(n), &n) < 0) {
60                                 tprints("?");
61                                 failed = 1;
62                                 break;
63                         }
64                         tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
65                 }
66                 tprints("}");
67                 if (failed) {
68                         tprints(" ");
69                         printaddr(ptr);
70                 }
71         } else {
72                 tprints(" ");
73                 printaddr(ptr);
74         }
75         tprintf(", %lu", maxnodes);
76 }
77
78 SYS_FUNC(migrate_pages)
79 {
80         tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
81         get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
82         tprints(", ");
83         get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
84
85         return RVAL_DECODED;
86 }
87
88 #include "xlat/policies.h"
89 #include "xlat/mbindflags.h"
90
91 SYS_FUNC(mbind)
92 {
93         printaddr(tcp->u_arg[0]);
94         tprintf(", %lu, ", tcp->u_arg[1]);
95         printxval(policies, tcp->u_arg[2], "MPOL_???");
96         get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
97         tprints(", ");
98         printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
99
100         return RVAL_DECODED;
101 }
102
103 SYS_FUNC(set_mempolicy)
104 {
105         printxval(policies, tcp->u_arg[0], "MPOL_???");
106         get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
107
108         return RVAL_DECODED;
109 }
110
111 #include "xlat/mempolicyflags.h"
112
113 SYS_FUNC(get_mempolicy)
114 {
115         if (exiting(tcp)) {
116                 int pol;
117                 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol))
118                         printxval(policies, pol, "MPOL_???");
119                 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
120                 tprints(", ");
121                 printaddr(tcp->u_arg[3]);
122                 tprints(", ");
123                 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
124         }
125         return 0;
126 }
127
128 #include "xlat/move_pages_flags.h"
129
130 SYS_FUNC(move_pages)
131 {
132         if (entering(tcp)) {
133                 unsigned long npages = tcp->u_arg[1];
134                 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
135                 if (tcp->u_arg[2] == 0)
136                         tprints("NULL, ");
137                 else {
138                         unsigned int i;
139                         long puser = tcp->u_arg[2];
140                         tprints("{");
141                         for (i = 0; i < npages; ++i) {
142                                 void *p;
143                                 if (i > 0)
144                                         tprints(", ");
145                                 if (umove(tcp, puser, &p) < 0) {
146                                         tprints("???");
147                                         break;
148                                 }
149                                 tprintf("%p", p);
150                                 puser += sizeof(void *);
151                         }
152                         tprints("}, ");
153                 }
154                 if (tcp->u_arg[3] == 0)
155                         tprints("NULL, ");
156                 else {
157                         unsigned int i;
158                         long nodeuser = tcp->u_arg[3];
159                         tprints("{");
160                         for (i = 0; i < npages; ++i) {
161                                 int node;
162                                 if (i > 0)
163                                         tprints(", ");
164                                 if (umove(tcp, nodeuser, &node) < 0) {
165                                         tprints("???");
166                                         break;
167                                 }
168                                 tprintf("%#x", node);
169                                 nodeuser += sizeof(int);
170                         }
171                         tprints("}, ");
172                 }
173         } else {
174                 unsigned long npages = tcp->u_arg[1];
175                 if (tcp->u_arg[4] == 0)
176                         tprints("NULL, ");
177                 else {
178                         unsigned int i;
179                         long statususer = tcp->u_arg[4];
180                         tprints("{");
181                         for (i = 0; i < npages; ++i) {
182                                 int status;
183                                 if (i > 0)
184                                         tprints(", ");
185                                 if (umove(tcp, statususer, &status) < 0) {
186                                         tprints("???");
187                                         break;
188                                 }
189                                 tprintf("%#x", status);
190                                 statususer += sizeof(int);
191                         }
192                         tprints("}, ");
193                 }
194                 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
195         }
196         return 0;
197 }