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.
36 #if defined(I386) || defined(X86_64) || defined(X32)
38 # ifdef HAVE_STRUCT_USER_DESC
39 # define modify_ldt_ldt_s user_desc
41 #endif /* I386 || X86_64 || X32 */
46 static unsigned long pagesize;
49 pagesize = sysconf(_SC_PAGESIZE);
54 sys_brk(struct tcb *tcp)
57 tprintf("%#lx", tcp->u_arg[0]);
62 static const struct xlat mmap_prot[] = {
82 static const struct xlat mmap_flags[] = {
105 * XXX - this was introduced in SunOS 4.x to distinguish between
106 * the old pre-4.x "mmap()", which:
108 * only let you map devices with an "mmap" routine (e.g.,
111 * required you to specify the mapping address;
113 * returned 0 on success and -1 on failure;
115 * memory and which, and the 4.x "mmap()" which:
117 * can map plain files;
119 * can be asked to pick where to map the file;
121 * returns the address where it mapped the file on success
124 * It's not actually used in source code that calls "mmap()"; the
125 * "mmap()" routine adds it for you.
127 * It'd be nice to come up with some way of eliminating it from
128 * the flags, e.g. reporting calls *without* it as "old_mmap()"
129 * and calls with it as "mmap()".
140 #ifdef MAP_EXECUTABLE
141 XLAT(MAP_EXECUTABLE),
153 #if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
156 #ifdef MAP_HASSEMAPHORE
157 XLAT(MAP_HASSEMAPHORE),
165 #if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
166 XLAT(MAP_UNINITIALIZED),
178 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
185 tprintf("%#lx, ", u_arg[0]);
187 tprintf("%lu, ", u_arg[1]);
189 printflags(mmap_prot, u_arg[2], "PROT_???");
193 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
194 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
196 printflags(mmap_flags, u_arg[3], "MAP_???");
200 printfd(tcp, u_arg[4]);
202 tprintf(", %#llx", offset);
207 /* Syscall name<->function correspondence is messed up on many arches.
209 * i386 has __NR_mmap == 90, and it is "old mmap", and
210 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
211 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
215 /* Params are pointed to by u_arg[0], offset is in bytes */
217 sys_old_mmap(struct tcb *tcp)
222 * IA64 processes never call this routine, they only use the
223 * new 'sys_mmap' interface. Only IA32 processes come here.
226 unsigned narrow_arg[6];
227 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
229 for (i = 0; i < 6; i++)
230 u_arg[i] = (unsigned long) narrow_arg[i];
231 #elif defined(X86_64)
232 /* We are here only in personality 1 (i386) */
234 unsigned narrow_arg[6];
235 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
237 for (i = 0; i < 6; ++i)
238 u_arg[i] = (unsigned long) narrow_arg[i];
240 if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
243 return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
247 /* Params are pointed to by u_arg[0], offset is in pages */
249 sys_old_mmap_pgoff(struct tcb *tcp)
253 unsigned narrow_arg[6];
254 unsigned long long offset;
255 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
257 for (i = 0; i < 5; i++)
258 u_arg[i] = (unsigned long) narrow_arg[i];
259 offset = narrow_arg[5];
260 offset *= get_pagesize();
261 return print_mmap(tcp, u_arg, offset);
265 /* Params are passed directly, offset is in bytes */
267 sys_mmap(struct tcb *tcp)
269 unsigned long long offset = (unsigned long) tcp->u_arg[5];
270 #if defined(LINUX_MIPSN32) || defined(X32)
271 /* Try test/x32_mmap.c */
272 offset = tcp->ext_arg[5];
274 /* Example of kernel-side handling of this variety of mmap:
275 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
276 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
277 * since the above code converts off to pages.
279 return print_mmap(tcp, tcp->u_arg, offset);
282 /* Params are passed directly, offset is in pages */
284 sys_mmap_pgoff(struct tcb *tcp)
286 /* Try test/mmap_offset_decode.c */
287 unsigned long long offset;
288 offset = (unsigned long) tcp->u_arg[5];
289 offset *= get_pagesize();
290 return print_mmap(tcp, tcp->u_arg, offset);
293 /* Params are passed directly, offset is in 4k units */
295 sys_mmap_4koff(struct tcb *tcp)
297 unsigned long long offset;
298 offset = (unsigned long) tcp->u_arg[5];
300 return print_mmap(tcp, tcp->u_arg, offset);
304 sys_munmap(struct tcb *tcp)
308 tcp->u_arg[0], tcp->u_arg[1]);
314 sys_mprotect(struct tcb *tcp)
317 tprintf("%#lx, %lu, ",
318 tcp->u_arg[0], tcp->u_arg[1]);
319 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
324 static const struct xlat mremap_flags[] = {
325 XLAT(MREMAP_MAYMOVE),
333 sys_mremap(struct tcb *tcp)
336 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
338 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
340 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
341 (MREMAP_MAYMOVE | MREMAP_FIXED))
342 tprintf(", %#lx", tcp->u_arg[4]);
348 static const struct xlat madvise_cmds[] = {
355 #ifdef MADV_SEQUENTIAL
356 XLAT(MADV_SEQUENTIAL),
376 #ifdef MADV_SOFT_OFFLINE
377 XLAT(MADV_SOFT_OFFLINE),
379 #ifdef MADV_MERGEABLE
380 XLAT(MADV_MERGEABLE),
382 #ifdef MADV_UNMERGEABLE
383 XLAT(MADV_UNMERGEABLE),
388 #ifdef MADV_NOHUGEPAGE
389 XLAT(MADV_NOHUGEPAGE),
401 sys_madvise(struct tcb *tcp)
404 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
405 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
410 static const struct xlat mlockall_flags[] = {
421 sys_mlockall(struct tcb *tcp)
424 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
431 static const struct xlat mctl_sync[] = {
441 sys_msync(struct tcb *tcp)
445 tprintf("%#lx", tcp->u_arg[0]);
447 tprintf(", %lu, ", tcp->u_arg[1]);
449 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
454 #endif /* MS_ASYNC */
458 static const struct xlat mctl_funcs[] = {
467 static const struct xlat mctl_lockas[] = {
474 sys_mctl(struct tcb *tcp)
480 tprintf("%#lx", tcp->u_arg[0]);
482 tprintf(", %lu, ", tcp->u_arg[1]);
484 function = tcp->u_arg[2];
485 printflags(mctl_funcs, function, "MC_???");
491 printflags(mctl_sync, arg, "MS_???");
494 printflags(mctl_lockas, arg, "MCL_???");
507 sys_mincore(struct tcb *tcp)
510 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
512 unsigned long i, len;
516 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
517 (vec = malloc(len)) == NULL ||
518 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
519 tprintf("%#lx", tcp->u_arg[2]);
522 for (i = 0; i < len; i++) {
523 if (abbrev(tcp) && i >= max_strlen) {
527 tprints((vec[i] & 1) ? "1" : "0");
536 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
538 sys_getpagesize(struct tcb *tcp)
546 #if defined(I386) || defined(X86_64) || defined(X32)
548 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
550 tprintf("base_addr:%#08lx, "
554 "read_exec_only:%d, "
555 "limit_in_pages:%d, "
556 "seg_not_present:%d, "
558 (long) ldt_entry->base_addr,
560 ldt_entry->seg_32bit,
562 ldt_entry->read_exec_only,
563 ldt_entry->limit_in_pages,
564 ldt_entry->seg_not_present,
569 sys_modify_ldt(struct tcb *tcp)
572 struct modify_ldt_ldt_s copy;
573 tprintf("%ld", tcp->u_arg[0]);
574 if (tcp->u_arg[1] == 0
575 || tcp->u_arg[2] != sizeof(struct modify_ldt_ldt_s)
576 || umove(tcp, tcp->u_arg[1], ©) == -1)
577 tprintf(", %lx", tcp->u_arg[1]);
579 tprintf(", {entry_number:%d, ", copy.entry_number);
583 print_ldt_entry(©);
586 tprintf(", %lu", tcp->u_arg[2]);
592 sys_set_thread_area(struct tcb *tcp)
594 struct modify_ldt_ldt_s copy;
596 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
597 if (copy.entry_number == -1)
598 tprintf("{entry_number:%d -> ",
601 tprints("{entry_number:");
604 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
605 tprintf("%d, ", copy.entry_number);
609 print_ldt_entry(©);
612 tprintf("%lx", tcp->u_arg[0]);
620 sys_get_thread_area(struct tcb *tcp)
622 struct modify_ldt_ldt_s copy;
624 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
625 tprintf("{entry_number:%d, ", copy.entry_number);
629 print_ldt_entry(©);
632 tprintf("%lx", tcp->u_arg[0]);
638 #endif /* I386 || X86_64 || X32 */
640 #if defined(M68K) || defined(MIPS)
642 sys_set_thread_area(struct tcb *tcp)
645 tprintf("%#lx", tcp->u_arg[0]);
653 sys_get_thread_area(struct tcb *tcp)
660 sys_remap_file_pages(struct tcb *tcp)
663 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
664 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
665 tprintf(", %lu, ", tcp->u_arg[3]);
667 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
668 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
670 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
676 #define MPOL_DEFAULT 0
677 #define MPOL_PREFERRED 1
679 #define MPOL_INTERLEAVE 3
681 #define MPOL_F_NODE (1<<0)
682 #define MPOL_F_ADDR (1<<1)
684 #define MPOL_MF_STRICT (1<<0)
685 #define MPOL_MF_MOVE (1<<1)
686 #define MPOL_MF_MOVE_ALL (1<<2)
688 static const struct xlat policies[] = {
690 XLAT(MPOL_PREFERRED),
692 XLAT(MPOL_INTERLEAVE),
696 static const struct xlat mbindflags[] = {
697 XLAT(MPOL_MF_STRICT),
699 XLAT(MPOL_MF_MOVE_ALL),
703 static const struct xlat mempolicyflags[] = {
709 static const struct xlat move_pages_flags[] = {
711 XLAT(MPOL_MF_MOVE_ALL),
716 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
718 unsigned long nlongs, size, end;
720 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
721 size = nlongs * sizeof(long);
723 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
725 unsigned long n, cur, abbrev_end;
729 abbrev_end = ptr + max_strlen * sizeof(long);
730 if (abbrev_end < ptr)
736 for (cur = ptr; cur < end; cur += sizeof(long)) {
739 if (cur >= abbrev_end) {
743 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
748 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
752 tprintf(" %#lx", ptr);
754 tprintf(", %#lx", ptr);
755 tprintf(", %lu", maxnodes);
759 sys_mbind(struct tcb *tcp)
762 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
763 printxval(policies, tcp->u_arg[2], "MPOL_???");
764 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
766 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
772 sys_set_mempolicy(struct tcb *tcp)
775 printxval(policies, tcp->u_arg[0], "MPOL_???");
776 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
782 sys_get_mempolicy(struct tcb *tcp)
786 if (tcp->u_arg[0] == 0)
788 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
789 tprintf("%#lx", tcp->u_arg[0]);
791 printxval(policies, pol, "MPOL_???");
792 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
793 tprintf(", %#lx, ", tcp->u_arg[3]);
794 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
800 sys_migrate_pages(struct tcb *tcp)
803 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
804 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
806 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
812 sys_move_pages(struct tcb *tcp)
815 unsigned long npages = tcp->u_arg[1];
816 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
817 if (tcp->u_arg[2] == 0)
821 long puser = tcp->u_arg[2];
823 for (i = 0; i < npages; ++i) {
827 if (umove(tcp, puser, &p) < 0) {
832 puser += sizeof(void *);
836 if (tcp->u_arg[3] == 0)
840 long nodeuser = tcp->u_arg[3];
842 for (i = 0; i < npages; ++i) {
846 if (umove(tcp, nodeuser, &node) < 0) {
850 tprintf("%#x", node);
851 nodeuser += sizeof(int);
857 unsigned long npages = tcp->u_arg[1];
858 if (tcp->u_arg[4] == 0)
862 long statususer = tcp->u_arg[4];
864 for (i = 0; i < npages; ++i) {
868 if (umove(tcp, statususer, &status) < 0) {
872 tprintf("%#x", status);
873 statususer += sizeof(int);
877 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
884 sys_subpage_prot(struct tcb *tcp)
887 unsigned long cur, end, abbrev_end, entries;
890 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
891 entries = tcp->u_arg[1] >> 16;
892 if (!entries || !tcp->u_arg[2]) {
897 end = cur + (sizeof(int) * entries);
898 if (!verbose(tcp) || end < tcp->u_arg[2]) {
899 tprintf("%#lx", tcp->u_arg[2]);
903 abbrev_end = cur + (sizeof(int) * max_strlen);
904 if (abbrev_end > end)
910 for (; cur < end; cur += sizeof(int)) {
911 if (cur > tcp->u_arg[2])
913 if (cur >= abbrev_end) {
917 if (umove(tcp, cur, &entry) < 0) {
918 tprintf("??? [%#lx]", cur);
922 tprintf("%#08x", entry);