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