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.
38 # ifdef HAVE_STRUCT_USER_DESC
39 # define modify_ldt_ldt_s user_desc
43 # include <asm/page.h> /* for PAGE_SHIFT */
47 sys_brk(struct tcb *tcp)
50 tprintf("%#lx", tcp->u_arg[0]);
55 static const struct xlat mmap_prot[] = {
56 { PROT_NONE, "PROT_NONE", },
57 { PROT_READ, "PROT_READ" },
58 { PROT_WRITE, "PROT_WRITE" },
59 { PROT_EXEC, "PROT_EXEC" },
61 { PROT_SEM, "PROT_SEM" },
64 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
67 { PROT_GROWSUP, "PROT_GROWSUP" },
70 { PROT_SAO, "PROT_SAO" },
75 static const struct xlat mmap_flags[] = {
76 { MAP_SHARED, "MAP_SHARED" },
77 { MAP_PRIVATE, "MAP_PRIVATE" },
78 { MAP_FIXED, "MAP_FIXED" },
80 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
83 { MAP_32BIT, "MAP_32BIT" },
86 { MAP_RENAME, "MAP_RENAME" },
89 { MAP_NORESERVE,"MAP_NORESERVE" },
92 { MAP_POPULATE, "MAP_POPULATE" },
95 { MAP_NONBLOCK, "MAP_NONBLOCK" },
98 * XXX - this was introduced in SunOS 4.x to distinguish between
99 * the old pre-4.x "mmap()", which:
101 * only let you map devices with an "mmap" routine (e.g.,
104 * required you to specify the mapping address;
106 * returned 0 on success and -1 on failure;
108 * memory and which, and the 4.x "mmap()" which:
110 * can map plain files;
112 * can be asked to pick where to map the file;
114 * returns the address where it mapped the file on success
117 * It's not actually used in source code that calls "mmap()"; the
118 * "mmap()" routine adds it for you.
120 * It'd be nice to come up with some way of eliminating it from
121 * the flags, e.g. reporting calls *without* it as "old_mmap()"
122 * and calls with it as "mmap()".
125 { _MAP_NEW, "_MAP_NEW" },
128 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
131 { MAP_DENYWRITE,"MAP_DENYWRITE" },
133 #ifdef MAP_EXECUTABLE
134 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
137 { MAP_INHERIT, "MAP_INHERIT" },
140 { MAP_FILE, "MAP_FILE" },
143 { MAP_LOCKED, "MAP_LOCKED" },
146 #if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
147 { MAP_ANON, "MAP_ANON" },
149 #ifdef MAP_HASSEMAPHORE
150 { MAP_HASSEMAPHORE,"MAP_HASSEMAPHORE"},
153 { MAP_STACK, "MAP_STACK" },
155 #if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
156 { MAP_UNINITIALIZED,"MAP_UNINITIALIZED"},
159 { MAP_NOSYNC, "MAP_NOSYNC" },
162 { MAP_NOCORE, "MAP_NOCORE" },
165 { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
166 { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
167 { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
174 addtileflags(long flags)
176 long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
177 flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
179 if (flags & _MAP_CACHE_INCOHERENT) {
180 flags &= ~_MAP_CACHE_INCOHERENT;
181 if (home == MAP_CACHE_HOME_NONE) {
182 tprints("|MAP_CACHE_INCOHERENT");
185 tprints("|_MAP_CACHE_INCOHERENT");
190 case MAP_CACHE_HOME_HERE: tprints("|MAP_CACHE_HOME_HERE"); break;
191 case MAP_CACHE_HOME_NONE: tprints("|MAP_CACHE_HOME_NONE"); break;
192 case MAP_CACHE_HOME_SINGLE: tprints("|MAP_CACHE_HOME_SINGLE"); break;
193 case MAP_CACHE_HOME_TASK: tprints("|MAP_CACHE_HOME_TASK"); break;
194 case MAP_CACHE_HOME_HASH: tprints("|MAP_CACHE_HOME_HASH"); break;
196 tprintf("|MAP_CACHE_HOME(%ld)",
197 (home >> _MAP_CACHE_HOME_SHIFT) );
205 #if !HAVE_LONG_LONG_OFF_T
207 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
214 tprintf("%#lx, ", u_arg[0]);
216 tprintf("%lu, ", u_arg[1]);
218 printflags(mmap_prot, u_arg[2], "PROT_???");
222 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
224 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
226 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
229 printflags(mmap_flags, u_arg[3], "MAP_???");
233 printfd(tcp, u_arg[4]);
235 tprintf(", %#llx", offset);
240 int sys_old_mmap(struct tcb *tcp)
244 * IA64 processes never call this routine, they only use the
245 * new `sys_mmap' interface.
246 * For IA32 processes, this code converts the integer arguments
247 * that they pushed onto the stack, into longs.
251 unsigned narrow_arg[6];
252 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
254 for (i = 0; i < 6; i++)
255 u_arg[i] = narrow_arg[i];
256 #elif defined(SH) || defined(SH64)
257 /* SH has always passed the args in registers */
258 long *u_arg = tcp->u_arg;
259 #elif defined(X86_64)
261 if (current_personality == 1) {
263 unsigned narrow_arg[6];
264 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
266 for (i = 0; i < 6; ++i)
267 u_arg[i] = narrow_arg[i];
269 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
274 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
277 return print_mmap(tcp, u_arg, (unsigned long)u_arg[5]);
281 sys_mmap(struct tcb *tcp)
283 unsigned long long offset = (unsigned long) tcp->u_arg[5];
287 * Old mmap differs from new mmap in specifying the
288 * offset in units of bytes rather than pages. We
289 * pretend it's in byte units so the user only ever
290 * sees bytes in the printout.
292 offset <<= PAGE_SHIFT;
294 /* Try test/mmap_offset_decode.c */
295 offset <<= 12; /* 4096 byte pages */
296 #elif defined(LINUX_MIPSN32) || defined(X32)
297 /* Try test/x32_mmap.c */
298 /* At least for X32 it definitely should not be page-shifted! */
299 offset = tcp->ext_arg[5];
301 return print_mmap(tcp, tcp->u_arg, offset);
303 #endif /* !HAVE_LONG_LONG_OFF_T */
305 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
306 /* TODO: comment which arches use this routine.
307 * For one, does ALPHA on Linux use this??
308 * From code it seems that it might use 7 or 8 registers,
309 * which is strange - Linux syscalls can pass maximum of 6 parameters!
311 # ifdef HAVE_LONG_LONG_OFF_T
312 /* For systems that have a long long off_t,
313 * sys_mmap in syscall tables is handled by sys_mmap64:
315 # define sys_mmap64 sys_mmap
318 sys_mmap64(struct tcb *tcp)
321 #if defined(ALPHA) || defined(X32)
322 long *u_arg = tcp->u_arg;
325 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
326 (char *) u_arg) == -1)
333 tprintf("%#lx, ", u_arg[0]);
335 tprintf("%lu, ", u_arg[1]);
337 printflags(mmap_prot, u_arg[2], "PROT_???");
341 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
342 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
344 printflags(mmap_flags, u_arg[3], "MAP_???");
348 printfd(tcp, u_arg[4]);
350 #if defined(ALPHA) || defined(X32)
351 printllval(tcp, ", %#llx", 5);
353 /* NOTE: not verified that [5] and [6] should be used.
354 * It's possible that long long is 64-bit aligned in memory
355 * and we need to use [6] and [7] here instead:
357 tprintf(", %#llx", LONG_LONG(u_arg[5], u_arg[6]));
362 #endif /* _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T */
365 sys_munmap(struct tcb *tcp)
369 tcp->u_arg[0], tcp->u_arg[1]);
375 sys_mprotect(struct tcb *tcp)
378 tprintf("%#lx, %lu, ",
379 tcp->u_arg[0], tcp->u_arg[1]);
380 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
385 static const struct xlat mremap_flags[] = {
386 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
388 { MREMAP_FIXED, "MREMAP_FIXED" },
394 sys_mremap(struct tcb *tcp)
397 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
399 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
401 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
402 (MREMAP_MAYMOVE | MREMAP_FIXED))
403 tprintf(", %#lx", tcp->u_arg[4]);
409 static const struct xlat madvise_cmds[] = {
411 { MADV_NORMAL, "MADV_NORMAL" },
414 { MADV_RANDOM, "MADV_RANDOM" },
416 #ifdef MADV_SEQUENTIAL
417 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
420 { MADV_WILLNEED, "MADV_WILLNEED" },
423 { MADV_DONTNEED, "MADV_DONTNEED" },
429 sys_madvise(struct tcb *tcp)
432 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
433 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
438 static const struct xlat mlockall_flags[] = {
440 { MCL_CURRENT, "MCL_CURRENT" },
443 { MCL_FUTURE, "MCL_FUTURE" },
449 sys_mlockall(struct tcb *tcp)
452 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
459 static const struct xlat mctl_sync[] = {
461 { MS_SYNC, "MS_SYNC" },
463 { MS_ASYNC, "MS_ASYNC" },
464 { MS_INVALIDATE,"MS_INVALIDATE" },
469 sys_msync(struct tcb *tcp)
473 tprintf("%#lx", tcp->u_arg[0]);
475 tprintf(", %lu, ", tcp->u_arg[1]);
477 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
482 #endif /* MS_ASYNC */
486 static const struct xlat mctl_funcs[] = {
487 { MC_LOCK, "MC_LOCK" },
488 { MC_LOCKAS, "MC_LOCKAS" },
489 { MC_SYNC, "MC_SYNC" },
490 { MC_UNLOCK, "MC_UNLOCK" },
491 { MC_UNLOCKAS, "MC_UNLOCKAS" },
495 static const struct xlat mctl_lockas[] = {
496 { MCL_CURRENT, "MCL_CURRENT" },
497 { MCL_FUTURE, "MCL_FUTURE" },
502 sys_mctl(struct tcb *tcp)
508 tprintf("%#lx", tcp->u_arg[0]);
510 tprintf(", %lu, ", tcp->u_arg[1]);
512 function = tcp->u_arg[2];
513 printflags(mctl_funcs, function, "MC_???");
519 printflags(mctl_sync, arg, "MS_???");
522 printflags(mctl_lockas, arg, "MCL_???");
535 sys_mincore(struct tcb *tcp)
538 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
540 unsigned long i, len;
544 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
545 (vec = malloc(len)) == NULL ||
546 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
547 tprintf("%#lx", tcp->u_arg[2]);
550 for (i = 0; i < len; i++) {
551 if (abbrev(tcp) && i >= max_strlen) {
555 tprints((vec[i] & 1) ? "1" : "0");
564 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
566 sys_getpagesize(struct tcb *tcp)
576 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
578 tprintf("base_addr:%#08lx, "
582 "read_exec_only:%d, "
583 "limit_in_pages:%d, "
584 "seg_not_present:%d, "
586 (long) ldt_entry->base_addr,
588 ldt_entry->seg_32bit,
590 ldt_entry->read_exec_only,
591 ldt_entry->limit_in_pages,
592 ldt_entry->seg_not_present,
597 sys_modify_ldt(struct tcb *tcp)
600 struct modify_ldt_ldt_s copy;
601 tprintf("%ld", tcp->u_arg[0]);
602 if (tcp->u_arg[1] == 0
603 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
604 || umove(tcp, tcp->u_arg[1], ©) == -1)
605 tprintf(", %lx", tcp->u_arg[1]);
607 tprintf(", {entry_number:%d, ", copy.entry_number);
611 print_ldt_entry(©);
614 tprintf(", %lu", tcp->u_arg[2]);
620 sys_set_thread_area(struct tcb *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 tprints("{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(struct tcb *tcp)
650 struct modify_ldt_ldt_s copy;
652 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
653 tprintf("{entry_number:%d, ", copy.entry_number);
657 print_ldt_entry(©);
660 tprintf("%lx", tcp->u_arg[0]);
670 sys_set_thread_area(struct tcb *tcp)
673 tprintf("%#lx", tcp->u_arg[0]);
679 sys_get_thread_area(struct tcb *tcp)
686 sys_remap_file_pages(struct tcb *tcp)
689 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
690 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
691 tprintf(", %lu, ", tcp->u_arg[3]);
693 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
694 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
696 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
702 #define MPOL_DEFAULT 0
703 #define MPOL_PREFERRED 1
705 #define MPOL_INTERLEAVE 3
707 #define MPOL_F_NODE (1<<0)
708 #define MPOL_F_ADDR (1<<1)
710 #define MPOL_MF_STRICT (1<<0)
711 #define MPOL_MF_MOVE (1<<1)
712 #define MPOL_MF_MOVE_ALL (1<<2)
714 static const struct xlat policies[] = {
715 { MPOL_DEFAULT, "MPOL_DEFAULT" },
716 { MPOL_PREFERRED, "MPOL_PREFERRED" },
717 { MPOL_BIND, "MPOL_BIND" },
718 { MPOL_INTERLEAVE, "MPOL_INTERLEAVE" },
722 static const struct xlat mbindflags[] = {
723 { MPOL_MF_STRICT, "MPOL_MF_STRICT" },
724 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
725 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
729 static const struct xlat mempolicyflags[] = {
730 { MPOL_F_NODE, "MPOL_F_NODE" },
731 { MPOL_F_ADDR, "MPOL_F_ADDR" },
735 static const struct xlat move_pages_flags[] = {
736 { MPOL_MF_MOVE, "MPOL_MF_MOVE" },
737 { MPOL_MF_MOVE_ALL, "MPOL_MF_MOVE_ALL" },
742 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
744 unsigned long nlongs, size, end;
746 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
747 size = nlongs * sizeof(long);
749 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
751 unsigned long n, cur, abbrev_end;
755 abbrev_end = ptr + max_strlen * sizeof(long);
756 if (abbrev_end < ptr)
762 for (cur = ptr; cur < end; cur += sizeof(long)) {
765 if (cur >= abbrev_end) {
769 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
774 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
778 tprintf(" %#lx", ptr);
780 tprintf(", %#lx", ptr);
781 tprintf(", %lu", maxnodes);
785 sys_mbind(struct tcb *tcp)
788 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
789 printxval(policies, tcp->u_arg[2], "MPOL_???");
790 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
792 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
798 sys_set_mempolicy(struct tcb *tcp)
801 printxval(policies, tcp->u_arg[0], "MPOL_???");
802 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
808 sys_get_mempolicy(struct tcb *tcp)
812 if (tcp->u_arg[0] == 0)
814 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
815 tprintf("%#lx", tcp->u_arg[0]);
817 printxval(policies, pol, "MPOL_???");
818 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
819 tprintf(", %#lx, ", tcp->u_arg[3]);
820 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
826 sys_migrate_pages(struct tcb *tcp)
829 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
830 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
832 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
838 sys_move_pages(struct tcb *tcp)
841 unsigned long npages = tcp->u_arg[1];
842 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
843 if (tcp->u_arg[2] == 0)
847 long puser = tcp->u_arg[2];
849 for (i = 0; i < npages; ++i) {
853 if (umove(tcp, puser, &p) < 0) {
858 puser += sizeof(void *);
862 if (tcp->u_arg[3] == 0)
866 long nodeuser = tcp->u_arg[3];
868 for (i = 0; i < npages; ++i) {
872 if (umove(tcp, nodeuser, &node) < 0) {
876 tprintf("%#x", node);
877 nodeuser += sizeof(int);
883 unsigned long npages = tcp->u_arg[1];
884 if (tcp->u_arg[4] == 0)
888 long statususer = tcp->u_arg[4];
890 for (i = 0; i < npages; ++i) {
894 if (umove(tcp, statususer, &status) < 0) {
898 tprintf("%#x", status);
899 statususer += sizeof(int);
903 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
910 sys_subpage_prot(struct tcb *tcp)
913 unsigned long cur, end, abbrev_end, entries;
916 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
917 entries = tcp->u_arg[1] >> 16;
918 if (!entries || !tcp->u_arg[2]) {
923 end = cur + (sizeof(int) * entries);
924 if (!verbose(tcp) || end < tcp->u_arg[2]) {
925 tprintf("%#lx", tcp->u_arg[2]);
929 abbrev_end = cur + (sizeof(int) * max_strlen);
930 if (abbrev_end > end)
936 for (; cur < end; cur += sizeof(int)) {
937 if (cur > tcp->u_arg[2])
939 if (cur >= abbrev_end) {
943 if (umove(tcp, cur, &entry) < 0) {
944 tprintf("??? [%#lx]", cur);
948 tprintf("%#08x", entry);