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" },
194 #if !HAVE_LONG_LONG_OFF_T
197 print_mmap(tcp,u_arg, offset)
207 tprintf("%#lx, ", u_arg[0]);
209 tprintf("%lu, ", u_arg[1]);
211 printflags(mmap_prot, u_arg[2], "PROT_???");
215 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
216 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
218 printflags(mmap_flags, u_arg[3], "MAP_???");
220 /* fd (is always int, not long) */
221 tprintf(", %d, ", (int)u_arg[4]);
223 tprintf("%#llx", offset);
229 int sys_old_mmap(tcp)
237 * IA64 processes never call this routine, they only use the
238 * new `sys_mmap' interface. This code converts the integer
239 * arguments that the IA32 process pushed onto the stack into
242 * Note that addresses with bit 31 set will be sign extended.
243 * Fortunately, those addresses are not currently being generated
244 * for IA32 processes so it's not a problem.
246 for (i = 0; i < 6; i++)
247 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
251 #elif defined(SH) || defined(SH64)
252 /* SH has always passed the args in registers */
255 u_arg[i] = tcp->u_arg[i];
258 if (current_personality == 1) {
260 for (i = 0; i < 6; ++i) {
262 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
269 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
271 #endif // defined(IA64)
272 return print_mmap(tcp, u_arg, u_arg[5]);
280 long long offset = tcp->u_arg[5];
282 #if defined(LINUX) && defined(SH64)
284 * Old mmap differs from new mmap in specifying the
285 * offset in units of bytes rather than pages. We
286 * pretend it's in byte units so the user only ever
287 * sees bytes in the printout.
289 offset <<= PAGE_SHIFT;
291 #if defined(LINUX_MIPSN32)
292 offset = tcp->ext_arg[5];
294 return print_mmap(tcp, tcp->u_arg, offset);
296 #endif /* !HAVE_LONG_LONG_OFF_T */
298 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
305 long *u_arg = tcp->u_arg;
310 long *u_arg = tcp->u_arg;
316 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
317 (char *) u_arg) == -1)
323 tprintf("%#lx, ", u_arg[0]);
325 tprintf("%lu, ", u_arg[1]);
327 printflags(mmap_prot, u_arg[2], "PROT_???");
331 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
332 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
334 printflags(mmap_flags, u_arg[3], "MAP_???");
337 tprintf(", %ld, ", u_arg[4]);
339 printllval(tcp, "%#llx", 5);
352 tcp->u_arg[0], tcp->u_arg[1]);
362 tprintf("%#lx, %lu, ",
363 tcp->u_arg[0], tcp->u_arg[1]);
364 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
371 static const struct xlat mremap_flags[] = {
372 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
374 { MREMAP_FIXED, "MREMAP_FIXED" },
384 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
386 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
391 static const struct xlat madvise_cmds[] = {
393 { MADV_NORMAL, "MADV_NORMAL" },
396 { MADV_RANDOM, "MADV_RANDOM" },
398 #ifdef MADV_SEQUENTIAL
399 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
402 { MADV_WILLNEED, "MADV_WILLNEED" },
405 { MADV_DONTNEED, "MADV_DONTNEED" },
416 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
417 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
423 static const struct xlat mlockall_flags[] = {
425 { MCL_CURRENT, "MCL_CURRENT" },
428 { MCL_FUTURE, "MCL_FUTURE" },
438 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
448 static const struct xlat mctl_sync[] = {
450 { MS_SYNC, "MS_SYNC" },
452 { MS_ASYNC, "MS_ASYNC" },
453 { MS_INVALIDATE,"MS_INVALIDATE" },
463 tprintf("%#lx", tcp->u_arg[0]);
465 tprintf(", %lu, ", tcp->u_arg[1]);
467 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
472 #endif /* MS_ASYNC */
476 static const struct xlat mctl_funcs[] = {
477 { MC_LOCK, "MC_LOCK" },
478 { MC_LOCKAS, "MC_LOCKAS" },
479 { MC_SYNC, "MC_SYNC" },
480 { MC_UNLOCK, "MC_UNLOCK" },
481 { MC_UNLOCKAS, "MC_UNLOCKAS" },
485 static const struct xlat mctl_lockas[] = {
486 { MCL_CURRENT, "MCL_CURRENT" },
487 { MCL_FUTURE, "MCL_FUTURE" },
499 tprintf("%#lx", tcp->u_arg[0]);
501 tprintf(", %lu, ", tcp->u_arg[1]);
503 function = tcp->u_arg[2];
504 printflags(mctl_funcs, function, "MC_???");
510 printflags(mctl_sync, arg, "MS_???");
513 printflags(mctl_lockas, arg, "MCL_???");
529 unsigned long i, len;
533 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
536 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
537 (vec = malloc(len)) == NULL ||
538 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
539 tprintf("%#lx", tcp->u_arg[2]);
542 for (i = 0; i < len; i++) {
543 if (abbrev(tcp) && i >= max_strlen) {
547 tprintf((vec[i] & 1) ? "1" : "0");
557 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
566 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
568 #if defined(LINUX) && defined(__i386__)
570 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
572 tprintf("base_addr:%#08lx, "
576 "read_exec_only:%d, "
577 "limit_in_pages:%d, "
578 "seg_not_present:%d, "
580 (long) ldt_entry->base_addr,
582 ldt_entry->seg_32bit,
584 ldt_entry->read_exec_only,
585 ldt_entry->limit_in_pages,
586 ldt_entry->seg_not_present,
595 struct modify_ldt_ldt_s copy;
596 tprintf("%ld", tcp->u_arg[0]);
597 if (tcp->u_arg[1] == 0
598 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
599 || umove(tcp, tcp->u_arg[1], ©) == -1)
600 tprintf(", %lx", tcp->u_arg[1]);
602 tprintf(", {entry_number:%d, ", copy.entry_number);
606 print_ldt_entry(©);
609 tprintf(", %lu", tcp->u_arg[2]);
615 sys_set_thread_area(tcp)
618 struct modify_ldt_ldt_s copy;
620 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
621 if (copy.entry_number == -1)
622 tprintf("{entry_number:%d -> ",
625 tprintf("{entry_number:");
628 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
629 tprintf("%d, ", copy.entry_number);
633 print_ldt_entry(©);
636 tprintf("%lx", tcp->u_arg[0]);
644 sys_get_thread_area(tcp)
647 struct modify_ldt_ldt_s copy;
649 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
650 tprintf("{entry_number:%d, ", copy.entry_number);
654 print_ldt_entry(©);
657 tprintf("%lx", tcp->u_arg[0]);
663 #endif /* LINUX && __i386__ */
667 sys_remap_file_pages(tcp)
671 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
672 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
673 tprintf(", %lu, ", tcp->u_arg[3]);
675 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
676 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
678 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
685 #define MPOL_DEFAULT 0
686 #define MPOL_PREFERRED 1
688 #define MPOL_INTERLEAVE 3
690 #define MPOL_F_NODE (1<<0)
691 #define MPOL_F_ADDR (1<<1)
693 #define MPOL_MF_STRICT (1<<0)
694 #define MPOL_MF_MOVE (1<<1)
695 #define MPOL_MF_MOVE_ALL (1<<2)
698 static const struct xlat policies[] = {
699 { MPOL_DEFAULT, "MPOL_DEFAULT" },
700 { MPOL_PREFERRED, "MPOL_PREFERRED" },
701 { MPOL_BIND, "MPOL_BIND" },
702 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
706 static const struct xlat mbindflags[] = {
707 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
708 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
709 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
713 static const struct xlat mempolicyflags[] = {
714 { MPOL_F_NODE, "MPOL_F_NODE" },
715 { MPOL_F_ADDR, "MPOL_F_ADDR" },
719 static const struct xlat move_pages_flags[] = {
720 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
721 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
727 get_nodes(tcp, ptr, maxnodes, err)
730 unsigned long maxnodes;
733 unsigned long nlongs, size, end;
735 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
736 size = nlongs * sizeof(long);
738 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
740 unsigned long n, cur, abbrev_end;
744 abbrev_end = ptr + max_strlen * sizeof(long);
745 if (abbrev_end < ptr)
751 for (cur = ptr; cur < end; cur += sizeof(long)) {
754 if (cur >= abbrev_end) {
758 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
763 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
767 tprintf(" %#lx", ptr);
769 tprintf(", %#lx", ptr);
770 tprintf(", %lu", maxnodes);
778 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
779 printxval(policies, tcp->u_arg[2], "MPOL_???");
780 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
782 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
788 sys_set_mempolicy(tcp)
792 printxval(policies, tcp->u_arg[0], "MPOL_???");
793 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
799 sys_get_mempolicy(tcp)
804 if (tcp->u_arg[0] == 0)
806 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
807 tprintf("%#lx", tcp->u_arg[0]);
809 printxval(policies, pol, "MPOL_???");
810 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
811 tprintf(", %#lx, ", tcp->u_arg[3]);
812 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
822 unsigned long npages = tcp->u_arg[1];
823 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
824 if (tcp->u_arg[2] == 0)
828 long puser = tcp->u_arg[2];
830 for (i = 0; i < npages; ++i) {
834 if (umove(tcp, puser, &p) < 0) {
839 puser += sizeof (void *);
843 if (tcp->u_arg[3] == 0)
847 long nodeuser = tcp->u_arg[3];
849 for (i = 0; i < npages; ++i) {
853 if (umove(tcp, nodeuser, &node) < 0) {
857 tprintf("%#x", node);
858 nodeuser += sizeof (int);
864 unsigned long npages = tcp->u_arg[1];
865 if (tcp->u_arg[4] == 0)
869 long statususer = tcp->u_arg[4];
871 for (i = 0; i < npages; ++i) {
875 if (umove(tcp, statususer, &status) < 0) {
879 tprintf("%#x", status);
880 statususer += sizeof (int);
884 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
890 #if defined(LINUX) && defined(POWERPC)
892 sys_subpage_prot(tcp)
896 unsigned long cur, end, abbrev_end, entries;
899 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
900 entries = tcp->u_arg[1] >> 16;
901 if (!entries || !tcp->u_arg[2]) {
906 end = cur + (sizeof(int) * entries);
907 if (!verbose(tcp) || end < tcp->u_arg[2]) {
908 tprintf("%#lx", tcp->u_arg[2]);
912 abbrev_end = cur + (sizeof(int) * max_strlen);
913 if (abbrev_end > end)
919 for (; cur < end; cur += sizeof(int)) {
920 if (cur > tcp->u_arg[2])
922 if (cur >= abbrev_end) {
926 if (umove(tcp, cur, &entry) < 0) {
927 tprintf("??? [%#lx]", cur);
931 tprintf("%#08x", entry);