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)
64 if (stack_trace_enabled) {
65 unwind_capture_stacktrace(tcp);
66 unwind_cache_invalidate(tcp);
74 tprintf("%#lx, ", u_arg[0]);
76 tprintf("%lu, ", u_arg[1]);
78 printflags(mmap_prot, u_arg[2], "PROT_???");
82 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
83 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
85 printflags(mmap_flags, u_arg[3], "MAP_???");
89 printfd(tcp, u_arg[4]);
91 tprintf(", %#llx", offset);
96 /* Syscall name<->function correspondence is messed up on many arches.
98 * i386 has __NR_mmap == 90, and it is "old mmap", and
99 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
100 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
104 /* Params are pointed to by u_arg[0], offset is in bytes */
106 sys_old_mmap(struct tcb *tcp)
111 * IA64 processes never call this routine, they only use the
112 * new 'sys_mmap' interface. Only IA32 processes come here.
115 unsigned narrow_arg[6];
116 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
118 for (i = 0; i < 6; i++)
119 u_arg[i] = (unsigned long) narrow_arg[i];
120 #elif defined(X86_64)
121 /* We are here only in personality 1 (i386) */
123 unsigned narrow_arg[6];
124 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
126 for (i = 0; i < 6; ++i)
127 u_arg[i] = (unsigned long) narrow_arg[i];
129 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
132 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
136 /* Params are pointed to by u_arg[0], offset is in pages */
138 sys_old_mmap_pgoff(struct tcb *tcp)
142 unsigned narrow_arg[6];
143 unsigned long long offset;
144 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
146 for (i = 0; i < 5; i++)
147 u_arg[i] = (unsigned long) narrow_arg[i];
148 offset = narrow_arg[5];
149 offset *= get_pagesize();
150 return print_mmap(tcp, u_arg, offset);
154 /* Params are passed directly, offset is in bytes */
156 sys_mmap(struct tcb *tcp)
158 unsigned long long offset = (unsigned long) tcp->u_arg[5];
159 #if defined(LINUX_MIPSN32) || defined(X32)
160 /* Try test/x32_mmap.c */
161 offset = tcp->ext_arg[5];
163 /* Example of kernel-side handling of this variety of mmap:
164 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
165 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
166 * since the above code converts off to pages.
168 return print_mmap(tcp, tcp->u_arg, offset);
171 /* Params are passed directly, offset is in pages */
173 sys_mmap_pgoff(struct tcb *tcp)
175 /* Try test/mmap_offset_decode.c */
176 unsigned long long offset;
177 offset = (unsigned long) tcp->u_arg[5];
178 offset *= get_pagesize();
179 return print_mmap(tcp, tcp->u_arg, offset);
182 /* Params are passed directly, offset is in 4k units */
184 sys_mmap_4koff(struct tcb *tcp)
186 unsigned long long offset;
187 offset = (unsigned long) tcp->u_arg[5];
189 return print_mmap(tcp, tcp->u_arg, offset);
193 sys_munmap(struct tcb *tcp)
197 tcp->u_arg[0], tcp->u_arg[1]);
199 if (stack_trace_enabled)
200 unwind_capture_stacktrace(tcp);
205 if (stack_trace_enabled)
206 unwind_cache_invalidate(tcp);
213 sys_mprotect(struct tcb *tcp)
216 tprintf("%#lx, %lu, ",
217 tcp->u_arg[0], tcp->u_arg[1]);
218 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
220 if (stack_trace_enabled)
221 unwind_capture_stacktrace(tcp);
226 if (stack_trace_enabled)
227 unwind_cache_invalidate(tcp);
233 #include "xlat/mremap_flags.h"
236 sys_mremap(struct tcb *tcp)
239 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
241 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
243 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
244 (MREMAP_MAYMOVE | MREMAP_FIXED))
245 tprintf(", %#lx", tcp->u_arg[4]);
251 #include "xlat/madvise_cmds.h"
254 sys_madvise(struct tcb *tcp)
257 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
258 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
263 #include "xlat/mlockall_flags.h"
266 sys_mlockall(struct tcb *tcp)
269 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
276 #include "xlat/mctl_sync.h"
279 sys_msync(struct tcb *tcp)
283 tprintf("%#lx", tcp->u_arg[0]);
285 tprintf(", %lu, ", tcp->u_arg[1]);
287 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
292 #endif /* MS_ASYNC */
296 #include "xlat/mctl_funcs.h"
297 #include "xlat/mctl_lockas.h"
300 sys_mctl(struct tcb *tcp)
306 tprintf("%#lx", tcp->u_arg[0]);
308 tprintf(", %lu, ", tcp->u_arg[1]);
310 function = tcp->u_arg[2];
311 printflags(mctl_funcs, function, "MC_???");
317 printflags(mctl_sync, arg, "MS_???");
320 printflags(mctl_lockas, arg, "MCL_???");
333 sys_mincore(struct tcb *tcp)
336 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
338 unsigned long i, len;
342 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
343 (vec = malloc(len)) == NULL ||
344 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
345 tprintf("%#lx", tcp->u_arg[2]);
348 for (i = 0; i < len; i++) {
349 if (abbrev(tcp) && i >= max_strlen) {
353 tprints((vec[i] & 1) ? "1" : "0");
362 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
364 sys_getpagesize(struct tcb *tcp)
373 sys_remap_file_pages(struct tcb *tcp)
376 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
377 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
378 tprintf(", %lu, ", tcp->u_arg[3]);
380 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
381 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
383 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
389 #define MPOL_DEFAULT 0
390 #define MPOL_PREFERRED 1
392 #define MPOL_INTERLEAVE 3
394 #define MPOL_F_NODE (1<<0)
395 #define MPOL_F_ADDR (1<<1)
397 #define MPOL_MF_STRICT (1<<0)
398 #define MPOL_MF_MOVE (1<<1)
399 #define MPOL_MF_MOVE_ALL (1<<2)
401 #include "xlat/policies.h"
402 #include "xlat/mbindflags.h"
403 #include "xlat/mempolicyflags.h"
404 #include "xlat/move_pages_flags.h"
407 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
409 unsigned long nlongs, size, end;
411 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
412 size = nlongs * sizeof(long);
414 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
416 unsigned long n, cur, abbrev_end;
420 abbrev_end = ptr + max_strlen * sizeof(long);
421 if (abbrev_end < ptr)
427 for (cur = ptr; cur < end; cur += sizeof(long)) {
430 if (cur >= abbrev_end) {
434 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
439 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
443 tprintf(" %#lx", ptr);
445 tprintf(", %#lx", ptr);
446 tprintf(", %lu", maxnodes);
450 sys_mbind(struct tcb *tcp)
453 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
454 printxval(policies, tcp->u_arg[2], "MPOL_???");
455 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
457 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
463 sys_set_mempolicy(struct tcb *tcp)
466 printxval(policies, tcp->u_arg[0], "MPOL_???");
467 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
473 sys_get_mempolicy(struct tcb *tcp)
477 if (tcp->u_arg[0] == 0)
479 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
480 tprintf("%#lx", tcp->u_arg[0]);
482 printxval(policies, pol, "MPOL_???");
483 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
484 tprintf(", %#lx, ", tcp->u_arg[3]);
485 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
491 sys_migrate_pages(struct tcb *tcp)
494 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
495 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
497 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
503 sys_move_pages(struct tcb *tcp)
506 unsigned long npages = tcp->u_arg[1];
507 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
508 if (tcp->u_arg[2] == 0)
512 long puser = tcp->u_arg[2];
514 for (i = 0; i < npages; ++i) {
518 if (umove(tcp, puser, &p) < 0) {
523 puser += sizeof(void *);
527 if (tcp->u_arg[3] == 0)
531 long nodeuser = tcp->u_arg[3];
533 for (i = 0; i < npages; ++i) {
537 if (umove(tcp, nodeuser, &node) < 0) {
541 tprintf("%#x", node);
542 nodeuser += sizeof(int);
548 unsigned long npages = tcp->u_arg[1];
549 if (tcp->u_arg[4] == 0)
553 long statususer = tcp->u_arg[4];
555 for (i = 0; i < npages; ++i) {
559 if (umove(tcp, statususer, &status) < 0) {
563 tprintf("%#x", status);
564 statususer += sizeof(int);
568 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
575 sys_subpage_prot(struct tcb *tcp)
578 unsigned long cur, end, abbrev_end, entries;
581 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
582 entries = tcp->u_arg[1] >> 16;
583 if (!entries || !tcp->u_arg[2]) {
588 end = cur + (sizeof(int) * entries);
589 if (!verbose(tcp) || end < tcp->u_arg[2]) {
590 tprintf("%#lx", tcp->u_arg[2]);
594 abbrev_end = cur + (sizeof(int) * max_strlen);
595 if (abbrev_end > end)
601 for (; cur < end; cur += sizeof(int)) {
602 if (cur > tcp->u_arg[2])
604 if (cur >= abbrev_end) {
608 if (umove(tcp, cur, &entry) < 0) {
609 tprintf("??? [%#lx]", cur);
613 tprintf("%#08x", entry);