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-2018 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
35 if (elem_size < sizeof(kernel_ulong_t)) {
36 tprintf("%#0*x", (int) elem_size * 2 + 2,
37 *(unsigned int *) elem_buf);
39 tprintf("%#0*" PRI_klx, (int) elem_size * 2 + 2,
40 *(kernel_ulong_t *) elem_buf);
47 print_nodemask(struct tcb *const tcp, const kernel_ulong_t addr,
48 const kernel_ulong_t maxnodes)
50 const unsigned int bits_per_long = 8 * current_wordsize;
51 const kernel_ulong_t nmemb =
52 (maxnodes + bits_per_long - 2) / bits_per_long;
54 if (nmemb < maxnodes / bits_per_long ||
55 (maxnodes && !nmemb)) {
61 print_array(tcp, addr, nmemb, &buf, current_wordsize,
62 tfetch_mem, print_node, 0);
65 SYS_FUNC(migrate_pages)
67 tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], tcp->u_arg[1]);
68 print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]);
70 print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]);
75 #include "xlat/policies.h"
76 #include "xlat/mbindflags.h"
80 printaddr(tcp->u_arg[0]);
81 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
82 printxval64(policies, tcp->u_arg[2], "MPOL_???");
84 print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]);
85 tprintf(", %" PRI_klu ", ", tcp->u_arg[4]);
86 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
91 SYS_FUNC(set_mempolicy)
93 printxval(policies, tcp->u_arg[0], "MPOL_???");
95 print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
96 tprintf(", %" PRI_klu, tcp->u_arg[2]);
101 #include "xlat/mempolicyflags.h"
103 SYS_FUNC(get_mempolicy)
107 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) {
109 printxval(policies, pol, "MPOL_???");
113 print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]);
114 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
115 printaddr(tcp->u_arg[3]);
117 printflags64(mempolicyflags, tcp->u_arg[4], "MPOL_???");
122 #include "xlat/move_pages_flags.h"
125 print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
129 if (elem_size < sizeof(addr)) {
130 addr = *(unsigned int *) elem_buf;
132 addr = *(kernel_ulong_t *) elem_buf;
141 print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
143 const int status = *(int *) elem_buf;
145 if (status < 0 && (unsigned) -status < nerrnos)
146 tprintf("-%s", errnoent[-status]);
148 tprintf("%d", status);
154 print_int(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
156 tprintf("%d", *(int *) elem_buf);
163 const kernel_ulong_t npages = tcp->u_arg[1];
167 tprintf("%d, %" PRI_klu ", ", (int) tcp->u_arg[0], npages);
168 print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize,
169 tfetch_mem, print_addr, 0);
171 print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int),
172 tfetch_mem, print_int, 0);
175 print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int),
176 tfetch_mem, print_status, 0);
178 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");