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.
42 # ifdef HAVE_STRUCT_USER_DESC
43 # define modify_ldt_ldt_s user_desc
47 # include <asm/page.h> /* for PAGE_SHIFT */
50 #ifdef HAVE_LONG_LONG_OFF_T
52 * Ugly hacks for systems that have a long long off_t
54 #define sys_mmap64 sys_mmap
58 sys_brk(struct tcb *tcp)
61 tprintf("%#lx", tcp->u_arg[0]);
66 static const struct xlat mmap_prot[] = {
67 { PROT_NONE, "PROT_NONE", },
68 { PROT_READ, "PROT_READ" },
69 { PROT_WRITE, "PROT_WRITE" },
70 { PROT_EXEC, "PROT_EXEC" },
72 { PROT_SEM, "PROT_SEM" },
75 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
78 { PROT_GROWSUP, "PROT_GROWSUP" },
81 { PROT_SAO, "PROT_SAO" },
86 static const struct xlat mmap_flags[] = {
87 { MAP_SHARED, "MAP_SHARED" },
88 { MAP_PRIVATE, "MAP_PRIVATE" },
89 { MAP_FIXED, "MAP_FIXED" },
91 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
94 { MAP_32BIT, "MAP_32BIT" },
97 { MAP_RENAME, "MAP_RENAME" },
100 { MAP_NORESERVE,"MAP_NORESERVE" },
103 { MAP_POPULATE, "MAP_POPULATE" },
106 { MAP_NONBLOCK, "MAP_NONBLOCK" },
109 * XXX - this was introduced in SunOS 4.x to distinguish between
110 * the old pre-4.x "mmap()", which:
112 * only let you map devices with an "mmap" routine (e.g.,
115 * required you to specify the mapping address;
117 * returned 0 on success and -1 on failure;
119 * memory and which, and the 4.x "mmap()" which:
121 * can map plain files;
123 * can be asked to pick where to map the file;
125 * returns the address where it mapped the file on success
128 * It's not actually used in source code that calls "mmap()"; the
129 * "mmap()" routine adds it for you.
131 * It'd be nice to come up with some way of eliminating it from
132 * the flags, e.g. reporting calls *without* it as "old_mmap()"
133 * and calls with it as "mmap()".
136 { _MAP_NEW, "_MAP_NEW" },
139 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
142 { MAP_DENYWRITE,"MAP_DENYWRITE" },
144 #ifdef MAP_EXECUTABLE
145 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
148 { MAP_INHERIT,"MAP_INHERIT" },
151 { MAP_FILE,"MAP_FILE"},
154 { MAP_LOCKED,"MAP_LOCKED"},
158 { MAP_ANON, "MAP_ANON" },
160 #ifdef MAP_HASSEMAPHORE
161 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
164 { MAP_STACK, "MAP_STACK" },
167 { MAP_NOSYNC, "MAP_NOSYNC" },
170 { MAP_NOCORE, "MAP_NOCORE" },
173 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
174 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
175 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
182 addtileflags(long flags)
184 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
185 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
187 if (flags & _MAP_CACHE_INCOHERENT) {
188 flags &= ~_MAP_CACHE_INCOHERENT;
189 if (home == MAP_CACHE_HOME_NONE) {
190 tprints("|MAP_CACHE_INCOHERENT");
193 tprints("|_MAP_CACHE_INCOHERENT");
198 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
199 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
200 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
201 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
202 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
204 tprintf("|MAP_CACHE_HOME(%d)",
205 (home >> _MAP_CACHE_HOME_SHIFT) );
213 #if !HAVE_LONG_LONG_OFF_T
215 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
222 tprintf("%#lx, ", u_arg[0]);
224 tprintf("%lu, ", u_arg[1]);
226 printflags(mmap_prot, u_arg[2], "PROT_???");
230 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
232 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
234 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
237 printflags(mmap_flags, u_arg[3], "MAP_???");
241 printfd(tcp, u_arg[4]);
243 tprintf(", %#llx", offset);
248 int sys_old_mmap(struct tcb *tcp)
252 * IA64 processes never call this routine, they only use the
253 * new `sys_mmap' interface.
254 * For IA32 processes, this code converts the integer arguments
255 * that they pushed onto the stack, into longs.
257 * Note that addresses with bit 31 set will be sign extended.
258 * Fortunately, those addresses are not currently being generated
259 * for IA32 processes so it's not a problem.
264 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
266 for (i = 0; i < 6; i++)
267 u_arg[i] = narrow_arg[i];
268 #elif defined(SH) || defined(SH64)
269 /* SH has always passed the args in registers */
270 long *u_arg = tcp->u_arg;
274 if (current_personality == 1) {
276 unsigned narrow_arg[6];
277 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
279 for (i = 0; i < 6; ++i)
280 u_arg[i] = narrow_arg[i];
284 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
286 #endif /* other architectures */
288 return print_mmap(tcp, u_arg, u_arg[5]);
292 sys_mmap(struct tcb *tcp)
294 long long offset = tcp->u_arg[5];
296 /* FIXME: why only SH64? i386 mmap2 syscall ends up
297 * in this function, but does not convert offset
298 * from pages to bytes. See test/mmap_offset_decode.c
299 * Why SH64 and i386 are handled differently?
303 * Old mmap differs from new mmap in specifying the
304 * offset in units of bytes rather than pages. We
305 * pretend it's in byte units so the user only ever
306 * sees bytes in the printout.
308 offset <<= PAGE_SHIFT;
310 #if defined(LINUX_MIPSN32)
311 offset = tcp->ext_arg[5];
313 return print_mmap(tcp, tcp->u_arg, offset);
315 #endif /* !HAVE_LONG_LONG_OFF_T */
317 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
318 /* TODO: comment which arches use this routine.
319 * For one, does ALPHA on Linux use this??
320 * From code it seems that it might use 7 or 8 registers,
321 * which is strange - Linux syscalls can pass maximum of 6 parameters!
324 sys_mmap64(struct tcb *tcp)
328 long *u_arg = tcp->u_arg;
331 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
332 (char *) u_arg) == -1)
339 tprintf("%#lx, ", u_arg[0]);
341 tprintf("%lu, ", u_arg[1]);
343 printflags(mmap_prot, u_arg[2], "PROT_???");
347 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
348 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
350 printflags(mmap_flags, u_arg[3], "MAP_???");
354 printfd(tcp, u_arg[4]);
357 printllval(tcp, ", %#llx", 5);
359 /* NOTE: not verified that [5] and [6] should be used.
360 * It's possible that long long is 64-bit aligned in memory
361 * and we need to use [6] and [7] here instead:
363 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
368 #endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
371 sys_munmap(struct tcb *tcp)
375 tcp->u_arg[0], tcp->u_arg[1]);
381 sys_mprotect(struct tcb *tcp)
384 tprintf("%#lx, %lu, ",
385 tcp->u_arg[0], tcp->u_arg[1]);
386 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
391 static const struct xlat mremap_flags[] = {
392 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
394 { MREMAP_FIXED, "MREMAP_FIXED" },
400 sys_mremap(struct tcb *tcp)
403 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
405 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
407 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
408 (MREMAP_MAYMOVE | MREMAP_FIXED))
409 tprintf(", %#lx", tcp->u_arg[4]);
415 static const struct xlat madvise_cmds[] = {
417 { MADV_NORMAL, "MADV_NORMAL" },
420 { MADV_RANDOM, "MADV_RANDOM" },
422 #ifdef MADV_SEQUENTIAL
423 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
426 { MADV_WILLNEED, "MADV_WILLNEED" },
429 { MADV_DONTNEED, "MADV_DONTNEED" },
435 sys_madvise(struct tcb *tcp)
438 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
439 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
444 static const struct xlat mlockall_flags[] = {
446 { MCL_CURRENT, "MCL_CURRENT" },
449 { MCL_FUTURE, "MCL_FUTURE" },
455 sys_mlockall(struct tcb *tcp)
458 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
465 static const struct xlat mctl_sync[] = {
467 { MS_SYNC, "MS_SYNC" },
469 { MS_ASYNC, "MS_ASYNC" },
470 { MS_INVALIDATE,"MS_INVALIDATE" },
475 sys_msync(struct tcb *tcp)
479 tprintf("%#lx", tcp->u_arg[0]);
481 tprintf(", %lu, ", tcp->u_arg[1]);
483 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
488 #endif /* MS_ASYNC */
492 static const struct xlat mctl_funcs[] = {
493 { MC_LOCK, "MC_LOCK" },
494 { MC_LOCKAS, "MC_LOCKAS" },
495 { MC_SYNC, "MC_SYNC" },
496 { MC_UNLOCK, "MC_UNLOCK" },
497 { MC_UNLOCKAS, "MC_UNLOCKAS" },
501 static const struct xlat mctl_lockas[] = {
502 { MCL_CURRENT, "MCL_CURRENT" },
503 { MCL_FUTURE, "MCL_FUTURE" },
508 sys_mctl(struct tcb *tcp)
514 tprintf("%#lx", tcp->u_arg[0]);
516 tprintf(", %lu, ", tcp->u_arg[1]);
518 function = tcp->u_arg[2];
519 printflags(mctl_funcs, function, "MC_???");
525 printflags(mctl_sync, arg, "MS_???");
528 printflags(mctl_lockas, arg, "MCL_???");
541 sys_mincore(struct tcb *tcp)
544 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
546 unsigned long i, len;
550 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
551 (vec = malloc(len)) == NULL ||
552 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
553 tprintf("%#lx", tcp->u_arg[2]);
556 for (i = 0; i < len; i++) {
557 if (abbrev(tcp) && i >= max_strlen) {
561 tprints((vec[i] & 1) ? "1" : "0");
570 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
572 sys_getpagesize(struct tcb *tcp)
582 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
584 tprintf("base_addr:%#08lx, "
588 "read_exec_only:%d, "
589 "limit_in_pages:%d, "
590 "seg_not_present:%d, "
592 (long) ldt_entry->base_addr,
594 ldt_entry->seg_32bit,
596 ldt_entry->read_exec_only,
597 ldt_entry->limit_in_pages,
598 ldt_entry->seg_not_present,
603 sys_modify_ldt(struct tcb *tcp)
606 struct modify_ldt_ldt_s copy;
607 tprintf("%ld", tcp->u_arg[0]);
608 if (tcp->u_arg[1] == 0
609 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
610 || umove(tcp, tcp->u_arg[1], ©) == -1)
611 tprintf(", %lx", tcp->u_arg[1]);
613 tprintf(", {entry_number:%d, ", copy.entry_number);
617 print_ldt_entry(©);
620 tprintf(", %lu", tcp->u_arg[2]);
626 sys_set_thread_area(struct tcb *tcp)
628 struct modify_ldt_ldt_s copy;
630 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
631 if (copy.entry_number == -1)
632 tprintf("{entry_number:%d -> ",
635 tprints("{entry_number:");
638 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
639 tprintf("%d, ", copy.entry_number);
643 print_ldt_entry(©);
646 tprintf("%lx", tcp->u_arg[0]);
654 sys_get_thread_area(struct tcb *tcp)
656 struct modify_ldt_ldt_s copy;
658 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
659 tprintf("{entry_number:%d, ", copy.entry_number);
663 print_ldt_entry(©);
666 tprintf("%lx", tcp->u_arg[0]);
676 sys_set_thread_area(struct tcb *tcp)
679 tprintf("%#lx", tcp->u_arg[0]);
685 sys_get_thread_area(struct tcb *tcp)
692 sys_remap_file_pages(struct tcb *tcp)
695 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
696 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
697 tprintf(", %lu, ", tcp->u_arg[3]);
699 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
700 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
702 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
708 #define MPOL_DEFAULT 0
709 #define MPOL_PREFERRED 1
711 #define MPOL_INTERLEAVE 3
713 #define MPOL_F_NODE (1<<0)
714 #define MPOL_F_ADDR (1<<1)
716 #define MPOL_MF_STRICT (1<<0)
717 #define MPOL_MF_MOVE (1<<1)
718 #define MPOL_MF_MOVE_ALL (1<<2)
720 static const struct xlat policies[] = {
721 { MPOL_DEFAULT, "MPOL_DEFAULT" },
722 { MPOL_PREFERRED, "MPOL_PREFERRED" },
723 { MPOL_BIND, "MPOL_BIND" },
724 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
728 static const struct xlat mbindflags[] = {
729 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
730 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
731 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
735 static const struct xlat mempolicyflags[] = {
736 { MPOL_F_NODE, "MPOL_F_NODE" },
737 { MPOL_F_ADDR, "MPOL_F_ADDR" },
741 static const struct xlat move_pages_flags[] = {
742 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
743 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
748 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
750 unsigned long nlongs, size, end;
752 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
753 size = nlongs * sizeof(long);
755 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
757 unsigned long n, cur, abbrev_end;
761 abbrev_end = ptr + max_strlen * sizeof(long);
762 if (abbrev_end < ptr)
768 for (cur = ptr; cur < end; cur += sizeof(long)) {
771 if (cur >= abbrev_end) {
775 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
780 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
784 tprintf(" %#lx", ptr);
786 tprintf(", %#lx", ptr);
787 tprintf(", %lu", maxnodes);
791 sys_mbind(struct tcb *tcp)
794 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
795 printxval(policies, tcp->u_arg[2], "MPOL_???");
796 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
798 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
804 sys_set_mempolicy(struct tcb *tcp)
807 printxval(policies, tcp->u_arg[0], "MPOL_???");
808 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
814 sys_get_mempolicy(struct tcb *tcp)
818 if (tcp->u_arg[0] == 0)
820 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
821 tprintf("%#lx", tcp->u_arg[0]);
823 printxval(policies, pol, "MPOL_???");
824 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
825 tprintf(", %#lx, ", tcp->u_arg[3]);
826 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
832 sys_migrate_pages(struct tcb *tcp)
835 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
836 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
838 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
844 sys_move_pages(struct tcb *tcp)
847 unsigned long npages = tcp->u_arg[1];
848 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
849 if (tcp->u_arg[2] == 0)
853 long puser = tcp->u_arg[2];
855 for (i = 0; i < npages; ++i) {
859 if (umove(tcp, puser, &p) < 0) {
864 puser += sizeof(void *);
868 if (tcp->u_arg[3] == 0)
872 long nodeuser = tcp->u_arg[3];
874 for (i = 0; i < npages; ++i) {
878 if (umove(tcp, nodeuser, &node) < 0) {
882 tprintf("%#x", node);
883 nodeuser += sizeof(int);
889 unsigned long npages = tcp->u_arg[1];
890 if (tcp->u_arg[4] == 0)
894 long statususer = tcp->u_arg[4];
896 for (i = 0; i < npages; ++i) {
900 if (umove(tcp, statususer, &status) < 0) {
904 tprintf("%#x", status);
905 statususer += sizeof(int);
909 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
916 sys_subpage_prot(struct tcb *tcp)
919 unsigned long cur, end, abbrev_end, entries;
922 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
923 entries = tcp->u_arg[1] >> 16;
924 if (!entries || !tcp->u_arg[2]) {
929 end = cur + (sizeof(int) * entries);
930 if (!verbose(tcp) || end < tcp->u_arg[2]) {
931 tprintf("%#lx", tcp->u_arg[2]);
935 abbrev_end = cur + (sizeof(int) * max_strlen);
936 if (abbrev_end > end)
942 for (; cur < end; cur += sizeof(int)) {
943 if (cur > tcp->u_arg[2])
945 if (cur >= abbrev_end) {
949 if (umove(tcp, cur, &entry) < 0) {
950 tprintf("??? [%#lx]", cur);
954 tprintf("%#08x", entry);