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.
38 # ifdef HAVE_STRUCT_USER_DESC
39 # define modify_ldt_ldt_s user_desc
46 static unsigned long pagesize;
49 pagesize = sysconf(_SC_PAGESIZE);
54 sys_brk(struct tcb *tcp)
57 tprintf("%#lx", tcp->u_arg[0]);
62 static const struct xlat mmap_prot[] = {
63 { PROT_NONE, "PROT_NONE", },
64 { PROT_READ, "PROT_READ" },
65 { PROT_WRITE, "PROT_WRITE" },
66 { PROT_EXEC, "PROT_EXEC" },
68 { PROT_SEM, "PROT_SEM" },
71 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
74 { PROT_GROWSUP, "PROT_GROWSUP" },
77 { PROT_SAO, "PROT_SAO" },
82 static const struct xlat mmap_flags[] = {
83 { MAP_SHARED, "MAP_SHARED" },
84 { MAP_PRIVATE, "MAP_PRIVATE" },
85 { MAP_FIXED, "MAP_FIXED" },
87 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
90 { MAP_32BIT, "MAP_32BIT" },
93 { MAP_RENAME, "MAP_RENAME" },
96 { MAP_NORESERVE,"MAP_NORESERVE" },
99 { MAP_POPULATE, "MAP_POPULATE" },
102 { MAP_NONBLOCK, "MAP_NONBLOCK" },
105 * XXX - this was introduced in SunOS 4.x to distinguish between
106 * the old pre-4.x "mmap()", which:
108 * only let you map devices with an "mmap" routine (e.g.,
111 * required you to specify the mapping address;
113 * returned 0 on success and -1 on failure;
115 * memory and which, and the 4.x "mmap()" which:
117 * can map plain files;
119 * can be asked to pick where to map the file;
121 * returns the address where it mapped the file on success
124 * It's not actually used in source code that calls "mmap()"; the
125 * "mmap()" routine adds it for you.
127 * It'd be nice to come up with some way of eliminating it from
128 * the flags, e.g. reporting calls *without* it as "old_mmap()"
129 * and calls with it as "mmap()".
132 { _MAP_NEW, "_MAP_NEW" },
135 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
138 { MAP_DENYWRITE,"MAP_DENYWRITE" },
140 #ifdef MAP_EXECUTABLE
141 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
144 { MAP_INHERIT, "MAP_INHERIT" },
147 { MAP_FILE, "MAP_FILE" },
150 { MAP_LOCKED, "MAP_LOCKED" },
153 #if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
154 { MAP_ANON, "MAP_ANON" },
156 #ifdef MAP_HASSEMAPHORE
157 { MAP_HASSEMAPHORE,"MAP_HASSEMAPHORE"},
160 { MAP_STACK, "MAP_STACK" },
162 #if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
163 { MAP_UNINITIALIZED,"MAP_UNINITIALIZED"},
166 { MAP_NOSYNC, "MAP_NOSYNC" },
169 { MAP_NOCORE, "MAP_NOCORE" },
175 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
182 tprintf("%#lx, ", u_arg[0]);
184 tprintf("%lu, ", u_arg[1]);
186 printflags(mmap_prot, u_arg[2], "PROT_???");
190 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
191 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
193 printflags(mmap_flags, u_arg[3], "MAP_???");
197 printfd(tcp, u_arg[4]);
199 tprintf(", %#llx", offset);
204 /* Syscall name<->function correspondence is messed up on many arches.
206 * i386 has __NR_mmap == 90, and it is "old mmap", and
207 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
208 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
212 /* Params are pointed to by u_arg[0], offset is in bytes */
214 sys_old_mmap(struct tcb *tcp)
219 * IA64 processes never call this routine, they only use the
220 * new 'sys_mmap' interface. Only IA32 processes come here.
223 unsigned narrow_arg[6];
224 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
226 for (i = 0; i < 6; i++)
227 u_arg[i] = (unsigned long) narrow_arg[i];
228 #elif defined(X86_64)
229 /* We are here only in personality 1 (i386) */
231 unsigned narrow_arg[6];
232 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
234 for (i = 0; i < 6; ++i)
235 u_arg[i] = (unsigned long) narrow_arg[i];
237 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
240 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
244 /* Params are pointed to by u_arg[0], offset is in pages */
246 sys_old_mmap_pgoff(struct tcb *tcp)
250 unsigned narrow_arg[6];
251 unsigned long long offset;
252 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
254 for (i = 0; i < 5; i++)
255 u_arg[i] = (unsigned long) narrow_arg[i];
256 offset = narrow_arg[5];
257 offset *= get_pagesize();
258 return print_mmap(tcp, u_arg, offset);
262 /* Params are passed directly, offset is in bytes */
264 sys_mmap(struct tcb *tcp)
266 unsigned long long offset = (unsigned long) tcp->u_arg[5];
267 #if defined(LINUX_MIPSN32) || defined(X32)
268 /* Try test/x32_mmap.c */
269 offset = tcp->ext_arg[5];
271 /* Example of kernel-side handling of this variety of mmap:
272 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
273 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
274 * since the above code converts off to pages.
276 return print_mmap(tcp, tcp->u_arg, offset);
279 /* Params are passed directly, offset is in pages */
281 sys_mmap_pgoff(struct tcb *tcp)
283 /* Try test/mmap_offset_decode.c */
284 unsigned long long offset;
285 offset = (unsigned long) tcp->u_arg[5];
286 offset *= get_pagesize();
287 return print_mmap(tcp, tcp->u_arg, offset);
290 /* Params are passed directly, offset is in 4k units */
292 sys_mmap_4koff(struct tcb *tcp)
294 unsigned long long offset;
295 offset = (unsigned long) tcp->u_arg[5];
297 return print_mmap(tcp, tcp->u_arg, offset);
301 sys_munmap(struct tcb *tcp)
305 tcp->u_arg[0], tcp->u_arg[1]);
311 sys_mprotect(struct tcb *tcp)
314 tprintf("%#lx, %lu, ",
315 tcp->u_arg[0], tcp->u_arg[1]);
316 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
321 static const struct xlat mremap_flags[] = {
322 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
324 { MREMAP_FIXED, "MREMAP_FIXED" },
330 sys_mremap(struct tcb *tcp)
333 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
335 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
337 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
338 (MREMAP_MAYMOVE | MREMAP_FIXED))
339 tprintf(", %#lx", tcp->u_arg[4]);
345 static const struct xlat madvise_cmds[] = {
347 { MADV_NORMAL, "MADV_NORMAL" },
350 { MADV_RANDOM, "MADV_RANDOM" },
352 #ifdef MADV_SEQUENTIAL
353 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
356 { MADV_WILLNEED, "MADV_WILLNEED" },
359 { MADV_DONTNEED, "MADV_DONTNEED" },
362 { MADV_REMOVE, "MADV_REMOVE" },
365 { MADV_DONTFORK, "MADV_DONTFORK" },
368 { MADV_DOFORK, "MADV_DOFORK" },
371 { MADV_HWPOISON, "MADV_HWPOISON" },
373 #ifdef MADV_SOFT_OFFLINE
374 { MADV_SOFT_OFFLINE, "MADV_SOFT_OFFLINE" },
376 #ifdef MADV_MERGEABLE
377 { MADV_MERGEABLE, "MADV_MERGEABLE" },
379 #ifdef MADV_UNMERGEABLE
380 { MADV_UNMERGEABLE, "MADV_UNMERGEABLE" },
383 { MADV_HUGEPAGE, "MADV_HUGEPAGE" },
385 #ifdef MADV_NOHUGEPAGE
386 { MADV_NOHUGEPAGE, "MADV_NOHUGEPAGE" },
389 { MADV_DONTDUMP, "MADV_DONTDUMP" },
392 { MADV_DODUMP, "MADV_DODUMP" },
398 sys_madvise(struct tcb *tcp)
401 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
402 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
407 static const struct xlat mlockall_flags[] = {
409 { MCL_CURRENT, "MCL_CURRENT" },
412 { MCL_FUTURE, "MCL_FUTURE" },
418 sys_mlockall(struct tcb *tcp)
421 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
428 static const struct xlat mctl_sync[] = {
430 { MS_SYNC, "MS_SYNC" },
432 { MS_ASYNC, "MS_ASYNC" },
433 { MS_INVALIDATE,"MS_INVALIDATE" },
438 sys_msync(struct tcb *tcp)
442 tprintf("%#lx", tcp->u_arg[0]);
444 tprintf(", %lu, ", tcp->u_arg[1]);
446 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
451 #endif /* MS_ASYNC */
455 static const struct xlat mctl_funcs[] = {
456 { MC_LOCK, "MC_LOCK" },
457 { MC_LOCKAS, "MC_LOCKAS" },
458 { MC_SYNC, "MC_SYNC" },
459 { MC_UNLOCK, "MC_UNLOCK" },
460 { MC_UNLOCKAS, "MC_UNLOCKAS" },
464 static const struct xlat mctl_lockas[] = {
465 { MCL_CURRENT, "MCL_CURRENT" },
466 { MCL_FUTURE, "MCL_FUTURE" },
471 sys_mctl(struct tcb *tcp)
477 tprintf("%#lx", tcp->u_arg[0]);
479 tprintf(", %lu, ", tcp->u_arg[1]);
481 function = tcp->u_arg[2];
482 printflags(mctl_funcs, function, "MC_???");
488 printflags(mctl_sync, arg, "MS_???");
491 printflags(mctl_lockas, arg, "MCL_???");
504 sys_mincore(struct tcb *tcp)
507 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
509 unsigned long i, len;
513 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
514 (vec = malloc(len)) == NULL ||
515 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
516 tprintf("%#lx", tcp->u_arg[2]);
519 for (i = 0; i < len; i++) {
520 if (abbrev(tcp) && i >= max_strlen) {
524 tprints((vec[i] & 1) ? "1" : "0");
533 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
535 sys_getpagesize(struct tcb *tcp)
545 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
547 tprintf("base_addr:%#08lx, "
551 "read_exec_only:%d, "
552 "limit_in_pages:%d, "
553 "seg_not_present:%d, "
555 (long) ldt_entry->base_addr,
557 ldt_entry->seg_32bit,
559 ldt_entry->read_exec_only,
560 ldt_entry->limit_in_pages,
561 ldt_entry->seg_not_present,
566 sys_modify_ldt(struct tcb *tcp)
569 struct modify_ldt_ldt_s copy;
570 tprintf("%ld", tcp->u_arg[0]);
571 if (tcp->u_arg[1] == 0
572 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
573 || umove(tcp, tcp->u_arg[1], ©) == -1)
574 tprintf(", %lx", tcp->u_arg[1]);
576 tprintf(", {entry_number:%d, ", copy.entry_number);
580 print_ldt_entry(©);
583 tprintf(", %lu", tcp->u_arg[2]);
589 sys_set_thread_area(struct tcb *tcp)
591 struct modify_ldt_ldt_s copy;
593 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
594 if (copy.entry_number == -1)
595 tprintf("{entry_number:%d -> ",
598 tprints("{entry_number:");
601 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
602 tprintf("%d, ", copy.entry_number);
606 print_ldt_entry(©);
609 tprintf("%lx", tcp->u_arg[0]);
617 sys_get_thread_area(struct tcb *tcp)
619 struct modify_ldt_ldt_s copy;
621 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
622 tprintf("{entry_number:%d, ", copy.entry_number);
626 print_ldt_entry(©);
629 tprintf("%lx", tcp->u_arg[0]);
639 sys_set_thread_area(struct tcb *tcp)
642 tprintf("%#lx", tcp->u_arg[0]);
648 sys_get_thread_area(struct tcb *tcp)
655 sys_remap_file_pages(struct tcb *tcp)
658 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
659 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
660 tprintf(", %lu, ", tcp->u_arg[3]);
662 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
663 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
665 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
671 #define MPOL_DEFAULT 0
672 #define MPOL_PREFERRED 1
674 #define MPOL_INTERLEAVE 3
676 #define MPOL_F_NODE (1<<0)
677 #define MPOL_F_ADDR (1<<1)
679 #define MPOL_MF_STRICT (1<<0)
680 #define MPOL_MF_MOVE (1<<1)
681 #define MPOL_MF_MOVE_ALL (1<<2)
683 static const struct xlat policies[] = {
684 { MPOL_DEFAULT, "MPOL_DEFAULT" },
685 { MPOL_PREFERRED, "MPOL_PREFERRED" },
686 { MPOL_BIND, "MPOL_BIND" },
687 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
691 static const struct xlat mbindflags[] = {
692 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
693 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
694 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
698 static const struct xlat mempolicyflags[] = {
699 { MPOL_F_NODE, "MPOL_F_NODE" },
700 { MPOL_F_ADDR, "MPOL_F_ADDR" },
704 static const struct xlat move_pages_flags[] = {
705 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
706 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
711 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
713 unsigned long nlongs, size, end;
715 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
716 size = nlongs * sizeof(long);
718 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
720 unsigned long n, cur, abbrev_end;
724 abbrev_end = ptr + max_strlen * sizeof(long);
725 if (abbrev_end < ptr)
731 for (cur = ptr; cur < end; cur += sizeof(long)) {
734 if (cur >= abbrev_end) {
738 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
743 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
747 tprintf(" %#lx", ptr);
749 tprintf(", %#lx", ptr);
750 tprintf(", %lu", maxnodes);
754 sys_mbind(struct tcb *tcp)
757 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
758 printxval(policies, tcp->u_arg[2], "MPOL_???");
759 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
761 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
767 sys_set_mempolicy(struct tcb *tcp)
770 printxval(policies, tcp->u_arg[0], "MPOL_???");
771 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
777 sys_get_mempolicy(struct tcb *tcp)
781 if (tcp->u_arg[0] == 0)
783 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
784 tprintf("%#lx", tcp->u_arg[0]);
786 printxval(policies, pol, "MPOL_???");
787 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
788 tprintf(", %#lx, ", tcp->u_arg[3]);
789 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
795 sys_migrate_pages(struct tcb *tcp)
798 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
799 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
801 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
807 sys_move_pages(struct tcb *tcp)
810 unsigned long npages = tcp->u_arg[1];
811 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
812 if (tcp->u_arg[2] == 0)
816 long puser = tcp->u_arg[2];
818 for (i = 0; i < npages; ++i) {
822 if (umove(tcp, puser, &p) < 0) {
827 puser += sizeof(void *);
831 if (tcp->u_arg[3] == 0)
835 long nodeuser = tcp->u_arg[3];
837 for (i = 0; i < npages; ++i) {
841 if (umove(tcp, nodeuser, &node) < 0) {
845 tprintf("%#x", node);
846 nodeuser += sizeof(int);
852 unsigned long npages = tcp->u_arg[1];
853 if (tcp->u_arg[4] == 0)
857 long statususer = tcp->u_arg[4];
859 for (i = 0; i < npages; ++i) {
863 if (umove(tcp, statususer, &status) < 0) {
867 tprintf("%#x", status);
868 statususer += sizeof(int);
872 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
879 sys_subpage_prot(struct tcb *tcp)
882 unsigned long cur, end, abbrev_end, entries;
885 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
886 entries = tcp->u_arg[1] >> 16;
887 if (!entries || !tcp->u_arg[2]) {
892 end = cur + (sizeof(int) * entries);
893 if (!verbose(tcp) || end < tcp->u_arg[2]) {
894 tprintf("%#lx", tcp->u_arg[2]);
898 abbrev_end = cur + (sizeof(int) * max_strlen);
899 if (abbrev_end > end)
905 for (; cur < end; cur += sizeof(int)) {
906 if (cur > tcp->u_arg[2])
908 if (cur >= abbrev_end) {
912 if (umove(tcp, cur, &entry) < 0) {
913 tprintf("??? [%#lx]", cur);
917 tprintf("%#08x", entry);