blob: 73a72fcc2a140ccf06fd6185ea50448d34f966a4 [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
137 { 0, NULL },
138};
139
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000140static
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141int
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000142print_mmap(tcp,u_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143struct tcb *tcp;
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000144long *u_arg;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147 /* addr */
Wichert Akkerman8829a551999-06-11 13:18:40 +0000148 if (!u_arg[0])
149 tprintf("NULL, ");
150 else
151 tprintf("%#lx, ", u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000152 /* len */
153 tprintf("%lu, ", u_arg[1]);
154 /* prot */
155 printflags(mmap_prot, u_arg[2]);
156 tprintf(", ");
157 /* flags */
158 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
159 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
160 /* fd */
161 tprintf(", %ld, ", u_arg[4]);
162 /* offset */
163 tprintf("%#lx", u_arg[5]);
164 }
165 return RVAL_HEX;
166}
167
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000168#ifdef LINUX
169int sys_old_mmap(tcp)
170struct tcb *tcp;
171{
172 long u_arg[6];
173
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000174#if defined(IA64)
Wichert Akkerman12f75d12000-02-14 16:23:40 +0000175 int i, v;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000176 /*
177 * IA64 processes never call this routine, they only use the
178 * new `sys_mmap' interface. This code converts the integer
179 * arguments that the IA32 process pushed onto the stack into
180 * longs.
181 *
182 * Note that addresses with bit 31 set will be sign extended.
183 * Fortunately, those addresses are not currently being generated
184 * for IA32 processes so it's not a problem.
185 */
186 for (i = 0; i < 6; i++)
187 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
188 return 0;
189 else
190 u_arg[i] = v;
191#else // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000192 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
193 return 0;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000194#endif // defined(IA64)
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000195 return print_mmap(tcp, u_arg);
196
197}
198#endif
199
200int
201sys_mmap(tcp)
202struct tcb *tcp;
203{
204 return print_mmap(tcp, tcp->u_arg);
205}
206
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000207int
208sys_munmap(tcp)
209struct tcb *tcp;
210{
211 if (entering(tcp)) {
212 tprintf("%#lx, %lu",
213 tcp->u_arg[0], tcp->u_arg[1]);
214 }
215 return 0;
216}
217
218int
219sys_mprotect(tcp)
220struct tcb *tcp;
221{
222 if (entering(tcp)) {
223 tprintf("%#lx, %lu, ",
224 tcp->u_arg[0], tcp->u_arg[1]);
225 if (!printflags(mmap_prot, tcp->u_arg[2]))
226 tprintf("PROT_???");
227 }
228 return 0;
229}
230
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000231#ifdef LINUX
232
233static struct xlat mremap_flags[] = {
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +0000234 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
235 { 0, NULL }
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000236};
237
238int
239sys_mremap(tcp)
240struct tcb *tcp;
241{
242 if (entering(tcp)) {
243 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
244 tcp->u_arg[2]);
245 printflags(mremap_flags, tcp->u_arg[3]);
246 }
247 return RVAL_HEX;
248}
249
Wichert Akkermanc7926982000-04-10 22:22:31 +0000250static struct xlat madvise_flags[] = {
251#ifdef MADV_NORMAL
252 { MADV_NORMAL, "MADV_NORMAL" },
253#endif
254#ifdef MADZV_RANDOM
255 { MADV_RANDOM, "MADV_RANDOM" },
256#endif
257#ifdef MADV_SEQUENTIAL
258 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
259#endif
260#ifdef MADV_WILLNEED
261 { MADV_WILLNEED, "MADV_WILLNEED" },
262#endif
263#ifdef MADV_DONTNED
264 { MADV_DONTNEED, "MADV_DONTNEED" },
265#endif
266 { 0, NULL },
267};
268
269
270int
271sys_madvise(tcp)
272struct tcb *tcp;
273{
274 if (entering(tcp)) {
275 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
276 printflags(madvise_flags, tcp->u_arg[2]);
277 }
278 return 0;
279}
280
281
282static struct xlat mlockall_flags[] = {
283#ifdef MCL_CURRENT
284 { MCL_CURRENT, "MCL_CURRENT" },
285#endif
286#ifdef MCL_FUTURE
287 { MCL_FUTURE, "MCL_FUTURE" },
288#endif
289 { 0, NULL}
290};
291
292int
293sys_mlockall(tcp)
294struct tcb *tcp;
295{
296 if (entering(tcp)) {
297 printflags(mlockall_flags, tcp->u_arg[0]);
298 }
299 return 0;
300}
301
302
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000303#endif /* LINUX */
304
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305#ifdef MS_ASYNC
306
307static struct xlat mctl_sync[] = {
308 { MS_ASYNC, "MS_ASYNC" },
309 { MS_INVALIDATE,"MS_INVALIDATE" },
310#ifdef MS_SYNC
311 { MS_SYNC, "MS_SYNC" },
312#endif
313 { 0, NULL },
314};
315
316int
317sys_msync(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 /* addr */
322 tprintf("%#lx", tcp->u_arg[0]);
323 /* len */
324 tprintf(", %lu, ", tcp->u_arg[1]);
325 /* flags */
326 if (!printflags(mctl_sync, tcp->u_arg[2]))
327 tprintf("MS_???");
328 }
329 return 0;
330}
331
332#endif /* MS_ASYNC */
333
334#ifdef MC_SYNC
335
336static struct xlat mctl_funcs[] = {
337 { MC_LOCK, "MC_LOCK" },
338 { MC_LOCKAS, "MC_LOCKAS" },
339 { MC_SYNC, "MC_SYNC" },
340 { MC_UNLOCK, "MC_UNLOCK" },
341 { MC_UNLOCKAS, "MC_UNLOCKAS" },
342 { 0, NULL },
343};
344
345static struct xlat mctl_lockas[] = {
346 { MCL_CURRENT, "MCL_CURRENT" },
347 { MCL_FUTURE, "MCL_FUTURE" },
348 { 0, NULL },
349};
350
351int
352sys_mctl(tcp)
353struct tcb *tcp;
354{
355 int arg, function;
356
357 if (entering(tcp)) {
358 /* addr */
359 tprintf("%#lx", tcp->u_arg[0]);
360 /* len */
361 tprintf(", %lu, ", tcp->u_arg[1]);
362 /* function */
363 function = tcp->u_arg[2];
364 if (!printflags(mctl_funcs, function))
365 tprintf("MC_???");
366 /* arg */
367 arg = tcp->u_arg[3];
368 tprintf(", ");
369 switch (function) {
370 case MC_SYNC:
371 if (!printflags(mctl_sync, arg))
372 tprintf("MS_???");
373 break;
374 case MC_LOCKAS:
375 if (!printflags(mctl_lockas, arg))
376 tprintf("MCL_???");
377 break;
378 default:
379 tprintf("%#x", arg);
380 break;
381 }
382 }
383 return 0;
384}
385
386#endif /* MC_SYNC */
387
388int
389sys_mincore(tcp)
390struct tcb *tcp;
391{
392 int i, len;
393 char *vec = NULL;
394
395 if (entering(tcp)) {
396 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
397 } else {
398 len = tcp->u_arg[1];
399 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
400 (vec = malloc((u_int)len)) == NULL ||
401 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
402 tprintf("%#lx", tcp->u_arg[2]);
403 else {
404 tprintf("[");
405 for (i = 0; i < len; i++) {
406 if (abbrev(tcp) && i >= max_strlen) {
407 tprintf("...");
408 break;
409 }
410 tprintf((vec[i] & 1) ? "1" : "0");
411 }
412 tprintf("]");
413 }
414 if (vec)
415 free(vec);
416 }
417 return 0;
418}
419
420int
421sys_getpagesize(tcp)
422struct tcb *tcp;
423{
424 if (exiting(tcp))
425 return RVAL_HEX;
426 return 0;
427}
428
429#if defined(LINUX) && defined(__i386__)
430int
431sys_modify_ldt(tcp)
432struct tcb *tcp;
433{
434 if (entering(tcp)) {
435 struct modify_ldt_ldt_s copy;
436 tprintf("%ld", tcp->u_arg[0]);
437 if (tcp->u_arg[1] == 0
438 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
439 || umove(tcp, tcp->u_arg[1], &copy) == -1)
440 tprintf(", %lx", tcp->u_arg[1]);
441 else {
442 tprintf(", {entry_number:%d, ", copy.entry_number);
443 if (!verbose(tcp))
444 tprintf("...}");
445 else {
446 tprintf("base_addr:%#08lx, "
447 "limit:%d, "
448 "seg_32bit:%d, "
449 "contents:%d, "
450 "read_exec_only:%d, "
451 "limit_in_pages:%d, "
452 "seg_not_present:%d, "
453 "useable:%d}",
454 copy.base_addr,
455 copy.limit,
456 copy.seg_32bit,
457 copy.contents,
458 copy.read_exec_only,
459 copy.limit_in_pages,
460 copy.seg_not_present,
461 copy.useable);
462 }
463 }
464 tprintf(", %lu", tcp->u_arg[2]);
465 }
466 return 0;
467}
468#endif /* LINUX && __i386__ */
469