blob: b4e0e6c74d4045ba396b9cbabd8fbbf577c18b72 [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
174 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
175 return 0;
176 return print_mmap(tcp, u_arg);
177
178}
179#endif
180
181int
182sys_mmap(tcp)
183struct tcb *tcp;
184{
185 return print_mmap(tcp, tcp->u_arg);
186}
187
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188int
189sys_munmap(tcp)
190struct tcb *tcp;
191{
192 if (entering(tcp)) {
193 tprintf("%#lx, %lu",
194 tcp->u_arg[0], tcp->u_arg[1]);
195 }
196 return 0;
197}
198
199int
200sys_mprotect(tcp)
201struct tcb *tcp;
202{
203 if (entering(tcp)) {
204 tprintf("%#lx, %lu, ",
205 tcp->u_arg[0], tcp->u_arg[1]);
206 if (!printflags(mmap_prot, tcp->u_arg[2]))
207 tprintf("PROT_???");
208 }
209 return 0;
210}
211
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000212#ifdef LINUX
213
214static struct xlat mremap_flags[] = {
215 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
216};
217
218int
219sys_mremap(tcp)
220struct tcb *tcp;
221{
222 if (entering(tcp)) {
223 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
224 tcp->u_arg[2]);
225 printflags(mremap_flags, tcp->u_arg[3]);
226 }
227 return RVAL_HEX;
228}
229
230#endif /* LINUX */
231
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232#ifdef MS_ASYNC
233
234static struct xlat mctl_sync[] = {
235 { MS_ASYNC, "MS_ASYNC" },
236 { MS_INVALIDATE,"MS_INVALIDATE" },
237#ifdef MS_SYNC
238 { MS_SYNC, "MS_SYNC" },
239#endif
240 { 0, NULL },
241};
242
243int
244sys_msync(tcp)
245struct tcb *tcp;
246{
247 if (entering(tcp)) {
248 /* addr */
249 tprintf("%#lx", tcp->u_arg[0]);
250 /* len */
251 tprintf(", %lu, ", tcp->u_arg[1]);
252 /* flags */
253 if (!printflags(mctl_sync, tcp->u_arg[2]))
254 tprintf("MS_???");
255 }
256 return 0;
257}
258
259#endif /* MS_ASYNC */
260
261#ifdef MC_SYNC
262
263static struct xlat mctl_funcs[] = {
264 { MC_LOCK, "MC_LOCK" },
265 { MC_LOCKAS, "MC_LOCKAS" },
266 { MC_SYNC, "MC_SYNC" },
267 { MC_UNLOCK, "MC_UNLOCK" },
268 { MC_UNLOCKAS, "MC_UNLOCKAS" },
269 { 0, NULL },
270};
271
272static struct xlat mctl_lockas[] = {
273 { MCL_CURRENT, "MCL_CURRENT" },
274 { MCL_FUTURE, "MCL_FUTURE" },
275 { 0, NULL },
276};
277
278int
279sys_mctl(tcp)
280struct tcb *tcp;
281{
282 int arg, function;
283
284 if (entering(tcp)) {
285 /* addr */
286 tprintf("%#lx", tcp->u_arg[0]);
287 /* len */
288 tprintf(", %lu, ", tcp->u_arg[1]);
289 /* function */
290 function = tcp->u_arg[2];
291 if (!printflags(mctl_funcs, function))
292 tprintf("MC_???");
293 /* arg */
294 arg = tcp->u_arg[3];
295 tprintf(", ");
296 switch (function) {
297 case MC_SYNC:
298 if (!printflags(mctl_sync, arg))
299 tprintf("MS_???");
300 break;
301 case MC_LOCKAS:
302 if (!printflags(mctl_lockas, arg))
303 tprintf("MCL_???");
304 break;
305 default:
306 tprintf("%#x", arg);
307 break;
308 }
309 }
310 return 0;
311}
312
313#endif /* MC_SYNC */
314
315int
316sys_mincore(tcp)
317struct tcb *tcp;
318{
319 int i, len;
320 char *vec = NULL;
321
322 if (entering(tcp)) {
323 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
324 } else {
325 len = tcp->u_arg[1];
326 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
327 (vec = malloc((u_int)len)) == NULL ||
328 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
329 tprintf("%#lx", tcp->u_arg[2]);
330 else {
331 tprintf("[");
332 for (i = 0; i < len; i++) {
333 if (abbrev(tcp) && i >= max_strlen) {
334 tprintf("...");
335 break;
336 }
337 tprintf((vec[i] & 1) ? "1" : "0");
338 }
339 tprintf("]");
340 }
341 if (vec)
342 free(vec);
343 }
344 return 0;
345}
346
347int
348sys_getpagesize(tcp)
349struct tcb *tcp;
350{
351 if (exiting(tcp))
352 return RVAL_HEX;
353 return 0;
354}
355
356#if defined(LINUX) && defined(__i386__)
357int
358sys_modify_ldt(tcp)
359struct tcb *tcp;
360{
361 if (entering(tcp)) {
362 struct modify_ldt_ldt_s copy;
363 tprintf("%ld", tcp->u_arg[0]);
364 if (tcp->u_arg[1] == 0
365 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
366 || umove(tcp, tcp->u_arg[1], &copy) == -1)
367 tprintf(", %lx", tcp->u_arg[1]);
368 else {
369 tprintf(", {entry_number:%d, ", copy.entry_number);
370 if (!verbose(tcp))
371 tprintf("...}");
372 else {
373 tprintf("base_addr:%#08lx, "
374 "limit:%d, "
375 "seg_32bit:%d, "
376 "contents:%d, "
377 "read_exec_only:%d, "
378 "limit_in_pages:%d, "
379 "seg_not_present:%d, "
380 "useable:%d}",
381 copy.base_addr,
382 copy.limit,
383 copy.seg_32bit,
384 copy.contents,
385 copy.read_exec_only,
386 copy.limit_in_pages,
387 copy.seg_not_present,
388 copy.useable);
389 }
390 }
391 tprintf(", %lu", tcp->u_arg[2]);
392 }
393 return 0;
394}
395#endif /* LINUX && __i386__ */
396