]> granicus.if.org Git - strace/blob - system.c
Update siginfo codes
[strace] / system.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  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "defs.h"
32
33 #define _LINUX_SOCKET_H
34 #define _LINUX_FS_H
35
36 #define MS_RDONLY        1      /* Mount read-only */
37 #define MS_NOSUID        2      /* Ignore suid and sgid bits */
38 #define MS_NODEV         4      /* Disallow access to device special files */
39 #define MS_NOEXEC        8      /* Disallow program execution */
40 #define MS_SYNCHRONOUS  16      /* Writes are synced at once */
41 #define MS_REMOUNT      32      /* Alter flags of a mounted FS */
42 #define MS_MANDLOCK     64      /* Allow mandatory locks on an FS */
43 #define MS_DIRSYNC      128     /* Directory modifications are synchronous */
44 #define MS_NOATIME      1024    /* Do not update access times. */
45 #define MS_NODIRATIME   2048    /* Do not update directory access times */
46 #define MS_BIND         4096
47 #define MS_MOVE         8192
48 #define MS_REC          16384
49 #define MS_SILENT       32768
50 #define MS_POSIXACL     (1<<16) /* VFS does not apply the umask */
51 #define MS_UNBINDABLE   (1<<17) /* change to unbindable */
52 #define MS_PRIVATE      (1<<18) /* change to private */
53 #define MS_SLAVE        (1<<19) /* change to slave */
54 #define MS_SHARED       (1<<20) /* change to shared */
55 #define MS_RELATIME     (1<<21)
56 #define MS_KERNMOUNT    (1<<22)
57 #define MS_I_VERSION    (1<<23)
58 #define MS_STRICTATIME  (1<<24)
59 #define MS_NOSEC        (1<<28)
60 #define MS_BORN         (1<<29)
61 #define MS_ACTIVE       (1<<30)
62 #define MS_NOUSER       (1<<31)
63 #define MS_MGC_VAL      0xc0ed0000      /* Magic flag number */
64 #define MS_MGC_MSK      0xffff0000      /* Magic flag mask */
65
66 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <arpa/inet.h>
69 #ifdef HAVE_LINUX_CAPABILITY_H
70 # include <linux/capability.h>
71 #endif
72 #ifdef HAVE_ASM_CACHECTL_H
73 # include <asm/cachectl.h>
74 #endif
75 #ifdef HAVE_LINUX_USTNAME_H
76 # include <linux/utsname.h>
77 #endif
78 #ifdef HAVE_ASM_SYSMIPS_H
79 # include <asm/sysmips.h>
80 #endif
81 #include <linux/sysctl.h>
82 #include <linux/personality.h>
83
84 static const struct xlat mount_flags[] = {
85         XLAT(MS_MGC_VAL),
86         XLAT(MS_RDONLY),
87         XLAT(MS_NOSUID),
88         XLAT(MS_NODEV),
89         XLAT(MS_NOEXEC),
90         XLAT(MS_SYNCHRONOUS),
91         XLAT(MS_REMOUNT),
92         XLAT(MS_RELATIME),
93         XLAT(MS_KERNMOUNT),
94         XLAT(MS_I_VERSION),
95         XLAT(MS_STRICTATIME),
96         XLAT(MS_NOSEC),
97         XLAT(MS_BORN),
98         XLAT(MS_MANDLOCK),
99         XLAT(MS_NOATIME),
100         XLAT(MS_NODIRATIME),
101         XLAT(MS_BIND),
102         XLAT(MS_MOVE),
103         XLAT(MS_REC),
104         XLAT(MS_SILENT),
105         XLAT(MS_POSIXACL),
106         XLAT(MS_UNBINDABLE),
107         XLAT(MS_PRIVATE),
108         XLAT(MS_SLAVE),
109         XLAT(MS_SHARED),
110         XLAT(MS_ACTIVE),
111         XLAT(MS_NOUSER),
112         XLAT_END
113 };
114
115 int
116 sys_mount(struct tcb *tcp)
117 {
118         if (entering(tcp)) {
119                 int ignore_type = 0, ignore_data = 0;
120                 unsigned long flags = tcp->u_arg[3];
121
122                 /* Discard magic */
123                 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
124                         flags &= ~MS_MGC_MSK;
125
126                 if (flags & MS_REMOUNT)
127                         ignore_type = 1;
128                 else if (flags & (MS_BIND | MS_MOVE))
129                         ignore_type = ignore_data = 1;
130
131                 printpath(tcp, tcp->u_arg[0]);
132                 tprints(", ");
133
134                 printpath(tcp, tcp->u_arg[1]);
135                 tprints(", ");
136
137                 if (ignore_type && tcp->u_arg[2])
138                         tprintf("%#lx", tcp->u_arg[2]);
139                 else
140                         printstr(tcp, tcp->u_arg[2], -1);
141                 tprints(", ");
142
143                 printflags(mount_flags, tcp->u_arg[3], "MS_???");
144                 tprints(", ");
145
146                 if (ignore_data && tcp->u_arg[4])
147                         tprintf("%#lx", tcp->u_arg[4]);
148                 else
149                         printstr(tcp, tcp->u_arg[4], -1);
150         }
151         return 0;
152 }
153
154 #define MNT_FORCE       0x00000001      /* Attempt to forcibily umount */
155 #define MNT_DETACH      0x00000002      /* Just detach from the tree */
156 #define MNT_EXPIRE      0x00000004      /* Mark for expiry */
157
158 static const struct xlat umount_flags[] = {
159         XLAT(MNT_FORCE),
160         XLAT(MNT_DETACH),
161         XLAT(MNT_EXPIRE),
162         XLAT_END
163 };
164
165 int
166 sys_umount2(struct tcb *tcp)
167 {
168         if (entering(tcp)) {
169                 printstr(tcp, tcp->u_arg[0], -1);
170                 tprints(", ");
171                 printflags(umount_flags, tcp->u_arg[1], "MNT_???");
172         }
173         return 0;
174 }
175
176 /* These are not macros, but enums.  We just copy the values by hand
177    from Linux 2.6.9 here.  */
178 static const struct xlat personality_options[] = {
179         XLAT(PER_LINUX),
180         XLAT(PER_LINUX_32BIT),
181         XLAT(PER_LINUX_FDPIC),
182         XLAT(PER_SVR4),
183         XLAT(PER_SVR3),
184         XLAT(PER_SCOSVR3),
185         XLAT(PER_OSR5),
186         XLAT(PER_WYSEV386),
187         XLAT(PER_ISCR4),
188         XLAT(PER_BSD),
189         XLAT(PER_SUNOS),
190         XLAT(PER_XENIX),
191         XLAT(PER_LINUX32),
192         XLAT(PER_LINUX32_3GB),
193         XLAT(PER_IRIX32),
194         XLAT(PER_IRIXN32),
195         XLAT(PER_IRIX64),
196         XLAT(PER_RISCOS),
197         XLAT(PER_SOLARIS),
198         XLAT(PER_UW7),
199         XLAT(PER_OSF4),
200         XLAT(PER_HPUX),
201         XLAT_END
202 };
203
204 int
205 sys_personality(struct tcb *tcp)
206 {
207         if (entering(tcp))
208                 printxval(personality_options, tcp->u_arg[0], "PER_???");
209         return 0;
210 }
211
212 enum {
213         SYSLOG_ACTION_CLOSE = 0,
214         SYSLOG_ACTION_OPEN,
215         SYSLOG_ACTION_READ,
216         SYSLOG_ACTION_READ_ALL,
217         SYSLOG_ACTION_READ_CLEAR,
218         SYSLOG_ACTION_CLEAR,
219         SYSLOG_ACTION_CONSOLE_OFF,
220         SYSLOG_ACTION_CONSOLE_ON,
221         SYSLOG_ACTION_CONSOLE_LEVEL,
222         SYSLOG_ACTION_SIZE_UNREAD,
223         SYSLOG_ACTION_SIZE_BUFFER
224 };
225
226 static const struct xlat syslog_action_type[] = {
227         XLAT(SYSLOG_ACTION_CLOSE),
228         XLAT(SYSLOG_ACTION_OPEN),
229         XLAT(SYSLOG_ACTION_READ),
230         XLAT(SYSLOG_ACTION_READ_ALL),
231         XLAT(SYSLOG_ACTION_READ_CLEAR),
232         XLAT(SYSLOG_ACTION_CLEAR),
233         XLAT(SYSLOG_ACTION_CONSOLE_OFF),
234         XLAT(SYSLOG_ACTION_CONSOLE_ON),
235         XLAT(SYSLOG_ACTION_CONSOLE_LEVEL),
236         XLAT(SYSLOG_ACTION_SIZE_UNREAD),
237         XLAT(SYSLOG_ACTION_SIZE_BUFFER),
238         XLAT_END
239 };
240
241 int
242 sys_syslog(struct tcb *tcp)
243 {
244         int type = tcp->u_arg[0];
245
246         if (entering(tcp)) {
247                 /* type */
248                 printxval(syslog_action_type, type, "SYSLOG_ACTION_???");
249                 tprints(", ");
250         }
251
252         switch (type) {
253                 case SYSLOG_ACTION_READ:
254                 case SYSLOG_ACTION_READ_ALL:
255                 case SYSLOG_ACTION_READ_CLEAR:
256                         if (entering(tcp))
257                                 return 0;
258                         break;
259                 default:
260                         if (entering(tcp)) {
261                                 tprintf("%#lx, %lu",
262                                         tcp->u_arg[1], tcp->u_arg[2]);
263                         }
264                         return 0;
265         }
266
267         /* bufp */
268         if (syserror(tcp))
269                 tprintf("%#lx", tcp->u_arg[1]);
270         else
271                 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
272         /* len */
273         tprintf(", %d", (int) tcp->u_arg[2]);
274
275         return 0;
276 }
277
278 #ifdef M68K
279 static const struct xlat cacheflush_scope[] = {
280 #ifdef FLUSH_SCOPE_LINE
281         XLAT(FLUSH_SCOPE_LINE),
282 #endif
283 #ifdef FLUSH_SCOPE_PAGE
284         XLAT(FLUSH_SCOPE_PAGE),
285 #endif
286 #ifdef FLUSH_SCOPE_ALL
287         XLAT(FLUSH_SCOPE_ALL),
288 #endif
289         XLAT_END
290 };
291
292 static const struct xlat cacheflush_flags[] = {
293 #ifdef FLUSH_CACHE_BOTH
294         XLAT(FLUSH_CACHE_BOTH),
295 #endif
296 #ifdef FLUSH_CACHE_DATA
297         XLAT(FLUSH_CACHE_DATA),
298 #endif
299 #ifdef FLUSH_CACHE_INSN
300         XLAT(FLUSH_CACHE_INSN),
301 #endif
302         XLAT_END
303 };
304
305 int
306 sys_cacheflush(struct tcb *tcp)
307 {
308         if (entering(tcp)) {
309                 /* addr */
310                 tprintf("%#lx, ", tcp->u_arg[0]);
311                 /* scope */
312                 printxval(cacheflush_scope, tcp->u_arg[1], "FLUSH_SCOPE_???");
313                 tprints(", ");
314                 /* flags */
315                 printflags(cacheflush_flags, tcp->u_arg[2], "FLUSH_CACHE_???");
316                 /* len */
317                 tprintf(", %lu", tcp->u_arg[3]);
318         }
319         return 0;
320 }
321 #endif /* M68K */
322
323 #ifdef BFIN
324
325 #include <bfin_sram.h>
326
327 static const struct xlat sram_alloc_flags[] = {
328         XLAT(L1_INST_SRAM),
329         XLAT(L1_DATA_A_SRAM),
330         XLAT(L1_DATA_B_SRAM),
331         XLAT(L1_DATA_SRAM),
332         XLAT(L2_SRAM),
333         XLAT_END
334 };
335
336 int
337 sys_sram_alloc(struct tcb *tcp)
338 {
339         if (entering(tcp)) {
340                 /* size */
341                 tprintf("%lu, ", tcp->u_arg[0]);
342                 /* flags */
343                 printflags(sram_alloc_flags, tcp->u_arg[1], "???_SRAM");
344         }
345         return 1;
346 }
347
348 #include <asm/cachectl.h>
349
350 static const struct xlat cacheflush_flags[] = {
351         XLAT(ICACHE),
352         XLAT(DCACHE),
353         XLAT(BCACHE),
354         XLAT_END
355 };
356
357 int
358 sys_cacheflush(struct tcb *tcp)
359 {
360         if (entering(tcp)) {
361                 /* start addr */
362                 tprintf("%#lx, ", tcp->u_arg[0]);
363                 /* length */
364                 tprintf("%ld, ", tcp->u_arg[1]);
365                 /* flags */
366                 printxval(cacheflush_flags, tcp->u_arg[1], "?CACHE");
367         }
368         return 0;
369 }
370
371 #endif
372
373 #ifdef SH
374 static const struct xlat cacheflush_flags[] = {
375 #ifdef CACHEFLUSH_D_INVAL
376         XLAT(CACHEFLUSH_D_INVAL),
377 #endif
378 #ifdef CACHEFLUSH_D_WB
379         XLAT(CACHEFLUSH_D_WB),
380 #endif
381 #ifdef CACHEFLUSH_D_PURGE
382         XLAT(CACHEFLUSH_D_PURGE),
383 #endif
384 #ifdef CACHEFLUSH_I
385         XLAT(CACHEFLUSH_I),
386 #endif
387         XLAT_END
388 };
389
390 int
391 sys_cacheflush(struct tcb *tcp)
392 {
393         if (entering(tcp)) {
394                 /* addr */
395                 tprintf("%#lx, ", tcp->u_arg[0]);
396                 /* len */
397                 tprintf("%lu, ", tcp->u_arg[1]);
398                 /* flags */
399                 printflags(cacheflush_flags, tcp->u_arg[2], "CACHEFLUSH_???");
400         }
401         return 0;
402 }
403 #endif /* SH */
404
405 #ifdef SYS_capget
406
407 static const struct xlat capabilities[] = {
408         { 1<<CAP_CHOWN,         "CAP_CHOWN"     },
409         { 1<<CAP_DAC_OVERRIDE,  "CAP_DAC_OVERRIDE"},
410         { 1<<CAP_DAC_READ_SEARCH,"CAP_DAC_READ_SEARCH"},
411         { 1<<CAP_FOWNER,        "CAP_FOWNER"    },
412         { 1<<CAP_FSETID,        "CAP_FSETID"    },
413         { 1<<CAP_KILL,          "CAP_KILL"      },
414         { 1<<CAP_SETGID,        "CAP_SETGID"    },
415         { 1<<CAP_SETUID,        "CAP_SETUID"    },
416         { 1<<CAP_SETPCAP,       "CAP_SETPCAP"   },
417         { 1<<CAP_LINUX_IMMUTABLE,"CAP_LINUX_IMMUTABLE"},
418         { 1<<CAP_NET_BIND_SERVICE,"CAP_NET_BIND_SERVICE"},
419         { 1<<CAP_NET_BROADCAST, "CAP_NET_BROADCAST"},
420         { 1<<CAP_NET_ADMIN,     "CAP_NET_ADMIN" },
421         { 1<<CAP_NET_RAW,       "CAP_NET_RAW"   },
422         { 1<<CAP_IPC_LOCK,      "CAP_IPC_LOCK"  },
423         { 1<<CAP_IPC_OWNER,     "CAP_IPC_OWNER" },
424         { 1<<CAP_SYS_MODULE,    "CAP_SYS_MODULE"},
425         { 1<<CAP_SYS_RAWIO,     "CAP_SYS_RAWIO" },
426         { 1<<CAP_SYS_CHROOT,    "CAP_SYS_CHROOT"},
427         { 1<<CAP_SYS_PTRACE,    "CAP_SYS_PTRACE"},
428         { 1<<CAP_SYS_PACCT,     "CAP_SYS_PACCT" },
429         { 1<<CAP_SYS_ADMIN,     "CAP_SYS_ADMIN" },
430         { 1<<CAP_SYS_BOOT,      "CAP_SYS_BOOT"  },
431         { 1<<CAP_SYS_NICE,      "CAP_SYS_NICE"  },
432         { 1<<CAP_SYS_RESOURCE,  "CAP_SYS_RESOURCE"},
433         { 1<<CAP_SYS_TIME,      "CAP_SYS_TIME"  },
434         { 1<<CAP_SYS_TTY_CONFIG,"CAP_SYS_TTY_CONFIG"},
435 #ifdef CAP_MKNOD
436         { 1<<CAP_MKNOD,         "CAP_MKNOD"     },
437 #endif
438 #ifdef CAP_LEASE
439         { 1<<CAP_LEASE,         "CAP_LEASE"     },
440 #endif
441 #ifdef CAP_AUDIT_WRITE
442         { 1<<CAP_AUDIT_WRITE,   "CAP_AUDIT_WRITE"},
443 #endif
444 #ifdef CAP_AUDIT_CONTROL
445         { 1<<CAP_AUDIT_CONTROL, "CAP_AUDIT_CONTROL"},
446 #endif
447 #ifdef CAP_SETFCAP
448         { 1<<CAP_SETFCAP,       "CAP_SETFCAP"   },
449 #endif
450         XLAT_END
451 };
452
453 #ifndef _LINUX_CAPABILITY_VERSION_1
454 # define _LINUX_CAPABILITY_VERSION_1 0x19980330
455 #endif
456 #ifndef _LINUX_CAPABILITY_VERSION_2
457 # define _LINUX_CAPABILITY_VERSION_2 0x20071026
458 #endif
459 #ifndef _LINUX_CAPABILITY_VERSION_3
460 # define _LINUX_CAPABILITY_VERSION_3 0x20080522
461 #endif
462
463 static const struct xlat cap_version[] = {
464         XLAT(_LINUX_CAPABILITY_VERSION_1),
465         XLAT(_LINUX_CAPABILITY_VERSION_2),
466         XLAT(_LINUX_CAPABILITY_VERSION_3),
467         XLAT_END
468 };
469
470 static void
471 print_cap_header(struct tcb *tcp, unsigned long addr)
472 {
473         union { cap_user_header_t p; long *a; char *c; } arg;
474         long a[sizeof(*arg.p) / sizeof(long) + 1];
475         arg.a = a;
476
477         if (!addr)
478                 tprints("NULL");
479         else if (!verbose(tcp) ||
480                  umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0)
481                 tprintf("%#lx", addr);
482         else {
483                 tprints("{");
484                 printxval(cap_version, arg.p->version,
485                           "_LINUX_CAPABILITY_VERSION_???");
486                 tprintf(", %d}", arg.p->pid);
487         }
488 }
489
490 static void
491 print_cap_data(struct tcb *tcp, unsigned long addr)
492 {
493         union { cap_user_data_t p; long *a; char *c; } arg;
494         long a[sizeof(*arg.p) / sizeof(long) + 1];
495         arg.a = a;
496
497         if (!addr)
498                 tprints("NULL");
499         else if (!verbose(tcp) ||
500                  (exiting(tcp) && syserror(tcp)) ||
501                  umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0)
502                 tprintf("%#lx", addr);
503         else {
504                 tprints("{");
505                 printflags(capabilities, arg.p->effective, "CAP_???");
506                 tprints(", ");
507                 printflags(capabilities, arg.p->permitted, "CAP_???");
508                 tprints(", ");
509                 printflags(capabilities, arg.p->inheritable, "CAP_???");
510                 tprints("}");
511         }
512 }
513
514 int
515 sys_capget(struct tcb *tcp)
516 {
517         if (entering(tcp)) {
518                 print_cap_header(tcp, tcp->u_arg[0]);
519                 tprints(", ");
520         } else {
521                 print_cap_data(tcp, tcp->u_arg[1]);
522         }
523         return 0;
524 }
525
526 int
527 sys_capset(struct tcb *tcp)
528 {
529         if (entering(tcp)) {
530                 print_cap_header(tcp, tcp->u_arg[0]);
531                 tprints(", ");
532                 print_cap_data(tcp, tcp->u_arg[1]);
533         }
534         return 0;
535 }
536
537 #else
538
539 int sys_capget(struct tcb *tcp)
540 {
541         return printargs(tcp);
542 }
543
544 int sys_capset(struct tcb *tcp)
545 {
546         return printargs(tcp);
547 }
548
549 #endif
550
551 /* Linux 2.6.18+ headers removed CTL_PROC enum.  */
552 # define CTL_PROC 4
553 # define CTL_CPU 10             /* older headers lack */
554 static const struct xlat sysctl_root[] = {
555         XLAT(CTL_KERN),
556         XLAT(CTL_VM),
557         XLAT(CTL_NET),
558         XLAT(CTL_PROC),
559         XLAT(CTL_FS),
560         XLAT(CTL_DEBUG),
561         XLAT(CTL_DEV),
562         XLAT(CTL_BUS),
563         XLAT(CTL_ABI),
564         XLAT(CTL_CPU),
565         XLAT_END
566 };
567
568 static const struct xlat sysctl_kern[] = {
569         XLAT(KERN_OSTYPE),
570         XLAT(KERN_OSRELEASE),
571         XLAT(KERN_OSREV),
572         XLAT(KERN_VERSION),
573         XLAT(KERN_SECUREMASK),
574         XLAT(KERN_PROF),
575         XLAT(KERN_NODENAME),
576         XLAT(KERN_DOMAINNAME),
577 #ifdef KERN_SECURELVL
578         XLAT(KERN_SECURELVL),
579 #endif
580         XLAT(KERN_PANIC),
581 #ifdef KERN_REALROOTDEV
582         XLAT(KERN_REALROOTDEV),
583 #endif
584 #ifdef KERN_JAVA_INTERPRETER
585         XLAT(KERN_JAVA_INTERPRETER),
586 #endif
587 #ifdef KERN_JAVA_APPLETVIEWER
588         XLAT(KERN_JAVA_APPLETVIEWER),
589 #endif
590         XLAT(KERN_SPARC_REBOOT),
591         XLAT(KERN_CTLALTDEL),
592         XLAT(KERN_PRINTK),
593         XLAT(KERN_NAMETRANS),
594         XLAT(KERN_PPC_HTABRECLAIM),
595         XLAT(KERN_PPC_ZEROPAGED),
596         XLAT(KERN_PPC_POWERSAVE_NAP),
597         XLAT(KERN_MODPROBE),
598         XLAT(KERN_SG_BIG_BUFF),
599         XLAT(KERN_ACCT),
600         XLAT(KERN_PPC_L2CR),
601         XLAT(KERN_RTSIGNR),
602         XLAT(KERN_RTSIGMAX),
603         XLAT(KERN_SHMMAX),
604         XLAT(KERN_MSGMAX),
605         XLAT(KERN_MSGMNB),
606         XLAT(KERN_MSGPOOL),
607         XLAT_END
608 };
609
610 static const struct xlat sysctl_vm[] = {
611 #ifdef VM_SWAPCTL
612         XLAT(VM_SWAPCTL),
613 #endif
614 #ifdef VM_UNUSED1
615         XLAT(VM_UNUSED1),
616 #endif
617 #ifdef VM_SWAPOUT
618         XLAT(VM_SWAPOUT),
619 #endif
620 #ifdef VM_UNUSED2
621         XLAT(VM_UNUSED2),
622 #endif
623 #ifdef VM_FREEPG
624         XLAT(VM_FREEPG),
625 #endif
626 #ifdef VM_UNUSED3
627         XLAT(VM_UNUSED3),
628 #endif
629 #ifdef VM_BDFLUSH
630         XLAT(VM_BDFLUSH),
631 #endif
632 #ifdef VM_UNUSED4
633         XLAT(VM_UNUSED4),
634 #endif
635         XLAT(VM_OVERCOMMIT_MEMORY),
636 #ifdef VM_BUFFERMEM
637         XLAT(VM_BUFFERMEM),
638 #endif
639 #ifdef VM_UNUSED5
640         XLAT(VM_UNUSED5),
641 #endif
642 #ifdef VM_PAGECACHE
643         XLAT(VM_PAGECACHE),
644 #endif
645 #ifdef VM_UNUSED7
646         XLAT(VM_UNUSED7),
647 #endif
648 #ifdef VM_PAGERDAEMON
649         XLAT(VM_PAGERDAEMON),
650 #endif
651 #ifdef VM_UNUSED8
652         XLAT(VM_UNUSED8),
653 #endif
654 #ifdef VM_PGT_CACHE
655         XLAT(VM_PGT_CACHE),
656 #endif
657 #ifdef VM_UNUSED9
658         XLAT(VM_UNUSED9),
659 #endif
660         XLAT(VM_PAGE_CLUSTER),
661         XLAT_END
662 };
663
664 static const struct xlat sysctl_net[] = {
665         XLAT(NET_CORE),
666         XLAT(NET_ETHER),
667         XLAT(NET_802),
668         XLAT(NET_UNIX),
669         XLAT(NET_IPV4),
670         XLAT(NET_IPX),
671         XLAT(NET_ATALK),
672         XLAT(NET_NETROM),
673         XLAT(NET_AX25),
674         XLAT(NET_BRIDGE),
675         XLAT(NET_ROSE),
676         XLAT(NET_IPV6),
677         XLAT(NET_X25),
678         XLAT(NET_TR),
679         XLAT(NET_DECNET),
680         XLAT_END
681 };
682
683 static const struct xlat sysctl_net_core[] = {
684         XLAT(NET_CORE_WMEM_MAX),
685         XLAT(NET_CORE_RMEM_MAX),
686         XLAT(NET_CORE_WMEM_DEFAULT),
687         XLAT(NET_CORE_RMEM_DEFAULT),
688         XLAT(NET_CORE_MAX_BACKLOG),
689         XLAT(NET_CORE_FASTROUTE),
690         XLAT(NET_CORE_MSG_COST),
691         XLAT(NET_CORE_MSG_BURST),
692         XLAT(NET_CORE_OPTMEM_MAX),
693         XLAT_END
694 };
695
696 static const struct xlat sysctl_net_unix[] = {
697         XLAT(NET_UNIX_DESTROY_DELAY),
698         XLAT(NET_UNIX_DELETE_DELAY),
699         XLAT_END
700 };
701
702 static const struct xlat sysctl_net_ipv4[] = {
703         XLAT(NET_IPV4_FORWARD),
704         XLAT(NET_IPV4_DYNADDR),
705         XLAT(NET_IPV4_CONF),
706         XLAT(NET_IPV4_NEIGH),
707         XLAT(NET_IPV4_ROUTE),
708         XLAT(NET_IPV4_FIB_HASH),
709         XLAT(NET_IPV4_TCP_TIMESTAMPS),
710         XLAT(NET_IPV4_TCP_WINDOW_SCALING),
711         XLAT(NET_IPV4_TCP_SACK),
712         XLAT(NET_IPV4_TCP_RETRANS_COLLAPSE),
713         XLAT(NET_IPV4_DEFAULT_TTL),
714         XLAT(NET_IPV4_AUTOCONFIG),
715         XLAT(NET_IPV4_NO_PMTU_DISC),
716         XLAT(NET_IPV4_TCP_SYN_RETRIES),
717         XLAT(NET_IPV4_IPFRAG_HIGH_THRESH),
718         XLAT(NET_IPV4_IPFRAG_LOW_THRESH),
719         XLAT(NET_IPV4_IPFRAG_TIME),
720         XLAT(NET_IPV4_TCP_MAX_KA_PROBES),
721         XLAT(NET_IPV4_TCP_KEEPALIVE_TIME),
722         XLAT(NET_IPV4_TCP_KEEPALIVE_PROBES),
723         XLAT(NET_IPV4_TCP_RETRIES1),
724         XLAT(NET_IPV4_TCP_RETRIES2),
725         XLAT(NET_IPV4_TCP_FIN_TIMEOUT),
726         XLAT(NET_IPV4_IP_MASQ_DEBUG),
727         XLAT(NET_TCP_SYNCOOKIES),
728         XLAT(NET_TCP_STDURG),
729         XLAT(NET_TCP_RFC1337),
730         XLAT(NET_TCP_SYN_TAILDROP),
731         XLAT(NET_TCP_MAX_SYN_BACKLOG),
732         XLAT(NET_IPV4_LOCAL_PORT_RANGE),
733         XLAT(NET_IPV4_ICMP_ECHO_IGNORE_ALL),
734         XLAT(NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS),
735         XLAT(NET_IPV4_ICMP_SOURCEQUENCH_RATE),
736         XLAT(NET_IPV4_ICMP_DESTUNREACH_RATE),
737         XLAT(NET_IPV4_ICMP_TIMEEXCEED_RATE),
738         XLAT(NET_IPV4_ICMP_PARAMPROB_RATE),
739         XLAT(NET_IPV4_ICMP_ECHOREPLY_RATE),
740         XLAT(NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES),
741         XLAT(NET_IPV4_IGMP_MAX_MEMBERSHIPS),
742         XLAT_END
743 };
744
745 static const struct xlat sysctl_net_ipv4_route[] = {
746         XLAT(NET_IPV4_ROUTE_FLUSH),
747         XLAT(NET_IPV4_ROUTE_MIN_DELAY),
748         XLAT(NET_IPV4_ROUTE_MAX_DELAY),
749         XLAT(NET_IPV4_ROUTE_GC_THRESH),
750         XLAT(NET_IPV4_ROUTE_MAX_SIZE),
751         XLAT(NET_IPV4_ROUTE_GC_MIN_INTERVAL),
752         XLAT(NET_IPV4_ROUTE_GC_TIMEOUT),
753         XLAT(NET_IPV4_ROUTE_GC_INTERVAL),
754         XLAT(NET_IPV4_ROUTE_REDIRECT_LOAD),
755         XLAT(NET_IPV4_ROUTE_REDIRECT_NUMBER),
756         XLAT(NET_IPV4_ROUTE_REDIRECT_SILENCE),
757         XLAT(NET_IPV4_ROUTE_ERROR_COST),
758         XLAT(NET_IPV4_ROUTE_ERROR_BURST),
759         XLAT(NET_IPV4_ROUTE_GC_ELASTICITY),
760         XLAT_END
761 };
762
763 static const struct xlat sysctl_net_ipv4_conf[] = {
764         XLAT(NET_IPV4_CONF_FORWARDING),
765         XLAT(NET_IPV4_CONF_MC_FORWARDING),
766         XLAT(NET_IPV4_CONF_PROXY_ARP),
767         XLAT(NET_IPV4_CONF_ACCEPT_REDIRECTS),
768         XLAT(NET_IPV4_CONF_SECURE_REDIRECTS),
769         XLAT(NET_IPV4_CONF_SEND_REDIRECTS),
770         XLAT(NET_IPV4_CONF_SHARED_MEDIA),
771         XLAT(NET_IPV4_CONF_RP_FILTER),
772         XLAT(NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE),
773         XLAT(NET_IPV4_CONF_BOOTP_RELAY),
774         XLAT(NET_IPV4_CONF_LOG_MARTIANS),
775         XLAT_END
776 };
777
778 static const struct xlat sysctl_net_ipv6[] = {
779         XLAT(NET_IPV6_CONF),
780         XLAT(NET_IPV6_NEIGH),
781         XLAT(NET_IPV6_ROUTE),
782         XLAT_END
783 };
784
785 static const struct xlat sysctl_net_ipv6_route[] = {
786         XLAT(NET_IPV6_ROUTE_FLUSH),
787         XLAT(NET_IPV6_ROUTE_GC_THRESH),
788         XLAT(NET_IPV6_ROUTE_MAX_SIZE),
789         XLAT(NET_IPV6_ROUTE_GC_MIN_INTERVAL),
790         XLAT(NET_IPV6_ROUTE_GC_TIMEOUT),
791         XLAT(NET_IPV6_ROUTE_GC_INTERVAL),
792         XLAT(NET_IPV6_ROUTE_GC_ELASTICITY),
793         XLAT_END
794 };
795
796 int
797 sys_sysctl(struct tcb *tcp)
798 {
799         struct __sysctl_args info;
800         int *name;
801         unsigned long size;
802
803         if (umove(tcp, tcp->u_arg[0], &info) < 0)
804                 return printargs(tcp);
805
806         size = sizeof(int) * (unsigned long) info.nlen;
807         name = (size / sizeof(int) != info.nlen) ? NULL : malloc(size);
808         if (name == NULL ||
809             umoven(tcp, (unsigned long) info.name, size, (char *) name) < 0) {
810                 free(name);
811                 if (entering(tcp))
812                         tprintf("{%p, %d, %p, %p, %p, %lu}",
813                                 info.name, info.nlen, info.oldval,
814                                 info.oldlenp, info.newval, (unsigned long)info.newlen);
815                 return 0;
816         }
817
818         if (entering(tcp)) {
819                 int cnt = 0, max_cnt;
820
821                 tprints("{{");
822
823                 if (info.nlen == 0)
824                         goto out;
825                 printxval(sysctl_root, name[0], "CTL_???");
826                 ++cnt;
827
828                 if (info.nlen == 1)
829                         goto out;
830                 switch (name[0]) {
831                 case CTL_KERN:
832                         tprints(", ");
833                         printxval(sysctl_kern, name[1], "KERN_???");
834                         ++cnt;
835                         break;
836                 case CTL_VM:
837                         tprints(", ");
838                         printxval(sysctl_vm, name[1], "VM_???");
839                         ++cnt;
840                         break;
841                 case CTL_NET:
842                         tprints(", ");
843                         printxval(sysctl_net, name[1], "NET_???");
844                         ++cnt;
845
846                         if (info.nlen == 2)
847                                 goto out;
848                         switch (name[1]) {
849                         case NET_CORE:
850                                 tprints(", ");
851                                 printxval(sysctl_net_core, name[2],
852                                           "NET_CORE_???");
853                                 break;
854                         case NET_UNIX:
855                                 tprints(", ");
856                                 printxval(sysctl_net_unix, name[2],
857                                           "NET_UNIX_???");
858                                 break;
859                         case NET_IPV4:
860                                 tprints(", ");
861                                 printxval(sysctl_net_ipv4, name[2],
862                                           "NET_IPV4_???");
863
864                                 if (info.nlen == 3)
865                                         goto out;
866                                 switch (name[2]) {
867                                 case NET_IPV4_ROUTE:
868                                         tprints(", ");
869                                         printxval(sysctl_net_ipv4_route,
870                                                   name[3],
871                                                   "NET_IPV4_ROUTE_???");
872                                         break;
873                                 case NET_IPV4_CONF:
874                                         tprints(", ");
875                                         printxval(sysctl_net_ipv4_conf,
876                                                   name[3],
877                                                   "NET_IPV4_CONF_???");
878                                         break;
879                                 default:
880                                         goto out;
881                                 }
882                                 break;
883                         case NET_IPV6:
884                                 tprints(", ");
885                                 printxval(sysctl_net_ipv6, name[2],
886                                           "NET_IPV6_???");
887
888                                 if (info.nlen == 3)
889                                         goto out;
890                                 switch (name[2]) {
891                                 case NET_IPV6_ROUTE:
892                                         tprints(", ");
893                                         printxval(sysctl_net_ipv6_route,
894                                                   name[3],
895                                                   "NET_IPV6_ROUTE_???");
896                                         break;
897                                 default:
898                                         goto out;
899                                 }
900                                 break;
901                         default:
902                                 goto out;
903                         }
904                         break;
905                 default:
906                         goto out;
907                 }
908         out:
909                 max_cnt = info.nlen;
910                 if (abbrev(tcp) && max_cnt > max_strlen)
911                         max_cnt = max_strlen;
912                 while (cnt < max_cnt)
913                         tprintf(", %x", name[cnt++]);
914                 if (cnt < info.nlen)
915                         tprints(", ...");
916                 tprintf("}, %d, ", info.nlen);
917         } else {
918                 size_t oldlen = 0;
919                 if (info.oldval == NULL) {
920                         tprints("NULL");
921                 } else if (umove(tcp, (long)info.oldlenp, &oldlen) >= 0
922                            && info.nlen >= 2
923                            && ((name[0] == CTL_KERN
924                                 && (name[1] == KERN_OSRELEASE
925                                     || name[1] == KERN_OSTYPE
926 #ifdef KERN_JAVA_INTERPRETER
927                                     || name[1] == KERN_JAVA_INTERPRETER
928 #endif
929 #ifdef KERN_JAVA_APPLETVIEWER
930                                     || name[1] == KERN_JAVA_APPLETVIEWER
931 #endif
932                                         )))) {
933                         printpath(tcp, (size_t)info.oldval);
934                 } else {
935                         tprintf("%p", info.oldval);
936                 }
937                 tprintf(", %lu, ", (unsigned long)oldlen);
938                 if (info.newval == NULL)
939                         tprints("NULL");
940                 else if (syserror(tcp))
941                         tprintf("%p", info.newval);
942                 else
943                         printpath(tcp, (size_t)info.newval);
944                 tprintf(", %lu", (unsigned long)info.newlen);
945         }
946
947         free(name);
948         return 0;
949 }
950
951 #ifdef MIPS
952
953 #ifndef __NEW_UTS_LEN
954 #define __NEW_UTS_LEN 64
955 #endif
956
957 static const struct xlat sysmips_operations[] = {
958         XLAT(SETNAME),
959         XLAT(FLUSH_CACHE),
960         XLAT(MIPS_FIXADE),
961         XLAT(MIPS_RDNVRAM),
962         XLAT(MIPS_ATOMIC_SET),
963         XLAT_END
964 };
965
966 int sys_sysmips(struct tcb *tcp)
967 {
968         if (entering(tcp)) {
969                 printxval(sysmips_operations, tcp->u_arg[0], "???");
970                 if (!verbose(tcp)) {
971                         tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
972                 } else if (tcp->u_arg[0] == SETNAME) {
973                         char nodename[__NEW_UTS_LEN + 1];
974                         if (umovestr(tcp, tcp->u_arg[1], (__NEW_UTS_LEN + 1), nodename) < 0)
975                                 tprintf(", %#lx", tcp->u_arg[1]);
976                         else
977                                 tprintf(", \"%.*s\"", (int)(__NEW_UTS_LEN + 1), nodename);
978                 } else if (tcp->u_arg[0] == MIPS_ATOMIC_SET) {
979                         tprintf(", %#lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
980                 } else if (tcp->u_arg[0] == MIPS_FIXADE) {
981                         tprintf(", 0x%lx", tcp->u_arg[1]);
982                 } else {
983                         tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
984                 }
985         }
986
987         return 0;
988 }
989
990 #endif /* MIPS */
991
992 #ifdef OR1K
993 #define OR1K_ATOMIC_SWAP        1
994 #define OR1K_ATOMIC_CMPXCHG     2
995 #define OR1K_ATOMIC_XCHG        3
996 #define OR1K_ATOMIC_ADD         4
997 #define OR1K_ATOMIC_DECPOS      5
998 #define OR1K_ATOMIC_AND         6
999 #define OR1K_ATOMIC_OR          7
1000 #define OR1K_ATOMIC_UMAX        8
1001 #define OR1K_ATOMIC_UMIN        9
1002
1003 static const struct xlat atomic_ops[] = {
1004         { OR1K_ATOMIC_SWAP,             "SWAP"          },
1005         { OR1K_ATOMIC_CMPXCHG,          "CMPXCHG"       },
1006         { OR1K_ATOMIC_XCHG,             "XCHG"          },
1007         { OR1K_ATOMIC_ADD,              "ADD"           },
1008         { OR1K_ATOMIC_DECPOS,           "DECPOS"        },
1009         { OR1K_ATOMIC_AND,              "AND"           },
1010         { OR1K_ATOMIC_OR,               "OR"            },
1011         { OR1K_ATOMIC_UMAX,             "UMAX"          },
1012         { OR1K_ATOMIC_UMIN,             "UMIN"          },
1013         XLAT_END
1014 };
1015
1016 int sys_or1k_atomic(struct tcb *tcp)
1017 {
1018         if (entering(tcp)) {
1019                 printxval(atomic_ops, tcp->u_arg[0], "???");
1020                 switch(tcp->u_arg[0]) {
1021                 case OR1K_ATOMIC_SWAP:
1022                         tprintf(", 0x%lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
1023                         break;
1024                 case OR1K_ATOMIC_CMPXCHG:
1025                         tprintf(", 0x%lx, %#lx, %#lx", tcp->u_arg[1], tcp->u_arg[2],
1026                                 tcp->u_arg[3]);
1027                         break;
1028
1029                 case OR1K_ATOMIC_XCHG:
1030                 case OR1K_ATOMIC_ADD:
1031                 case OR1K_ATOMIC_AND:
1032                 case OR1K_ATOMIC_OR:
1033                 case OR1K_ATOMIC_UMAX:
1034                 case OR1K_ATOMIC_UMIN:
1035                         tprintf(", 0x%lx, %#lx", tcp->u_arg[1], tcp->u_arg[2]);
1036                         break;
1037
1038                 case OR1K_ATOMIC_DECPOS:
1039                         tprintf(", 0x%lx", tcp->u_arg[1]);
1040                         break;
1041
1042                 default:
1043                         break;
1044                 }
1045         }
1046
1047         return RVAL_HEX;
1048 }
1049
1050 #endif /* OR1K */