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