]> granicus.if.org Git - strace/blob - mem.c
ec5707a347ac420cef2a9cf755ca5d9973a463e3
[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 #ifdef TILE
192         { MAP_CACHE_NO_LOCAL, "MAP_CACHE_NO_LOCAL" },
193         { MAP_CACHE_NO_L2, "MAP_CACHE_NO_L2" },
194         { MAP_CACHE_NO_L1, "MAP_CACHE_NO_L1" },
195 #endif
196         { 0,            NULL            },
197 };
198
199 #ifdef TILE
200 static
201 int
202 addtileflags(flags)
203 long flags;
204 {
205         long home = flags & _MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
206         flags &= ~_MAP_CACHE_MKHOME(_MAP_CACHE_HOME_MASK);
207
208         if (flags & _MAP_CACHE_INCOHERENT) {
209                 flags &= ~_MAP_CACHE_INCOHERENT;
210                 if (home == MAP_CACHE_HOME_NONE) {
211                         tprintf("|MAP_CACHE_INCOHERENT");
212                         return flags;
213                 }
214                 tprintf("|_MAP_CACHE_INCOHERENT");
215         }
216
217         switch (home) {
218         case 0: break;
219         case MAP_CACHE_HOME_HERE: tprintf("|MAP_CACHE_HOME_HERE"); break;
220         case MAP_CACHE_HOME_NONE: tprintf("|MAP_CACHE_HOME_NONE"); break;
221         case MAP_CACHE_HOME_SINGLE: tprintf("|MAP_CACHE_HOME_SINGLE"); break;
222         case MAP_CACHE_HOME_TASK: tprintf("|MAP_CACHE_HOME_TASK"); break;
223         case MAP_CACHE_HOME_HASH: tprintf("|MAP_CACHE_HOME_HASH"); break;
224         default:
225                 tprintf("|MAP_CACHE_HOME(%d)",
226                         (home >> _MAP_CACHE_HOME_SHIFT) );
227                 break;
228         }
229
230         return flags;
231 }
232 #endif
233
234 #if !HAVE_LONG_LONG_OFF_T
235 static
236 int
237 print_mmap(tcp,u_arg, offset)
238 struct tcb *tcp;
239 long *u_arg;
240 long long offset;
241 {
242         if (entering(tcp)) {
243                 /* addr */
244                 if (!u_arg[0])
245                         tprintf("NULL, ");
246                 else
247                         tprintf("%#lx, ", u_arg[0]);
248                 /* len */
249                 tprintf("%lu, ", u_arg[1]);
250                 /* prot */
251                 printflags(mmap_prot, u_arg[2], "PROT_???");
252                 tprintf(", ");
253                 /* flags */
254 #ifdef MAP_TYPE
255                 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
256 #ifdef TILE
257                 addflags(mmap_flags, addtileflags(u_arg[3] & ~MAP_TYPE));
258 #else
259                 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
260 #endif
261 #else
262                 printflags(mmap_flags, u_arg[3], "MAP_???");
263 #endif
264                 /* fd (is always int, not long) */
265                 tprintf(", %d, ", (int)u_arg[4]);
266                 /* offset */
267                 tprintf("%#llx", offset);
268         }
269         return RVAL_HEX;
270 }
271
272 #ifdef LINUX
273 int sys_old_mmap(tcp)
274 struct tcb *tcp;
275 {
276         long u_arg[6];
277
278 #if     defined(IA64)
279         int i, v;
280         /*
281          *  IA64 processes never call this routine, they only use the
282          *  new `sys_mmap' interface.  This code converts the integer
283          *  arguments that the IA32 process pushed onto the stack into
284          *  longs.
285          *
286          *  Note that addresses with bit 31 set will be sign extended.
287          *  Fortunately, those addresses are not currently being generated
288          *  for IA32 processes so it's not a problem.
289          */
290         for (i = 0; i < 6; i++)
291                 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
292                         return 0;
293                 else
294                         u_arg[i] = v;
295 #elif defined(SH) || defined(SH64)
296         /* SH has always passed the args in registers */
297         int i;
298         for (i=0; i<6; i++)
299                 u_arg[i] = tcp->u_arg[i];
300 #else
301 # if defined(X86_64)
302         if (current_personality == 1) {
303                 int i;
304                 for (i = 0; i < 6; ++i) {
305                         unsigned int val;
306                         if (umove(tcp, tcp->u_arg[0] + i * 4, &val) == -1)
307                                 return 0;
308                         u_arg[i] = val;
309                 }
310         }
311         else
312 # endif
313         if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
314                 return 0;
315 #endif  // defined(IA64)
316         return print_mmap(tcp, u_arg, u_arg[5]);
317 }
318 #endif
319
320 int
321 sys_mmap(tcp)
322 struct tcb *tcp;
323 {
324         long long offset = tcp->u_arg[5];
325
326 #if defined(LINUX) && defined(SH64)
327         /*
328          * Old mmap differs from new mmap in specifying the
329          * offset in units of bytes rather than pages.  We
330          * pretend it's in byte units so the user only ever
331          * sees bytes in the printout.
332          */
333         offset <<= PAGE_SHIFT;
334 #endif
335 #if defined(LINUX_MIPSN32)
336         offset = tcp->ext_arg[5];
337 #endif
338         return print_mmap(tcp, tcp->u_arg, offset);
339 }
340 #endif /* !HAVE_LONG_LONG_OFF_T */
341
342 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
343 int
344 sys_mmap64(tcp)
345 struct tcb *tcp;
346 {
347 #ifdef linux
348 #ifdef ALPHA
349         long *u_arg = tcp->u_arg;
350 #else /* !ALPHA */
351         long u_arg[7];
352 #endif /* !ALPHA */
353 #else /* !linux */
354         long *u_arg = tcp->u_arg;
355 #endif /* !linux */
356
357         if (entering(tcp)) {
358 #ifdef linux
359 #ifndef ALPHA
360                 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
361                                 (char *) u_arg) == -1)
362                         return 0;
363 #endif /* ALPHA */
364 #endif /* linux */
365
366                 /* addr */
367                 tprintf("%#lx, ", u_arg[0]);
368                 /* len */
369                 tprintf("%lu, ", u_arg[1]);
370                 /* prot */
371                 printflags(mmap_prot, u_arg[2], "PROT_???");
372                 tprintf(", ");
373                 /* flags */
374 #ifdef MAP_TYPE
375                 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
376                 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
377 #else
378                 printflags(mmap_flags, u_arg[3], "MAP_???");
379 #endif
380                 /* fd */
381                 tprintf(", %ld, ", u_arg[4]);
382                 /* offset */
383                 printllval(tcp, "%#llx", 5);
384         }
385         return RVAL_HEX;
386 }
387 #endif
388
389
390 int
391 sys_munmap(tcp)
392 struct tcb *tcp;
393 {
394         if (entering(tcp)) {
395                 tprintf("%#lx, %lu",
396                         tcp->u_arg[0], tcp->u_arg[1]);
397         }
398         return 0;
399 }
400
401 int
402 sys_mprotect(tcp)
403 struct tcb *tcp;
404 {
405         if (entering(tcp)) {
406                 tprintf("%#lx, %lu, ",
407                         tcp->u_arg[0], tcp->u_arg[1]);
408                 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
409         }
410         return 0;
411 }
412
413 #ifdef LINUX
414
415 static const struct xlat mremap_flags[] = {
416         { MREMAP_MAYMOVE,       "MREMAP_MAYMOVE"        },
417 #ifdef MREMAP_FIXED
418         { MREMAP_FIXED,         "MREMAP_FIXED"          },
419 #endif
420         { 0,                    NULL                    }
421 };
422
423 int
424 sys_mremap(struct tcb *tcp)
425 {
426         if (entering(tcp)) {
427                 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
428                         tcp->u_arg[2]);
429                 printflags(mremap_flags, tcp->u_arg[3], "MREMAP_???");
430 #ifdef MREMAP_FIXED
431                 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
432                     (MREMAP_MAYMOVE | MREMAP_FIXED))
433                         tprintf(", %#lx", tcp->u_arg[4]);
434 #endif
435         }
436         return RVAL_HEX;
437 }
438
439 static const struct xlat madvise_cmds[] = {
440 #ifdef MADV_NORMAL
441         { MADV_NORMAL,          "MADV_NORMAL" },
442 #endif
443 #ifdef MADV_RANDOM
444         { MADV_RANDOM,          "MADV_RANDOM" },
445 #endif
446 #ifdef MADV_SEQUENTIAL
447         { MADV_SEQUENTIAL,      "MADV_SEQUENTIAL" },
448 #endif
449 #ifdef MADV_WILLNEED
450         { MADV_WILLNEED,        "MADV_WILLNEED" },
451 #endif
452 #ifdef MADV_DONTNEED
453         { MADV_DONTNEED,        "MADV_DONTNEED" },
454 #endif
455         { 0,                    NULL },
456 };
457
458
459 int
460 sys_madvise(tcp)
461 struct tcb *tcp;
462 {
463         if (entering(tcp)) {
464                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
465                 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
466         }
467         return 0;
468 }
469
470
471 static const struct xlat mlockall_flags[] = {
472 #ifdef MCL_CURRENT
473         { MCL_CURRENT,  "MCL_CURRENT" },
474 #endif
475 #ifdef MCL_FUTURE
476         { MCL_FUTURE,   "MCL_FUTURE" },
477 #endif
478         { 0,            NULL}
479 };
480
481 int
482 sys_mlockall(tcp)
483 struct tcb *tcp;
484 {
485         if (entering(tcp)) {
486                 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
487         }
488         return 0;
489 }
490
491
492 #endif /* LINUX */
493
494 #ifdef MS_ASYNC
495
496 static const struct xlat mctl_sync[] = {
497 #ifdef MS_SYNC
498         { MS_SYNC,      "MS_SYNC"       },
499 #endif
500         { MS_ASYNC,     "MS_ASYNC"      },
501         { MS_INVALIDATE,"MS_INVALIDATE" },
502         { 0,            NULL            },
503 };
504
505 int
506 sys_msync(tcp)
507 struct tcb *tcp;
508 {
509         if (entering(tcp)) {
510                 /* addr */
511                 tprintf("%#lx", tcp->u_arg[0]);
512                 /* len */
513                 tprintf(", %lu, ", tcp->u_arg[1]);
514                 /* flags */
515                 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
516         }
517         return 0;
518 }
519
520 #endif /* MS_ASYNC */
521
522 #ifdef MC_SYNC
523
524 static const struct xlat mctl_funcs[] = {
525         { MC_LOCK,      "MC_LOCK"       },
526         { MC_LOCKAS,    "MC_LOCKAS"     },
527         { MC_SYNC,      "MC_SYNC"       },
528         { MC_UNLOCK,    "MC_UNLOCK"     },
529         { MC_UNLOCKAS,  "MC_UNLOCKAS"   },
530         { 0,            NULL            },
531 };
532
533 static const struct xlat mctl_lockas[] = {
534         { MCL_CURRENT,  "MCL_CURRENT"   },
535         { MCL_FUTURE,   "MCL_FUTURE"    },
536         { 0,            NULL            },
537 };
538
539 int
540 sys_mctl(tcp)
541 struct tcb *tcp;
542 {
543         int arg, function;
544
545         if (entering(tcp)) {
546                 /* addr */
547                 tprintf("%#lx", tcp->u_arg[0]);
548                 /* len */
549                 tprintf(", %lu, ", tcp->u_arg[1]);
550                 /* function */
551                 function = tcp->u_arg[2];
552                 printflags(mctl_funcs, function, "MC_???");
553                 /* arg */
554                 arg = tcp->u_arg[3];
555                 tprintf(", ");
556                 switch (function) {
557                 case MC_SYNC:
558                         printflags(mctl_sync, arg, "MS_???");
559                         break;
560                 case MC_LOCKAS:
561                         printflags(mctl_lockas, arg, "MCL_???");
562                         break;
563                 default:
564                         tprintf("%#x", arg);
565                         break;
566                 }
567         }
568         return 0;
569 }
570
571 #endif /* MC_SYNC */
572
573 int
574 sys_mincore(tcp)
575 struct tcb *tcp;
576 {
577         unsigned long i, len;
578         char *vec = NULL;
579
580         if (entering(tcp)) {
581                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
582         } else {
583                 len = tcp->u_arg[1];
584                 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
585                         (vec = malloc(len)) == NULL ||
586                         umoven(tcp, tcp->u_arg[2], len, vec) < 0)
587                         tprintf("%#lx", tcp->u_arg[2]);
588                 else {
589                         tprintf("[");
590                         for (i = 0; i < len; i++) {
591                                 if (abbrev(tcp) && i >= max_strlen) {
592                                         tprintf("...");
593                                         break;
594                                 }
595                                 tprintf((vec[i] & 1) ? "1" : "0");
596                         }
597                         tprintf("]");
598                 }
599                 if (vec)
600                         free(vec);
601         }
602         return 0;
603 }
604
605 #if defined(ALPHA) || defined(FREEBSD) || defined(IA64) || defined(SUNOS4) || defined(SVR4) || defined(SPARC) || defined(SPARC64)
606 int
607 sys_getpagesize(tcp)
608 struct tcb *tcp;
609 {
610         if (exiting(tcp))
611                 return RVAL_HEX;
612         return 0;
613 }
614 #endif /* ALPHA || FREEBSD || IA64 || SUNOS4 || SVR4 */
615
616 #if defined(LINUX) && defined(__i386__)
617 void
618 print_ldt_entry(struct modify_ldt_ldt_s *ldt_entry)
619 {
620         tprintf("base_addr:%#08lx, "
621                 "limit:%d, "
622                 "seg_32bit:%d, "
623                 "contents:%d, "
624                 "read_exec_only:%d, "
625                 "limit_in_pages:%d, "
626                 "seg_not_present:%d, "
627                 "useable:%d}",
628                 (long) ldt_entry->base_addr,
629                 ldt_entry->limit,
630                 ldt_entry->seg_32bit,
631                 ldt_entry->contents,
632                 ldt_entry->read_exec_only,
633                 ldt_entry->limit_in_pages,
634                 ldt_entry->seg_not_present,
635                 ldt_entry->useable);
636 }
637
638 int
639 sys_modify_ldt(tcp)
640 struct tcb *tcp;
641 {
642         if (entering(tcp)) {
643                 struct modify_ldt_ldt_s copy;
644                 tprintf("%ld", tcp->u_arg[0]);
645                 if (tcp->u_arg[1] == 0
646                                 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
647                                 || umove(tcp, tcp->u_arg[1], &copy) == -1)
648                         tprintf(", %lx", tcp->u_arg[1]);
649                 else {
650                         tprintf(", {entry_number:%d, ", copy.entry_number);
651                         if (!verbose(tcp))
652                                 tprintf("...}");
653                         else {
654                                 print_ldt_entry(&copy);
655                         }
656                 }
657                 tprintf(", %lu", tcp->u_arg[2]);
658         }
659         return 0;
660 }
661
662 int
663 sys_set_thread_area(tcp)
664 struct tcb *tcp;
665 {
666         struct modify_ldt_ldt_s copy;
667         if (entering(tcp)) {
668                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
669                         if (copy.entry_number == -1)
670                                 tprintf("{entry_number:%d -> ",
671                                         copy.entry_number);
672                         else
673                                 tprintf("{entry_number:");
674                 }
675         } else {
676                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
677                         tprintf("%d, ", copy.entry_number);
678                         if (!verbose(tcp))
679                                 tprintf("...}");
680                         else {
681                                 print_ldt_entry(&copy);
682                         }
683                 } else {
684                         tprintf("%lx", tcp->u_arg[0]);
685                 }
686         }
687         return 0;
688
689 }
690
691 int
692 sys_get_thread_area(tcp)
693 struct tcb *tcp;
694 {
695         struct modify_ldt_ldt_s copy;
696         if (exiting(tcp)) {
697                 if (umove(tcp, tcp->u_arg[0], &copy) != -1) {
698                         tprintf("{entry_number:%d, ", copy.entry_number);
699                         if (!verbose(tcp))
700                                 tprintf("...}");
701                         else {
702                                 print_ldt_entry(&copy);
703                         }
704                 } else {
705                         tprintf("%lx", tcp->u_arg[0]);
706                 }
707         }
708         return 0;
709
710 }
711 #endif /* LINUX && __i386__ */
712
713 #if defined(LINUX) && defined(M68K)
714
715 int
716 sys_set_thread_area(tcp)
717 struct tcb *tcp;
718 {
719         if (entering(tcp))
720                 tprintf("%#lx", tcp->u_arg[0]);
721         return 0;
722
723 }
724
725 int
726 sys_get_thread_area(tcp)
727 struct tcb *tcp;
728 {
729         return RVAL_HEX;
730 }
731 #endif
732
733 #if defined(LINUX)
734 int
735 sys_remap_file_pages(tcp)
736 struct tcb *tcp;
737 {
738         if (entering(tcp)) {
739                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
740                 printflags(mmap_prot, tcp->u_arg[2], "PROT_???");
741                 tprintf(", %lu, ", tcp->u_arg[3]);
742 #ifdef MAP_TYPE
743                 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
744                 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
745 #else
746                 printflags(mmap_flags, tcp->u_arg[4], "MAP_???");
747 #endif
748         }
749         return 0;
750 }
751
752
753 #define MPOL_DEFAULT    0
754 #define MPOL_PREFERRED  1
755 #define MPOL_BIND       2
756 #define MPOL_INTERLEAVE 3
757
758 #define MPOL_F_NODE     (1<<0)
759 #define MPOL_F_ADDR     (1<<1)
760
761 #define MPOL_MF_STRICT  (1<<0)
762 #define MPOL_MF_MOVE    (1<<1)
763 #define MPOL_MF_MOVE_ALL (1<<2)
764
765
766 static const struct xlat policies[] = {
767         { MPOL_DEFAULT,         "MPOL_DEFAULT"          },
768         { MPOL_PREFERRED,       "MPOL_PREFERRED"        },
769         { MPOL_BIND,            "MPOL_BIND"             },
770         { MPOL_INTERLEAVE,      "MPOL_INTERLEAVE"       },
771         { 0,                    NULL                    }
772 };
773
774 static const struct xlat mbindflags[] = {
775         { MPOL_MF_STRICT,       "MPOL_MF_STRICT"        },
776         { MPOL_MF_MOVE,         "MPOL_MF_MOVE"          },
777         { MPOL_MF_MOVE_ALL,     "MPOL_MF_MOVE_ALL"      },
778         { 0,                    NULL                    }
779 };
780
781 static const struct xlat mempolicyflags[] = {
782         { MPOL_F_NODE,          "MPOL_F_NODE"           },
783         { MPOL_F_ADDR,          "MPOL_F_ADDR"           },
784         { 0,                    NULL                    }
785 };
786
787 static const struct xlat move_pages_flags[] = {
788         { MPOL_MF_MOVE,         "MPOL_MF_MOVE"          },
789         { MPOL_MF_MOVE_ALL,     "MPOL_MF_MOVE_ALL"      },
790         { 0,                    NULL                    }
791 };
792
793
794 static void
795 get_nodes(tcp, ptr, maxnodes, err)
796 struct tcb *tcp;
797 unsigned long ptr;
798 unsigned long maxnodes;
799 int err;
800 {
801         unsigned long nlongs, size, end;
802
803         nlongs = (maxnodes + 8 * sizeof(long) - 1) / (8 * sizeof(long));
804         size = nlongs * sizeof(long);
805         end = ptr + size;
806         if (nlongs == 0 || ((err || verbose(tcp)) && (size * 8 == maxnodes)
807                             && (end > ptr))) {
808                 unsigned long n, cur, abbrev_end;
809                 int failed = 0;
810
811                 if (abbrev(tcp)) {
812                         abbrev_end = ptr + max_strlen * sizeof(long);
813                         if (abbrev_end < ptr)
814                                 abbrev_end = end;
815                 } else {
816                         abbrev_end = end;
817                 }
818                 tprintf(", {");
819                 for (cur = ptr; cur < end; cur += sizeof(long)) {
820                         if (cur > ptr)
821                                 tprintf(", ");
822                         if (cur >= abbrev_end) {
823                                 tprintf("...");
824                                 break;
825                         }
826                         if (umoven(tcp, cur, sizeof(n), (char *) &n) < 0) {
827                                 tprintf("?");
828                                 failed = 1;
829                                 break;
830                         }
831                         tprintf("%#0*lx", (int) sizeof(long) * 2 + 2, n);
832                 }
833                 tprintf("}");
834                 if (failed)
835                         tprintf(" %#lx", ptr);
836         } else
837                 tprintf(", %#lx", ptr);
838         tprintf(", %lu", maxnodes);
839 }
840
841 int
842 sys_mbind(tcp)
843 struct tcb *tcp;
844 {
845         if (entering(tcp)) {
846                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
847                 printxval(policies, tcp->u_arg[2], "MPOL_???");
848                 get_nodes(tcp, tcp->u_arg[3], tcp->u_arg[4], 0);
849                 tprintf(", ");
850                 printflags(mbindflags, tcp->u_arg[5], "MPOL_???");
851         }
852         return 0;
853 }
854
855 int
856 sys_set_mempolicy(tcp)
857 struct tcb *tcp;
858 {
859         if (entering(tcp)) {
860                 printxval(policies, tcp->u_arg[0], "MPOL_???");
861                 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], 0);
862         }
863         return 0;
864 }
865
866 int
867 sys_get_mempolicy(tcp)
868 struct tcb *tcp;
869 {
870         if (exiting(tcp)) {
871                 int pol;
872                 if (tcp->u_arg[0] == 0)
873                         tprintf("NULL");
874                 else if (syserror(tcp) || umove(tcp, tcp->u_arg[0], &pol) < 0)
875                         tprintf("%#lx", tcp->u_arg[0]);
876                 else
877                         printxval(policies, pol, "MPOL_???");
878                 get_nodes(tcp, tcp->u_arg[1], tcp->u_arg[2], syserror(tcp));
879                 tprintf(", %#lx, ", tcp->u_arg[3]);
880                 printflags(mempolicyflags, tcp->u_arg[4], "MPOL_???");
881         }
882         return 0;
883 }
884
885 int
886 sys_move_pages(tcp)
887 struct tcb *tcp;
888 {
889         if (entering(tcp)) {
890                 unsigned long npages = tcp->u_arg[1];
891                 tprintf("%ld, %lu, ", tcp->u_arg[0], npages);
892                 if (tcp->u_arg[2] == 0)
893                         tprintf("NULL, ");
894                 else {
895                         int i;
896                         long puser = tcp->u_arg[2];
897                         tprintf("{");
898                         for (i = 0; i < npages; ++i) {
899                                 void *p;
900                                 if (i > 0)
901                                         tprintf(", ");
902                                 if (umove(tcp, puser, &p) < 0) {
903                                         tprintf("???");
904                                         break;
905                                 }
906                                 tprintf("%p", p);
907                                 puser += sizeof (void *);
908                         }
909                         tprintf("}, ");
910                 }
911                 if (tcp->u_arg[3] == 0)
912                         tprintf("NULL, ");
913                 else {
914                         int i;
915                         long nodeuser = tcp->u_arg[3];
916                         tprintf("{");
917                         for (i = 0; i < npages; ++i) {
918                                 int node;
919                                 if (i > 0)
920                                         tprintf(", ");
921                                 if (umove(tcp, nodeuser, &node) < 0) {
922                                         tprintf("???");
923                                         break;
924                                 }
925                                 tprintf("%#x", node);
926                                 nodeuser += sizeof (int);
927                         }
928                         tprintf("}, ");
929                 }
930         }
931         if (exiting(tcp)) {
932                 unsigned long npages = tcp->u_arg[1];
933                 if (tcp->u_arg[4] == 0)
934                         tprintf("NULL, ");
935                 else {
936                         int i;
937                         long statususer = tcp->u_arg[4];
938                         tprintf("{");
939                         for (i = 0; i < npages; ++i) {
940                                 int status;
941                                 if (i > 0)
942                                         tprintf(", ");
943                                 if (umove(tcp, statususer, &status) < 0) {
944                                         tprintf("???");
945                                         break;
946                                 }
947                                 tprintf("%#x", status);
948                                 statususer += sizeof (int);
949                         }
950                         tprintf("}, ");
951                 }
952                 printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???");
953         }
954         return 0;
955 }
956 #endif
957
958 #if defined(LINUX) && defined(POWERPC)
959 int
960 sys_subpage_prot(tcp)
961 struct tcb *tcp;
962 {
963         if (entering(tcp)) {
964                 unsigned long cur, end, abbrev_end, entries;
965                 unsigned int entry;
966
967                 tprintf("%#lx, %#lx, ", tcp->u_arg[0], tcp->u_arg[1]);
968                 entries = tcp->u_arg[1] >> 16;
969                 if (!entries || !tcp->u_arg[2]) {
970                         tprintf("{}");
971                         return 0;
972                 }
973                 cur = tcp->u_arg[2];
974                 end = cur + (sizeof(int) * entries);
975                 if (!verbose(tcp) || end < tcp->u_arg[2]) {
976                         tprintf("%#lx", tcp->u_arg[2]);
977                         return 0;
978                 }
979                 if (abbrev(tcp)) {
980                         abbrev_end = cur + (sizeof(int) * max_strlen);
981                         if (abbrev_end > end)
982                                 abbrev_end = end;
983                 }
984                 else
985                         abbrev_end = end;
986                 tprintf("{");
987                 for (; cur < end; cur += sizeof(int)) {
988                         if (cur > tcp->u_arg[2])
989                                 tprintf(", ");
990                         if (cur >= abbrev_end) {
991                                 tprintf("...");
992                                 break;
993                         }
994                         if (umove(tcp, cur, &entry) < 0) {
995                                 tprintf("??? [%#lx]", cur);
996                                 break;
997                         }
998                         else
999                                 tprintf("%#08x", entry);
1000                 }
1001                 tprintf("}");
1002         }
1003
1004         return 0;
1005 }
1006 #endif