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