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" },
203 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
204 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
206 if (flags & _MAP_CACHE_INCOHERENT) {
207 flags &= ~_MAP_CACHE_INCOHERENT;
208 if (home == MAP_CACHE_HOME_NONE) {
209 tprintf("|MAP_CACHE_INCOHERENT");
212 tprintf("|_MAP_CACHE_INCOHERENT");
217 case MAP_CACHE_HOME_HERE: tprintf("|MAP_CACHE_HOME_HERE"); break;
218 case MAP_CACHE_HOME_NONE: tprintf("|MAP_CACHE_HOME_NONE"); break;
219 case MAP_CACHE_HOME_SINGLE: tprintf("|MAP_CACHE_HOME_SINGLE"); break;
220 case MAP_CACHE_HOME_TASK: tprintf("|MAP_CACHE_HOME_TASK"); break;
221 case MAP_CACHE_HOME_HASH: tprintf("|MAP_CACHE_HOME_HASH"); break;
223 tprintf("|MAP_CACHE_HOME(%d)",
224 (home >> _MAP_CACHE_HOME_SHIFT) );
232 #if !HAVE_LONG_LONG_OFF_T
234 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
241 tprintf("%#lx, ", u_arg[0]);
243 tprintf("%lu, ", u_arg[1]);
245 printflags(mmap_prot, u_arg[2], "PROT_???");
249 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
251 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
253 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
256 printflags(mmap_flags, u_arg[3], "MAP_???");
260 printfd(tcp, u_arg[4]);
262 tprintf(", %#llx", offset);
268 int sys_old_mmap(struct tcb *tcp)
275 * IA64 processes never call this routine, they only use the
276 * new `sys_mmap' interface. This code converts the integer
277 * arguments that the IA32 process pushed onto the stack into
280 * Note that addresses with bit 31 set will be sign extended.
281 * Fortunately, those addresses are not currently being generated
282 * for IA32 processes so it's not a problem.
284 for (i = 0; i < 6; i++)
285 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
289 #elif defined(SH) || defined(SH64)
290 /* SH has always passed the args in registers */
292 for (i = 0; i < 6; i++)
293 u_arg[i] = tcp->u_arg[i];
296 if (current_personality == 1) {
298 for (i = 0; i < 6; ++i) {
300 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
307 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
309 #endif // defined(IA64)
310 return print_mmap(tcp, u_arg, u_arg[5]);
315 sys_mmap(struct tcb *tcp)
317 long long offset = tcp->u_arg[5];
319 #if defined(LINUX) && defined(SH64)
321 * Old mmap differs from new mmap in specifying the
322 * offset in units of bytes rather than pages. We
323 * pretend it's in byte units so the user only ever
324 * sees bytes in the printout.
326 offset <<= PAGE_SHIFT;
328 #if defined(LINUX_MIPSN32)
329 offset = tcp->ext_arg[5];
331 return print_mmap(tcp, tcp->u_arg, offset);
333 #endif /* !HAVE_LONG_LONG_OFF_T */
335 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
337 sys_mmap64(struct tcb *tcp)
341 long *u_arg = tcp->u_arg;
346 long *u_arg = tcp->u_arg;
352 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
353 (char *) u_arg) == -1)
359 tprintf("%#lx, ", u_arg[0]);
361 tprintf("%lu, ", u_arg[1]);
363 printflags(mmap_prot, u_arg[2], "PROT_???");
367 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
368 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
370 printflags(mmap_flags, u_arg[3], "MAP_???");
374 printfd(tcp, tcp->u_arg[4]);
376 printllval(tcp, ", %#llx", 5);
384 sys_munmap(struct tcb *tcp)
388 tcp->u_arg[0], tcp->u_arg[1]);
394 sys_mprotect(struct tcb *tcp)
397 tprintf("%#lx, %lu, ",
398 tcp->u_arg[0], tcp->u_arg[1]);
399 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
406 static const struct xlat mremap_flags[] = {
407 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
409 { MREMAP_FIXED, "MREMAP_FIXED" },
415 sys_mremap(struct tcb *tcp)
418 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
420 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
422 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
423 (MREMAP_MAYMOVE | MREMAP_FIXED))
424 tprintf(", %#lx", tcp->u_arg[4]);
430 static const struct xlat madvise_cmds[] = {
432 { MADV_NORMAL, "MADV_NORMAL" },
435 { MADV_RANDOM, "MADV_RANDOM" },
437 #ifdef MADV_SEQUENTIAL
438 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
441 { MADV_WILLNEED, "MADV_WILLNEED" },
444 { MADV_DONTNEED, "MADV_DONTNEED" },
451 sys_madvise(struct tcb *tcp)
454 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
455 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
461 static const struct xlat mlockall_flags[] = {
463 { MCL_CURRENT, "MCL_CURRENT" },
466 { MCL_FUTURE, "MCL_FUTURE" },
472 sys_mlockall(struct tcb *tcp)
475 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
485 static const struct xlat mctl_sync[] = {
487 { MS_SYNC, "MS_SYNC" },
489 { MS_ASYNC, "MS_ASYNC" },
490 { MS_INVALIDATE,"MS_INVALIDATE" },
495 sys_msync(struct tcb *tcp)
499 tprintf("%#lx", tcp->u_arg[0]);
501 tprintf(", %lu, ", tcp->u_arg[1]);
503 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
508 #endif /* MS_ASYNC */
512 static const struct xlat mctl_funcs[] = {
513 { MC_LOCK, "MC_LOCK" },
514 { MC_LOCKAS, "MC_LOCKAS" },
515 { MC_SYNC, "MC_SYNC" },
516 { MC_UNLOCK, "MC_UNLOCK" },
517 { MC_UNLOCKAS, "MC_UNLOCKAS" },
521 static const struct xlat mctl_lockas[] = {
522 { MCL_CURRENT, "MCL_CURRENT" },
523 { MCL_FUTURE, "MCL_FUTURE" },
528 sys_mctl(struct tcb *tcp)
534 tprintf("%#lx", tcp->u_arg[0]);
536 tprintf(", %lu, ", tcp->u_arg[1]);
538 function = tcp->u_arg[2];
539 printflags(mctl_funcs, function, "MC_???");
545 printflags(mctl_sync, arg, "MS_???");
548 printflags(mctl_lockas, arg, "MCL_???");
561 sys_mincore(struct tcb *tcp)
563 unsigned long i, len;
567 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
570 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
571 (vec = malloc(len)) == NULL ||
572 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
573 tprintf("%#lx", tcp->u_arg[2]);
576 for (i = 0; i < len; i++) {
577 if (abbrev(tcp) && i >= max_strlen) {
581 tprintf((vec[i] & 1) ? "1" : "0");
591 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
593 sys_getpagesize(struct tcb *tcp)
599 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
601 #if defined(LINUX) && defined(__i386__)
603 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
605 tprintf("base_addr:%#08lx, "
609 "read_exec_only:%d, "
610 "limit_in_pages:%d, "
611 "seg_not_present:%d, "
613 (long) ldt_entry->base_addr,
615 ldt_entry->seg_32bit,
617 ldt_entry->read_exec_only,
618 ldt_entry->limit_in_pages,
619 ldt_entry->seg_not_present,
624 sys_modify_ldt(struct tcb *tcp)
627 struct modify_ldt_ldt_s copy;
628 tprintf("%ld", tcp->u_arg[0]);
629 if (tcp->u_arg[1] == 0
630 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
631 || umove(tcp, tcp->u_arg[1], ©) == -1)
632 tprintf(", %lx", tcp->u_arg[1]);
634 tprintf(", {entry_number:%d, ", copy.entry_number);
638 print_ldt_entry(©);
641 tprintf(", %lu", tcp->u_arg[2]);
647 sys_set_thread_area(struct tcb *tcp)
649 struct modify_ldt_ldt_s copy;
651 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
652 if (copy.entry_number == -1)
653 tprintf("{entry_number:%d -> ",
656 tprintf("{entry_number:");
659 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
660 tprintf("%d, ", copy.entry_number);
664 print_ldt_entry(©);
667 tprintf("%lx", tcp->u_arg[0]);
675 sys_get_thread_area(struct tcb *tcp)
677 struct modify_ldt_ldt_s copy;
679 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
680 tprintf("{entry_number:%d, ", copy.entry_number);
684 print_ldt_entry(©);
687 tprintf("%lx", tcp->u_arg[0]);
693 #endif /* LINUX && __i386__ */
695 #if defined(LINUX) && defined(M68K)
698 sys_set_thread_area(struct tcb *tcp)
701 tprintf("%#lx", tcp->u_arg[0]);
707 sys_get_thread_area(struct tcb *tcp)
715 sys_remap_file_pages(struct tcb *tcp)
718 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
719 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
720 tprintf(", %lu, ", tcp->u_arg[3]);
722 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
723 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
725 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
732 #define MPOL_DEFAULT 0
733 #define MPOL_PREFERRED 1
735 #define MPOL_INTERLEAVE 3
737 #define MPOL_F_NODE (1<<0)
738 #define MPOL_F_ADDR (1<<1)
740 #define MPOL_MF_STRICT (1<<0)
741 #define MPOL_MF_MOVE (1<<1)
742 #define MPOL_MF_MOVE_ALL (1<<2)
745 static const struct xlat policies[] = {
746 { MPOL_DEFAULT, "MPOL_DEFAULT" },
747 { MPOL_PREFERRED, "MPOL_PREFERRED" },
748 { MPOL_BIND, "MPOL_BIND" },
749 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
753 static const struct xlat mbindflags[] = {
754 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
755 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
756 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
760 static const struct xlat mempolicyflags[] = {
761 { MPOL_F_NODE, "MPOL_F_NODE" },
762 { MPOL_F_ADDR, "MPOL_F_ADDR" },
766 static const struct xlat move_pages_flags[] = {
767 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
768 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
774 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
776 unsigned long nlongs, size, end;
778 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
779 size = nlongs * sizeof(long);
781 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
783 unsigned long n, cur, abbrev_end;
787 abbrev_end = ptr + max_strlen * sizeof(long);
788 if (abbrev_end < ptr)
794 for (cur = ptr; cur < end; cur += sizeof(long)) {
797 if (cur >= abbrev_end) {
801 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
806 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
810 tprintf(" %#lx", ptr);
812 tprintf(", %#lx", ptr);
813 tprintf(", %lu", maxnodes);
817 sys_mbind(struct tcb *tcp)
820 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
821 printxval(policies, tcp->u_arg[2], "MPOL_???");
822 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
824 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
830 sys_set_mempolicy(struct tcb *tcp)
833 printxval(policies, tcp->u_arg[0], "MPOL_???");
834 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
840 sys_get_mempolicy(struct tcb *tcp)
844 if (tcp->u_arg[0] == 0)
846 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
847 tprintf("%#lx", tcp->u_arg[0]);
849 printxval(policies, pol, "MPOL_???");
850 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
851 tprintf(", %#lx, ", tcp->u_arg[3]);
852 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
858 sys_move_pages(struct tcb *tcp)
861 unsigned long npages = tcp->u_arg[1];
862 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
863 if (tcp->u_arg[2] == 0)
867 long puser = tcp->u_arg[2];
869 for (i = 0; i < npages; ++i) {
873 if (umove(tcp, puser, &p) < 0) {
878 puser += sizeof(void *);
882 if (tcp->u_arg[3] == 0)
886 long nodeuser = tcp->u_arg[3];
888 for (i = 0; i < npages; ++i) {
892 if (umove(tcp, nodeuser, &node) < 0) {
896 tprintf("%#x", node);
897 nodeuser += sizeof(int);
903 unsigned long npages = tcp->u_arg[1];
904 if (tcp->u_arg[4] == 0)
908 long statususer = tcp->u_arg[4];
910 for (i = 0; i < npages; ++i) {
914 if (umove(tcp, statususer, &status) < 0) {
918 tprintf("%#x", status);
919 statususer += sizeof(int);
923 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
929 #if defined(LINUX) && defined(POWERPC)
931 sys_subpage_prot(struct tcb *tcp)
934 unsigned long cur, end, abbrev_end, entries;
937 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
938 entries = tcp->u_arg[1] >> 16;
939 if (!entries || !tcp->u_arg[2]) {
944 end = cur + (sizeof(int) * entries);
945 if (!verbose(tcp) || end < tcp->u_arg[2]) {
946 tprintf("%#lx", tcp->u_arg[2]);
950 abbrev_end = cur + (sizeof(int) * max_strlen);
951 if (abbrev_end > end)
957 for (; cur < end; cur += sizeof(int)) {
958 if (cur > tcp->u_arg[2])
960 if (cur >= abbrev_end) {
964 if (umove(tcp, cur, &entry) < 0) {
965 tprintf("??? [%#lx]", cur);
969 tprintf("%#08x", entry);