]> granicus.if.org Git - strace/blob - mem.c
mips: enable decoding of set_thread_area
[strace] / mem.c
1 /*
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>
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
20  *
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.
31  */
32
33 #include "defs.h"
34 #include <asm/mman.h>
35 #include <sys/mman.h>
36 #if defined(I386) || defined(X86_64) || defined(X32)
37 # include <asm/ldt.h>
38 # ifdef HAVE_STRUCT_USER_DESC
39 #  define modify_ldt_ldt_s user_desc
40 # endif
41 #endif /* I386 || X86_64 || X32 */
42
43 static unsigned long
44 get_pagesize()
45 {
46         static unsigned long pagesize;
47
48         if (!pagesize)
49                 pagesize = sysconf(_SC_PAGESIZE);
50         return pagesize;
51 }
52
53 int
54 sys_brk(struct tcb *tcp)
55 {
56         if (entering(tcp)) {
57                 tprintf("%#lx", tcp->u_arg[0]);
58         }
59         return RVAL_HEX;
60 }
61
62 static const struct xlat mmap_prot[] = {
63         XLAT(PROT_NONE),
64         XLAT(PROT_READ),
65         XLAT(PROT_WRITE),
66         XLAT(PROT_EXEC),
67 #ifdef PROT_SEM
68         XLAT(PROT_SEM),
69 #endif
70 #ifdef PROT_GROWSDOWN
71         XLAT(PROT_GROWSDOWN),
72 #endif
73 #ifdef PROT_GROWSUP
74         XLAT(PROT_GROWSUP),
75 #endif
76 #ifdef PROT_SAO
77         XLAT(PROT_SAO),
78 #endif
79         XLAT_END
80 };
81
82 static const struct xlat mmap_flags[] = {
83         XLAT(MAP_SHARED),
84         XLAT(MAP_PRIVATE),
85         XLAT(MAP_FIXED),
86 #ifdef MAP_ANONYMOUS
87         XLAT(MAP_ANONYMOUS),
88 #endif
89 #ifdef MAP_32BIT
90         XLAT(MAP_32BIT),
91 #endif
92 #ifdef MAP_RENAME
93         XLAT(MAP_RENAME),
94 #endif
95 #ifdef MAP_NORESERVE
96         XLAT(MAP_NORESERVE),
97 #endif
98 #ifdef MAP_POPULATE
99         XLAT(MAP_POPULATE),
100 #endif
101 #ifdef MAP_NONBLOCK
102         XLAT(MAP_NONBLOCK),
103 #endif
104         /*
105          * XXX - this was introduced in SunOS 4.x to distinguish between
106          * the old pre-4.x "mmap()", which:
107          *
108          *      only let you map devices with an "mmap" routine (e.g.,
109          *      frame buffers) in;
110          *
111          *      required you to specify the mapping address;
112          *
113          *      returned 0 on success and -1 on failure;
114          *
115          * memory and which, and the 4.x "mmap()" which:
116          *
117          *      can map plain files;
118          *
119          *      can be asked to pick where to map the file;
120          *
121          *      returns the address where it mapped the file on success
122          *      and -1 on failure.
123          *
124          * It's not actually used in source code that calls "mmap()"; the
125          * "mmap()" routine adds it for you.
126          *
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()".
130          */
131 #ifdef _MAP_NEW
132         XLAT(_MAP_NEW),
133 #endif
134 #ifdef MAP_GROWSDOWN
135         XLAT(MAP_GROWSDOWN),
136 #endif
137 #ifdef MAP_DENYWRITE
138         XLAT(MAP_DENYWRITE),
139 #endif
140 #ifdef MAP_EXECUTABLE
141         XLAT(MAP_EXECUTABLE),
142 #endif
143 #ifdef MAP_INHERIT
144         XLAT(MAP_INHERIT),
145 #endif
146 #ifdef MAP_FILE
147         XLAT(MAP_FILE),
148 #endif
149 #ifdef MAP_LOCKED
150         XLAT(MAP_LOCKED),
151 #endif
152         /* FreeBSD ones */
153 #if defined(MAP_ANON) && (!defined(MAP_ANONYMOUS) || MAP_ANON != MAP_ANONYMOUS)
154         XLAT(MAP_ANON),
155 #endif
156 #ifdef MAP_HASSEMAPHORE
157         XLAT(MAP_HASSEMAPHORE),
158 #endif
159 #ifdef MAP_STACK
160         XLAT(MAP_STACK),
161 #endif
162 #ifdef MAP_HUGETLB
163         XLAT(MAP_HUGETLB),
164 #endif
165 #if defined MAP_UNINITIALIZED && MAP_UNINITIALIZED > 0
166         XLAT(MAP_UNINITIALIZED),
167 #endif
168 #ifdef MAP_NOSYNC
169         XLAT(MAP_NOSYNC),
170 #endif
171 #ifdef MAP_NOCORE
172         XLAT(MAP_NOCORE),
173 #endif
174         XLAT_END
175 };
176
177 static int
178 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
179 {
180         if (entering(tcp)) {
181                 /* addr */
182                 if (!u_arg[0])
183                         tprints("NULL, ");
184                 else
185                         tprintf("%#lx, ", u_arg[0]);
186                 /* len */
187                 tprintf("%lu, ", u_arg[1]);
188                 /* prot */
189                 printflags(mmap_prot, u_arg[2], "PROT_???");
190                 tprints(", ");
191                 /* flags */
192 #ifdef MAP_TYPE
193                 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
194                 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
195 #else
196                 printflags(mmap_flags, u_arg[3], "MAP_???");
197 #endif
198                 tprints(", ");
199                 /* fd */
200                 printfd(tcp, u_arg[4]);
201                 /* offset */
202                 tprintf(", %#llx", offset);
203         }
204         return RVAL_HEX;
205 }
206
207 /* Syscall name<->function correspondence is messed up on many arches.
208  * For example:
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".
212  * Confused? Me too!
213  */
214
215 /* Params are pointed to by u_arg[0], offset is in bytes */
216 int
217 sys_old_mmap(struct tcb *tcp)
218 {
219         long u_arg[6];
220 #if defined(IA64)
221         /*
222          * IA64 processes never call this routine, they only use the
223          * new 'sys_mmap' interface. Only IA32 processes come here.
224          */
225         int i;
226         unsigned narrow_arg[6];
227         if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
228                 return 0;
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) */
233         int i;
234         unsigned narrow_arg[6];
235         if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), (char *) narrow_arg) == -1)
236                 return 0;
237         for (i = 0; i < 6; ++i)
238                 u_arg[i] = (unsigned long) narrow_arg[i];
239 #else
240         if (umoven(tcp, tcp->u_arg[0], sizeof(u_arg), (char *) u_arg) == -1)
241                 return 0;
242 #endif
243         return print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
244 }
245
246 #if defined(S390)
247 /* Params are pointed to by u_arg[0], offset is in pages */
248 int
249 sys_old_mmap_pgoff(struct tcb *tcp)
250 {
251         long u_arg[5];
252         int i;
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)
256                 return 0;
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);
262 }
263 #endif
264
265 /* Params are passed directly, offset is in bytes */
266 int
267 sys_mmap(struct tcb *tcp)
268 {
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];
273 #endif
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.
278          */
279         return print_mmap(tcp, tcp->u_arg, offset);
280 }
281
282 /* Params are passed directly, offset is in pages */
283 int
284 sys_mmap_pgoff(struct tcb *tcp)
285 {
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);
291 }
292
293 /* Params are passed directly, offset is in 4k units */
294 int
295 sys_mmap_4koff(struct tcb *tcp)
296 {
297         unsigned long long offset;
298         offset = (unsigned long) tcp->u_arg[5];
299         offset <<= 12;
300         return print_mmap(tcp, tcp->u_arg, offset);
301 }
302
303 int
304 sys_munmap(struct tcb *tcp)
305 {
306         if (entering(tcp)) {
307                 tprintf("%#lx, %lu",
308                         tcp->u_arg[0], tcp->u_arg[1]);
309         }
310         return 0;
311 }
312
313 int
314 sys_mprotect(struct tcb *tcp)
315 {
316         if (entering(tcp)) {
317                 tprintf("%#lx, %lu, ",
318                         tcp->u_arg[0], tcp->u_arg[1]);
319                 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
320         }
321         return 0;
322 }
323
324 static const struct xlat mremap_flags[] = {
325         XLAT(MREMAP_MAYMOVE),
326 #ifdef MREMAP_FIXED
327         XLAT(MREMAP_FIXED),
328 #endif
329         XLAT_END
330 };
331
332 int
333 sys_mremap(struct tcb *tcp)
334 {
335         if (entering(tcp)) {
336                 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
337                         tcp->u_arg[2]);
338                 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
339 #ifdef MREMAP_FIXED
340                 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
341                     (MREMAP_MAYMOVE | MREMAP_FIXED))
342                         tprintf(", %#lx", tcp->u_arg[4]);
343 #endif
344         }
345         return RVAL_HEX;
346 }
347
348 static const struct xlat madvise_cmds[] = {
349 #ifdef MADV_NORMAL
350         XLAT(MADV_NORMAL),
351 #endif
352 #ifdef MADV_RANDOM
353         XLAT(MADV_RANDOM),
354 #endif
355 #ifdef MADV_SEQUENTIAL
356         XLAT(MADV_SEQUENTIAL),
357 #endif
358 #ifdef MADV_WILLNEED
359         XLAT(MADV_WILLNEED),
360 #endif
361 #ifdef MADV_DONTNEED
362         XLAT(MADV_DONTNEED),
363 #endif
364 #ifdef MADV_REMOVE
365         XLAT(MADV_REMOVE),
366 #endif
367 #ifdef MADV_DONTFORK
368         XLAT(MADV_DONTFORK),
369 #endif
370 #ifdef MADV_DOFORK
371         XLAT(MADV_DOFORK),
372 #endif
373 #ifdef MADV_HWPOISON
374         XLAT(MADV_HWPOISON),
375 #endif
376 #ifdef MADV_SOFT_OFFLINE
377         XLAT(MADV_SOFT_OFFLINE),
378 #endif
379 #ifdef MADV_MERGEABLE
380         XLAT(MADV_MERGEABLE),
381 #endif
382 #ifdef MADV_UNMERGEABLE
383         XLAT(MADV_UNMERGEABLE),
384 #endif
385 #ifdef MADV_HUGEPAGE
386         XLAT(MADV_HUGEPAGE),
387 #endif
388 #ifdef MADV_NOHUGEPAGE
389         XLAT(MADV_NOHUGEPAGE),
390 #endif
391 #ifdef MADV_DONTDUMP
392         XLAT(MADV_DONTDUMP),
393 #endif
394 #ifdef MADV_DODUMP
395         XLAT(MADV_DODUMP),
396 #endif
397         XLAT_END
398 };
399
400 int
401 sys_madvise(struct tcb *tcp)
402 {
403         if (entering(tcp)) {
404                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
405                 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
406         }
407         return 0;
408 }
409
410 static const struct xlat mlockall_flags[] = {
411 #ifdef MCL_CURRENT
412         XLAT(MCL_CURRENT),
413 #endif
414 #ifdef MCL_FUTURE
415         XLAT(MCL_FUTURE),
416 #endif
417         XLAT_END
418 };
419
420 int
421 sys_mlockall(struct tcb *tcp)
422 {
423         if (entering(tcp)) {
424                 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
425         }
426         return 0;
427 }
428
429 #ifdef MS_ASYNC
430
431 static const struct xlat mctl_sync[] = {
432 #ifdef MS_SYNC
433         XLAT(MS_SYNC),
434 #endif
435         XLAT(MS_ASYNC),
436         XLAT(MS_INVALIDATE),
437         XLAT_END
438 };
439
440 int
441 sys_msync(struct tcb *tcp)
442 {
443         if (entering(tcp)) {
444                 /* addr */
445                 tprintf("%#lx", tcp->u_arg[0]);
446                 /* len */
447                 tprintf(", %lu, ", tcp->u_arg[1]);
448                 /* flags */
449                 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
450         }
451         return 0;
452 }
453
454 #endif /* MS_ASYNC */
455
456 #ifdef MC_SYNC
457
458 static const struct xlat mctl_funcs[] = {
459         XLAT(MC_LOCK),
460         XLAT(MC_LOCKAS),
461         XLAT(MC_SYNC),
462         XLAT(MC_UNLOCK),
463         XLAT(MC_UNLOCKAS),
464         XLAT_END
465 };
466
467 static const struct xlat mctl_lockas[] = {
468         XLAT(MCL_CURRENT),
469         XLAT(MCL_FUTURE),
470         XLAT_END
471 };
472
473 int
474 sys_mctl(struct tcb *tcp)
475 {
476         int arg, function;
477
478         if (entering(tcp)) {
479                 /* addr */
480                 tprintf("%#lx", tcp->u_arg[0]);
481                 /* len */
482                 tprintf(", %lu, ", tcp->u_arg[1]);
483                 /* function */
484                 function = tcp->u_arg[2];
485                 printflags(mctl_funcs, function, "MC_???");
486                 /* arg */
487                 arg = tcp->u_arg[3];
488                 tprints(", ");
489                 switch (function) {
490                 case MC_SYNC:
491                         printflags(mctl_sync, arg, "MS_???");
492                         break;
493                 case MC_LOCKAS:
494                         printflags(mctl_lockas, arg, "MCL_???");
495                         break;
496                 default:
497                         tprintf("%#x", arg);
498                         break;
499                 }
500         }
501         return 0;
502 }
503
504 #endif /* MC_SYNC */
505
506 int
507 sys_mincore(struct tcb *tcp)
508 {
509         if (entering(tcp)) {
510                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
511         } else {
512                 unsigned long i, len;
513                 char *vec = NULL;
514
515                 len = tcp->u_arg[1];
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]);
520                 else {
521                         tprints("[");
522                         for (i = 0; i < len; i++) {
523                                 if (abbrev(tcp) && i >= max_strlen) {
524                                         tprints("...");
525                                         break;
526                                 }
527                                 tprints((vec[i] & 1) ? "1" : "0");
528                         }
529                         tprints("]");
530                 }
531                 free(vec);
532         }
533         return 0;
534 }
535
536 #if defined(ALPHA) || defined(IA64) || defined(SPARC) || defined(SPARC64)
537 int
538 sys_getpagesize(struct tcb *tcp)
539 {
540         if (exiting(tcp))
541                 return RVAL_HEX;
542         return 0;
543 }
544 #endif
545
546 #if defined(I386) || defined(X86_64) || defined(X32)
547 void
548 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
549 {
550         tprintf("base_addr:%#08lx, "
551                 "limit:%d, "
552                 "seg_32bit:%d, "
553                 "contents:%d, "
554                 "read_exec_only:%d, "
555                 "limit_in_pages:%d, "
556                 "seg_not_present:%d, "
557                 "useable:%d}",
558                 (long) ldt_entry->base_addr,
559                 ldt_entry->limit,
560                 ldt_entry->seg_32bit,
561                 ldt_entry->contents,
562                 ldt_entry->read_exec_only,
563                 ldt_entry->limit_in_pages,
564                 ldt_entry->seg_not_present,
565                 ldt_entry->useable);
566 }
567
568 int
569 sys_modify_ldt(struct tcb *tcp)
570 {
571         if (entering(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], &copy) == -1)
577                         tprintf(", %lx", tcp->u_arg[1]);
578                 else {
579                         tprintf(", {entry_number:%d, ", copy.entry_number);
580                         if (!verbose(tcp))
581                                 tprints("...}");
582                         else {
583                                 print_ldt_entry(&copy);
584                         }
585                 }
586                 tprintf(", %lu", tcp->u_arg[2]);
587         }
588         return 0;
589 }
590
591 int
592 sys_set_thread_area(struct tcb *tcp)
593 {
594         struct modify_ldt_ldt_s copy;
595         if (entering(tcp)) {
596                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
597                         if (copy.entry_number == -1)
598                                 tprintf("{entry_number:%d -> ",
599                                         copy.entry_number);
600                         else
601                                 tprints("{entry_number:");
602                 }
603         } else {
604                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
605                         tprintf("%d, ", copy.entry_number);
606                         if (!verbose(tcp))
607                                 tprints("...}");
608                         else {
609                                 print_ldt_entry(&copy);
610                         }
611                 } else {
612                         tprintf("%lx", tcp->u_arg[0]);
613                 }
614         }
615         return 0;
616
617 }
618
619 int
620 sys_get_thread_area(struct tcb *tcp)
621 {
622         struct modify_ldt_ldt_s copy;
623         if (exiting(tcp)) {
624                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
625                         tprintf("{entry_number:%d, ", copy.entry_number);
626                         if (!verbose(tcp))
627                                 tprints("...}");
628                         else {
629                                 print_ldt_entry(&copy);
630                         }
631                 } else {
632                         tprintf("%lx", tcp->u_arg[0]);
633                 }
634         }
635         return 0;
636
637 }
638 #endif /* I386 || X86_64 || X32 */
639
640 #if defined(M68K) || defined(MIPS)
641 int
642 sys_set_thread_area(struct tcb *tcp)
643 {
644         if (entering(tcp))
645                 tprintf("%#lx", tcp->u_arg[0]);
646         return 0;
647
648 }
649 #endif
650
651 #if defined(M68K)
652 int
653 sys_get_thread_area(struct tcb *tcp)
654 {
655         return RVAL_HEX;
656 }
657 #endif
658
659 int
660 sys_remap_file_pages(struct tcb *tcp)
661 {
662         if (entering(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]);
666 #ifdef MAP_TYPE
667                 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
668                 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
669 #else
670                 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
671 #endif
672         }
673         return 0;
674 }
675
676 #define MPOL_DEFAULT    0
677 #define MPOL_PREFERRED  1
678 #define MPOL_BIND       2
679 #define MPOL_INTERLEAVE 3
680
681 #define MPOL_F_NODE     (1<<0)
682 #define MPOL_F_ADDR     (1<<1)
683
684 #define MPOL_MF_STRICT  (1<<0)
685 #define MPOL_MF_MOVE    (1<<1)
686 #define MPOL_MF_MOVE_ALL (1<<2)
687
688 static const struct xlat policies[] = {
689         XLAT(MPOL_DEFAULT),
690         XLAT(MPOL_PREFERRED),
691         XLAT(MPOL_BIND),
692         XLAT(MPOL_INTERLEAVE),
693         XLAT_END
694 };
695
696 static const struct xlat mbindflags[] = {
697         XLAT(MPOL_MF_STRICT),
698         XLAT(MPOL_MF_MOVE),
699         XLAT(MPOL_MF_MOVE_ALL),
700         XLAT_END
701 };
702
703 static const struct xlat mempolicyflags[] = {
704         XLAT(MPOL_F_NODE),
705         XLAT(MPOL_F_ADDR),
706         XLAT_END
707 };
708
709 static const struct xlat move_pages_flags[] = {
710         XLAT(MPOL_MF_MOVE),
711         XLAT(MPOL_MF_MOVE_ALL),
712         XLAT_END
713 };
714
715 static void
716 get_nodes(struct tcb *tcp, unsigned long ptr, unsigned long maxnodes, int err)
717 {
718         unsigned long nlongs, size, end;
719
720         nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
721         size = nlongs * sizeof(long);
722         end = ptr + size;
723         if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
724                             && (end > ptr))) {
725                 unsigned long n, cur, abbrev_end;
726                 int failed = 0;
727
728                 if (abbrev(tcp)) {
729                         abbrev_end = ptr + max_strlen * sizeof(long);
730                         if (abbrev_end < ptr)
731                                 abbrev_end = end;
732                 } else {
733                         abbrev_end = end;
734                 }
735                 tprints(", {");
736                 for (cur = ptr; cur < end; cur += sizeof(long)) {
737                         if (cur > ptr)
738                                 tprints(", ");
739                         if (cur >= abbrev_end) {
740                                 tprints("...");
741                                 break;
742                         }
743                         if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
744                                 tprints("?");
745                                 failed = 1;
746                                 break;
747                         }
748                         tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
749                 }
750                 tprints("}");
751                 if (failed)
752                         tprintf(" %#lx", ptr);
753         } else
754                 tprintf(", %#lx", ptr);
755         tprintf(", %lu", maxnodes);
756 }
757
758 int
759 sys_mbind(struct tcb *tcp)
760 {
761         if (entering(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);
765                 tprints(", ");
766                 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
767         }
768         return 0;
769 }
770
771 int
772 sys_set_mempolicy(struct tcb *tcp)
773 {
774         if (entering(tcp)) {
775                 printxval(policies, tcp->u_arg[0], "MPOL_???");
776                 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
777         }
778         return 0;
779 }
780
781 int
782 sys_get_mempolicy(struct tcb *tcp)
783 {
784         if (exiting(tcp)) {
785                 int pol;
786                 if (tcp->u_arg[0] == 0)
787                         tprints("NULL");
788                 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
789                         tprintf("%#lx", tcp->u_arg[0]);
790                 else
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_???");
795         }
796         return 0;
797 }
798
799 int
800 sys_migrate_pages(struct tcb *tcp)
801 {
802         if (entering(tcp)) {
803                 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
804                 get_nodes(tcp, tcp->u_arg[2], tcp->u_arg[1], 0);
805                 tprints(", ");
806                 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[1], 0);
807         }
808         return 0;
809 }
810
811 int
812 sys_move_pages(struct tcb *tcp)
813 {
814         if (entering(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)
818                         tprints("NULL, ");
819                 else {
820                         int i;
821                         long puser = tcp->u_arg[2];
822                         tprints("{");
823                         for (i = 0; i < npages; ++i) {
824                                 void *p;
825                                 if (i > 0)
826                                         tprints(", ");
827                                 if (umove(tcp, puser, &p) < 0) {
828                                         tprints("???");
829                                         break;
830                                 }
831                                 tprintf("%p", p);
832                                 puser += sizeof(void *);
833                         }
834                         tprints("}, ");
835                 }
836                 if (tcp->u_arg[3] == 0)
837                         tprints("NULL, ");
838                 else {
839                         int i;
840                         long nodeuser = tcp->u_arg[3];
841                         tprints("{");
842                         for (i = 0; i < npages; ++i) {
843                                 int node;
844                                 if (i > 0)
845                                         tprints(", ");
846                                 if (umove(tcp, nodeuser, &node) < 0) {
847                                         tprints("???");
848                                         break;
849                                 }
850                                 tprintf("%#x", node);
851                                 nodeuser += sizeof(int);
852                         }
853                         tprints("}, ");
854                 }
855         }
856         if (exiting(tcp)) {
857                 unsigned long npages = tcp->u_arg[1];
858                 if (tcp->u_arg[4] == 0)
859                         tprints("NULL, ");
860                 else {
861                         int i;
862                         long statususer = tcp->u_arg[4];
863                         tprints("{");
864                         for (i = 0; i < npages; ++i) {
865                                 int status;
866                                 if (i > 0)
867                                         tprints(", ");
868                                 if (umove(tcp, statususer, &status) < 0) {
869                                         tprints("???");
870                                         break;
871                                 }
872                                 tprintf("%#x", status);
873                                 statususer += sizeof(int);
874                         }
875                         tprints("}, ");
876                 }
877                 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
878         }
879         return 0;
880 }
881
882 #if defined(POWERPC)
883 int
884 sys_subpage_prot(struct tcb *tcp)
885 {
886         if (entering(tcp)) {
887                 unsigned long cur, end, abbrev_end, entries;
888                 unsigned int entry;
889
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]) {
893                         tprints("{}");
894                         return 0;
895                 }
896                 cur = 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]);
900                         return 0;
901                 }
902                 if (abbrev(tcp)) {
903                         abbrev_end = cur + (sizeof(int) * max_strlen);
904                         if (abbrev_end > end)
905                                 abbrev_end = end;
906                 }
907                 else
908                         abbrev_end = end;
909                 tprints("{");
910                 for (; cur < end; cur += sizeof(int)) {
911                         if (cur > tcp->u_arg[2])
912                                 tprints(", ");
913                         if (cur >= abbrev_end) {
914                                 tprints("...");
915                                 break;
916                         }
917                         if (umove(tcp, cur, &entry) < 0) {
918                                 tprintf("??? [%#lx]", cur);
919                                 break;
920                         }
921                         else
922                                 tprintf("%#08x", entry);
923                 }
924                 tprints("}");
925         }
926
927         return 0;
928 }
929 #endif