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);
48 sys_brk(struct tcb *tcp)
51 tprintf("%#lx", tcp->u_arg[0]);
56 #include "xlat/mmap_prot.h"
57 #include "xlat/mmap_flags.h"
60 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
67 tprintf("%#lx, ", u_arg[0]);
69 tprintf("%lu, ", u_arg[1]);
71 printflags(mmap_prot, u_arg[2], "PROT_???");
75 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
76 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
78 printflags(mmap_flags, u_arg[3], "MAP_???");
82 printfd(tcp, u_arg[4]);
84 tprintf(", %#llx", offset);
89 /* Syscall name<->function correspondence is messed up on many arches.
91 * i386 has __NR_mmap == 90, and it is "old mmap", and
92 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
93 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
97 /* Params are pointed to by u_arg[0], offset is in bytes */
99 sys_old_mmap(struct tcb *tcp)
104 * IA64 processes never call this routine, they only use the
105 * new 'sys_mmap' interface. Only IA32 processes come here.
108 unsigned narrow_arg[6];
109 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
111 for (i = 0; i < 6; i++)
112 u_arg[i] = (unsigned long) narrow_arg[i];
113 #elif defined(X86_64)
114 /* We are here only in personality 1 (i386) */
116 unsigned narrow_arg[6];
117 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
119 for (i = 0; i < 6; ++i)
120 u_arg[i] = (unsigned long) narrow_arg[i];
122 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
125 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
129 /* Params are pointed to by u_arg[0], offset is in pages */
131 sys_old_mmap_pgoff(struct tcb *tcp)
135 unsigned narrow_arg[6];
136 unsigned long long offset;
137 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
139 for (i = 0; i < 5; i++)
140 u_arg[i] = (unsigned long) narrow_arg[i];
141 offset = narrow_arg[5];
142 offset *= get_pagesize();
143 return print_mmap(tcp, u_arg, offset);
147 /* Params are passed directly, offset is in bytes */
149 sys_mmap(struct tcb *tcp)
151 unsigned long long offset = (unsigned long) tcp->u_arg[5];
152 #if defined(LINUX_MIPSN32) || defined(X32)
153 /* Try test/x32_mmap.c */
154 offset = tcp->ext_arg[5];
156 /* Example of kernel-side handling of this variety of mmap:
157 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
158 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
159 * since the above code converts off to pages.
161 return print_mmap(tcp, tcp->u_arg, offset);
164 /* Params are passed directly, offset is in pages */
166 sys_mmap_pgoff(struct tcb *tcp)
168 /* Try test/mmap_offset_decode.c */
169 unsigned long long offset;
170 offset = (unsigned long) tcp->u_arg[5];
171 offset *= get_pagesize();
172 return print_mmap(tcp, tcp->u_arg, offset);
175 /* Params are passed directly, offset is in 4k units */
177 sys_mmap_4koff(struct tcb *tcp)
179 unsigned long long offset;
180 offset = (unsigned long) tcp->u_arg[5];
182 return print_mmap(tcp, tcp->u_arg, offset);
186 sys_munmap(struct tcb *tcp)
190 tcp->u_arg[0], tcp->u_arg[1]);
196 sys_mprotect(struct tcb *tcp)
199 tprintf("%#lx, %lu, ",
200 tcp->u_arg[0], tcp->u_arg[1]);
201 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
206 #include "xlat/mremap_flags.h"
209 sys_mremap(struct tcb *tcp)
212 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
214 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
216 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
217 (MREMAP_MAYMOVE | MREMAP_FIXED))
218 tprintf(", %#lx", tcp->u_arg[4]);
224 #include "xlat/madvise_cmds.h"
227 sys_madvise(struct tcb *tcp)
230 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
231 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
236 #include "xlat/mlockall_flags.h"
239 sys_mlockall(struct tcb *tcp)
242 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
247 #include "xlat/mctl_sync.h"
250 sys_msync(struct tcb *tcp)
254 tprintf("%#lx", tcp->u_arg[0]);
256 tprintf(", %lu, ", tcp->u_arg[1]);
258 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
264 sys_mincore(struct tcb *tcp)
267 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
269 unsigned long i, len;
273 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
274 (vec = malloc(len)) == NULL ||
275 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
276 tprintf("%#lx", tcp->u_arg[2]);
279 for (i = 0; i < len; i++) {
280 if (abbrev(tcp) && i >= max_strlen) {
284 tprints((vec[i] & 1) ? "1" : "0");
293 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
295 sys_getpagesize(struct tcb *tcp)
304 sys_remap_file_pages(struct tcb *tcp)
307 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
308 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
309 tprintf(", %lu, ", tcp->u_arg[3]);
311 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
312 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
314 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
320 #define MPOL_DEFAULT 0
321 #define MPOL_PREFERRED 1
323 #define MPOL_INTERLEAVE 3
325 #define MPOL_F_NODE (1<<0)
326 #define MPOL_F_ADDR (1<<1)
328 #define MPOL_MF_STRICT (1<<0)
329 #define MPOL_MF_MOVE (1<<1)
330 #define MPOL_MF_MOVE_ALL (1<<2)
332 #include "xlat/policies.h"
333 #include "xlat/mbindflags.h"
334 #include "xlat/mempolicyflags.h"
335 #include "xlat/move_pages_flags.h"
338 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
340 unsigned long nlongs, size, end;
342 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
343 size = nlongs * sizeof(long);
345 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
347 unsigned long n, cur, abbrev_end;
351 abbrev_end = ptr + max_strlen * sizeof(long);
352 if (abbrev_end < ptr)
358 for (cur = ptr; cur < end; cur += sizeof(long)) {
361 if (cur >= abbrev_end) {
365 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
370 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
374 tprintf(" %#lx", ptr);
376 tprintf(", %#lx", ptr);
377 tprintf(", %lu", maxnodes);
381 sys_mbind(struct tcb *tcp)
384 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
385 printxval(policies, tcp->u_arg[2], "MPOL_???");
386 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
388 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
394 sys_set_mempolicy(struct tcb *tcp)
397 printxval(policies, tcp->u_arg[0], "MPOL_???");
398 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
404 sys_get_mempolicy(struct tcb *tcp)
408 if (tcp->u_arg[0] == 0)
410 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
411 tprintf("%#lx", tcp->u_arg[0]);
413 printxval(policies, pol, "MPOL_???");
414 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
415 tprintf(", %#lx, ", tcp->u_arg[3]);
416 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
422 sys_migrate_pages(struct tcb *tcp)
425 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
426 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
428 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
434 sys_move_pages(struct tcb *tcp)
437 unsigned long npages = tcp->u_arg[1];
438 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
439 if (tcp->u_arg[2] == 0)
443 long puser = tcp->u_arg[2];
445 for (i = 0; i < npages; ++i) {
449 if (umove(tcp, puser, &p) < 0) {
454 puser += sizeof(void *);
458 if (tcp->u_arg[3] == 0)
462 long nodeuser = tcp->u_arg[3];
464 for (i = 0; i < npages; ++i) {
468 if (umove(tcp, nodeuser, &node) < 0) {
472 tprintf("%#x", node);
473 nodeuser += sizeof(int);
479 unsigned long npages = tcp->u_arg[1];
480 if (tcp->u_arg[4] == 0)
484 long statususer = tcp->u_arg[4];
486 for (i = 0; i < npages; ++i) {
490 if (umove(tcp, statususer, &status) < 0) {
494 tprintf("%#x", status);
495 statususer += sizeof(int);
499 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
506 sys_subpage_prot(struct tcb *tcp)
509 unsigned long cur, end, abbrev_end, entries;
512 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
513 entries = tcp->u_arg[1] >> 16;
514 if (!entries || !tcp->u_arg[2]) {
519 end = cur + (sizeof(int) * entries);
520 if (!verbose(tcp) || end < (unsigned long) tcp->u_arg[2]) {
521 tprintf("%#lx", tcp->u_arg[2]);
525 abbrev_end = cur + (sizeof(int) * max_strlen);
526 if (abbrev_end > end)
532 for (; cur < end; cur += sizeof(int)) {
533 if (cur > (unsigned long) tcp->u_arg[2])
535 if (cur >= abbrev_end) {
539 if (umove(tcp, cur, &entry) < 0) {
540 tprintf("??? [%#lx]", cur);
544 tprintf("%#08x", entry);