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" },
102 static const struct xlat mmap_flags[] = {
103 { MAP_SHARED, "MAP_SHARED" },
104 { MAP_PRIVATE, "MAP_PRIVATE" },
105 { MAP_FIXED, "MAP_FIXED" },
107 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
110 { MAP_RENAME, "MAP_RENAME" },
113 { MAP_NORESERVE,"MAP_NORESERVE" },
116 { MAP_POPULATE, "MAP_POPULATE" },
119 { MAP_NONBLOCK, "MAP_NONBLOCK" },
122 * XXX - this was introduced in SunOS 4.x to distinguish between
123 * the old pre-4.x "mmap()", which:
125 * only let you map devices with an "mmap" routine (e.g.,
128 * required you to specify the mapping address;
130 * returned 0 on success and -1 on failure;
132 * memory and which, and the 4.x "mmap()" which:
134 * can map plain files;
136 * can be asked to pick where to map the file;
138 * returns the address where it mapped the file on success
141 * It's not actually used in source code that calls "mmap()"; the
142 * "mmap()" routine adds it for you.
144 * It'd be nice to come up with some way of eliminating it from
145 * the flags, e.g. reporting calls *without* it as "old_mmap()"
146 * and calls with it as "mmap()".
149 { _MAP_NEW, "_MAP_NEW" },
152 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
155 { MAP_DENYWRITE,"MAP_DENYWRITE" },
157 #ifdef MAP_EXECUTABLE
158 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
161 { MAP_INHERIT,"MAP_INHERIT" },
164 { MAP_FILE,"MAP_FILE"},
167 { MAP_LOCKED,"MAP_LOCKED"},
171 { MAP_ANON, "MAP_ANON" },
173 #ifdef MAP_HASSEMAPHORE
174 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
177 { MAP_STACK, "MAP_STACK" },
180 { MAP_NOSYNC, "MAP_NOSYNC" },
183 { MAP_NOCORE, "MAP_NOCORE" },
188 #if !HAVE_LONG_LONG_OFF_T
191 print_mmap(tcp,u_arg)
200 tprintf("%#lx, ", u_arg[0]);
202 tprintf("%lu, ", u_arg[1]);
204 printflags(mmap_prot, u_arg[2], "PROT_???");
208 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
209 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
211 printflags(mmap_flags, u_arg[3], "MAP_???");
213 /* fd (is always int, not long) */
214 tprintf(", %d, ", (int)u_arg[4]);
216 tprintf("%#lx", u_arg[5]);
222 int sys_old_mmap(tcp)
230 * IA64 processes never call this routine, they only use the
231 * new `sys_mmap' interface. This code converts the integer
232 * arguments that the IA32 process pushed onto the stack into
235 * Note that addresses with bit 31 set will be sign extended.
236 * Fortunately, those addresses are not currently being generated
237 * for IA32 processes so it's not a problem.
239 for (i = 0; i < 6; i++)
240 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
244 #elif defined(SH) || defined(SH64)
245 /* SH has always passed the args in registers */
248 u_arg[i] = tcp->u_arg[i];
251 if (current_personality == 1) {
253 for (i = 0; i < 6; ++i) {
255 if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
262 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
264 #endif // defined(IA64)
265 return print_mmap(tcp, u_arg);
274 #if defined(LINUX) && defined(SH64)
276 * Old mmap differs from new mmap in specifying the
277 * offset in units of bytes rather than pages. We
278 * pretend it's in byte units so the user only ever
279 * sees bytes in the printout.
281 tcp->u_arg[5] <<= PAGE_SHIFT;
283 return print_mmap(tcp, tcp->u_arg);
285 #endif /* !HAVE_LONG_LONG_OFF_T */
287 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
294 long *u_arg = tcp->u_arg;
299 long *u_arg = tcp->u_arg;
305 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
306 (char *) u_arg) == -1)
310 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
313 tprintf("%#lx, ", u_arg[0]);
315 tprintf("%lu, ", u_arg[1]);
317 printflags(mmap_prot, u_arg[2], "PROT_???");
321 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
322 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
324 printflags(mmap_flags, u_arg[3], "MAP_???");
327 tprintf(", %ld, ", u_arg[4]);
329 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
342 tcp->u_arg[0], tcp->u_arg[1]);
352 tprintf("%#lx, %lu, ",
353 tcp->u_arg[0], tcp->u_arg[1]);
354 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
361 static const struct xlat mremap_flags[] = {
362 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
371 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
373 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
378 static const struct xlat madvise_flags[] = {
380 { MADV_NORMAL, "MADV_NORMAL" },
383 { MADV_RANDOM, "MADV_RANDOM" },
385 #ifdef MADV_SEQUENTIAL
386 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
389 { MADV_WILLNEED, "MADV_WILLNEED" },
392 { MADV_DONTNEED, "MADV_DONTNEED" },
403 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
404 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
410 static const struct xlat mlockall_flags[] = {
412 { MCL_CURRENT, "MCL_CURRENT" },
415 { MCL_FUTURE, "MCL_FUTURE" },
425 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
435 static const struct xlat mctl_sync[] = {
437 { MS_SYNC, "MS_SYNC" },
439 { MS_ASYNC, "MS_ASYNC" },
440 { MS_INVALIDATE,"MS_INVALIDATE" },
450 tprintf("%#lx", tcp->u_arg[0]);
452 tprintf(", %lu, ", tcp->u_arg[1]);
454 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
459 #endif /* MS_ASYNC */
463 static const struct xlat mctl_funcs[] = {
464 { MC_LOCK, "MC_LOCK" },
465 { MC_LOCKAS, "MC_LOCKAS" },
466 { MC_SYNC, "MC_SYNC" },
467 { MC_UNLOCK, "MC_UNLOCK" },
468 { MC_UNLOCKAS, "MC_UNLOCKAS" },
472 static const struct xlat mctl_lockas[] = {
473 { MCL_CURRENT, "MCL_CURRENT" },
474 { MCL_FUTURE, "MCL_FUTURE" },
486 tprintf("%#lx", tcp->u_arg[0]);
488 tprintf(", %lu, ", tcp->u_arg[1]);
490 function = tcp->u_arg[2];
491 printflags(mctl_funcs, function, "MC_???");
497 printflags(mctl_sync, arg, "MS_???");
500 printflags(mctl_lockas, arg, "MCL_???");
516 unsigned long i, len;
520 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
523 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
524 (vec = malloc(len)) == NULL ||
525 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
526 tprintf("%#lx", tcp->u_arg[2]);
529 for (i = 0; i < len; i++) {
530 if (abbrev(tcp) && i >= max_strlen) {
534 tprintf((vec[i] & 1) ? "1" : "0");
544 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4)
553 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
555 #if defined(LINUX) && defined(__i386__)
557 print_ldt_entry (ldt_entry)
558 struct modify_ldt_ldt_s *ldt_entry;
560 tprintf("base_addr:%#08lx, "
564 "read_exec_only:%d, "
565 "limit_in_pages:%d, "
566 "seg_not_present:%d, "
568 ldt_entry->base_addr,
570 ldt_entry->seg_32bit,
572 ldt_entry->read_exec_only,
573 ldt_entry->limit_in_pages,
574 ldt_entry->seg_not_present,
583 struct modify_ldt_ldt_s copy;
584 tprintf("%ld", tcp->u_arg[0]);
585 if (tcp->u_arg[1] == 0
586 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
587 || umove(tcp, tcp->u_arg[1], ©) == -1)
588 tprintf(", %lx", tcp->u_arg[1]);
590 tprintf(", {entry_number:%d, ", copy.entry_number);
594 print_ldt_entry(©);
597 tprintf(", %lu", tcp->u_arg[2]);
603 sys_set_thread_area(tcp)
606 struct modify_ldt_ldt_s copy;
608 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
609 if (copy.entry_number == -1)
610 tprintf("{entry_number:%d -> ",
613 tprintf("{entry_number:");
616 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
617 tprintf("%d, ", copy.entry_number);
621 print_ldt_entry(©);
624 tprintf("%lx", tcp->u_arg[0]);
632 sys_get_thread_area(tcp)
635 struct modify_ldt_ldt_s copy;
637 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
638 tprintf("{entry_number:%d, ", copy.entry_number);
642 print_ldt_entry(©);
645 tprintf("%lx", tcp->u_arg[0]);
651 #endif /* LINUX && __i386__ */
655 sys_remap_file_pages(tcp)
659 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
660 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
661 tprintf(", %lu, ", tcp->u_arg[3]);
663 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
664 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
666 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
673 #define MPOL_DEFAULT 0
674 #define MPOL_PREFERRED 1
676 #define MPOL_INTERLEAVE 3
678 #define MPOL_F_NODE (1<<0)
679 #define MPOL_F_ADDR (1<<1)
681 #define MPOL_MF_STRICT (1<<0)
684 static const struct xlat policies[] = {
685 { MPOL_DEFAULT, "MPOL_DEFAULT" },
686 { MPOL_PREFERRED, "MPOL_PREFERRED" },
687 { MPOL_BIND, "MPOL_BIND" },
688 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
692 static const struct xlat mbindflags[] = {
693 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
697 static const struct xlat mempolicyflags[] = {
698 { MPOL_F_NODE, "MPOL_F_NODE" },
699 { MPOL_F_ADDR, "MPOL_F_ADDR" },
705 get_nodes(tcp, ptr, maxnodes, err)
708 unsigned long maxnodes;
711 unsigned long nlongs, size, end;
713 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
714 size = nlongs * sizeof(long);
716 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
718 unsigned long n, cur, abbrev_end;
722 abbrev_end = ptr + max_strlen * sizeof(long);
723 if (abbrev_end < ptr)
729 for (cur = ptr; cur < end; cur += sizeof(long)) {
732 if (cur >= abbrev_end) {
736 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
741 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
745 tprintf(" %#lx", ptr);
747 tprintf(", %#lx", ptr);
748 tprintf(", %lu", maxnodes);
756 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
757 printxval(policies, tcp->u_arg[2], "MPOL_???");
758 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
760 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
766 sys_set_mempolicy(tcp)
770 printxval(policies, tcp->u_arg[0], "MPOL_???");
771 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
777 sys_get_mempolicy(tcp)
782 if (tcp->u_arg[0] == 0)
784 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
785 tprintf("%#lx", tcp->u_arg[0]);
787 printxval(policies, pol, "MPOL_???");
788 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
789 tprintf(", %#lx, ", tcp->u_arg[3]);
790 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");