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 #if defined(LINUX) && defined(I386)
44 # ifdef HAVE_STRUCT_USER_DESC
45 # define modify_ldt_ldt_s user_desc
48 #if defined(LINUX) && defined(SH64)
49 # include <asm/page.h> /* for PAGE_SHIFT */
52 #ifdef HAVE_LONG_LONG_OFF_T
54 * Ugly hacks for systems that have a long long off_t
56 #define sys_mmap64 sys_mmap
60 sys_brk(struct tcb *tcp)
63 tprintf("%#lx", tcp->u_arg[0]);
72 #if defined(FREEBSD) || defined(SUNOS4)
74 sys_sbrk(struct tcb *tcp)
77 tprintf("%lu", tcp->u_arg[0]);
81 #endif /* FREEBSD || SUNOS4 */
83 static const struct xlat mmap_prot[] = {
84 { PROT_NONE, "PROT_NONE", },
85 { PROT_READ, "PROT_READ" },
86 { PROT_WRITE, "PROT_WRITE" },
87 { PROT_EXEC, "PROT_EXEC" },
89 { PROT_SEM, "PROT_SEM" },
92 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
95 { PROT_GROWSUP, "PROT_GROWSUP" },
98 { PROT_SAO, "PROT_SAO" },
103 static const struct xlat mmap_flags[] = {
104 { MAP_SHARED, "MAP_SHARED" },
105 { MAP_PRIVATE, "MAP_PRIVATE" },
106 { MAP_FIXED, "MAP_FIXED" },
108 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
111 { MAP_32BIT, "MAP_32BIT" },
114 { MAP_RENAME, "MAP_RENAME" },
117 { MAP_NORESERVE,"MAP_NORESERVE" },
120 { MAP_POPULATE, "MAP_POPULATE" },
123 { MAP_NONBLOCK, "MAP_NONBLOCK" },
126 * XXX - this was introduced in SunOS 4.x to distinguish between
127 * the old pre-4.x "mmap()", which:
129 * only let you map devices with an "mmap" routine (e.g.,
132 * required you to specify the mapping address;
134 * returned 0 on success and -1 on failure;
136 * memory and which, and the 4.x "mmap()" which:
138 * can map plain files;
140 * can be asked to pick where to map the file;
142 * returns the address where it mapped the file on success
145 * It's not actually used in source code that calls "mmap()"; the
146 * "mmap()" routine adds it for you.
148 * It'd be nice to come up with some way of eliminating it from
149 * the flags, e.g. reporting calls *without* it as "old_mmap()"
150 * and calls with it as "mmap()".
153 { _MAP_NEW, "_MAP_NEW" },
156 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
159 { MAP_DENYWRITE,"MAP_DENYWRITE" },
161 #ifdef MAP_EXECUTABLE
162 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
165 { MAP_INHERIT,"MAP_INHERIT" },
168 { MAP_FILE,"MAP_FILE"},
171 { MAP_LOCKED,"MAP_LOCKED"},
175 { MAP_ANON, "MAP_ANON" },
177 #ifdef MAP_HASSEMAPHORE
178 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
181 { MAP_STACK, "MAP_STACK" },
184 { MAP_NOSYNC, "MAP_NOSYNC" },
187 { MAP_NOCORE, "MAP_NOCORE" },
190 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
191 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
192 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
199 addtileflags(long flags)
201 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
202 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
204 if (flags & _MAP_CACHE_INCOHERENT) {
205 flags &= ~_MAP_CACHE_INCOHERENT;
206 if (home == MAP_CACHE_HOME_NONE) {
207 tprintf("|MAP_CACHE_INCOHERENT");
210 tprintf("|_MAP_CACHE_INCOHERENT");
215 case MAP_CACHE_HOME_HERE: tprintf("|MAP_CACHE_HOME_HERE"); break;
216 case MAP_CACHE_HOME_NONE: tprintf("|MAP_CACHE_HOME_NONE"); break;
217 case MAP_CACHE_HOME_SINGLE: tprintf("|MAP_CACHE_HOME_SINGLE"); break;
218 case MAP_CACHE_HOME_TASK: tprintf("|MAP_CACHE_HOME_TASK"); break;
219 case MAP_CACHE_HOME_HASH: tprintf("|MAP_CACHE_HOME_HASH"); break;
221 tprintf("|MAP_CACHE_HOME(%d)",
222 (home >> _MAP_CACHE_HOME_SHIFT) );
230 #if !HAVE_LONG_LONG_OFF_T
232 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
239 tprintf("%#lx, ", u_arg[0]);
241 tprintf("%lu, ", u_arg[1]);
243 printflags(mmap_prot, u_arg[2], "PROT_???");
247 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
249 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
251 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
254 printflags(mmap_flags, u_arg[3], "MAP_???");
258 printfd(tcp, u_arg[4]);
260 tprintf(", %#llx", offset);
266 int sys_old_mmap(struct tcb *tcp)
273 * IA64 processes never call this routine, they only use the
274 * new `sys_mmap' interface. This code converts the integer
275 * arguments that the IA32 process pushed onto the stack into
278 * Note that addresses with bit 31 set will be sign extended.
279 * Fortunately, those addresses are not currently being generated
280 * for IA32 processes so it's not a problem.
282 for (i = 0; i < 6; i++)
283 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
287 #elif defined(SH) || defined(SH64)
288 /* SH has always passed the args in registers */
290 for (i = 0; i < 6; i++)
291 u_arg[i] = tcp->u_arg[i];
294 if (current_personality == 1) {
296 for (i = 0; i < 6; ++i) {
298 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
305 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
307 #endif /* !IA64 && !SH[64] */
308 return print_mmap(tcp, u_arg, u_arg[5]);
313 sys_mmap(struct tcb *tcp)
315 long long offset = tcp->u_arg[5];
317 #if defined(LINUX) && defined(SH64)
319 * Old mmap differs from new mmap in specifying the
320 * offset in units of bytes rather than pages. We
321 * pretend it's in byte units so the user only ever
322 * sees bytes in the printout.
324 offset <<= PAGE_SHIFT;
326 #if defined(LINUX_MIPSN32)
327 offset = tcp->ext_arg[5];
329 return print_mmap(tcp, tcp->u_arg, offset);
331 #endif /* !HAVE_LONG_LONG_OFF_T */
333 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
335 sys_mmap64(struct tcb *tcp)
338 #if !defined(LINUX) || defined(ALPHA)
339 long *u_arg = tcp->u_arg;
342 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
343 (char *) u_arg) == -1)
347 tprintf("%#lx, ", u_arg[0]);
349 tprintf("%lu, ", u_arg[1]);
351 printflags(mmap_prot, u_arg[2], "PROT_???");
355 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
356 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
358 printflags(mmap_flags, u_arg[3], "MAP_???");
362 /* BUG?! should be u_arg[4] (without tcp->)? */
363 printfd(tcp, tcp->u_arg[4]);
365 /* BUG?! on non-ALPHA linux, offset will be not in tcp->u_arg,
366 * but in local u_arg, but printllval prints tcp->u_arg! */
367 printllval(tcp, ", %#llx", 5);
371 #endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
375 sys_munmap(struct tcb *tcp)
379 tcp->u_arg[0], tcp->u_arg[1]);
385 sys_mprotect(struct tcb *tcp)
388 tprintf("%#lx, %lu, ",
389 tcp->u_arg[0], tcp->u_arg[1]);
390 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
397 static const struct xlat mremap_flags[] = {
398 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
400 { MREMAP_FIXED, "MREMAP_FIXED" },
406 sys_mremap(struct tcb *tcp)
409 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
411 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
413 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
414 (MREMAP_MAYMOVE | MREMAP_FIXED))
415 tprintf(", %#lx", tcp->u_arg[4]);
421 static const struct xlat madvise_cmds[] = {
423 { MADV_NORMAL, "MADV_NORMAL" },
426 { MADV_RANDOM, "MADV_RANDOM" },
428 #ifdef MADV_SEQUENTIAL
429 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
432 { MADV_WILLNEED, "MADV_WILLNEED" },
435 { MADV_DONTNEED, "MADV_DONTNEED" },
442 sys_madvise(struct tcb *tcp)
445 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
446 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
452 static const struct xlat mlockall_flags[] = {
454 { MCL_CURRENT, "MCL_CURRENT" },
457 { MCL_FUTURE, "MCL_FUTURE" },
463 sys_mlockall(struct tcb *tcp)
466 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
476 static const struct xlat mctl_sync[] = {
478 { MS_SYNC, "MS_SYNC" },
480 { MS_ASYNC, "MS_ASYNC" },
481 { MS_INVALIDATE,"MS_INVALIDATE" },
486 sys_msync(struct tcb *tcp)
490 tprintf("%#lx", tcp->u_arg[0]);
492 tprintf(", %lu, ", tcp->u_arg[1]);
494 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
499 #endif /* MS_ASYNC */
503 static const struct xlat mctl_funcs[] = {
504 { MC_LOCK, "MC_LOCK" },
505 { MC_LOCKAS, "MC_LOCKAS" },
506 { MC_SYNC, "MC_SYNC" },
507 { MC_UNLOCK, "MC_UNLOCK" },
508 { MC_UNLOCKAS, "MC_UNLOCKAS" },
512 static const struct xlat mctl_lockas[] = {
513 { MCL_CURRENT, "MCL_CURRENT" },
514 { MCL_FUTURE, "MCL_FUTURE" },
519 sys_mctl(struct tcb *tcp)
525 tprintf("%#lx", tcp->u_arg[0]);
527 tprintf(", %lu, ", tcp->u_arg[1]);
529 function = tcp->u_arg[2];
530 printflags(mctl_funcs, function, "MC_???");
536 printflags(mctl_sync, arg, "MS_???");
539 printflags(mctl_lockas, arg, "MCL_???");
552 sys_mincore(struct tcb *tcp)
554 unsigned long i, len;
558 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
561 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
562 (vec = malloc(len)) == NULL ||
563 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
564 tprintf("%#lx", tcp->u_arg[2]);
567 for (i = 0; i < len; i++) {
568 if (abbrev(tcp) && i >= max_strlen) {
572 tprintf((vec[i] & 1) ? "1" : "0");
582 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
584 sys_getpagesize(struct tcb *tcp)
590 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
592 #if defined(LINUX) && defined(__i386__)
594 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
596 tprintf("base_addr:%#08lx, "
600 "read_exec_only:%d, "
601 "limit_in_pages:%d, "
602 "seg_not_present:%d, "
604 (long) ldt_entry->base_addr,
606 ldt_entry->seg_32bit,
608 ldt_entry->read_exec_only,
609 ldt_entry->limit_in_pages,
610 ldt_entry->seg_not_present,
615 sys_modify_ldt(struct tcb *tcp)
618 struct modify_ldt_ldt_s copy;
619 tprintf("%ld", tcp->u_arg[0]);
620 if (tcp->u_arg[1] == 0
621 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
622 || umove(tcp, tcp->u_arg[1], ©) == -1)
623 tprintf(", %lx", tcp->u_arg[1]);
625 tprintf(", {entry_number:%d, ", copy.entry_number);
629 print_ldt_entry(©);
632 tprintf(", %lu", tcp->u_arg[2]);
638 sys_set_thread_area(struct tcb *tcp)
640 struct modify_ldt_ldt_s copy;
642 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
643 if (copy.entry_number == -1)
644 tprintf("{entry_number:%d -> ",
647 tprintf("{entry_number:");
650 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
651 tprintf("%d, ", copy.entry_number);
655 print_ldt_entry(©);
658 tprintf("%lx", tcp->u_arg[0]);
666 sys_get_thread_area(struct tcb *tcp)
668 struct modify_ldt_ldt_s copy;
670 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
671 tprintf("{entry_number:%d, ", copy.entry_number);
675 print_ldt_entry(©);
678 tprintf("%lx", tcp->u_arg[0]);
684 #endif /* LINUX && __i386__ */
686 #if defined(LINUX) && defined(M68K)
689 sys_set_thread_area(struct tcb *tcp)
692 tprintf("%#lx", tcp->u_arg[0]);
698 sys_get_thread_area(struct tcb *tcp)
706 sys_remap_file_pages(struct tcb *tcp)
709 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
710 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
711 tprintf(", %lu, ", tcp->u_arg[3]);
713 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
714 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
716 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
723 #define MPOL_DEFAULT 0
724 #define MPOL_PREFERRED 1
726 #define MPOL_INTERLEAVE 3
728 #define MPOL_F_NODE (1<<0)
729 #define MPOL_F_ADDR (1<<1)
731 #define MPOL_MF_STRICT (1<<0)
732 #define MPOL_MF_MOVE (1<<1)
733 #define MPOL_MF_MOVE_ALL (1<<2)
736 static const struct xlat policies[] = {
737 { MPOL_DEFAULT, "MPOL_DEFAULT" },
738 { MPOL_PREFERRED, "MPOL_PREFERRED" },
739 { MPOL_BIND, "MPOL_BIND" },
740 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
744 static const struct xlat mbindflags[] = {
745 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
746 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
747 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
751 static const struct xlat mempolicyflags[] = {
752 { MPOL_F_NODE, "MPOL_F_NODE" },
753 { MPOL_F_ADDR, "MPOL_F_ADDR" },
757 static const struct xlat move_pages_flags[] = {
758 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
759 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
765 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
767 unsigned long nlongs, size, end;
769 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
770 size = nlongs * sizeof(long);
772 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
774 unsigned long n, cur, abbrev_end;
778 abbrev_end = ptr + max_strlen * sizeof(long);
779 if (abbrev_end < ptr)
785 for (cur = ptr; cur < end; cur += sizeof(long)) {
788 if (cur >= abbrev_end) {
792 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
797 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
801 tprintf(" %#lx", ptr);
803 tprintf(", %#lx", ptr);
804 tprintf(", %lu", maxnodes);
808 sys_mbind(struct tcb *tcp)
811 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
812 printxval(policies, tcp->u_arg[2], "MPOL_???");
813 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
815 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
821 sys_set_mempolicy(struct tcb *tcp)
824 printxval(policies, tcp->u_arg[0], "MPOL_???");
825 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
831 sys_get_mempolicy(struct tcb *tcp)
835 if (tcp->u_arg[0] == 0)
837 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
838 tprintf("%#lx", tcp->u_arg[0]);
840 printxval(policies, pol, "MPOL_???");
841 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
842 tprintf(", %#lx, ", tcp->u_arg[3]);
843 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
849 sys_move_pages(struct tcb *tcp)
852 unsigned long npages = tcp->u_arg[1];
853 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
854 if (tcp->u_arg[2] == 0)
858 long puser = tcp->u_arg[2];
860 for (i = 0; i < npages; ++i) {
864 if (umove(tcp, puser, &p) < 0) {
869 puser += sizeof(void *);
873 if (tcp->u_arg[3] == 0)
877 long nodeuser = tcp->u_arg[3];
879 for (i = 0; i < npages; ++i) {
883 if (umove(tcp, nodeuser, &node) < 0) {
887 tprintf("%#x", node);
888 nodeuser += sizeof(int);
894 unsigned long npages = tcp->u_arg[1];
895 if (tcp->u_arg[4] == 0)
899 long statususer = tcp->u_arg[4];
901 for (i = 0; i < npages; ++i) {
905 if (umove(tcp, statususer, &status) < 0) {
909 tprintf("%#x", status);
910 statususer += sizeof(int);
914 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
920 #if defined(LINUX) && defined(POWERPC)
922 sys_subpage_prot(struct tcb *tcp)
925 unsigned long cur, end, abbrev_end, entries;
928 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
929 entries = tcp->u_arg[1] >> 16;
930 if (!entries || !tcp->u_arg[2]) {
935 end = cur + (sizeof(int) * entries);
936 if (!verbose(tcp) || end < tcp->u_arg[2]) {
937 tprintf("%#lx", tcp->u_arg[2]);
941 abbrev_end = cur + (sizeof(int) * max_strlen);
942 if (abbrev_end > end)
948 for (; cur < end; cur += sizeof(int)) {
949 if (cur > tcp->u_arg[2])
951 if (cur >= abbrev_end) {
955 if (umove(tcp, cur, &entry) < 0) {
956 tprintf("??? [%#lx]", cur);
960 tprintf("%#08x", entry);