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
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)
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]);
642 sys_set_thread_area(struct tcb *tcp)
645 tprintf("%#lx", tcp->u_arg[0]);
651 sys_get_thread_area(struct tcb *tcp)
658 sys_remap_file_pages(struct tcb *tcp)
661 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
662 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
663 tprintf(", %lu, ", tcp->u_arg[3]);
665 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
666 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
668 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
674 #define MPOL_DEFAULT 0
675 #define MPOL_PREFERRED 1
677 #define MPOL_INTERLEAVE 3
679 #define MPOL_F_NODE (1<<0)
680 #define MPOL_F_ADDR (1<<1)
682 #define MPOL_MF_STRICT (1<<0)
683 #define MPOL_MF_MOVE (1<<1)
684 #define MPOL_MF_MOVE_ALL (1<<2)
686 static const struct xlat policies[] = {
688 XLAT(MPOL_PREFERRED),
690 XLAT(MPOL_INTERLEAVE),
694 static const struct xlat mbindflags[] = {
695 XLAT(MPOL_MF_STRICT),
697 XLAT(MPOL_MF_MOVE_ALL),
701 static const struct xlat mempolicyflags[] = {
707 static const struct xlat move_pages_flags[] = {
709 XLAT(MPOL_MF_MOVE_ALL),
714 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
716 unsigned long nlongs, size, end;
718 nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
719 size = nlongs * sizeof(long);
721 if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
723 unsigned long n, cur, abbrev_end;
727 abbrev_end = ptr + max_strlen * sizeof(long);
728 if (abbrev_end < ptr)
734 for (cur = ptr; cur < end; cur += sizeof(long)) {
737 if (cur >= abbrev_end) {
741 if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
746 tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
750 tprintf(" %#lx", ptr);
752 tprintf(", %#lx", ptr);
753 tprintf(", %lu", maxnodes);
757 sys_mbind(struct tcb *tcp)
760 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
761 printxval(policies, tcp->u_arg[2], "MPOL_???");
762 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
764 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
770 sys_set_mempolicy(struct tcb *tcp)
773 printxval(policies, tcp->u_arg[0], "MPOL_???");
774 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
780 sys_get_mempolicy(struct tcb *tcp)
784 if (tcp->u_arg[0] == 0)
786 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
787 tprintf("%#lx", tcp->u_arg[0]);
789 printxval(policies, pol, "MPOL_???");
790 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
791 tprintf(", %#lx, ", tcp->u_arg[3]);
792 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
798 sys_migrate_pages(struct tcb *tcp)
801 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
802 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
804 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
810 sys_move_pages(struct tcb *tcp)
813 unsigned long npages = tcp->u_arg[1];
814 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
815 if (tcp->u_arg[2] == 0)
819 long puser = tcp->u_arg[2];
821 for (i = 0; i < npages; ++i) {
825 if (umove(tcp, puser, &p) < 0) {
830 puser += sizeof(void *);
834 if (tcp->u_arg[3] == 0)
838 long nodeuser = tcp->u_arg[3];
840 for (i = 0; i < npages; ++i) {
844 if (umove(tcp, nodeuser, &node) < 0) {
848 tprintf("%#x", node);
849 nodeuser += sizeof(int);
855 unsigned long npages = tcp->u_arg[1];
856 if (tcp->u_arg[4] == 0)
860 long statususer = tcp->u_arg[4];
862 for (i = 0; i < npages; ++i) {
866 if (umove(tcp, statususer, &status) < 0) {
870 tprintf("%#x", status);
871 statususer += sizeof(int);
875 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
882 sys_subpage_prot(struct tcb *tcp)
885 unsigned long cur, end, abbrev_end, entries;
888 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
889 entries = tcp->u_arg[1] >> 16;
890 if (!entries || !tcp->u_arg[2]) {
895 end = cur + (sizeof(int) * entries);
896 if (!verbose(tcp) || end < tcp->u_arg[2]) {
897 tprintf("%#lx", tcp->u_arg[2]);
901 abbrev_end = cur + (sizeof(int) * max_strlen);
902 if (abbrev_end > end)
908 for (; cur < end; cur += sizeof(int)) {
909 if (cur > tcp->u_arg[2])
911 if (cur >= abbrev_end) {
915 if (umove(tcp, cur, &entry) < 0) {
916 tprintf("??? [%#lx]", cur);
920 tprintf("%#08x", entry);