blob: 20a9de2155cf04daad93d00b8edcd96a56406efa [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033#define _LINUX_SOCKET_H
Wichert Akkerman14cd9f01999-07-09 18:56:34 +000034#define _LINUX_FS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035
Roland McGrathcbd33582005-02-02 04:36:11 +000036#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
Dmitry V. Levin817b7082007-01-16 15:10:07 +000049#define MS_SILENT 32768
Roland McGrathcbd33582005-02-02 04:36:11 +000050#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
Dmitry V. Levin817b7082007-01-16 15:10:07 +000051#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 */
Mike Frysinger22485b72011-02-21 23:04:30 -050055#define MS_RELATIME (1<<21)
56#define MS_KERNMOUNT (1<<22)
57#define MS_I_VERSION (1<<23)
58#define MS_STRICTATIME (1<<24)
Bernhard Reutner-Fischer9e1a7d82013-02-05 19:31:56 +010059#define MS_NOSEC (1<<28)
Mike Frysinger22485b72011-02-21 23:04:30 -050060#define MS_BORN (1<<29)
Roland McGrathcbd33582005-02-02 04:36:11 +000061#define MS_ACTIVE (1<<30)
62#define MS_NOUSER (1<<31)
Roland McGrath6af37482006-01-12 21:21:06 +000063#define MS_MGC_VAL 0xc0ed0000 /* Magic flag number */
Dmitry V. Levin817b7082007-01-16 15:10:07 +000064#define MS_MGC_MSK 0xffff0000 /* Magic flag mask */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065
66#include <sys/socket.h>
67#include <netinet/in.h>
68#include <arpa/inet.h>
Dmitry V. Levinf48df6c2009-06-01 09:59:11 +000069#ifdef HAVE_LINUX_CAPABILITY_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010070# include <linux/capability.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071#endif
Dmitry V. Levinf48df6c2009-06-01 09:59:11 +000072#ifdef HAVE_ASM_CACHECTL_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010073# include <asm/cachectl.h>
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000074#endif
Wichert Akkermand6b92492001-04-07 21:37:12 +000075#ifdef HAVE_LINUX_USTNAME_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010076# include <linux/utsname.h>
Wichert Akkermand6b92492001-04-07 21:37:12 +000077#endif
Dmitry V. Levinf48df6c2009-06-01 09:59:11 +000078#ifdef HAVE_ASM_SYSMIPS_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010079# include <asm/sysmips.h>
Wichert Akkermand6b92492001-04-07 21:37:12 +000080#endif
Wichert Akkerman22fe9d21999-05-27 12:00:57 +000081#include <linux/sysctl.h>
Dmitry V. Levin2a32eaa2014-02-05 02:09:49 +000082#include <linux/personality.h>
Wichert Akkerman22fe9d21999-05-27 12:00:57 +000083
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000084#include "xlat/mount_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085
86int
Dmitry V. Levin817b7082007-01-16 15:10:07 +000087sys_mount(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088{
89 if (entering(tcp)) {
Dmitry V. Levin817b7082007-01-16 15:10:07 +000090 int ignore_type = 0, ignore_data = 0;
91 unsigned long flags = tcp->u_arg[3];
92
93 /* Discard magic */
94 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
95 flags &= ~MS_MGC_MSK;
96
97 if (flags & MS_REMOUNT)
98 ignore_type = 1;
99 else if (flags & (MS_BIND | MS_MOVE))
100 ignore_type = ignore_data = 1;
101
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000102 printpath(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200103 tprints(", ");
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000104
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105 printpath(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200106 tprints(", ");
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000107
108 if (ignore_type && tcp->u_arg[2])
Roland McGrathcbd33582005-02-02 04:36:11 +0000109 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000110 else
111 printstr(tcp, tcp->u_arg[2], -1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200112 tprints(", ");
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000113
Roland McGrathb2dee132005-06-01 19:02:36 +0000114 printflags(mount_flags, tcp->u_arg[3], "MS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200115 tprints(", ");
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000116
117 if (ignore_data && tcp->u_arg[4])
Roland McGrath6af37482006-01-12 21:21:06 +0000118 tprintf("%#lx", tcp->u_arg[4]);
Dmitry V. Levin817b7082007-01-16 15:10:07 +0000119 else
120 printstr(tcp, tcp->u_arg[4], -1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121 }
122 return 0;
123}
124
Dmitry V. Levin5c7ad8c2007-01-13 11:15:48 +0000125#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
126#define MNT_DETACH 0x00000002 /* Just detach from the tree */
127#define MNT_EXPIRE 0x00000004 /* Mark for expiry */
128
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000129#include "xlat/umount_flags.h"
Dmitry V. Levin5c7ad8c2007-01-13 11:15:48 +0000130
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000131int
Dmitry V. Levin5c7ad8c2007-01-13 11:15:48 +0000132sys_umount2(struct tcb *tcp)
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000133{
134 if (entering(tcp)) {
135 printstr(tcp, tcp->u_arg[0], -1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200136 tprints(", ");
Dmitry V. Levin5c7ad8c2007-01-13 11:15:48 +0000137 printflags(umount_flags, tcp->u_arg[1], "MNT_???");
Wichert Akkermandacfb6e1999-06-03 14:21:07 +0000138 }
139 return 0;
140}
141
Roland McGrathced50da2004-08-31 06:48:46 +0000142/* These are not macros, but enums. We just copy the values by hand
143 from Linux 2.6.9 here. */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000144#include "xlat/personality_options.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145
146int
Denys Vlasenko12014262011-05-30 14:00:14 +0200147sys_personality(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148{
149 if (entering(tcp))
150 printxval(personality_options, tcp->u_arg[0], "PER_???");
151 return 0;
152}
153
Dmitry V. Levinee3c22c2012-03-13 15:28:01 +0000154enum {
155 SYSLOG_ACTION_CLOSE = 0,
156 SYSLOG_ACTION_OPEN,
157 SYSLOG_ACTION_READ,
158 SYSLOG_ACTION_READ_ALL,
159 SYSLOG_ACTION_READ_CLEAR,
160 SYSLOG_ACTION_CLEAR,
161 SYSLOG_ACTION_CONSOLE_OFF,
162 SYSLOG_ACTION_CONSOLE_ON,
163 SYSLOG_ACTION_CONSOLE_LEVEL,
164 SYSLOG_ACTION_SIZE_UNREAD,
165 SYSLOG_ACTION_SIZE_BUFFER
166};
167
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000168#include "xlat/syslog_action_type.h"
Dmitry V. Levinee3c22c2012-03-13 15:28:01 +0000169
170int
171sys_syslog(struct tcb *tcp)
172{
173 int type = tcp->u_arg[0];
174
175 if (entering(tcp)) {
176 /* type */
177 printxval(syslog_action_type, type, "SYSLOG_ACTION_???");
178 tprints(", ");
179 }
180
181 switch (type) {
182 case SYSLOG_ACTION_READ:
183 case SYSLOG_ACTION_READ_ALL:
184 case SYSLOG_ACTION_READ_CLEAR:
185 if (entering(tcp))
186 return 0;
187 break;
188 default:
189 if (entering(tcp)) {
190 tprintf("%#lx, %lu",
191 tcp->u_arg[1], tcp->u_arg[2]);
192 }
193 return 0;
194 }
195
196 /* bufp */
197 if (syserror(tcp))
198 tprintf("%#lx", tcp->u_arg[1]);
199 else
200 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
201 /* len */
202 tprintf(", %d", (int) tcp->u_arg[2]);
203
204 return 0;
205}
206
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000207#ifdef M68K
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000208#include "xlat/cacheflush_scope.h"
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000209
Roland McGrathd9f816f2004-09-04 03:39:20 +0000210static const struct xlat cacheflush_flags[] = {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000211#ifdef FLUSH_CACHE_BOTH
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000212 XLAT(FLUSH_CACHE_BOTH),
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000213#endif
214#ifdef FLUSH_CACHE_DATA
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000215 XLAT(FLUSH_CACHE_DATA),
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000216#endif
217#ifdef FLUSH_CACHE_INSN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000218 XLAT(FLUSH_CACHE_INSN),
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000219#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000220 XLAT_END
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000221};
222
223int
Denys Vlasenko12014262011-05-30 14:00:14 +0200224sys_cacheflush(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000225{
226 if (entering(tcp)) {
227 /* addr */
228 tprintf("%#lx, ", tcp->u_arg[0]);
229 /* scope */
230 printxval(cacheflush_scope, tcp->u_arg[1], "FLUSH_SCOPE_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200231 tprints(", ");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000232 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000233 printflags(cacheflush_flags, tcp->u_arg[2], "FLUSH_CACHE_???");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000234 /* len */
235 tprintf(", %lu", tcp->u_arg[3]);
236 }
237 return 0;
238}
239#endif /* M68K */
240
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000241#ifdef BFIN
242
243#include <bfin_sram.h>
244
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000245#include "xlat/sram_alloc_flags.h"
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000246
247int
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000248sys_sram_alloc(struct tcb *tcp)
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000249{
250 if (entering(tcp)) {
251 /* size */
Denys Vlasenko132c52a2009-03-23 13:12:46 +0000252 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000253 /* flags */
Mike Frysinger149d7de2013-04-03 00:19:31 -0400254 printflags(sram_alloc_flags, tcp->u_arg[1], "???_SRAM");
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000255 }
256 return 1;
257}
258
Mike Frysinger260e5712010-09-11 15:04:18 -0400259#include <asm/cachectl.h>
260
261static const struct xlat cacheflush_flags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000262 XLAT(ICACHE),
263 XLAT(DCACHE),
264 XLAT(BCACHE),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000265 XLAT_END
Mike Frysinger260e5712010-09-11 15:04:18 -0400266};
267
268int
269sys_cacheflush(struct tcb *tcp)
270{
271 if (entering(tcp)) {
272 /* start addr */
273 tprintf("%#lx, ", tcp->u_arg[0]);
274 /* length */
275 tprintf("%ld, ", tcp->u_arg[1]);
276 /* flags */
277 printxval(cacheflush_flags, tcp->u_arg[1], "?CACHE");
278 }
279 return 0;
280}
281
Dmitry V. Levin87ea1f42008-11-10 22:21:41 +0000282#endif
283
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100284#ifdef SH
285static const struct xlat cacheflush_flags[] = {
286#ifdef CACHEFLUSH_D_INVAL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000287 XLAT(CACHEFLUSH_D_INVAL),
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100288#endif
289#ifdef CACHEFLUSH_D_WB
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000290 XLAT(CACHEFLUSH_D_WB),
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100291#endif
292#ifdef CACHEFLUSH_D_PURGE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000293 XLAT(CACHEFLUSH_D_PURGE),
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100294#endif
295#ifdef CACHEFLUSH_I
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000296 XLAT(CACHEFLUSH_I),
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100297#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000298 XLAT_END
Carmelo AMOROSOf8e56502010-12-01 14:27:07 +0100299};
300
301int
302sys_cacheflush(struct tcb *tcp)
303{
304 if (entering(tcp)) {
305 /* addr */
306 tprintf("%#lx, ", tcp->u_arg[0]);
307 /* len */
308 tprintf("%lu, ", tcp->u_arg[1]);
309 /* flags */
310 printflags(cacheflush_flags, tcp->u_arg[2], "CACHEFLUSH_???");
311 }
312 return 0;
313}
314#endif /* SH */
315
Nate Sammons8d5860c1999-07-03 18:53:05 +0000316#ifdef SYS_capget
Wichert Akkermanc7926982000-04-10 22:22:31 +0000317
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000318#include "xlat/capabilities.h"
Wichert Akkermanc7926982000-04-10 22:22:31 +0000319
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000320#ifndef _LINUX_CAPABILITY_VERSION_1
321# define _LINUX_CAPABILITY_VERSION_1 0x19980330
322#endif
323#ifndef _LINUX_CAPABILITY_VERSION_2
324# define _LINUX_CAPABILITY_VERSION_2 0x20071026
325#endif
326#ifndef _LINUX_CAPABILITY_VERSION_3
327# define _LINUX_CAPABILITY_VERSION_3 0x20080522
328#endif
329
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000330#include "xlat/cap_version.h"
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000331
332static void
333print_cap_header(struct tcb *tcp, unsigned long addr)
334{
335 union { cap_user_header_t p; long *a; char *c; } arg;
336 long a[sizeof(*arg.p) / sizeof(long) + 1];
337 arg.a = a;
338
339 if (!addr)
340 tprints("NULL");
341 else if (!verbose(tcp) ||
342 umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0)
343 tprintf("%#lx", addr);
344 else {
345 tprints("{");
346 printxval(cap_version, arg.p->version,
347 "_LINUX_CAPABILITY_VERSION_???");
348 tprintf(", %d}", arg.p->pid);
349 }
350}
351
352static void
353print_cap_data(struct tcb *tcp, unsigned long addr)
354{
355 union { cap_user_data_t p; long *a; char *c; } arg;
356 long a[sizeof(*arg.p) / sizeof(long) + 1];
357 arg.a = a;
358
359 if (!addr)
360 tprints("NULL");
361 else if (!verbose(tcp) ||
362 (exiting(tcp) && syserror(tcp)) ||
363 umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0)
364 tprintf("%#lx", addr);
365 else {
366 tprints("{");
367 printflags(capabilities, arg.p->effective, "CAP_???");
368 tprints(", ");
369 printflags(capabilities, arg.p->permitted, "CAP_???");
370 tprints(", ");
371 printflags(capabilities, arg.p->inheritable, "CAP_???");
372 tprints("}");
373 }
374}
375
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376int
Denys Vlasenko12014262011-05-30 14:00:14 +0200377sys_capget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378{
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000379 if (entering(tcp)) {
380 print_cap_header(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200381 tprints(", ");
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000382 } else {
383 print_cap_data(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 }
385 return 0;
386}
387
388int
Denys Vlasenko12014262011-05-30 14:00:14 +0200389sys_capset(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390{
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200391 if (entering(tcp)) {
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000392 print_cap_header(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200393 tprints(", ");
Dmitry V. Levin4a0ffea2012-03-15 22:58:39 +0000394 print_cap_data(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395 }
396 return 0;
397}
398
399#else
400
Denys Vlasenko12014262011-05-30 14:00:14 +0200401int sys_capget(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402{
403 return printargs(tcp);
404}
405
Denys Vlasenko12014262011-05-30 14:00:14 +0200406int sys_capset(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407{
408 return printargs(tcp);
409}
410
411#endif
412
Dmitry V. Levin35a55782006-12-04 13:48:10 +0000413/* Linux 2.6.18+ headers removed CTL_PROC enum. */
414# define CTL_PROC 4
Roland McGrath5eb1aa52007-01-11 22:48:39 +0000415# define CTL_CPU 10 /* older headers lack */
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000416#include "xlat/sysctl_root.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000417
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000418#include "xlat/sysctl_kern.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000419
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000420#include "xlat/sysctl_vm.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000421
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000422#include "xlat/sysctl_net.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000423
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000424#include "xlat/sysctl_net_core.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000425
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000426#include "xlat/sysctl_net_unix.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000427
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000428#include "xlat/sysctl_net_ipv4.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000429
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000430#include "xlat/sysctl_net_ipv4_route.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000431
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000432#include "xlat/sysctl_net_ipv4_conf.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000433
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000434#include "xlat/sysctl_net_ipv6.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000435
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000436#include "xlat/sysctl_net_ipv6_route.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000437
438int
Denys Vlasenko12014262011-05-30 14:00:14 +0200439sys_sysctl(struct tcb *tcp)
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000440{
441 struct __sysctl_args info;
442 int *name;
Roland McGrathaa524c82005-06-01 19:22:06 +0000443 unsigned long size;
444
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200445 if (umove(tcp, tcp->u_arg[0], &info) < 0)
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000446 return printargs(tcp);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000447
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200448 size = sizeof(int) * (unsigned long) info.nlen;
449 name = (size / sizeof(int) != info.nlen) ? NULL : malloc(size);
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000450 if (name == NULL ||
Roland McGrathaa524c82005-06-01 19:22:06 +0000451 umoven(tcp, (unsigned long) info.name, size, (char *) name) < 0) {
452 free(name);
453 if (entering(tcp))
Denys Vlasenko048cc422012-05-16 12:20:17 +0200454 tprintf("{%p, %d, %p, %p, %p, %lu}",
Roland McGrathaa524c82005-06-01 19:22:06 +0000455 info.name, info.nlen, info.oldval,
Denys Vlasenko048cc422012-05-16 12:20:17 +0200456 info.oldlenp, info.newval, (unsigned long)info.newlen);
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000457 return 0;
458 }
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000459
460 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000461 int cnt = 0, max_cnt;
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000462
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200463 tprints("{{");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000464
465 if (info.nlen == 0)
466 goto out;
467 printxval(sysctl_root, name[0], "CTL_???");
468 ++cnt;
469
470 if (info.nlen == 1)
471 goto out;
472 switch (name[0]) {
473 case CTL_KERN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200474 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000475 printxval(sysctl_kern, name[1], "KERN_???");
476 ++cnt;
477 break;
478 case CTL_VM:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200479 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000480 printxval(sysctl_vm, name[1], "VM_???");
481 ++cnt;
482 break;
483 case CTL_NET:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200484 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000485 printxval(sysctl_net, name[1], "NET_???");
486 ++cnt;
487
488 if (info.nlen == 2)
489 goto out;
490 switch (name[1]) {
491 case NET_CORE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200492 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000493 printxval(sysctl_net_core, name[2],
494 "NET_CORE_???");
495 break;
496 case NET_UNIX:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200497 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000498 printxval(sysctl_net_unix, name[2],
499 "NET_UNIX_???");
500 break;
501 case NET_IPV4:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200502 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000503 printxval(sysctl_net_ipv4, name[2],
504 "NET_IPV4_???");
505
506 if (info.nlen == 3)
507 goto out;
508 switch (name[2]) {
509 case NET_IPV4_ROUTE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000511 printxval(sysctl_net_ipv4_route,
512 name[3],
513 "NET_IPV4_ROUTE_???");
514 break;
515 case NET_IPV4_CONF:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000517 printxval(sysctl_net_ipv4_conf,
518 name[3],
519 "NET_IPV4_CONF_???");
520 break;
521 default:
522 goto out;
523 }
524 break;
525 case NET_IPV6:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200526 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000527 printxval(sysctl_net_ipv6, name[2],
528 "NET_IPV6_???");
529
530 if (info.nlen == 3)
531 goto out;
532 switch (name[2]) {
533 case NET_IPV6_ROUTE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200534 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000535 printxval(sysctl_net_ipv6_route,
536 name[3],
537 "NET_IPV6_ROUTE_???");
538 break;
539 default:
540 goto out;
541 }
542 break;
543 default:
544 goto out;
545 }
546 break;
547 default:
548 goto out;
549 }
550 out:
Roland McGrath8e4a3e62006-01-12 11:03:46 +0000551 max_cnt = info.nlen;
552 if (abbrev(tcp) && max_cnt > max_strlen)
553 max_cnt = max_strlen;
Roland McGrathaa524c82005-06-01 19:22:06 +0000554 while (cnt < max_cnt)
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000555 tprintf(", %x", name[cnt++]);
Roland McGrathaa524c82005-06-01 19:22:06 +0000556 if (cnt < info.nlen)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200557 tprints(", ...");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000558 tprintf("}, %d, ", info.nlen);
559 } else {
Denys Vlasenko8560ef22012-05-16 12:23:58 +0200560 size_t oldlen = 0;
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500561 if (info.oldval == NULL) {
562 tprints("NULL");
563 } else if (umove(tcp, (long)info.oldlenp, &oldlen) >= 0
564 && info.nlen >= 2
565 && ((name[0] == CTL_KERN
566 && (name[1] == KERN_OSRELEASE
567 || name[1] == KERN_OSTYPE
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000568#ifdef KERN_JAVA_INTERPRETER
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500569 || name[1] == KERN_JAVA_INTERPRETER
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000570#endif
571#ifdef KERN_JAVA_APPLETVIEWER
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500572 || name[1] == KERN_JAVA_APPLETVIEWER
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000573#endif
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500574 )))) {
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000575 printpath(tcp, (size_t)info.oldval);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000576 } else {
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500577 tprintf("%p", info.oldval);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000578 }
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500579 tprintf(", %lu, ", (unsigned long)oldlen);
580 if (info.newval == NULL)
581 tprints("NULL");
582 else if (syserror(tcp))
583 tprintf("%p", info.newval);
584 else
585 printpath(tcp, (size_t)info.newval);
586 tprintf(", %lu", (unsigned long)info.newlen);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000587 }
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000588
589 free(name);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000590 return 0;
591}
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000592
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000593#ifdef MIPS
594
Wichert Akkermand6b92492001-04-07 21:37:12 +0000595#ifndef __NEW_UTS_LEN
596#define __NEW_UTS_LEN 64
597#endif
598
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000599#include "xlat/sysmips_operations.h"
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000600
Denys Vlasenko12014262011-05-30 14:00:14 +0200601int sys_sysmips(struct tcb *tcp)
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000602{
603 if (entering(tcp)) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000604 printxval(sysmips_operations, tcp->u_arg[0], "???");
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000605 if (!verbose(tcp)) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000606 tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200607 } else if (tcp->u_arg[0] == SETNAME) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000608 char nodename[__NEW_UTS_LEN + 1];
609 if (umovestr(tcp, tcp->u_arg[1], (__NEW_UTS_LEN + 1), nodename) < 0)
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000610 tprintf(", %#lx", tcp->u_arg[1]);
611 else
Denys Vlasenkoa17e55c2012-01-20 11:52:12 +0100612 tprintf(", \"%.*s\"", (int)(__NEW_UTS_LEN + 1), nodename);
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000613 } else if (tcp->u_arg[0] == MIPS_ATOMIC_SET) {
614 tprintf(", %#lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
615 } else if (tcp->u_arg[0] == MIPS_FIXADE) {
616 tprintf(", 0x%lx", tcp->u_arg[1]);
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000617 } else {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000618 tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000619 }
620 }
621
622 return 0;
623}
624
625#endif /* MIPS */
Christian Svensson492f81f2013-02-14 13:26:27 +0100626
627#ifdef OR1K
628#define OR1K_ATOMIC_SWAP 1
629#define OR1K_ATOMIC_CMPXCHG 2
630#define OR1K_ATOMIC_XCHG 3
631#define OR1K_ATOMIC_ADD 4
632#define OR1K_ATOMIC_DECPOS 5
633#define OR1K_ATOMIC_AND 6
634#define OR1K_ATOMIC_OR 7
635#define OR1K_ATOMIC_UMAX 8
636#define OR1K_ATOMIC_UMIN 9
637
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000638#include "xlat/atomic_ops.h"
Christian Svensson492f81f2013-02-14 13:26:27 +0100639
640int sys_or1k_atomic(struct tcb *tcp)
641{
642 if (entering(tcp)) {
643 printxval(atomic_ops, tcp->u_arg[0], "???");
644 switch(tcp->u_arg[0]) {
645 case OR1K_ATOMIC_SWAP:
646 tprintf(", 0x%lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
647 break;
648 case OR1K_ATOMIC_CMPXCHG:
649 tprintf(", 0x%lx, %#lx, %#lx", tcp->u_arg[1], tcp->u_arg[2],
650 tcp->u_arg[3]);
651 break;
652
653 case OR1K_ATOMIC_XCHG:
654 case OR1K_ATOMIC_ADD:
655 case OR1K_ATOMIC_AND:
656 case OR1K_ATOMIC_OR:
657 case OR1K_ATOMIC_UMAX:
658 case OR1K_ATOMIC_UMIN:
659 tprintf(", 0x%lx, %#lx", tcp->u_arg[1], tcp->u_arg[2]);
660 break;
661
662 case OR1K_ATOMIC_DECPOS:
663 tprintf(", 0x%lx", tcp->u_arg[1]);
664 break;
665
666 default:
667 break;
668 }
669 }
670
671 return RVAL_HEX;
672}
673
674#endif /* OR1K */