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]);
78 tprintf("%lu", tcp->u_arg[0]);
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" },
100 static const struct xlat mmap_flags[] = {
101 { MAP_SHARED, "MAP_SHARED" },
102 { MAP_PRIVATE, "MAP_PRIVATE" },
103 { MAP_FIXED, "MAP_FIXED" },
105 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
108 { MAP_RENAME, "MAP_RENAME" },
111 { MAP_NORESERVE,"MAP_NORESERVE" },
114 { MAP_POPULATE, "MAP_POPULATE" },
117 { MAP_NONBLOCK, "MAP_NONBLOCK" },
120 * XXX - this was introduced in SunOS 4.x to distinguish between
121 * the old pre-4.x "mmap()", which:
123 * only let you map devices with an "mmap" routine (e.g.,
126 * required you to specify the mapping address;
128 * returned 0 on success and -1 on failure;
130 * memory and which, and the 4.x "mmap()" which:
132 * can map plain files;
134 * can be asked to pick where to map the file;
136 * returns the address where it mapped the file on success
139 * It's not actually used in source code that calls "mmap()"; the
140 * "mmap()" routine adds it for you.
142 * It'd be nice to come up with some way of eliminating it from
143 * the flags, e.g. reporting calls *without* it as "old_mmap()"
144 * and calls with it as "mmap()".
147 { _MAP_NEW, "_MAP_NEW" },
150 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
153 { MAP_DENYWRITE,"MAP_DENYWRITE" },
155 #ifdef MAP_EXECUTABLE
156 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
159 { MAP_INHERIT,"MAP_INHERIT" },
162 { MAP_FILE,"MAP_FILE"},
165 { MAP_LOCKED,"MAP_LOCKED"},
169 { MAP_ANON, "MAP_ANON" },
171 #ifdef MAP_HASSEMAPHORE
172 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
175 { MAP_STACK, "MAP_STACK" },
178 { MAP_NOSYNC, "MAP_NOSYNC" },
181 { MAP_NOCORE, "MAP_NOCORE" },
186 #if !HAVE_LONG_LONG_OFF_T
189 print_mmap(tcp,u_arg)
198 tprintf("%#lx, ", u_arg[0]);
200 tprintf("%lu, ", u_arg[1]);
202 printflags(mmap_prot, u_arg[2], "PROT_???");
206 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
207 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
209 printflags(mmap_flags, u_arg[3], "MAP_???");
211 /* fd (is always int, not long) */
212 tprintf(", %d, ", (int)u_arg[4]);
214 tprintf("%#lx", u_arg[5]);
220 int sys_old_mmap(tcp)
228 * IA64 processes never call this routine, they only use the
229 * new `sys_mmap' interface. This code converts the integer
230 * arguments that the IA32 process pushed onto the stack into
233 * Note that addresses with bit 31 set will be sign extended.
234 * Fortunately, those addresses are not currently being generated
235 * for IA32 processes so it's not a problem.
237 for (i = 0; i < 6; i++)
238 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
242 #elif defined(SH) || defined(SH64)
243 /* SH has always passed the args in registers */
246 u_arg[i] = tcp->u_arg[i];
248 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
250 #endif // defined(IA64)
251 return print_mmap(tcp, u_arg);
260 #if defined(LINUX) && defined(SH64)
262 * Old mmap differs from new mmap in specifying the
263 * offset in units of bytes rather than pages. We
264 * pretend it's in byte units so the user only ever
265 * sees bytes in the printout.
267 tcp->u_arg[5] <<= PAGE_SHIFT;
269 return print_mmap(tcp, tcp->u_arg);
271 #endif /* !HAVE_LONG_LONG_OFF_T */
273 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
280 long *u_arg = tcp->u_arg;
285 long *u_arg = tcp->u_arg;
291 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
292 (char *) u_arg) == -1)
296 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
299 tprintf("%#lx, ", u_arg[0]);
301 tprintf("%lu, ", u_arg[1]);
303 printflags(mmap_prot, u_arg[2], "PROT_???");
307 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
308 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
310 printflags(mmap_flags, u_arg[3], "MAP_???");
313 tprintf(", %ld, ", u_arg[4]);
315 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
328 tcp->u_arg[0], tcp->u_arg[1]);
338 tprintf("%#lx, %lu, ",
339 tcp->u_arg[0], tcp->u_arg[1]);
340 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
347 static const struct xlat mremap_flags[] = {
348 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
357 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
359 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
364 static const struct xlat madvise_flags[] = {
366 { MADV_NORMAL, "MADV_NORMAL" },
369 { MADV_RANDOM, "MADV_RANDOM" },
371 #ifdef MADV_SEQUENTIAL
372 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
375 { MADV_WILLNEED, "MADV_WILLNEED" },
378 { MADV_DONTNEED, "MADV_DONTNEED" },
389 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
390 printflags(madvise_flags, tcp->u_arg[2], "MADV_???");
396 static const struct xlat mlockall_flags[] = {
398 { MCL_CURRENT, "MCL_CURRENT" },
401 { MCL_FUTURE, "MCL_FUTURE" },
411 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
421 static const struct xlat mctl_sync[] = {
423 { MS_SYNC, "MS_SYNC" },
425 { MS_ASYNC, "MS_ASYNC" },
426 { MS_INVALIDATE,"MS_INVALIDATE" },
436 tprintf("%#lx", tcp->u_arg[0]);
438 tprintf(", %lu, ", tcp->u_arg[1]);
440 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
445 #endif /* MS_ASYNC */
449 static const struct xlat mctl_funcs[] = {
450 { MC_LOCK, "MC_LOCK" },
451 { MC_LOCKAS, "MC_LOCKAS" },
452 { MC_SYNC, "MC_SYNC" },
453 { MC_UNLOCK, "MC_UNLOCK" },
454 { MC_UNLOCKAS, "MC_UNLOCKAS" },
458 static const struct xlat mctl_lockas[] = {
459 { MCL_CURRENT, "MCL_CURRENT" },
460 { MCL_FUTURE, "MCL_FUTURE" },
472 tprintf("%#lx", tcp->u_arg[0]);
474 tprintf(", %lu, ", tcp->u_arg[1]);
476 function = tcp->u_arg[2];
477 printflags(mctl_funcs, function, "MC_???");
483 printflags(mctl_sync, arg, "MS_???");
486 printflags(mctl_lockas, arg, "MCL_???");
502 unsigned long i, len;
506 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
509 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
510 (vec = malloc(len)) == NULL ||
511 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
512 tprintf("%#lx", tcp->u_arg[2]);
515 for (i = 0; i < len; i++) {
516 if (abbrev(tcp) && i >= max_strlen) {
520 tprintf((vec[i] & 1) ? "1" : "0");
539 #if defined(LINUX) && defined(__i386__)
541 print_ldt_entry (ldt_entry)
542 struct modify_ldt_ldt_s *ldt_entry;
544 tprintf("base_addr:%#08lx, "
548 "read_exec_only:%d, "
549 "limit_in_pages:%d, "
550 "seg_not_present:%d, "
552 ldt_entry->base_addr,
554 ldt_entry->seg_32bit,
556 ldt_entry->read_exec_only,
557 ldt_entry->limit_in_pages,
558 ldt_entry->seg_not_present,
567 struct modify_ldt_ldt_s copy;
568 tprintf("%ld", tcp->u_arg[0]);
569 if (tcp->u_arg[1] == 0
570 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
571 || umove(tcp, tcp->u_arg[1], ©) == -1)
572 tprintf(", %lx", tcp->u_arg[1]);
574 tprintf(", {entry_number:%d, ", copy.entry_number);
578 print_ldt_entry(©);
581 tprintf(", %lu", tcp->u_arg[2]);
587 sys_set_thread_area(tcp)
590 struct modify_ldt_ldt_s copy;
592 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
593 if (copy.entry_number == -1)
594 tprintf("{entry_number:%d -> ",
597 tprintf("{entry_number:");
600 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
601 tprintf("%d, ", copy.entry_number);
605 print_ldt_entry(©);
608 tprintf("%lx", tcp->u_arg[0]);
616 sys_get_thread_area(tcp)
619 struct modify_ldt_ldt_s copy;
621 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
622 tprintf("{entry_number:%d, ", copy.entry_number);
626 print_ldt_entry(©);
629 tprintf("%lx", tcp->u_arg[0]);
635 #endif /* LINUX && __i386__ */
639 sys_remap_file_pages(tcp)
643 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
644 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
645 tprintf(", %lu, ", tcp->u_arg[3]);
647 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
648 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
650 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
657 #define MPOL_DEFAULT 0
658 #define MPOL_PREFERRED 1
660 #define MPOL_INTERLEAVE 3
662 #define MPOL_F_NODE (1<<0)
663 #define MPOL_F_ADDR (1<<1)
665 #define MPOL_MF_STRICT (1<<0)
668 static const struct xlat policies[] = {
669 { MPOL_DEFAULT, "MPOL_DEFAULT" },
670 { MPOL_PREFERRED, "MPOL_PREFERRED" },
671 { MPOL_BIND, "MPOL_BIND" },
672 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
676 static const struct xlat mbindflags[] = {
677 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
681 static const struct xlat mempolicyflags[] = {
682 { MPOL_F_NODE, "MPOL_F_NODE" },
683 { MPOL_F_ADDR, "MPOL_F_ADDR" },
689 get_nodes(tcp, ptr, maxnodes, err)
692 unsigned long maxnodes;
695 int nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
696 if (err || !abbrev(tcp) || nlongs > getpagesize() / sizeof(long)
699 if (umoven(tcp, ptr, nlongs * sizeof(long),
701 tprintf(", %lx", ptr);
705 for (i = 0; i < nlongs; ++i) {
708 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2,
714 tprintf(", %lx", ptr);
715 tprintf(", %lu", maxnodes);
723 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
724 printxval(policies, tcp->u_arg[2], "MPOL_???");
725 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
727 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
733 sys_set_mempolicy(tcp)
737 printxval(policies, tcp->u_arg[0], "MPOL_???");
738 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
744 sys_get_mempolicy(tcp)
749 if (tcp->u_arg[0] == 0)
751 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
752 tprintf("%#lx", tcp->u_arg[0]);
754 printxval(policies, pol, "MPOL_???");
755 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
756 tprintf(", %#lx, ", tcp->u_arg[3]);
757 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");