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
43 # include <asm/page.h> /* for PAGE_SHIFT */
46 #ifdef HAVE_LONG_LONG_OFF_T
48 * Ugly hacks for systems that have a long long off_t
50 # define sys_mmap64 sys_mmap
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" },
163 { MAP_NOSYNC, "MAP_NOSYNC" },
166 { MAP_NOCORE, "MAP_NOCORE" },
169 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
170 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
171 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
178 addtileflags(long flags)
180 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
181 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
183 if (flags & _MAP_CACHE_INCOHERENT) {
184 flags &= ~_MAP_CACHE_INCOHERENT;
185 if (home == MAP_CACHE_HOME_NONE) {
186 tprints("|MAP_CACHE_INCOHERENT");
189 tprints("|_MAP_CACHE_INCOHERENT");
194 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
195 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
196 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
197 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
198 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
200 tprintf("|MAP_CACHE_HOME(%d)",
201 (home >> _MAP_CACHE_HOME_SHIFT) );
209 #if !HAVE_LONG_LONG_OFF_T
211 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
218 tprintf("%#lx, ", u_arg[0]);
220 tprintf("%lu, ", u_arg[1]);
222 printflags(mmap_prot, u_arg[2], "PROT_???");
226 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
228 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
230 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
233 printflags(mmap_flags, u_arg[3], "MAP_???");
237 printfd(tcp, u_arg[4]);
239 tprintf(", %#llx", offset);
244 int sys_old_mmap(struct tcb *tcp)
248 * IA64 processes never call this routine, they only use the
249 * new `sys_mmap' interface.
250 * For IA32 processes, this code converts the integer arguments
251 * that they pushed onto the stack, into longs.
253 * Note that addresses with bit 31 set will be sign extended.
254 * Fortunately, those addresses are not currently being generated
255 * for IA32 processes so it's not a problem.
260 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
262 for (i = 0; i < 6; i++)
263 u_arg[i] = narrow_arg[i];
264 #elif defined(SH) || defined(SH64)
265 /* SH has always passed the args in registers */
266 long *u_arg = tcp->u_arg;
270 if (current_personality == 1) {
272 unsigned narrow_arg[6];
273 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
275 for (i = 0; i < 6; ++i)
276 u_arg[i] = narrow_arg[i];
280 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
282 #endif /* other architectures */
284 return print_mmap(tcp, u_arg, u_arg[5]);
288 sys_mmap(struct tcb *tcp)
290 long long offset = tcp->u_arg[5];
292 /* FIXME: why only SH64? i386 mmap2 syscall ends up
293 * in this function, but does not convert offset
294 * from pages to bytes. See test/mmap_offset_decode.c
295 * Why SH64 and i386 are handled differently?
299 * Old mmap differs from new mmap in specifying the
300 * offset in units of bytes rather than pages. We
301 * pretend it's in byte units so the user only ever
302 * sees bytes in the printout.
304 offset <<= PAGE_SHIFT;
306 #if defined(LINUX_MIPSN32)
307 offset = tcp->ext_arg[5];
309 return print_mmap(tcp, tcp->u_arg, offset);
311 #endif /* !HAVE_LONG_LONG_OFF_T */
313 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
314 /* TODO: comment which arches use this routine.
315 * For one, does ALPHA on Linux use this??
316 * From code it seems that it might use 7 or 8 registers,
317 * which is strange - Linux syscalls can pass maximum of 6 parameters!
320 sys_mmap64(struct tcb *tcp)
323 #if defined(ALPHA) || defined(X32)
324 long *u_arg = tcp->u_arg;
327 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
328 (char *) u_arg) == -1)
335 tprintf("%#lx, ", u_arg[0]);
337 tprintf("%lu, ", u_arg[1]);
339 printflags(mmap_prot, u_arg[2], "PROT_???");
343 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
344 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
346 printflags(mmap_flags, u_arg[3], "MAP_???");
350 printfd(tcp, u_arg[4]);
352 #if defined(ALPHA) || defined(X32)
353 printllval(tcp, ", %#llx", 5);
355 /* NOTE: not verified that [5] and [6] should be used.
356 * It's possible that long long is 64-bit aligned in memory
357 * and we need to use [6] and [7] here instead:
359 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
364 #endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
367 sys_munmap(struct tcb *tcp)
371 tcp->u_arg[0], tcp->u_arg[1]);
377 sys_mprotect(struct tcb *tcp)
380 tprintf("%#lx, %lu, ",
381 tcp->u_arg[0], tcp->u_arg[1]);
382 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
387 static const struct xlat mremap_flags[] = {
388 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
390 { MREMAP_FIXED, "MREMAP_FIXED" },
396 sys_mremap(struct tcb *tcp)
399 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
401 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
403 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
404 (MREMAP_MAYMOVE | MREMAP_FIXED))
405 tprintf(", %#lx", tcp->u_arg[4]);
411 static const struct xlat madvise_cmds[] = {
413 { MADV_NORMAL, "MADV_NORMAL" },
416 { MADV_RANDOM, "MADV_RANDOM" },
418 #ifdef MADV_SEQUENTIAL
419 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
422 { MADV_WILLNEED, "MADV_WILLNEED" },
425 { MADV_DONTNEED, "MADV_DONTNEED" },
431 sys_madvise(struct tcb *tcp)
434 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
435 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
440 static const struct xlat mlockall_flags[] = {
442 { MCL_CURRENT, "MCL_CURRENT" },
445 { MCL_FUTURE, "MCL_FUTURE" },
451 sys_mlockall(struct tcb *tcp)
454 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
461 static const struct xlat mctl_sync[] = {
463 { MS_SYNC, "MS_SYNC" },
465 { MS_ASYNC, "MS_ASYNC" },
466 { MS_INVALIDATE,"MS_INVALIDATE" },
471 sys_msync(struct tcb *tcp)
475 tprintf("%#lx", tcp->u_arg[0]);
477 tprintf(", %lu, ", tcp->u_arg[1]);
479 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
484 #endif /* MS_ASYNC */
488 static const struct xlat mctl_funcs[] = {
489 { MC_LOCK, "MC_LOCK" },
490 { MC_LOCKAS, "MC_LOCKAS" },
491 { MC_SYNC, "MC_SYNC" },
492 { MC_UNLOCK, "MC_UNLOCK" },
493 { MC_UNLOCKAS, "MC_UNLOCKAS" },
497 static const struct xlat mctl_lockas[] = {
498 { MCL_CURRENT, "MCL_CURRENT" },
499 { MCL_FUTURE, "MCL_FUTURE" },
504 sys_mctl(struct tcb *tcp)
510 tprintf("%#lx", tcp->u_arg[0]);
512 tprintf(", %lu, ", tcp->u_arg[1]);
514 function = tcp->u_arg[2];
515 printflags(mctl_funcs, function, "MC_???");
521 printflags(mctl_sync, arg, "MS_???");
524 printflags(mctl_lockas, arg, "MCL_???");
537 sys_mincore(struct tcb *tcp)
540 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
542 unsigned long i, len;
546 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
547 (vec = malloc(len)) == NULL ||
548 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
549 tprintf("%#lx", tcp->u_arg[2]);
552 for (i = 0; i < len; i++) {
553 if (abbrev(tcp) && i >= max_strlen) {
557 tprints((vec[i] & 1) ? "1" : "0");
566 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
568 sys_getpagesize(struct tcb *tcp)
578 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
580 tprintf("base_addr:%#08lx, "
584 "read_exec_only:%d, "
585 "limit_in_pages:%d, "
586 "seg_not_present:%d, "
588 (long) ldt_entry->base_addr,
590 ldt_entry->seg_32bit,
592 ldt_entry->read_exec_only,
593 ldt_entry->limit_in_pages,
594 ldt_entry->seg_not_present,
599 sys_modify_ldt(struct tcb *tcp)
602 struct modify_ldt_ldt_s copy;
603 tprintf("%ld", tcp->u_arg[0]);
604 if (tcp->u_arg[1] == 0
605 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
606 || umove(tcp, tcp->u_arg[1], ©) == -1)
607 tprintf(", %lx", tcp->u_arg[1]);
609 tprintf(", {entry_number:%d, ", copy.entry_number);
613 print_ldt_entry(©);
616 tprintf(", %lu", tcp->u_arg[2]);
622 sys_set_thread_area(struct tcb *tcp)
624 struct modify_ldt_ldt_s copy;
626 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
627 if (copy.entry_number == -1)
628 tprintf("{entry_number:%d -> ",
631 tprints("{entry_number:");
634 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
635 tprintf("%d, ", copy.entry_number);
639 print_ldt_entry(©);
642 tprintf("%lx", tcp->u_arg[0]);
650 sys_get_thread_area(struct tcb *tcp)
652 struct modify_ldt_ldt_s copy;
654 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
655 tprintf("{entry_number:%d, ", copy.entry_number);
659 print_ldt_entry(©);
662 tprintf("%lx", tcp->u_arg[0]);
672 sys_set_thread_area(struct tcb *tcp)
675 tprintf("%#lx", tcp->u_arg[0]);
681 sys_get_thread_area(struct tcb *tcp)
688 sys_remap_file_pages(struct tcb *tcp)
691 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
692 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
693 tprintf(", %lu, ", tcp->u_arg[3]);
695 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
696 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
698 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
704 #define MPOL_DEFAULT 0
705 #define MPOL_PREFERRED 1
707 #define MPOL_INTERLEAVE 3
709 #define MPOL_F_NODE (1<<0)
710 #define MPOL_F_ADDR (1<<1)
712 #define MPOL_MF_STRICT (1<<0)
713 #define MPOL_MF_MOVE (1<<1)
714 #define MPOL_MF_MOVE_ALL (1<<2)
716 static const struct xlat policies[] = {
717 { MPOL_DEFAULT, "MPOL_DEFAULT" },
718 { MPOL_PREFERRED, "MPOL_PREFERRED" },
719 { MPOL_BIND, "MPOL_BIND" },
720 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
724 static const struct xlat mbindflags[] = {
725 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
726 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
727 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
731 static const struct xlat mempolicyflags[] = {
732 { MPOL_F_NODE, "MPOL_F_NODE" },
733 { MPOL_F_ADDR, "MPOL_F_ADDR" },
737 static const struct xlat move_pages_flags[] = {
738 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
739 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
744 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
746 unsigned long nlongs, size, end;
748 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
749 size = nlongs * sizeof(long);
751 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
753 unsigned long n, cur, abbrev_end;
757 abbrev_end = ptr + max_strlen * sizeof(long);
758 if (abbrev_end < ptr)
764 for (cur = ptr; cur < end; cur += sizeof(long)) {
767 if (cur >= abbrev_end) {
771 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
776 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
780 tprintf(" %#lx", ptr);
782 tprintf(", %#lx", ptr);
783 tprintf(", %lu", maxnodes);
787 sys_mbind(struct tcb *tcp)
790 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
791 printxval(policies, tcp->u_arg[2], "MPOL_???");
792 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
794 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
800 sys_set_mempolicy(struct tcb *tcp)
803 printxval(policies, tcp->u_arg[0], "MPOL_???");
804 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
810 sys_get_mempolicy(struct tcb *tcp)
814 if (tcp->u_arg[0] == 0)
816 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
817 tprintf("%#lx", tcp->u_arg[0]);
819 printxval(policies, pol, "MPOL_???");
820 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
821 tprintf(", %#lx, ", tcp->u_arg[3]);
822 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
828 sys_migrate_pages(struct tcb *tcp)
831 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
832 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
834 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
840 sys_move_pages(struct tcb *tcp)
843 unsigned long npages = tcp->u_arg[1];
844 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
845 if (tcp->u_arg[2] == 0)
849 long puser = tcp->u_arg[2];
851 for (i = 0; i < npages; ++i) {
855 if (umove(tcp, puser, &p) < 0) {
860 puser += sizeof(void *);
864 if (tcp->u_arg[3] == 0)
868 long nodeuser = tcp->u_arg[3];
870 for (i = 0; i < npages; ++i) {
874 if (umove(tcp, nodeuser, &node) < 0) {
878 tprintf("%#x", node);
879 nodeuser += sizeof(int);
885 unsigned long npages = tcp->u_arg[1];
886 if (tcp->u_arg[4] == 0)
890 long statususer = tcp->u_arg[4];
892 for (i = 0; i < npages; ++i) {
896 if (umove(tcp, statususer, &status) < 0) {
900 tprintf("%#x", status);
901 statususer += sizeof(int);
905 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
912 sys_subpage_prot(struct tcb *tcp)
915 unsigned long cur, end, abbrev_end, entries;
918 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
919 entries = tcp->u_arg[1] >> 16;
920 if (!entries || !tcp->u_arg[2]) {
925 end = cur + (sizeof(int) * entries);
926 if (!verbose(tcp) || end < tcp->u_arg[2]) {
927 tprintf("%#lx", tcp->u_arg[2]);
931 abbrev_end = cur + (sizeof(int) * max_strlen);
932 if (abbrev_end > end)
938 for (; cur < end; cur += sizeof(int)) {
939 if (cur > tcp->u_arg[2])
941 if (cur >= abbrev_end) {
945 if (umove(tcp, cur, &entry) < 0) {
946 tprintf("??? [%#lx]", cur);
950 tprintf("%#08x", entry);