blob: 0d728703db99fd925023cd56646f0cef46469fb1 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000035#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#include <linux/mman.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000038#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000039
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040#if defined(LINUX) && defined(__i386__)
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000041#include <asm/ldt.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042#endif
43
44int
45sys_brk(tcp)
46struct tcb *tcp;
47{
48 if (entering(tcp)) {
49 tprintf("%#lx", tcp->u_arg[0]);
50 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +000051#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 return RVAL_HEX;
53#else
54 return 0;
55#endif
56}
57
58int
59sys_sbrk(tcp)
60struct tcb *tcp;
61{
62 if (entering(tcp)) {
63 tprintf("%lu", tcp->u_arg[0]);
64 }
65 return RVAL_HEX;
66}
67
68static struct xlat mmap_prot[] = {
69 { PROT_NONE, "PROT_NONE", },
70 { PROT_READ, "PROT_READ" },
71 { PROT_WRITE, "PROT_WRITE" },
72 { PROT_EXEC, "PROT_EXEC" },
73 { 0, NULL },
74};
75
76static struct xlat mmap_flags[] = {
77 { MAP_SHARED, "MAP_SHARED" },
78 { MAP_PRIVATE, "MAP_PRIVATE" },
79 { MAP_FIXED, "MAP_FIXED" },
80#ifdef MAP_ANONYMOUS
81 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
82#endif
83#ifdef MAP_RENAME
84 { MAP_RENAME, "MAP_RENAME" },
85#endif
86#ifdef MAP_NORESERVE
87 { MAP_NORESERVE,"MAP_NORESERVE" },
88#endif
Wichert Akkerman8829a551999-06-11 13:18:40 +000089 /*
90 * XXX - this was introduced in SunOS 4.x to distinguish between
91 * the old pre-4.x "mmap()", which:
92 *
93 * only let you map devices with an "mmap" routine (e.g.,
94 * frame buffers) in;
95 *
96 * required you to specify the mapping address;
97 *
98 * returned 0 on success and -1 on failure;
99 *
100 * memory and which, and the 4.x "mmap()" which:
101 *
102 * can map plain files;
103 *
104 * can be asked to pick where to map the file;
105 *
106 * returns the address where it mapped the file on success
107 * and -1 on failure.
108 *
109 * It's not actually used in source code that calls "mmap()"; the
110 * "mmap()" routine adds it for you.
111 *
112 * It'd be nice to come up with some way of eliminating it from
113 * the flags, e.g. reporting calls *without* it as "old_mmap()"
114 * and calls with it as "mmap()".
115 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116#ifdef _MAP_NEW
117 { _MAP_NEW, "_MAP_NEW" },
118#endif
119#ifdef MAP_GROWSDOWN
120 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
121#endif
122#ifdef MAP_DENYWRITE
123 { MAP_DENYWRITE,"MAP_DENYWRITE" },
124#endif
125#ifdef MAP_EXECUTABLE
126 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
127#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000128#ifdef MAP_INHERIT
129 { MAP_INHERIT,"MAP_INHERIT" },
130#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#ifdef MAP_FILE
132 { MAP_FILE,"MAP_FILE"},
133#endif
134#ifdef MAP_LOCKED
135 { MAP_LOCKED,"MAP_LOCKED"},
136#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000137 /* FreeBSD ones */
138#ifdef MAP_ANON
139 { MAP_ANON, "MAP_ANON" },
140#endif
141#ifdef MAP_HASSEMAPHORE
142 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
143#endif
144#ifdef MAP_STACK
145 { MAP_STACK, "MAP_STACK" },
146#endif
147#ifdef MAP_NOSYNC
148 { MAP_NOSYNC, "MAP_NOSYNC" },
149#endif
150#ifdef MAP_NOCORE
151 { MAP_NOCORE, "MAP_NOCORE" },
152#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153 { 0, NULL },
154};
155
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000156static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157int
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000158print_mmap(tcp,u_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000160long *u_arg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000164 if (!u_arg[0])
165 tprintf("NULL, ");
166 else
167 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168 /* len */
169 tprintf("%lu, ", u_arg[1]);
170 /* prot */
171 printflags(mmap_prot, u_arg[2]);
172 tprintf(", ");
173 /* flags */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000174#ifdef MAP_TYPE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
176 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000177#else
178 printflags(mmap_flags, u_arg[3]);
179#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180 /* fd */
181 tprintf(", %ld, ", u_arg[4]);
182 /* offset */
183 tprintf("%#lx", u_arg[5]);
184 }
185 return RVAL_HEX;
186}
187
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000188#ifdef LINUX
189int sys_old_mmap(tcp)
190struct tcb *tcp;
191{
192 long u_arg[6];
193
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000194#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000195 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000196 /*
197 * IA64 processes never call this routine, they only use the
198 * new `sys_mmap' interface. This code converts the integer
199 * arguments that the IA32 process pushed onto the stack into
200 * longs.
201 *
202 * Note that addresses with bit 31 set will be sign extended.
203 * Fortunately, those addresses are not currently being generated
204 * for IA32 processes so it's not a problem.
205 */
206 for (i = 0; i < 6; i++)
207 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
208 return 0;
209 else
210 u_arg[i] = v;
211#else // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000212 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
213 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000214#endif // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000215 return print_mmap(tcp, u_arg);
216
217}
218#endif
219
220int
221sys_mmap(tcp)
222struct tcb *tcp;
223{
224 return print_mmap(tcp, tcp->u_arg);
225}
226
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227int
228sys_munmap(tcp)
229struct tcb *tcp;
230{
231 if (entering(tcp)) {
232 tprintf("%#lx, %lu",
233 tcp->u_arg[0], tcp->u_arg[1]);
234 }
235 return 0;
236}
237
238int
239sys_mprotect(tcp)
240struct tcb *tcp;
241{
242 if (entering(tcp)) {
243 tprintf("%#lx, %lu, ",
244 tcp->u_arg[0], tcp->u_arg[1]);
245 if (!printflags(mmap_prot, tcp->u_arg[2]))
246 tprintf("PROT_???");
247 }
248 return 0;
249}
250
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000251#ifdef LINUX
252
253static struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000254 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
255 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000256};
257
258int
259sys_mremap(tcp)
260struct tcb *tcp;
261{
262 if (entering(tcp)) {
263 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
264 tcp->u_arg[2]);
265 printflags(mremap_flags, tcp->u_arg[3]);
266 }
267 return RVAL_HEX;
268}
269
Wichert Akkermanc7926982000-04-10 22:22:31 +0000270static struct xlat madvise_flags[] = {
271#ifdef MADV_NORMAL
272 { MADV_NORMAL, "MADV_NORMAL" },
273#endif
274#ifdef MADZV_RANDOM
275 { MADV_RANDOM, "MADV_RANDOM" },
276#endif
277#ifdef MADV_SEQUENTIAL
278 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
279#endif
280#ifdef MADV_WILLNEED
281 { MADV_WILLNEED, "MADV_WILLNEED" },
282#endif
283#ifdef MADV_DONTNED
284 { MADV_DONTNEED, "MADV_DONTNEED" },
285#endif
286 { 0, NULL },
287};
288
289
290int
291sys_madvise(tcp)
292struct tcb *tcp;
293{
294 if (entering(tcp)) {
295 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
296 printflags(madvise_flags, tcp->u_arg[2]);
297 }
298 return 0;
299}
300
301
302static struct xlat mlockall_flags[] = {
303#ifdef MCL_CURRENT
304 { MCL_CURRENT, "MCL_CURRENT" },
305#endif
306#ifdef MCL_FUTURE
307 { MCL_FUTURE, "MCL_FUTURE" },
308#endif
309 { 0, NULL}
310};
311
312int
313sys_mlockall(tcp)
314struct tcb *tcp;
315{
316 if (entering(tcp)) {
317 printflags(mlockall_flags, tcp->u_arg[0]);
318 }
319 return 0;
320}
321
322
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000323#endif /* LINUX */
324
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000325#ifdef MS_ASYNC
326
327static struct xlat mctl_sync[] = {
328 { MS_ASYNC, "MS_ASYNC" },
329 { MS_INVALIDATE,"MS_INVALIDATE" },
330#ifdef MS_SYNC
331 { MS_SYNC, "MS_SYNC" },
332#endif
333 { 0, NULL },
334};
335
336int
337sys_msync(tcp)
338struct tcb *tcp;
339{
340 if (entering(tcp)) {
341 /* addr */
342 tprintf("%#lx", tcp->u_arg[0]);
343 /* len */
344 tprintf(", %lu, ", tcp->u_arg[1]);
345 /* flags */
346 if (!printflags(mctl_sync, tcp->u_arg[2]))
347 tprintf("MS_???");
348 }
349 return 0;
350}
351
352#endif /* MS_ASYNC */
353
354#ifdef MC_SYNC
355
356static struct xlat mctl_funcs[] = {
357 { MC_LOCK, "MC_LOCK" },
358 { MC_LOCKAS, "MC_LOCKAS" },
359 { MC_SYNC, "MC_SYNC" },
360 { MC_UNLOCK, "MC_UNLOCK" },
361 { MC_UNLOCKAS, "MC_UNLOCKAS" },
362 { 0, NULL },
363};
364
365static struct xlat mctl_lockas[] = {
366 { MCL_CURRENT, "MCL_CURRENT" },
367 { MCL_FUTURE, "MCL_FUTURE" },
368 { 0, NULL },
369};
370
371int
372sys_mctl(tcp)
373struct tcb *tcp;
374{
375 int arg, function;
376
377 if (entering(tcp)) {
378 /* addr */
379 tprintf("%#lx", tcp->u_arg[0]);
380 /* len */
381 tprintf(", %lu, ", tcp->u_arg[1]);
382 /* function */
383 function = tcp->u_arg[2];
384 if (!printflags(mctl_funcs, function))
385 tprintf("MC_???");
386 /* arg */
387 arg = tcp->u_arg[3];
388 tprintf(", ");
389 switch (function) {
390 case MC_SYNC:
391 if (!printflags(mctl_sync, arg))
392 tprintf("MS_???");
393 break;
394 case MC_LOCKAS:
395 if (!printflags(mctl_lockas, arg))
396 tprintf("MCL_???");
397 break;
398 default:
399 tprintf("%#x", arg);
400 break;
401 }
402 }
403 return 0;
404}
405
406#endif /* MC_SYNC */
407
408int
409sys_mincore(tcp)
410struct tcb *tcp;
411{
412 int i, len;
413 char *vec = NULL;
414
415 if (entering(tcp)) {
416 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
417 } else {
418 len = tcp->u_arg[1];
419 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
420 (vec = malloc((u_int)len)) == NULL ||
421 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
422 tprintf("%#lx", tcp->u_arg[2]);
423 else {
424 tprintf("[");
425 for (i = 0; i < len; i++) {
426 if (abbrev(tcp) && i >= max_strlen) {
427 tprintf("...");
428 break;
429 }
430 tprintf((vec[i] & 1) ? "1" : "0");
431 }
432 tprintf("]");
433 }
434 if (vec)
435 free(vec);
436 }
437 return 0;
438}
439
440int
441sys_getpagesize(tcp)
442struct tcb *tcp;
443{
444 if (exiting(tcp))
445 return RVAL_HEX;
446 return 0;
447}
448
449#if defined(LINUX) && defined(__i386__)
450int
451sys_modify_ldt(tcp)
452struct tcb *tcp;
453{
454 if (entering(tcp)) {
455 struct modify_ldt_ldt_s copy;
456 tprintf("%ld", tcp->u_arg[0]);
457 if (tcp->u_arg[1] == 0
458 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
459 || umove(tcp, tcp->u_arg[1], &copy) == -1)
460 tprintf(", %lx", tcp->u_arg[1]);
461 else {
462 tprintf(", {entry_number:%d, ", copy.entry_number);
463 if (!verbose(tcp))
464 tprintf("...}");
465 else {
466 tprintf("base_addr:%#08lx, "
467 "limit:%d, "
468 "seg_32bit:%d, "
469 "contents:%d, "
470 "read_exec_only:%d, "
471 "limit_in_pages:%d, "
472 "seg_not_present:%d, "
473 "useable:%d}",
474 copy.base_addr,
475 copy.limit,
476 copy.seg_32bit,
477 copy.contents,
478 copy.read_exec_only,
479 copy.limit_in_pages,
480 copy.seg_not_present,
481 copy.useable);
482 }
483 }
484 tprintf(", %lu", tcp->u_arg[2]);
485 }
486 return 0;
487}
488#endif /* LINUX && __i386__ */
489