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
60 sys_brk(struct tcb *tcp)
63 tprintf("%#lx", tcp->u_arg[0]);
72 #if defined(FREEBSD) || defined(SUNOS4)
74 sys_sbrk(struct tcb *tcp)
77 tprintf("%lu", tcp->u_arg[0]);
81 #endif /* FREEBSD || SUNOS4 */
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" },
98 { PROT_SAO, "PROT_SAO" },
103 static const struct xlat mmap_flags[] = {
104 { MAP_SHARED, "MAP_SHARED" },
105 { MAP_PRIVATE, "MAP_PRIVATE" },
106 { MAP_FIXED, "MAP_FIXED" },
108 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
111 { MAP_32BIT, "MAP_32BIT" },
114 { MAP_RENAME, "MAP_RENAME" },
117 { MAP_NORESERVE,"MAP_NORESERVE" },
120 { MAP_POPULATE, "MAP_POPULATE" },
123 { MAP_NONBLOCK, "MAP_NONBLOCK" },
126 * XXX - this was introduced in SunOS 4.x to distinguish between
127 * the old pre-4.x "mmap()", which:
129 * only let you map devices with an "mmap" routine (e.g.,
132 * required you to specify the mapping address;
134 * returned 0 on success and -1 on failure;
136 * memory and which, and the 4.x "mmap()" which:
138 * can map plain files;
140 * can be asked to pick where to map the file;
142 * returns the address where it mapped the file on success
145 * It's not actually used in source code that calls "mmap()"; the
146 * "mmap()" routine adds it for you.
148 * It'd be nice to come up with some way of eliminating it from
149 * the flags, e.g. reporting calls *without* it as "old_mmap()"
150 * and calls with it as "mmap()".
153 { _MAP_NEW, "_MAP_NEW" },
156 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
159 { MAP_DENYWRITE,"MAP_DENYWRITE" },
161 #ifdef MAP_EXECUTABLE
162 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
165 { MAP_INHERIT,"MAP_INHERIT" },
168 { MAP_FILE,"MAP_FILE"},
171 { MAP_LOCKED,"MAP_LOCKED"},
175 { MAP_ANON, "MAP_ANON" },
177 #ifdef MAP_HASSEMAPHORE
178 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
181 { MAP_STACK, "MAP_STACK" },
184 { MAP_NOSYNC, "MAP_NOSYNC" },
187 { MAP_NOCORE, "MAP_NOCORE" },
190 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
191 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
192 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
199 addtileflags(long flags)
201 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
202 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
204 if (flags & _MAP_CACHE_INCOHERENT) {
205 flags &= ~_MAP_CACHE_INCOHERENT;
206 if (home == MAP_CACHE_HOME_NONE) {
207 tprints("|MAP_CACHE_INCOHERENT");
210 tprints("|_MAP_CACHE_INCOHERENT");
215 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
216 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
217 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
218 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
219 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
221 tprintf("|MAP_CACHE_HOME(%d)",
222 (home >> _MAP_CACHE_HOME_SHIFT) );
230 #if !HAVE_LONG_LONG_OFF_T
232 print_mmap(struct tcb *tcp, long *u_arg, long long offset)
239 tprintf("%#lx, ", u_arg[0]);
241 tprintf("%lu, ", u_arg[1]);
243 printflags(mmap_prot, u_arg[2], "PROT_???");
247 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
249 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
251 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
254 printflags(mmap_flags, u_arg[3], "MAP_???");
258 printfd(tcp, u_arg[4]);
260 tprintf(", %#llx", offset);
266 int sys_old_mmap(struct tcb *tcp)
270 * IA64 processes never call this routine, they only use the
271 * new `sys_mmap' interface.
272 * For IA32 processes, this code converts the integer arguments
273 * that they pushed onto the stack, into longs.
275 * Note that addresses with bit 31 set will be sign extended.
276 * Fortunately, those addresses are not currently being generated
277 * for IA32 processes so it's not a problem.
282 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
284 for (i = 0; i < 6; i++)
285 u_arg[i] = narrow_arg[i];
286 #elif defined(SH) || defined(SH64)
287 /* SH has always passed the args in registers */
288 long *u_arg = tcp->u_arg;
292 if (current_personality == 1) {
294 unsigned narrow_arg[6];
295 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
297 for (i = 0; i < 6; ++i)
298 u_arg[i] = narrow_arg[i];
302 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
304 #endif /* other architectures */
306 return print_mmap(tcp, u_arg, u_arg[5]);
311 sys_mmap(struct tcb *tcp)
313 long long offset = tcp->u_arg[5];
315 /* FIXME: why only SH64? i386 mmap2 syscall ends up
316 * in this function, but does not convert offset
317 * from pages to bytes. See test/mmap_offset_decode.c
318 * Why SH64 and i386 are handled differently?
320 #if defined(LINUX) && defined(SH64)
322 * Old mmap differs from new mmap in specifying the
323 * offset in units of bytes rather than pages. We
324 * pretend it's in byte units so the user only ever
325 * sees bytes in the printout.
327 offset <<= PAGE_SHIFT;
329 #if defined(LINUX_MIPSN32)
330 offset = tcp->ext_arg[5];
332 return print_mmap(tcp, tcp->u_arg, offset);
334 #endif /* !HAVE_LONG_LONG_OFF_T */
336 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
337 /* TODO: comment which arches use this routine.
338 * For one, does ALPHA on Linux use this??
339 * From code it seems that it might use 7 or 8 registers,
340 * which is strange - Linux syscalls can pass maximum of 6 parameters!
343 sys_mmap64(struct tcb *tcp)
346 #if !defined(LINUX) || defined(ALPHA)
347 long *u_arg = tcp->u_arg;
350 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
351 (char *) u_arg) == -1)
355 tprintf("%#lx, ", u_arg[0]);
357 tprintf("%lu, ", u_arg[1]);
359 printflags(mmap_prot, u_arg[2], "PROT_???");
363 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
364 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
366 printflags(mmap_flags, u_arg[3], "MAP_???");
370 printfd(tcp, u_arg[4]);
372 #if !defined(LINUX) || defined(ALPHA)
373 printllval(tcp, ", %#llx", 5);
375 /* NOTE: not verified that [5] and [6] should be used.
376 * It's possible that long long is 64-bit aligned in memory
377 * and we need to use [6] and [7] here instead:
379 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
384 #endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
388 sys_munmap(struct tcb *tcp)
392 tcp->u_arg[0], tcp->u_arg[1]);
398 sys_mprotect(struct tcb *tcp)
401 tprintf("%#lx, %lu, ",
402 tcp->u_arg[0], tcp->u_arg[1]);
403 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
410 static const struct xlat mremap_flags[] = {
411 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
413 { MREMAP_FIXED, "MREMAP_FIXED" },
419 sys_mremap(struct tcb *tcp)
422 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
424 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
426 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
427 (MREMAP_MAYMOVE | MREMAP_FIXED))
428 tprintf(", %#lx", tcp->u_arg[4]);
434 static const struct xlat madvise_cmds[] = {
436 { MADV_NORMAL, "MADV_NORMAL" },
439 { MADV_RANDOM, "MADV_RANDOM" },
441 #ifdef MADV_SEQUENTIAL
442 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
445 { MADV_WILLNEED, "MADV_WILLNEED" },
448 { MADV_DONTNEED, "MADV_DONTNEED" },
455 sys_madvise(struct tcb *tcp)
458 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
459 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
465 static const struct xlat mlockall_flags[] = {
467 { MCL_CURRENT, "MCL_CURRENT" },
470 { MCL_FUTURE, "MCL_FUTURE" },
476 sys_mlockall(struct tcb *tcp)
479 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
489 static const struct xlat mctl_sync[] = {
491 { MS_SYNC, "MS_SYNC" },
493 { MS_ASYNC, "MS_ASYNC" },
494 { MS_INVALIDATE,"MS_INVALIDATE" },
499 sys_msync(struct tcb *tcp)
503 tprintf("%#lx", tcp->u_arg[0]);
505 tprintf(", %lu, ", tcp->u_arg[1]);
507 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
512 #endif /* MS_ASYNC */
516 static const struct xlat mctl_funcs[] = {
517 { MC_LOCK, "MC_LOCK" },
518 { MC_LOCKAS, "MC_LOCKAS" },
519 { MC_SYNC, "MC_SYNC" },
520 { MC_UNLOCK, "MC_UNLOCK" },
521 { MC_UNLOCKAS, "MC_UNLOCKAS" },
525 static const struct xlat mctl_lockas[] = {
526 { MCL_CURRENT, "MCL_CURRENT" },
527 { MCL_FUTURE, "MCL_FUTURE" },
532 sys_mctl(struct tcb *tcp)
538 tprintf("%#lx", tcp->u_arg[0]);
540 tprintf(", %lu, ", tcp->u_arg[1]);
542 function = tcp->u_arg[2];
543 printflags(mctl_funcs, function, "MC_???");
549 printflags(mctl_sync, arg, "MS_???");
552 printflags(mctl_lockas, arg, "MCL_???");
565 sys_mincore(struct tcb *tcp)
568 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
570 unsigned long i, len;
574 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
575 (vec = malloc(len)) == NULL ||
576 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
577 tprintf("%#lx", tcp->u_arg[2]);
580 for (i = 0; i < len; i++) {
581 if (abbrev(tcp) && i >= max_strlen) {
585 tprints((vec[i] & 1) ? "1" : "0");
594 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
596 sys_getpagesize(struct tcb *tcp)
602 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
604 #if defined(LINUX) && defined(__i386__)
606 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
608 tprintf("base_addr:%#08lx, "
612 "read_exec_only:%d, "
613 "limit_in_pages:%d, "
614 "seg_not_present:%d, "
616 (long) ldt_entry->base_addr,
618 ldt_entry->seg_32bit,
620 ldt_entry->read_exec_only,
621 ldt_entry->limit_in_pages,
622 ldt_entry->seg_not_present,
627 sys_modify_ldt(struct tcb *tcp)
630 struct modify_ldt_ldt_s copy;
631 tprintf("%ld", tcp->u_arg[0]);
632 if (tcp->u_arg[1] == 0
633 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
634 || umove(tcp, tcp->u_arg[1], ©) == -1)
635 tprintf(", %lx", tcp->u_arg[1]);
637 tprintf(", {entry_number:%d, ", copy.entry_number);
641 print_ldt_entry(©);
644 tprintf(", %lu", tcp->u_arg[2]);
650 sys_set_thread_area(struct tcb *tcp)
652 struct modify_ldt_ldt_s copy;
654 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
655 if (copy.entry_number == -1)
656 tprintf("{entry_number:%d -> ",
659 tprints("{entry_number:");
662 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
663 tprintf("%d, ", copy.entry_number);
667 print_ldt_entry(©);
670 tprintf("%lx", tcp->u_arg[0]);
678 sys_get_thread_area(struct tcb *tcp)
680 struct modify_ldt_ldt_s copy;
682 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
683 tprintf("{entry_number:%d, ", copy.entry_number);
687 print_ldt_entry(©);
690 tprintf("%lx", tcp->u_arg[0]);
696 #endif /* LINUX && __i386__ */
698 #if defined(LINUX) && defined(M68K)
701 sys_set_thread_area(struct tcb *tcp)
704 tprintf("%#lx", tcp->u_arg[0]);
710 sys_get_thread_area(struct tcb *tcp)
718 sys_remap_file_pages(struct tcb *tcp)
721 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
722 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
723 tprintf(", %lu, ", tcp->u_arg[3]);
725 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
726 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
728 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
735 #define MPOL_DEFAULT 0
736 #define MPOL_PREFERRED 1
738 #define MPOL_INTERLEAVE 3
740 #define MPOL_F_NODE (1<<0)
741 #define MPOL_F_ADDR (1<<1)
743 #define MPOL_MF_STRICT (1<<0)
744 #define MPOL_MF_MOVE (1<<1)
745 #define MPOL_MF_MOVE_ALL (1<<2)
748 static const struct xlat policies[] = {
749 { MPOL_DEFAULT, "MPOL_DEFAULT" },
750 { MPOL_PREFERRED, "MPOL_PREFERRED" },
751 { MPOL_BIND, "MPOL_BIND" },
752 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
756 static const struct xlat mbindflags[] = {
757 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
758 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
759 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
763 static const struct xlat mempolicyflags[] = {
764 { MPOL_F_NODE, "MPOL_F_NODE" },
765 { MPOL_F_ADDR, "MPOL_F_ADDR" },
769 static const struct xlat move_pages_flags[] = {
770 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
771 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
777 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
779 unsigned long nlongs, size, end;
781 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
782 size = nlongs * sizeof(long);
784 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
786 unsigned long n, cur, abbrev_end;
790 abbrev_end = ptr + max_strlen * sizeof(long);
791 if (abbrev_end < ptr)
797 for (cur = ptr; cur < end; cur += sizeof(long)) {
800 if (cur >= abbrev_end) {
804 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
809 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
813 tprintf(" %#lx", ptr);
815 tprintf(", %#lx", ptr);
816 tprintf(", %lu", maxnodes);
820 sys_mbind(struct tcb *tcp)
823 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
824 printxval(policies, tcp->u_arg[2], "MPOL_???");
825 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
827 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
833 sys_set_mempolicy(struct tcb *tcp)
836 printxval(policies, tcp->u_arg[0], "MPOL_???");
837 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
843 sys_get_mempolicy(struct tcb *tcp)
847 if (tcp->u_arg[0] == 0)
849 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
850 tprintf("%#lx", tcp->u_arg[0]);
852 printxval(policies, pol, "MPOL_???");
853 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
854 tprintf(", %#lx, ", tcp->u_arg[3]);
855 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
861 sys_move_pages(struct tcb *tcp)
864 unsigned long npages = tcp->u_arg[1];
865 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
866 if (tcp->u_arg[2] == 0)
870 long puser = tcp->u_arg[2];
872 for (i = 0; i < npages; ++i) {
876 if (umove(tcp, puser, &p) < 0) {
881 puser += sizeof(void *);
885 if (tcp->u_arg[3] == 0)
889 long nodeuser = tcp->u_arg[3];
891 for (i = 0; i < npages; ++i) {
895 if (umove(tcp, nodeuser, &node) < 0) {
899 tprintf("%#x", node);
900 nodeuser += sizeof(int);
906 unsigned long npages = tcp->u_arg[1];
907 if (tcp->u_arg[4] == 0)
911 long statususer = tcp->u_arg[4];
913 for (i = 0; i < npages; ++i) {
917 if (umove(tcp, statususer, &status) < 0) {
921 tprintf("%#x", status);
922 statususer += sizeof(int);
926 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
932 #if defined(LINUX) && defined(POWERPC)
934 sys_subpage_prot(struct tcb *tcp)
937 unsigned long cur, end, abbrev_end, entries;
940 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
941 entries = tcp->u_arg[1] >> 16;
942 if (!entries || !tcp->u_arg[2]) {
947 end = cur + (sizeof(int) * entries);
948 if (!verbose(tcp) || end < tcp->u_arg[2]) {
949 tprintf("%#lx", tcp->u_arg[2]);
953 abbrev_end = cur + (sizeof(int) * max_strlen);
954 if (abbrev_end > end)
960 for (; cur < end; cur += sizeof(int)) {
961 if (cur > tcp->u_arg[2])
963 if (cur >= abbrev_end) {
967 if (umove(tcp, cur, &entry) < 0) {
968 tprintf("??? [%#lx]", cur);
972 tprintf("%#08x", entry);