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" },
172 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
173 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
174 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
181 addtileflags(long flags)
183 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
184 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
186 if (flags & _MAP_CACHE_INCOHERENT) {
187 flags &= ~_MAP_CACHE_INCOHERENT;
188 if (home == MAP_CACHE_HOME_NONE) {
189 tprints("|MAP_CACHE_INCOHERENT");
192 tprints("|_MAP_CACHE_INCOHERENT");
197 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
198 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
199 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
200 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
201 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
203 tprintf("|MAP_CACHE_HOME(%ld)",
204 (home >> _MAP_CACHE_HOME_SHIFT) );
213 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
220 tprintf("%#lx, ", u_arg[0]);
222 tprintf("%lu, ", u_arg[1]);
224 printflags(mmap_prot, u_arg[2], "PROT_???");
228 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
230 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
232 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
235 printflags(mmap_flags, u_arg[3], "MAP_???");
239 printfd(tcp, u_arg[4]);
241 tprintf(", %#llx", offset);
246 /* Syscall name<->function correspondence is messed up on many arches.
248 * i386 has __NR_mmap == 90, and it is "old mmap", and
249 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
250 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
254 /* Params are pointed to by u_arg[0], offset is in bytes */
256 sys_old_mmap(struct tcb *tcp)
261 * IA64 processes never call this routine, they only use the
262 * new 'sys_mmap' interface. Only IA32 processes come here.
265 unsigned narrow_arg[6];
266 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
268 for (i = 0; i < 6; i++)
269 u_arg[i] = (unsigned long) narrow_arg[i];
270 #elif defined(X86_64)
271 /* We are here only in personality 1 (i386) */
273 unsigned narrow_arg[6];
274 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
276 for (i = 0; i < 6; ++i)
277 u_arg[i] = (unsigned long) narrow_arg[i];
279 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
282 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
286 /* Params are pointed to by u_arg[0], offset is in pages */
288 sys_old_mmap_pgoff(struct tcb *tcp)
292 unsigned narrow_arg[6];
293 unsigned long long offset;
294 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
296 for (i = 0; i < 5; i++)
297 u_arg[i] = (unsigned long) narrow_arg[i];
298 offset = narrow_arg[5];
299 offset *= get_pagesize();
300 return print_mmap(tcp, u_arg, offset);
304 /* Params are passed directly, offset is in bytes */
306 sys_mmap(struct tcb *tcp)
308 unsigned long long offset = (unsigned long) tcp->u_arg[5];
309 #if defined(LINUX_MIPSN32) || defined(X32)
310 /* Try test/x32_mmap.c */
311 offset = tcp->ext_arg[5];
313 /* Example of kernel-side handling of this variety of mmap:
314 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
315 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
316 * since the above code converts off to pages.
318 return print_mmap(tcp, tcp->u_arg, offset);
321 /* Params are passed directly, offset is in pages */
323 sys_mmap_pgoff(struct tcb *tcp)
325 /* Try test/mmap_offset_decode.c */
326 unsigned long long offset;
327 offset = (unsigned long) tcp->u_arg[5];
328 offset *= get_pagesize();
329 return print_mmap(tcp, tcp->u_arg, offset);
332 /* Params are passed directly, offset is in 4k units */
334 sys_mmap_4koff(struct tcb *tcp)
336 unsigned long long offset;
337 offset = (unsigned long) tcp->u_arg[5];
339 return print_mmap(tcp, tcp->u_arg, offset);
343 sys_munmap(struct tcb *tcp)
347 tcp->u_arg[0], tcp->u_arg[1]);
353 sys_mprotect(struct tcb *tcp)
356 tprintf("%#lx, %lu, ",
357 tcp->u_arg[0], tcp->u_arg[1]);
358 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
363 static const struct xlat mremap_flags[] = {
364 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
366 { MREMAP_FIXED, "MREMAP_FIXED" },
372 sys_mremap(struct tcb *tcp)
375 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
377 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
379 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
380 (MREMAP_MAYMOVE | MREMAP_FIXED))
381 tprintf(", %#lx", tcp->u_arg[4]);
387 static const struct xlat madvise_cmds[] = {
389 { MADV_NORMAL, "MADV_NORMAL" },
392 { MADV_RANDOM, "MADV_RANDOM" },
394 #ifdef MADV_SEQUENTIAL
395 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
398 { MADV_WILLNEED, "MADV_WILLNEED" },
401 { MADV_DONTNEED, "MADV_DONTNEED" },
407 sys_madvise(struct tcb *tcp)
410 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
411 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
416 static const struct xlat mlockall_flags[] = {
418 { MCL_CURRENT, "MCL_CURRENT" },
421 { MCL_FUTURE, "MCL_FUTURE" },
427 sys_mlockall(struct tcb *tcp)
430 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
437 static const struct xlat mctl_sync[] = {
439 { MS_SYNC, "MS_SYNC" },
441 { MS_ASYNC, "MS_ASYNC" },
442 { MS_INVALIDATE,"MS_INVALIDATE" },
447 sys_msync(struct tcb *tcp)
451 tprintf("%#lx", tcp->u_arg[0]);
453 tprintf(", %lu, ", tcp->u_arg[1]);
455 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
460 #endif /* MS_ASYNC */
464 static const struct xlat mctl_funcs[] = {
465 { MC_LOCK, "MC_LOCK" },
466 { MC_LOCKAS, "MC_LOCKAS" },
467 { MC_SYNC, "MC_SYNC" },
468 { MC_UNLOCK, "MC_UNLOCK" },
469 { MC_UNLOCKAS, "MC_UNLOCKAS" },
473 static const struct xlat mctl_lockas[] = {
474 { MCL_CURRENT, "MCL_CURRENT" },
475 { MCL_FUTURE, "MCL_FUTURE" },
480 sys_mctl(struct tcb *tcp)
486 tprintf("%#lx", tcp->u_arg[0]);
488 tprintf(", %lu, ", tcp->u_arg[1]);
490 function = tcp->u_arg[2];
491 printflags(mctl_funcs, function, "MC_???");
497 printflags(mctl_sync, arg, "MS_???");
500 printflags(mctl_lockas, arg, "MCL_???");
513 sys_mincore(struct tcb *tcp)
516 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
518 unsigned long i, len;
522 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
523 (vec = malloc(len)) == NULL ||
524 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
525 tprintf("%#lx", tcp->u_arg[2]);
528 for (i = 0; i < len; i++) {
529 if (abbrev(tcp) && i >= max_strlen) {
533 tprints((vec[i] & 1) ? "1" : "0");
542 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
544 sys_getpagesize(struct tcb *tcp)
554 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
556 tprintf("base_addr:%#08lx, "
560 "read_exec_only:%d, "
561 "limit_in_pages:%d, "
562 "seg_not_present:%d, "
564 (long) ldt_entry->base_addr,
566 ldt_entry->seg_32bit,
568 ldt_entry->read_exec_only,
569 ldt_entry->limit_in_pages,
570 ldt_entry->seg_not_present,
575 sys_modify_ldt(struct tcb *tcp)
578 struct modify_ldt_ldt_s copy;
579 tprintf("%ld", tcp->u_arg[0]);
580 if (tcp->u_arg[1] == 0
581 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
582 || umove(tcp, tcp->u_arg[1], ©) == -1)
583 tprintf(", %lx", tcp->u_arg[1]);
585 tprintf(", {entry_number:%d, ", copy.entry_number);
589 print_ldt_entry(©);
592 tprintf(", %lu", tcp->u_arg[2]);
598 sys_set_thread_area(struct tcb *tcp)
600 struct modify_ldt_ldt_s copy;
602 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
603 if (copy.entry_number == -1)
604 tprintf("{entry_number:%d -> ",
607 tprints("{entry_number:");
610 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
611 tprintf("%d, ", copy.entry_number);
615 print_ldt_entry(©);
618 tprintf("%lx", tcp->u_arg[0]);
626 sys_get_thread_area(struct tcb *tcp)
628 struct modify_ldt_ldt_s copy;
630 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
631 tprintf("{entry_number:%d, ", copy.entry_number);
635 print_ldt_entry(©);
638 tprintf("%lx", tcp->u_arg[0]);
648 sys_set_thread_area(struct tcb *tcp)
651 tprintf("%#lx", tcp->u_arg[0]);
657 sys_get_thread_area(struct tcb *tcp)
664 sys_remap_file_pages(struct tcb *tcp)
667 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
668 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
669 tprintf(", %lu, ", tcp->u_arg[3]);
671 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
672 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
674 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
680 #define MPOL_DEFAULT 0
681 #define MPOL_PREFERRED 1
683 #define MPOL_INTERLEAVE 3
685 #define MPOL_F_NODE (1<<0)
686 #define MPOL_F_ADDR (1<<1)
688 #define MPOL_MF_STRICT (1<<0)
689 #define MPOL_MF_MOVE (1<<1)
690 #define MPOL_MF_MOVE_ALL (1<<2)
692 static const struct xlat policies[] = {
693 { MPOL_DEFAULT, "MPOL_DEFAULT" },
694 { MPOL_PREFERRED, "MPOL_PREFERRED" },
695 { MPOL_BIND, "MPOL_BIND" },
696 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
700 static const struct xlat mbindflags[] = {
701 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
702 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
703 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
707 static const struct xlat mempolicyflags[] = {
708 { MPOL_F_NODE, "MPOL_F_NODE" },
709 { MPOL_F_ADDR, "MPOL_F_ADDR" },
713 static const struct xlat move_pages_flags[] = {
714 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
715 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
720 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
722 unsigned long nlongs, size, end;
724 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
725 size = nlongs * sizeof(long);
727 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
729 unsigned long n, cur, abbrev_end;
733 abbrev_end = ptr + max_strlen * sizeof(long);
734 if (abbrev_end < ptr)
740 for (cur = ptr; cur < end; cur += sizeof(long)) {
743 if (cur >= abbrev_end) {
747 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
752 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
756 tprintf(" %#lx", ptr);
758 tprintf(", %#lx", ptr);
759 tprintf(", %lu", maxnodes);
763 sys_mbind(struct tcb *tcp)
766 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
767 printxval(policies, tcp->u_arg[2], "MPOL_???");
768 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
770 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
776 sys_set_mempolicy(struct tcb *tcp)
779 printxval(policies, tcp->u_arg[0], "MPOL_???");
780 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
786 sys_get_mempolicy(struct tcb *tcp)
790 if (tcp->u_arg[0] == 0)
792 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
793 tprintf("%#lx", tcp->u_arg[0]);
795 printxval(policies, pol, "MPOL_???");
796 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
797 tprintf(", %#lx, ", tcp->u_arg[3]);
798 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
804 sys_migrate_pages(struct tcb *tcp)
807 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
808 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
810 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
816 sys_move_pages(struct tcb *tcp)
819 unsigned long npages = tcp->u_arg[1];
820 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
821 if (tcp->u_arg[2] == 0)
825 long puser = tcp->u_arg[2];
827 for (i = 0; i < npages; ++i) {
831 if (umove(tcp, puser, &p) < 0) {
836 puser += sizeof(void *);
840 if (tcp->u_arg[3] == 0)
844 long nodeuser = tcp->u_arg[3];
846 for (i = 0; i < npages; ++i) {
850 if (umove(tcp, nodeuser, &node) < 0) {
854 tprintf("%#x", node);
855 nodeuser += sizeof(int);
861 unsigned long npages = tcp->u_arg[1];
862 if (tcp->u_arg[4] == 0)
866 long statususer = tcp->u_arg[4];
868 for (i = 0; i < npages; ++i) {
872 if (umove(tcp, statususer, &status) < 0) {
876 tprintf("%#x", status);
877 statususer += sizeof(int);
881 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
888 sys_subpage_prot(struct tcb *tcp)
891 unsigned long cur, end, abbrev_end, entries;
894 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
895 entries = tcp->u_arg[1] >> 16;
896 if (!entries || !tcp->u_arg[2]) {
901 end = cur + (sizeof(int) * entries);
902 if (!verbose(tcp) || end < tcp->u_arg[2]) {
903 tprintf("%#lx", tcp->u_arg[2]);
907 abbrev_end = cur + (sizeof(int) * max_strlen);
908 if (abbrev_end > end)
914 for (; cur < end; cur += sizeof(int)) {
915 if (cur > tcp->u_arg[2])
917 if (cur >= abbrev_end) {
921 if (umove(tcp, cur, &entry) < 0) {
922 tprintf("??? [%#lx]", cur);
926 tprintf("%#08x", entry);