2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 static unsigned long pagesize;
43 pagesize = sysconf(_SC_PAGESIZE);
49 printaddr(tcp->u_arg[0]);
51 return RVAL_DECODED | RVAL_HEX;
54 #include "xlat/mmap_prot.h"
55 #include "xlat/mmap_flags.h"
58 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
63 tprintf(", %lu, ", u_arg[1]);
65 printflags(mmap_prot, u_arg[2], "PROT_???");
69 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
70 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
72 printflags(mmap_flags, u_arg[3], "MAP_???");
76 printfd(tcp, u_arg[4]);
78 tprintf(", %#llx", offset);
81 /* Syscall name<->function correspondence is messed up on many arches.
83 * i386 has __NR_mmap == 90, and it is "old mmap", and
84 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
85 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
89 /* Params are pointed to by u_arg[0], offset is in bytes */
95 * IA64 processes never call this routine, they only use the
96 * new 'sys_mmap' interface. Only IA32 processes come here.
99 unsigned narrow_arg[6];
100 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
102 for (i = 0; i < 6; i++)
103 u_arg[i] = (unsigned long) narrow_arg[i];
104 #elif defined(X86_64)
105 /* We are here only in personality 1 (i386) */
107 unsigned narrow_arg[6];
108 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
110 for (i = 0; i < 6; ++i)
111 u_arg[i] = (unsigned long) narrow_arg[i];
113 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), u_arg) == -1)
116 print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
118 return RVAL_DECODED | RVAL_HEX;
122 /* Params are pointed to by u_arg[0], offset is in pages */
123 SYS_FUNC(old_mmap_pgoff)
127 unsigned narrow_arg[6];
128 unsigned long long offset;
129 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
131 for (i = 0; i < 5; i++)
132 u_arg[i] = (unsigned long) narrow_arg[i];
133 offset = narrow_arg[5];
134 offset *= get_pagesize();
135 print_mmap(tcp, u_arg, offset);
137 return RVAL_DECODED | RVAL_HEX;
141 /* Params are passed directly, offset is in bytes */
144 unsigned long long offset = (unsigned long) tcp->u_arg[5];
145 #if defined(LINUX_MIPSN32) || defined(X32)
146 /* Try test/x32_mmap.c */
147 offset = tcp->ext_arg[5];
149 /* Example of kernel-side handling of this variety of mmap:
150 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
151 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
152 * since the above code converts off to pages.
154 print_mmap(tcp, tcp->u_arg, offset);
156 return RVAL_DECODED | RVAL_HEX;
159 /* Params are passed directly, offset is in pages */
162 /* Try test/mmap_offset_decode.c */
163 unsigned long long offset;
164 offset = (unsigned long) tcp->u_arg[5];
165 offset *= get_pagesize();
166 print_mmap(tcp, tcp->u_arg, offset);
168 return RVAL_DECODED | RVAL_HEX;
171 /* Params are passed directly, offset is in 4k units */
174 unsigned long long offset;
175 offset = (unsigned long) tcp->u_arg[5];
177 print_mmap(tcp, tcp->u_arg, offset);
179 return RVAL_DECODED | RVAL_HEX;
184 printaddr(tcp->u_arg[0]);
185 tprintf(", %lu", tcp->u_arg[1]);
192 printaddr(tcp->u_arg[0]);
193 tprintf(", %lu, ", tcp->u_arg[1]);
194 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
199 #include "xlat/mremap_flags.h"
203 printaddr(tcp->u_arg[0]);
204 tprintf(", %lu, %lu, ", tcp->u_arg[1], tcp->u_arg[2]);
205 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
207 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
208 (MREMAP_MAYMOVE | MREMAP_FIXED)) {
210 printaddr(tcp->u_arg[4]);
213 return RVAL_DECODED | RVAL_HEX;
216 #include "xlat/madvise_cmds.h"
220 printaddr(tcp->u_arg[0]);
221 tprintf(", %lu, ", tcp->u_arg[1]);
222 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
227 #include "xlat/mlockall_flags.h"
231 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
236 #include "xlat/mctl_sync.h"
241 printaddr(tcp->u_arg[0]);
243 tprintf(", %lu, ", tcp->u_arg[1]);
245 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
250 #include "xlat/mlock_flags.h"
254 printaddr(tcp->u_arg[0]);
255 tprintf(", %lu, ", tcp->u_arg[1]);
256 printflags(mlock_flags, tcp->u_arg[2], "MLOCK_???");
264 printaddr(tcp->u_arg[0]);
265 tprintf(", %lu, ", tcp->u_arg[1]);
267 const unsigned long page_size = get_pagesize();
268 const unsigned long page_mask = page_size - 1;
269 unsigned long len = tcp->u_arg[1];
270 unsigned char *vec = NULL;
272 len = len / page_size + (len & page_mask ? 1 : 0);
273 if (syserror(tcp) || !verbose(tcp) ||
274 !tcp->u_arg[2] || !(vec = malloc(len)) ||
275 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
276 printaddr(tcp->u_arg[2]);
280 for (i = 0; i < len; i++) {
281 if (abbrev(tcp) && i >= max_strlen) {
285 tprints((vec[i] & 1) ? "1" : "0");
294 #if defined ALPHA || defined IA64 || defined M68K \
295 || defined SPARC || defined SPARC64
296 SYS_FUNC(getpagesize)
298 return RVAL_DECODED | RVAL_HEX;
302 SYS_FUNC(remap_file_pages)
304 printaddr(tcp->u_arg[0]);
305 tprintf(", %lu, ", tcp->u_arg[1]);
306 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
307 tprintf(", %lu, ", tcp->u_arg[3]);
309 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
310 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
312 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
318 #define MPOL_DEFAULT 0
319 #define MPOL_PREFERRED 1
321 #define MPOL_INTERLEAVE 3
323 #define MPOL_F_NODE (1<<0)
324 #define MPOL_F_ADDR (1<<1)
326 #define MPOL_MF_STRICT (1<<0)
327 #define MPOL_MF_MOVE (1<<1)
328 #define MPOL_MF_MOVE_ALL (1<<2)
330 #include "xlat/policies.h"
331 #include "xlat/mbindflags.h"
332 #include "xlat/mempolicyflags.h"
333 #include "xlat/move_pages_flags.h"
336 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
338 unsigned long nlongs, size, end;
340 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
341 size = nlongs * sizeof(long);
343 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
345 unsigned long n, cur, abbrev_end;
349 abbrev_end = ptr + max_strlen * sizeof(long);
350 if (abbrev_end < ptr)
356 for (cur = ptr; cur < end; cur += sizeof(long)) {
359 if (cur >= abbrev_end) {
363 if (umoven(tcp, cur, sizeof(n), &n) < 0) {
368 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
379 tprintf(", %lu", maxnodes);
384 printaddr(tcp->u_arg[0]);
385 tprintf(", %lu, ", tcp->u_arg[1]);
386 printxval(policies, tcp->u_arg[2], "MPOL_???");
387 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
389 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
394 SYS_FUNC(set_mempolicy)
396 printxval(policies, tcp->u_arg[0], "MPOL_???");
397 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
402 SYS_FUNC(get_mempolicy)
406 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol))
407 printxval(policies, pol, "MPOL_???");
408 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
410 printaddr(tcp->u_arg[3]);
412 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
417 SYS_FUNC(migrate_pages)
419 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
420 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
422 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
430 unsigned long npages = tcp->u_arg[1];
431 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
432 if (tcp->u_arg[2] == 0)
436 long puser = tcp->u_arg[2];
438 for (i = 0; i < npages; ++i) {
442 if (umove(tcp, puser, &p) < 0) {
447 puser += sizeof(void *);
451 if (tcp->u_arg[3] == 0)
455 long nodeuser = tcp->u_arg[3];
457 for (i = 0; i < npages; ++i) {
461 if (umove(tcp, nodeuser, &node) < 0) {
465 tprintf("%#x", node);
466 nodeuser += sizeof(int);
471 unsigned long npages = tcp->u_arg[1];
472 if (tcp->u_arg[4] == 0)
476 long statususer = tcp->u_arg[4];
478 for (i = 0; i < npages; ++i) {
482 if (umove(tcp, statususer, &status) < 0) {
486 tprintf("%#x", status);
487 statususer += sizeof(int);
491 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
497 SYS_FUNC(subpage_prot)
499 unsigned long cur, end, abbrev_end, entries;
502 printaddr(tcp->u_arg[0]);
504 printaddr(tcp->u_arg[1]);
506 entries = tcp->u_arg[1] >> 16;
507 if (!entries || !tcp->u_arg[2]) {
512 end = cur + (sizeof(int) * entries);
513 if (!verbose(tcp) || end < (unsigned long) tcp->u_arg[2]) {
514 printaddr(tcp->u_arg[2]);
518 abbrev_end = cur + (sizeof(int) * max_strlen);
519 if (abbrev_end > end)
525 for (; cur < end; cur += sizeof(int)) {
526 if (cur > (unsigned long) tcp->u_arg[2])
528 if (cur >= abbrev_end) {
532 if (umove(tcp, cur, &entry) < 0) {
533 tprintf("??? [%#lx]", cur);
537 tprintf("%#08x", entry);