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