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)
321 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
324 tprintf("%#lx, ", u_arg[0]);
326 tprintf("%lu, ", u_arg[1]);
328 printflags(mmap_prot, u_arg[2], "PROT_???");
332 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
333 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
335 printflags(mmap_flags, u_arg[3], "MAP_???");
338 tprintf(", %ld, ", u_arg[4]);
340 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
353 tcp->u_arg[0], tcp->u_arg[1]);
363 tprintf("%#lx, %lu, ",
364 tcp->u_arg[0], tcp->u_arg[1]);
365 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
372 static const struct xlat mremap_flags[] = {
373 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
382 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
384 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
389 static const struct xlat madvise_cmds[] = {
391 { MADV_NORMAL, "MADV_NORMAL" },
394 { MADV_RANDOM, "MADV_RANDOM" },
396 #ifdef MADV_SEQUENTIAL
397 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
400 { MADV_WILLNEED, "MADV_WILLNEED" },
403 { MADV_DONTNEED, "MADV_DONTNEED" },
414 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
415 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
421 static const struct xlat mlockall_flags[] = {
423 { MCL_CURRENT, "MCL_CURRENT" },
426 { MCL_FUTURE, "MCL_FUTURE" },
436 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
446 static const struct xlat mctl_sync[] = {
448 { MS_SYNC, "MS_SYNC" },
450 { MS_ASYNC, "MS_ASYNC" },
451 { MS_INVALIDATE,"MS_INVALIDATE" },
461 tprintf("%#lx", tcp->u_arg[0]);
463 tprintf(", %lu, ", tcp->u_arg[1]);
465 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
470 #endif /* MS_ASYNC */
474 static const struct xlat mctl_funcs[] = {
475 { MC_LOCK, "MC_LOCK" },
476 { MC_LOCKAS, "MC_LOCKAS" },
477 { MC_SYNC, "MC_SYNC" },
478 { MC_UNLOCK, "MC_UNLOCK" },
479 { MC_UNLOCKAS, "MC_UNLOCKAS" },
483 static const struct xlat mctl_lockas[] = {
484 { MCL_CURRENT, "MCL_CURRENT" },
485 { MCL_FUTURE, "MCL_FUTURE" },
497 tprintf("%#lx", tcp->u_arg[0]);
499 tprintf(", %lu, ", tcp->u_arg[1]);
501 function = tcp->u_arg[2];
502 printflags(mctl_funcs, function, "MC_???");
508 printflags(mctl_sync, arg, "MS_???");
511 printflags(mctl_lockas, arg, "MCL_???");
527 unsigned long i, len;
531 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
534 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
535 (vec = malloc(len)) == NULL ||
536 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
537 tprintf("%#lx", tcp->u_arg[2]);
540 for (i = 0; i < len; i++) {
541 if (abbrev(tcp) && i >= max_strlen) {
545 tprintf((vec[i] & 1) ? "1" : "0");
555 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
564 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
566 #if defined(LINUX) && defined(__i386__)
568 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
570 tprintf("base_addr:%#08lx, "
574 "read_exec_only:%d, "
575 "limit_in_pages:%d, "
576 "seg_not_present:%d, "
578 (long) ldt_entry->base_addr,
580 ldt_entry->seg_32bit,
582 ldt_entry->read_exec_only,
583 ldt_entry->limit_in_pages,
584 ldt_entry->seg_not_present,
593 struct modify_ldt_ldt_s copy;
594 tprintf("%ld", tcp->u_arg[0]);
595 if (tcp->u_arg[1] == 0
596 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
597 || umove(tcp, tcp->u_arg[1], ©) == -1)
598 tprintf(", %lx", tcp->u_arg[1]);
600 tprintf(", {entry_number:%d, ", copy.entry_number);
604 print_ldt_entry(©);
607 tprintf(", %lu", tcp->u_arg[2]);
613 sys_set_thread_area(tcp)
616 struct modify_ldt_ldt_s copy;
618 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
619 if (copy.entry_number == -1)
620 tprintf("{entry_number:%d -> ",
623 tprintf("{entry_number:");
626 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
627 tprintf("%d, ", copy.entry_number);
631 print_ldt_entry(©);
634 tprintf("%lx", tcp->u_arg[0]);
642 sys_get_thread_area(tcp)
645 struct modify_ldt_ldt_s copy;
647 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
648 tprintf("{entry_number:%d, ", copy.entry_number);
652 print_ldt_entry(©);
655 tprintf("%lx", tcp->u_arg[0]);
661 #endif /* LINUX && __i386__ */
665 sys_remap_file_pages(tcp)
669 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
670 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
671 tprintf(", %lu, ", tcp->u_arg[3]);
673 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
674 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
676 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
683 #define MPOL_DEFAULT 0
684 #define MPOL_PREFERRED 1
686 #define MPOL_INTERLEAVE 3
688 #define MPOL_F_NODE (1<<0)
689 #define MPOL_F_ADDR (1<<1)
691 #define MPOL_MF_STRICT (1<<0)
692 #define MPOL_MF_MOVE (1<<1)
693 #define MPOL_MF_MOVE_ALL (1<<2)
696 static const struct xlat policies[] = {
697 { MPOL_DEFAULT, "MPOL_DEFAULT" },
698 { MPOL_PREFERRED, "MPOL_PREFERRED" },
699 { MPOL_BIND, "MPOL_BIND" },
700 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
704 static const struct xlat mbindflags[] = {
705 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
706 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
707 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
711 static const struct xlat mempolicyflags[] = {
712 { MPOL_F_NODE, "MPOL_F_NODE" },
713 { MPOL_F_ADDR, "MPOL_F_ADDR" },
717 static const struct xlat move_pages_flags[] = {
718 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
719 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
725 get_nodes(tcp, ptr, maxnodes, err)
728 unsigned long maxnodes;
731 unsigned long nlongs, size, end;
733 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
734 size = nlongs * sizeof(long);
736 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
738 unsigned long n, cur, abbrev_end;
742 abbrev_end = ptr + max_strlen * sizeof(long);
743 if (abbrev_end < ptr)
749 for (cur = ptr; cur < end; cur += sizeof(long)) {
752 if (cur >= abbrev_end) {
756 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
761 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
765 tprintf(" %#lx", ptr);
767 tprintf(", %#lx", ptr);
768 tprintf(", %lu", maxnodes);
776 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
777 printxval(policies, tcp->u_arg[2], "MPOL_???");
778 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
780 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
786 sys_set_mempolicy(tcp)
790 printxval(policies, tcp->u_arg[0], "MPOL_???");
791 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
797 sys_get_mempolicy(tcp)
802 if (tcp->u_arg[0] == 0)
804 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
805 tprintf("%#lx", tcp->u_arg[0]);
807 printxval(policies, pol, "MPOL_???");
808 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
809 tprintf(", %#lx, ", tcp->u_arg[3]);
810 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
820 unsigned long npages = tcp->u_arg[1];
821 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
822 if (tcp->u_arg[2] == 0)
826 long puser = tcp->u_arg[2];
828 for (i = 0; i < npages; ++i) {
832 if (umove(tcp, puser, &p) < 0) {
837 puser += sizeof (void *);
841 if (tcp->u_arg[3] == 0)
845 long nodeuser = tcp->u_arg[3];
847 for (i = 0; i < npages; ++i) {
851 if (umove(tcp, nodeuser, &node) < 0) {
855 tprintf("%#x", node);
856 nodeuser += sizeof (int);
862 unsigned long npages = tcp->u_arg[1];
863 if (tcp->u_arg[4] == 0)
867 long statususer = tcp->u_arg[4];
869 for (i = 0; i < npages; ++i) {
873 if (umove(tcp, statususer, &status) < 0) {
877 tprintf("%#x", status);
878 statususer += sizeof (int);
882 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
888 #if defined(LINUX) && defined(POWERPC)
890 sys_subpage_prot(tcp)
894 unsigned long cur, end, abbrev_end, entries;
897 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
898 entries = tcp->u_arg[1] >> 16;
899 if (!entries || !tcp->u_arg[2]) {
904 end = cur + (sizeof(int) * entries);
905 if (!verbose(tcp) || end < tcp->u_arg[2]) {
906 tprintf("%#lx", tcp->u_arg[2]);
910 abbrev_end = cur + (sizeof(int) * max_strlen);
911 if (abbrev_end > end)
917 for (; cur < end; cur += sizeof(int)) {
918 if (cur > tcp->u_arg[2])
920 if (cur >= abbrev_end) {
924 if (umove(tcp, cur, &entry) < 0) {
925 tprintf("??? [%#lx]", cur);
929 tprintf("%#08x", entry);