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