blob: 435e2c18614fda17cf9e645a8ce71d77a39f82e2 [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. Levin0ed617b2014-04-25 23:30:54 +0000413#include "xlat/sysctl_root.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000414#include "xlat/sysctl_kern.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000415#include "xlat/sysctl_vm.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000416#include "xlat/sysctl_net.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000417#include "xlat/sysctl_net_core.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000418#include "xlat/sysctl_net_unix.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000419#include "xlat/sysctl_net_ipv4.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000420#include "xlat/sysctl_net_ipv4_route.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000421#include "xlat/sysctl_net_ipv4_conf.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000422#include "xlat/sysctl_net_ipv6.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000423#include "xlat/sysctl_net_ipv6_route.h"
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000424
425int
Denys Vlasenko12014262011-05-30 14:00:14 +0200426sys_sysctl(struct tcb *tcp)
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000427{
428 struct __sysctl_args info;
429 int *name;
Roland McGrathaa524c82005-06-01 19:22:06 +0000430 unsigned long size;
431
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200432 if (umove(tcp, tcp->u_arg[0], &info) < 0)
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000433 return printargs(tcp);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000434
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200435 size = sizeof(int) * (unsigned long) info.nlen;
436 name = (size / sizeof(int) != info.nlen) ? NULL : malloc(size);
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000437 if (name == NULL ||
Roland McGrathaa524c82005-06-01 19:22:06 +0000438 umoven(tcp, (unsigned long) info.name, size, (char *) name) < 0) {
439 free(name);
440 if (entering(tcp))
Denys Vlasenko048cc422012-05-16 12:20:17 +0200441 tprintf("{%p, %d, %p, %p, %p, %lu}",
Roland McGrathaa524c82005-06-01 19:22:06 +0000442 info.name, info.nlen, info.oldval,
Denys Vlasenko048cc422012-05-16 12:20:17 +0200443 info.oldlenp, info.newval, (unsigned long)info.newlen);
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000444 return 0;
445 }
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000446
447 if (entering(tcp)) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000448 int cnt = 0, max_cnt;
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000449
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200450 tprints("{{");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000451
452 if (info.nlen == 0)
453 goto out;
454 printxval(sysctl_root, name[0], "CTL_???");
455 ++cnt;
456
457 if (info.nlen == 1)
458 goto out;
459 switch (name[0]) {
460 case CTL_KERN:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200461 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000462 printxval(sysctl_kern, name[1], "KERN_???");
463 ++cnt;
464 break;
465 case CTL_VM:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200466 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000467 printxval(sysctl_vm, name[1], "VM_???");
468 ++cnt;
469 break;
470 case CTL_NET:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200471 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000472 printxval(sysctl_net, name[1], "NET_???");
473 ++cnt;
474
475 if (info.nlen == 2)
476 goto out;
477 switch (name[1]) {
478 case NET_CORE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200479 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000480 printxval(sysctl_net_core, name[2],
481 "NET_CORE_???");
482 break;
483 case NET_UNIX:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200484 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000485 printxval(sysctl_net_unix, name[2],
486 "NET_UNIX_???");
487 break;
488 case NET_IPV4:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200489 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000490 printxval(sysctl_net_ipv4, name[2],
491 "NET_IPV4_???");
492
493 if (info.nlen == 3)
494 goto out;
495 switch (name[2]) {
496 case NET_IPV4_ROUTE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200497 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000498 printxval(sysctl_net_ipv4_route,
499 name[3],
500 "NET_IPV4_ROUTE_???");
501 break;
502 case NET_IPV4_CONF:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200503 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000504 printxval(sysctl_net_ipv4_conf,
505 name[3],
506 "NET_IPV4_CONF_???");
507 break;
508 default:
509 goto out;
510 }
511 break;
512 case NET_IPV6:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000514 printxval(sysctl_net_ipv6, name[2],
515 "NET_IPV6_???");
516
517 if (info.nlen == 3)
518 goto out;
519 switch (name[2]) {
520 case NET_IPV6_ROUTE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints(", ");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000522 printxval(sysctl_net_ipv6_route,
523 name[3],
524 "NET_IPV6_ROUTE_???");
525 break;
526 default:
527 goto out;
528 }
529 break;
530 default:
531 goto out;
532 }
533 break;
534 default:
535 goto out;
536 }
537 out:
Roland McGrath8e4a3e62006-01-12 11:03:46 +0000538 max_cnt = info.nlen;
539 if (abbrev(tcp) && max_cnt > max_strlen)
540 max_cnt = max_strlen;
Roland McGrathaa524c82005-06-01 19:22:06 +0000541 while (cnt < max_cnt)
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000542 tprintf(", %x", name[cnt++]);
Roland McGrathaa524c82005-06-01 19:22:06 +0000543 if (cnt < info.nlen)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200544 tprints(", ...");
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000545 tprintf("}, %d, ", info.nlen);
546 } else {
Denys Vlasenko8560ef22012-05-16 12:23:58 +0200547 size_t oldlen = 0;
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500548 if (info.oldval == NULL) {
549 tprints("NULL");
550 } else if (umove(tcp, (long)info.oldlenp, &oldlen) >= 0
551 && info.nlen >= 2
552 && ((name[0] == CTL_KERN
553 && (name[1] == KERN_OSRELEASE
554 || name[1] == KERN_OSTYPE
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000555#ifdef KERN_JAVA_INTERPRETER
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500556 || name[1] == KERN_JAVA_INTERPRETER
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000557#endif
558#ifdef KERN_JAVA_APPLETVIEWER
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500559 || name[1] == KERN_JAVA_APPLETVIEWER
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000560#endif
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500561 )))) {
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000562 printpath(tcp, (size_t)info.oldval);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000563 } else {
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500564 tprintf("%p", info.oldval);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000565 }
Mike Frysinger0cf04b62013-02-08 19:10:07 -0500566 tprintf(", %lu, ", (unsigned long)oldlen);
567 if (info.newval == NULL)
568 tprints("NULL");
569 else if (syserror(tcp))
570 tprintf("%p", info.newval);
571 else
572 printpath(tcp, (size_t)info.newval);
573 tprintf(", %lu", (unsigned long)info.newlen);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000574 }
Roland McGrath2cbe44e2005-05-26 23:21:09 +0000575
576 free(name);
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000577 return 0;
578}
Wichert Akkerman22fe9d21999-05-27 12:00:57 +0000579
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000580#ifdef MIPS
581
Wichert Akkermand6b92492001-04-07 21:37:12 +0000582#ifndef __NEW_UTS_LEN
583#define __NEW_UTS_LEN 64
584#endif
585
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000586#include "xlat/sysmips_operations.h"
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000587
Denys Vlasenko12014262011-05-30 14:00:14 +0200588int sys_sysmips(struct tcb *tcp)
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000589{
590 if (entering(tcp)) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000591 printxval(sysmips_operations, tcp->u_arg[0], "???");
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000592 if (!verbose(tcp)) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000593 tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200594 } else if (tcp->u_arg[0] == SETNAME) {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000595 char nodename[__NEW_UTS_LEN + 1];
596 if (umovestr(tcp, tcp->u_arg[1], (__NEW_UTS_LEN + 1), nodename) < 0)
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000597 tprintf(", %#lx", tcp->u_arg[1]);
598 else
Denys Vlasenkoa17e55c2012-01-20 11:52:12 +0100599 tprintf(", \"%.*s\"", (int)(__NEW_UTS_LEN + 1), nodename);
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000600 } else if (tcp->u_arg[0] == MIPS_ATOMIC_SET) {
601 tprintf(", %#lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
602 } else if (tcp->u_arg[0] == MIPS_FIXADE) {
603 tprintf(", 0x%lx", tcp->u_arg[1]);
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000604 } else {
Wichert Akkerman3472dd52001-04-10 10:27:52 +0000605 tprintf("%ld, %ld, %ld", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
Wichert Akkerman0cbfb322001-02-19 13:35:53 +0000606 }
607 }
608
609 return 0;
610}
611
612#endif /* MIPS */
Christian Svensson492f81f2013-02-14 13:26:27 +0100613
614#ifdef OR1K
615#define OR1K_ATOMIC_SWAP 1
616#define OR1K_ATOMIC_CMPXCHG 2
617#define OR1K_ATOMIC_XCHG 3
618#define OR1K_ATOMIC_ADD 4
619#define OR1K_ATOMIC_DECPOS 5
620#define OR1K_ATOMIC_AND 6
621#define OR1K_ATOMIC_OR 7
622#define OR1K_ATOMIC_UMAX 8
623#define OR1K_ATOMIC_UMIN 9
624
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000625#include "xlat/atomic_ops.h"
Christian Svensson492f81f2013-02-14 13:26:27 +0100626
627int sys_or1k_atomic(struct tcb *tcp)
628{
629 if (entering(tcp)) {
630 printxval(atomic_ops, tcp->u_arg[0], "???");
631 switch(tcp->u_arg[0]) {
632 case OR1K_ATOMIC_SWAP:
633 tprintf(", 0x%lx, 0x%lx", tcp->u_arg[1], tcp->u_arg[2]);
634 break;
635 case OR1K_ATOMIC_CMPXCHG:
636 tprintf(", 0x%lx, %#lx, %#lx", tcp->u_arg[1], tcp->u_arg[2],
637 tcp->u_arg[3]);
638 break;
639
640 case OR1K_ATOMIC_XCHG:
641 case OR1K_ATOMIC_ADD:
642 case OR1K_ATOMIC_AND:
643 case OR1K_ATOMIC_OR:
644 case OR1K_ATOMIC_UMAX:
645 case OR1K_ATOMIC_UMIN:
646 tprintf(", 0x%lx, %#lx", tcp->u_arg[1], tcp->u_arg[2]);
647 break;
648
649 case OR1K_ATOMIC_DECPOS:
650 tprintf(", 0x%lx", tcp->u_arg[1]);
651 break;
652
653 default:
654 break;
655 }
656 }
657
658 return RVAL_HEX;
659}
660
661#endif /* OR1K */