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" },
380 sys_mremap(struct tcb *tcp)
383 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
385 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
387 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
388 (MREMAP_MAYMOVE | MREMAP_FIXED))
389 tprintf(", %#lx", tcp->u_arg[4]);
395 static const struct xlat madvise_cmds[] = {
397 { MADV_NORMAL, "MADV_NORMAL" },
400 { MADV_RANDOM, "MADV_RANDOM" },
402 #ifdef MADV_SEQUENTIAL
403 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
406 { MADV_WILLNEED, "MADV_WILLNEED" },
409 { MADV_DONTNEED, "MADV_DONTNEED" },
420 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
421 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
427 static const struct xlat mlockall_flags[] = {
429 { MCL_CURRENT, "MCL_CURRENT" },
432 { MCL_FUTURE, "MCL_FUTURE" },
442 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
452 static const struct xlat mctl_sync[] = {
454 { MS_SYNC, "MS_SYNC" },
456 { MS_ASYNC, "MS_ASYNC" },
457 { MS_INVALIDATE,"MS_INVALIDATE" },
467 tprintf("%#lx", tcp->u_arg[0]);
469 tprintf(", %lu, ", tcp->u_arg[1]);
471 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
476 #endif /* MS_ASYNC */
480 static const struct xlat mctl_funcs[] = {
481 { MC_LOCK, "MC_LOCK" },
482 { MC_LOCKAS, "MC_LOCKAS" },
483 { MC_SYNC, "MC_SYNC" },
484 { MC_UNLOCK, "MC_UNLOCK" },
485 { MC_UNLOCKAS, "MC_UNLOCKAS" },
489 static const struct xlat mctl_lockas[] = {
490 { MCL_CURRENT, "MCL_CURRENT" },
491 { MCL_FUTURE, "MCL_FUTURE" },
503 tprintf("%#lx", tcp->u_arg[0]);
505 tprintf(", %lu, ", tcp->u_arg[1]);
507 function = tcp->u_arg[2];
508 printflags(mctl_funcs, function, "MC_???");
514 printflags(mctl_sync, arg, "MS_???");
517 printflags(mctl_lockas, arg, "MCL_???");
533 unsigned long i, len;
537 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
540 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
541 (vec = malloc(len)) == NULL ||
542 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
543 tprintf("%#lx", tcp->u_arg[2]);
546 for (i = 0; i < len; i++) {
547 if (abbrev(tcp) && i >= max_strlen) {
551 tprintf((vec[i] & 1) ? "1" : "0");
561 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
570 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
572 #if defined(LINUX) && defined(__i386__)
574 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
576 tprintf("base_addr:%#08lx, "
580 "read_exec_only:%d, "
581 "limit_in_pages:%d, "
582 "seg_not_present:%d, "
584 (long) ldt_entry->base_addr,
586 ldt_entry->seg_32bit,
588 ldt_entry->read_exec_only,
589 ldt_entry->limit_in_pages,
590 ldt_entry->seg_not_present,
599 struct modify_ldt_ldt_s copy;
600 tprintf("%ld", tcp->u_arg[0]);
601 if (tcp->u_arg[1] == 0
602 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
603 || umove(tcp, tcp->u_arg[1], ©) == -1)
604 tprintf(", %lx", tcp->u_arg[1]);
606 tprintf(", {entry_number:%d, ", copy.entry_number);
610 print_ldt_entry(©);
613 tprintf(", %lu", tcp->u_arg[2]);
619 sys_set_thread_area(tcp)
622 struct modify_ldt_ldt_s copy;
624 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
625 if (copy.entry_number == -1)
626 tprintf("{entry_number:%d -> ",
629 tprintf("{entry_number:");
632 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
633 tprintf("%d, ", copy.entry_number);
637 print_ldt_entry(©);
640 tprintf("%lx", tcp->u_arg[0]);
648 sys_get_thread_area(tcp)
651 struct modify_ldt_ldt_s copy;
653 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
654 tprintf("{entry_number:%d, ", copy.entry_number);
658 print_ldt_entry(©);
661 tprintf("%lx", tcp->u_arg[0]);
667 #endif /* LINUX && __i386__ */
671 sys_remap_file_pages(tcp)
675 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
676 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
677 tprintf(", %lu, ", tcp->u_arg[3]);
679 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
680 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
682 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
689 #define MPOL_DEFAULT 0
690 #define MPOL_PREFERRED 1
692 #define MPOL_INTERLEAVE 3
694 #define MPOL_F_NODE (1<<0)
695 #define MPOL_F_ADDR (1<<1)
697 #define MPOL_MF_STRICT (1<<0)
698 #define MPOL_MF_MOVE (1<<1)
699 #define MPOL_MF_MOVE_ALL (1<<2)
702 static const struct xlat policies[] = {
703 { MPOL_DEFAULT, "MPOL_DEFAULT" },
704 { MPOL_PREFERRED, "MPOL_PREFERRED" },
705 { MPOL_BIND, "MPOL_BIND" },
706 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
710 static const struct xlat mbindflags[] = {
711 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
712 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
713 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
717 static const struct xlat mempolicyflags[] = {
718 { MPOL_F_NODE, "MPOL_F_NODE" },
719 { MPOL_F_ADDR, "MPOL_F_ADDR" },
723 static const struct xlat move_pages_flags[] = {
724 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
725 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
731 get_nodes(tcp, ptr, maxnodes, err)
734 unsigned long maxnodes;
737 unsigned long nlongs, size, end;
739 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
740 size = nlongs * sizeof(long);
742 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
744 unsigned long n, cur, abbrev_end;
748 abbrev_end = ptr + max_strlen * sizeof(long);
749 if (abbrev_end < ptr)
755 for (cur = ptr; cur < end; cur += sizeof(long)) {
758 if (cur >= abbrev_end) {
762 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
767 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
771 tprintf(" %#lx", ptr);
773 tprintf(", %#lx", ptr);
774 tprintf(", %lu", maxnodes);
782 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
783 printxval(policies, tcp->u_arg[2], "MPOL_???");
784 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
786 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
792 sys_set_mempolicy(tcp)
796 printxval(policies, tcp->u_arg[0], "MPOL_???");
797 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
803 sys_get_mempolicy(tcp)
808 if (tcp->u_arg[0] == 0)
810 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
811 tprintf("%#lx", tcp->u_arg[0]);
813 printxval(policies, pol, "MPOL_???");
814 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
815 tprintf(", %#lx, ", tcp->u_arg[3]);
816 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
826 unsigned long npages = tcp->u_arg[1];
827 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
828 if (tcp->u_arg[2] == 0)
832 long puser = tcp->u_arg[2];
834 for (i = 0; i < npages; ++i) {
838 if (umove(tcp, puser, &p) < 0) {
843 puser += sizeof (void *);
847 if (tcp->u_arg[3] == 0)
851 long nodeuser = tcp->u_arg[3];
853 for (i = 0; i < npages; ++i) {
857 if (umove(tcp, nodeuser, &node) < 0) {
861 tprintf("%#x", node);
862 nodeuser += sizeof (int);
868 unsigned long npages = tcp->u_arg[1];
869 if (tcp->u_arg[4] == 0)
873 long statususer = tcp->u_arg[4];
875 for (i = 0; i < npages; ++i) {
879 if (umove(tcp, statususer, &status) < 0) {
883 tprintf("%#x", status);
884 statususer += sizeof (int);
888 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
894 #if defined(LINUX) && defined(POWERPC)
896 sys_subpage_prot(tcp)
900 unsigned long cur, end, abbrev_end, entries;
903 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
904 entries = tcp->u_arg[1] >> 16;
905 if (!entries || !tcp->u_arg[2]) {
910 end = cur + (sizeof(int) * entries);
911 if (!verbose(tcp) || end < tcp->u_arg[2]) {
912 tprintf("%#lx", tcp->u_arg[2]);
916 abbrev_end = cur + (sizeof(int) * max_strlen);
917 if (abbrev_end > end)
923 for (; cur < end; cur += sizeof(int)) {
924 if (cur > tcp->u_arg[2])
926 if (cur >= abbrev_end) {
930 if (umove(tcp, cur, &entry) < 0) {
931 tprintf("??? [%#lx]", cur);
935 tprintf("%#08x", entry);