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
64 tprintf("%#lx", tcp->u_arg[0]);
73 #if defined(FREEBSD) || defined(SUNOS4)
79 tprintf("%lu", tcp->u_arg[0]);
83 #endif /* FREEBSD || SUNOS4 */
85 static const struct xlat mmap_prot[] = {
86 { PROT_NONE, "PROT_NONE", },
87 { PROT_READ, "PROT_READ" },
88 { PROT_WRITE, "PROT_WRITE" },
89 { PROT_EXEC, "PROT_EXEC" },
91 { PROT_SEM, "PROT_SEM" },
94 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
97 { PROT_GROWSUP, "PROT_GROWSUP" },
100 { PROT_SAO, "PROT_SAO" },
105 static const struct xlat mmap_flags[] = {
106 { MAP_SHARED, "MAP_SHARED" },
107 { MAP_PRIVATE, "MAP_PRIVATE" },
108 { MAP_FIXED, "MAP_FIXED" },
110 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
113 { MAP_32BIT, "MAP_32BIT" },
116 { MAP_RENAME, "MAP_RENAME" },
119 { MAP_NORESERVE,"MAP_NORESERVE" },
122 { MAP_POPULATE, "MAP_POPULATE" },
125 { MAP_NONBLOCK, "MAP_NONBLOCK" },
128 * XXX - this was introduced in SunOS 4.x to distinguish between
129 * the old pre-4.x "mmap()", which:
131 * only let you map devices with an "mmap" routine (e.g.,
134 * required you to specify the mapping address;
136 * returned 0 on success and -1 on failure;
138 * memory and which, and the 4.x "mmap()" which:
140 * can map plain files;
142 * can be asked to pick where to map the file;
144 * returns the address where it mapped the file on success
147 * It's not actually used in source code that calls "mmap()"; the
148 * "mmap()" routine adds it for you.
150 * It'd be nice to come up with some way of eliminating it from
151 * the flags, e.g. reporting calls *without* it as "old_mmap()"
152 * and calls with it as "mmap()".
155 { _MAP_NEW, "_MAP_NEW" },
158 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
161 { MAP_DENYWRITE,"MAP_DENYWRITE" },
163 #ifdef MAP_EXECUTABLE
164 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
167 { MAP_INHERIT,"MAP_INHERIT" },
170 { MAP_FILE,"MAP_FILE"},
173 { MAP_LOCKED,"MAP_LOCKED"},
177 { MAP_ANON, "MAP_ANON" },
179 #ifdef MAP_HASSEMAPHORE
180 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
183 { MAP_STACK, "MAP_STACK" },
186 { MAP_NOSYNC, "MAP_NOSYNC" },
189 { MAP_NOCORE, "MAP_NOCORE" },
192 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
193 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
194 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
205 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
206 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
208 if (flags & _MAP_CACHE_INCOHERENT) {
209 flags &= ~_MAP_CACHE_INCOHERENT;
210 if (home == MAP_CACHE_HOME_NONE) {
211 tprintf("|MAP_CACHE_INCOHERENT");
214 tprintf("|_MAP_CACHE_INCOHERENT");
219 case MAP_CACHE_HOME_HERE: tprintf("|MAP_CACHE_HOME_HERE"); break;
220 case MAP_CACHE_HOME_NONE: tprintf("|MAP_CACHE_HOME_NONE"); break;
221 case MAP_CACHE_HOME_SINGLE: tprintf("|MAP_CACHE_HOME_SINGLE"); break;
222 case MAP_CACHE_HOME_TASK: tprintf("|MAP_CACHE_HOME_TASK"); break;
223 case MAP_CACHE_HOME_HASH: tprintf("|MAP_CACHE_HOME_HASH"); break;
225 tprintf("|MAP_CACHE_HOME(%d)",
226 (home >> _MAP_CACHE_HOME_SHIFT) );
234 #if !HAVE_LONG_LONG_OFF_T
236 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
243 tprintf("%#lx, ", u_arg[0]);
245 tprintf("%lu, ", u_arg[1]);
247 printflags(mmap_prot, u_arg[2], "PROT_???");
251 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
253 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
255 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
258 printflags(mmap_flags, u_arg[3], "MAP_???");
262 printfd(tcp, u_arg[4]);
264 tprintf(", %#llx", offset);
270 int sys_old_mmap(tcp)
278 * IA64 processes never call this routine, they only use the
279 * new `sys_mmap' interface. This code converts the integer
280 * arguments that the IA32 process pushed onto the stack into
283 * Note that addresses with bit 31 set will be sign extended.
284 * Fortunately, those addresses are not currently being generated
285 * for IA32 processes so it's not a problem.
287 for (i = 0; i < 6; i++)
288 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
292 #elif defined(SH) || defined(SH64)
293 /* SH has always passed the args in registers */
296 u_arg[i] = tcp->u_arg[i];
299 if (current_personality == 1) {
301 for (i = 0; i < 6; ++i) {
303 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
310 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
312 #endif // defined(IA64)
313 return print_mmap(tcp, u_arg, u_arg[5]);
321 long long offset = tcp->u_arg[5];
323 #if defined(LINUX) && defined(SH64)
325 * Old mmap differs from new mmap in specifying the
326 * offset in units of bytes rather than pages. We
327 * pretend it's in byte units so the user only ever
328 * sees bytes in the printout.
330 offset <<= PAGE_SHIFT;
332 #if defined(LINUX_MIPSN32)
333 offset = tcp->ext_arg[5];
335 return print_mmap(tcp, tcp->u_arg, offset);
337 #endif /* !HAVE_LONG_LONG_OFF_T */
339 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
341 sys_mmap64(struct tcb *tcp)
345 long *u_arg = tcp->u_arg;
350 long *u_arg = tcp->u_arg;
356 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
357 (char *) u_arg) == -1)
363 tprintf("%#lx, ", u_arg[0]);
365 tprintf("%lu, ", u_arg[1]);
367 printflags(mmap_prot, u_arg[2], "PROT_???");
371 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
372 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
374 printflags(mmap_flags, u_arg[3], "MAP_???");
378 printfd(tcp, tcp->u_arg[4]);
380 printllval(tcp, ", %#llx", 5);
393 tcp->u_arg[0], tcp->u_arg[1]);
403 tprintf("%#lx, %lu, ",
404 tcp->u_arg[0], tcp->u_arg[1]);
405 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
412 static const struct xlat mremap_flags[] = {
413 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
415 { MREMAP_FIXED, "MREMAP_FIXED" },
421 sys_mremap(struct tcb *tcp)
424 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
426 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
428 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
429 (MREMAP_MAYMOVE | MREMAP_FIXED))
430 tprintf(", %#lx", tcp->u_arg[4]);
436 static const struct xlat madvise_cmds[] = {
438 { MADV_NORMAL, "MADV_NORMAL" },
441 { MADV_RANDOM, "MADV_RANDOM" },
443 #ifdef MADV_SEQUENTIAL
444 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
447 { MADV_WILLNEED, "MADV_WILLNEED" },
450 { MADV_DONTNEED, "MADV_DONTNEED" },
461 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
462 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
468 static const struct xlat mlockall_flags[] = {
470 { MCL_CURRENT, "MCL_CURRENT" },
473 { MCL_FUTURE, "MCL_FUTURE" },
483 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
493 static const struct xlat mctl_sync[] = {
495 { MS_SYNC, "MS_SYNC" },
497 { MS_ASYNC, "MS_ASYNC" },
498 { MS_INVALIDATE,"MS_INVALIDATE" },
508 tprintf("%#lx", tcp->u_arg[0]);
510 tprintf(", %lu, ", tcp->u_arg[1]);
512 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
517 #endif /* MS_ASYNC */
521 static const struct xlat mctl_funcs[] = {
522 { MC_LOCK, "MC_LOCK" },
523 { MC_LOCKAS, "MC_LOCKAS" },
524 { MC_SYNC, "MC_SYNC" },
525 { MC_UNLOCK, "MC_UNLOCK" },
526 { MC_UNLOCKAS, "MC_UNLOCKAS" },
530 static const struct xlat mctl_lockas[] = {
531 { MCL_CURRENT, "MCL_CURRENT" },
532 { MCL_FUTURE, "MCL_FUTURE" },
544 tprintf("%#lx", tcp->u_arg[0]);
546 tprintf(", %lu, ", tcp->u_arg[1]);
548 function = tcp->u_arg[2];
549 printflags(mctl_funcs, function, "MC_???");
555 printflags(mctl_sync, arg, "MS_???");
558 printflags(mctl_lockas, arg, "MCL_???");
574 unsigned long i, len;
578 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
581 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
582 (vec = malloc(len)) == NULL ||
583 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
584 tprintf("%#lx", tcp->u_arg[2]);
587 for (i = 0; i < len; i++) {
588 if (abbrev(tcp) && i >= max_strlen) {
592 tprintf((vec[i] & 1) ? "1" : "0");
602 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
611 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
613 #if defined(LINUX) && defined(__i386__)
615 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
617 tprintf("base_addr:%#08lx, "
621 "read_exec_only:%d, "
622 "limit_in_pages:%d, "
623 "seg_not_present:%d, "
625 (long) ldt_entry->base_addr,
627 ldt_entry->seg_32bit,
629 ldt_entry->read_exec_only,
630 ldt_entry->limit_in_pages,
631 ldt_entry->seg_not_present,
640 struct modify_ldt_ldt_s copy;
641 tprintf("%ld", tcp->u_arg[0]);
642 if (tcp->u_arg[1] == 0
643 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
644 || umove(tcp, tcp->u_arg[1], ©) == -1)
645 tprintf(", %lx", tcp->u_arg[1]);
647 tprintf(", {entry_number:%d, ", copy.entry_number);
651 print_ldt_entry(©);
654 tprintf(", %lu", tcp->u_arg[2]);
660 sys_set_thread_area(tcp)
663 struct modify_ldt_ldt_s copy;
665 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
666 if (copy.entry_number == -1)
667 tprintf("{entry_number:%d -> ",
670 tprintf("{entry_number:");
673 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
674 tprintf("%d, ", copy.entry_number);
678 print_ldt_entry(©);
681 tprintf("%lx", tcp->u_arg[0]);
689 sys_get_thread_area(tcp)
692 struct modify_ldt_ldt_s copy;
694 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
695 tprintf("{entry_number:%d, ", copy.entry_number);
699 print_ldt_entry(©);
702 tprintf("%lx", tcp->u_arg[0]);
708 #endif /* LINUX && __i386__ */
710 #if defined(LINUX) && defined(M68K)
713 sys_set_thread_area(tcp)
717 tprintf("%#lx", tcp->u_arg[0]);
723 sys_get_thread_area(tcp)
732 sys_remap_file_pages(tcp)
736 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
737 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
738 tprintf(", %lu, ", tcp->u_arg[3]);
740 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
741 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
743 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
750 #define MPOL_DEFAULT 0
751 #define MPOL_PREFERRED 1
753 #define MPOL_INTERLEAVE 3
755 #define MPOL_F_NODE (1<<0)
756 #define MPOL_F_ADDR (1<<1)
758 #define MPOL_MF_STRICT (1<<0)
759 #define MPOL_MF_MOVE (1<<1)
760 #define MPOL_MF_MOVE_ALL (1<<2)
763 static const struct xlat policies[] = {
764 { MPOL_DEFAULT, "MPOL_DEFAULT" },
765 { MPOL_PREFERRED, "MPOL_PREFERRED" },
766 { MPOL_BIND, "MPOL_BIND" },
767 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
771 static const struct xlat mbindflags[] = {
772 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
773 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
774 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
778 static const struct xlat mempolicyflags[] = {
779 { MPOL_F_NODE, "MPOL_F_NODE" },
780 { MPOL_F_ADDR, "MPOL_F_ADDR" },
784 static const struct xlat move_pages_flags[] = {
785 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
786 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
792 get_nodes(tcp, ptr, maxnodes, err)
795 unsigned long maxnodes;
798 unsigned long nlongs, size, end;
800 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
801 size = nlongs * sizeof(long);
803 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
805 unsigned long n, cur, abbrev_end;
809 abbrev_end = ptr + max_strlen * sizeof(long);
810 if (abbrev_end < ptr)
816 for (cur = ptr; cur < end; cur += sizeof(long)) {
819 if (cur >= abbrev_end) {
823 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
828 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
832 tprintf(" %#lx", ptr);
834 tprintf(", %#lx", ptr);
835 tprintf(", %lu", maxnodes);
843 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
844 printxval(policies, tcp->u_arg[2], "MPOL_???");
845 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
847 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
853 sys_set_mempolicy(tcp)
857 printxval(policies, tcp->u_arg[0], "MPOL_???");
858 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
864 sys_get_mempolicy(tcp)
869 if (tcp->u_arg[0] == 0)
871 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
872 tprintf("%#lx", tcp->u_arg[0]);
874 printxval(policies, pol, "MPOL_???");
875 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
876 tprintf(", %#lx, ", tcp->u_arg[3]);
877 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
887 unsigned long npages = tcp->u_arg[1];
888 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
889 if (tcp->u_arg[2] == 0)
893 long puser = tcp->u_arg[2];
895 for (i = 0; i < npages; ++i) {
899 if (umove(tcp, puser, &p) < 0) {
904 puser += sizeof (void *);
908 if (tcp->u_arg[3] == 0)
912 long nodeuser = tcp->u_arg[3];
914 for (i = 0; i < npages; ++i) {
918 if (umove(tcp, nodeuser, &node) < 0) {
922 tprintf("%#x", node);
923 nodeuser += sizeof (int);
929 unsigned long npages = tcp->u_arg[1];
930 if (tcp->u_arg[4] == 0)
934 long statususer = tcp->u_arg[4];
936 for (i = 0; i < npages; ++i) {
940 if (umove(tcp, statususer, &status) < 0) {
944 tprintf("%#x", status);
945 statususer += sizeof (int);
949 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
955 #if defined(LINUX) && defined(POWERPC)
957 sys_subpage_prot(tcp)
961 unsigned long cur, end, abbrev_end, entries;
964 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
965 entries = tcp->u_arg[1] >> 16;
966 if (!entries || !tcp->u_arg[2]) {
971 end = cur + (sizeof(int) * entries);
972 if (!verbose(tcp) || end < tcp->u_arg[2]) {
973 tprintf("%#lx", tcp->u_arg[2]);
977 abbrev_end = cur + (sizeof(int) * max_strlen);
978 if (abbrev_end > end)
984 for (; cur < end; cur += sizeof(int)) {
985 if (cur > tcp->u_arg[2])
987 if (cur >= abbrev_end) {
991 if (umove(tcp, cur, &entry) < 0) {
992 tprintf("??? [%#lx]", cur);
996 tprintf("%#08x", entry);