blob: 7a394123c82341a403b0c6a5d7f324386a902c8b [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000034#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035#include <linux/mman.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000037#include <sys/mman.h>
Wichert Akkerman5daa0281999-03-15 19:49:42 +000038
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039#if defined(LINUX) && defined(__i386__)
Wichert Akkerman8bc6cfd1999-04-21 15:57:38 +000040#include <asm/ldt.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#endif
42
43int
44sys_brk(tcp)
45struct tcb *tcp;
46{
47 if (entering(tcp)) {
48 tprintf("%#lx", tcp->u_arg[0]);
49 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +000050#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051 return RVAL_HEX;
52#else
53 return 0;
54#endif
55}
56
57int
58sys_sbrk(tcp)
59struct tcb *tcp;
60{
61 if (entering(tcp)) {
62 tprintf("%lu", tcp->u_arg[0]);
63 }
64 return RVAL_HEX;
65}
66
67static struct xlat mmap_prot[] = {
68 { PROT_NONE, "PROT_NONE", },
69 { PROT_READ, "PROT_READ" },
70 { PROT_WRITE, "PROT_WRITE" },
71 { PROT_EXEC, "PROT_EXEC" },
72 { 0, NULL },
73};
74
75static struct xlat mmap_flags[] = {
76 { MAP_SHARED, "MAP_SHARED" },
77 { MAP_PRIVATE, "MAP_PRIVATE" },
78 { MAP_FIXED, "MAP_FIXED" },
79#ifdef MAP_ANONYMOUS
80 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
81#endif
82#ifdef MAP_RENAME
83 { MAP_RENAME, "MAP_RENAME" },
84#endif
85#ifdef MAP_NORESERVE
86 { MAP_NORESERVE,"MAP_NORESERVE" },
87#endif
88#ifdef _MAP_NEW
89 { _MAP_NEW, "_MAP_NEW" },
90#endif
91#ifdef MAP_GROWSDOWN
92 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
93#endif
94#ifdef MAP_DENYWRITE
95 { MAP_DENYWRITE,"MAP_DENYWRITE" },
96#endif
97#ifdef MAP_EXECUTABLE
98 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
99#endif
100#ifdef MAP_FILE
101 { MAP_FILE,"MAP_FILE"},
102#endif
103#ifdef MAP_LOCKED
104 { MAP_LOCKED,"MAP_LOCKED"},
105#endif
106 { 0, NULL },
107};
108
109int
110sys_mmap(tcp)
111struct tcb *tcp;
112{
113#ifdef LINUX
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000114# if defined(ALPHA) || defined(sparc)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115 long *u_arg = tcp->u_arg;
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000116# else /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117 long u_arg[6];
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000118# endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000119#else /* !LINUX */
120 long *u_arg = tcp->u_arg;
121#endif /* !LINUX */
122
123 if (entering(tcp)) {
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000124#if defined(LINUX) && !defined(ALPHA) && !defined(__sparc__)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
126 (char *) u_arg) == -1)
127 return 0;
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000128#endif /* LINUX && !ALPHA && !sparc */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129
130 /* addr */
131 tprintf("%#lx, ", u_arg[0]);
132 /* len */
133 tprintf("%lu, ", u_arg[1]);
134 /* prot */
135 printflags(mmap_prot, u_arg[2]);
136 tprintf(", ");
137 /* flags */
138 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
139 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
140 /* fd */
141 tprintf(", %ld, ", u_arg[4]);
142 /* offset */
143 tprintf("%#lx", u_arg[5]);
144 }
145 return RVAL_HEX;
146}
147
148int
149sys_munmap(tcp)
150struct tcb *tcp;
151{
152 if (entering(tcp)) {
153 tprintf("%#lx, %lu",
154 tcp->u_arg[0], tcp->u_arg[1]);
155 }
156 return 0;
157}
158
159int
160sys_mprotect(tcp)
161struct tcb *tcp;
162{
163 if (entering(tcp)) {
164 tprintf("%#lx, %lu, ",
165 tcp->u_arg[0], tcp->u_arg[1]);
166 if (!printflags(mmap_prot, tcp->u_arg[2]))
167 tprintf("PROT_???");
168 }
169 return 0;
170}
171
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000172#ifdef LINUX
173
174static struct xlat mremap_flags[] = {
175 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
176};
177
178int
179sys_mremap(tcp)
180struct tcb *tcp;
181{
182 if (entering(tcp)) {
183 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
184 tcp->u_arg[2]);
185 printflags(mremap_flags, tcp->u_arg[3]);
186 }
187 return RVAL_HEX;
188}
189
190#endif /* LINUX */
191
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000192#ifdef MS_ASYNC
193
194static struct xlat mctl_sync[] = {
195 { MS_ASYNC, "MS_ASYNC" },
196 { MS_INVALIDATE,"MS_INVALIDATE" },
197#ifdef MS_SYNC
198 { MS_SYNC, "MS_SYNC" },
199#endif
200 { 0, NULL },
201};
202
203int
204sys_msync(tcp)
205struct tcb *tcp;
206{
207 if (entering(tcp)) {
208 /* addr */
209 tprintf("%#lx", tcp->u_arg[0]);
210 /* len */
211 tprintf(", %lu, ", tcp->u_arg[1]);
212 /* flags */
213 if (!printflags(mctl_sync, tcp->u_arg[2]))
214 tprintf("MS_???");
215 }
216 return 0;
217}
218
219#endif /* MS_ASYNC */
220
221#ifdef MC_SYNC
222
223static struct xlat mctl_funcs[] = {
224 { MC_LOCK, "MC_LOCK" },
225 { MC_LOCKAS, "MC_LOCKAS" },
226 { MC_SYNC, "MC_SYNC" },
227 { MC_UNLOCK, "MC_UNLOCK" },
228 { MC_UNLOCKAS, "MC_UNLOCKAS" },
229 { 0, NULL },
230};
231
232static struct xlat mctl_lockas[] = {
233 { MCL_CURRENT, "MCL_CURRENT" },
234 { MCL_FUTURE, "MCL_FUTURE" },
235 { 0, NULL },
236};
237
238int
239sys_mctl(tcp)
240struct tcb *tcp;
241{
242 int arg, function;
243
244 if (entering(tcp)) {
245 /* addr */
246 tprintf("%#lx", tcp->u_arg[0]);
247 /* len */
248 tprintf(", %lu, ", tcp->u_arg[1]);
249 /* function */
250 function = tcp->u_arg[2];
251 if (!printflags(mctl_funcs, function))
252 tprintf("MC_???");
253 /* arg */
254 arg = tcp->u_arg[3];
255 tprintf(", ");
256 switch (function) {
257 case MC_SYNC:
258 if (!printflags(mctl_sync, arg))
259 tprintf("MS_???");
260 break;
261 case MC_LOCKAS:
262 if (!printflags(mctl_lockas, arg))
263 tprintf("MCL_???");
264 break;
265 default:
266 tprintf("%#x", arg);
267 break;
268 }
269 }
270 return 0;
271}
272
273#endif /* MC_SYNC */
274
275int
276sys_mincore(tcp)
277struct tcb *tcp;
278{
279 int i, len;
280 char *vec = NULL;
281
282 if (entering(tcp)) {
283 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
284 } else {
285 len = tcp->u_arg[1];
286 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
287 (vec = malloc((u_int)len)) == NULL ||
288 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
289 tprintf("%#lx", tcp->u_arg[2]);
290 else {
291 tprintf("[");
292 for (i = 0; i < len; i++) {
293 if (abbrev(tcp) && i >= max_strlen) {
294 tprintf("...");
295 break;
296 }
297 tprintf((vec[i] & 1) ? "1" : "0");
298 }
299 tprintf("]");
300 }
301 if (vec)
302 free(vec);
303 }
304 return 0;
305}
306
307int
308sys_getpagesize(tcp)
309struct tcb *tcp;
310{
311 if (exiting(tcp))
312 return RVAL_HEX;
313 return 0;
314}
315
316#if defined(LINUX) && defined(__i386__)
317int
318sys_modify_ldt(tcp)
319struct tcb *tcp;
320{
321 if (entering(tcp)) {
322 struct modify_ldt_ldt_s copy;
323 tprintf("%ld", tcp->u_arg[0]);
324 if (tcp->u_arg[1] == 0
325 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
326 || umove(tcp, tcp->u_arg[1], &copy) == -1)
327 tprintf(", %lx", tcp->u_arg[1]);
328 else {
329 tprintf(", {entry_number:%d, ", copy.entry_number);
330 if (!verbose(tcp))
331 tprintf("...}");
332 else {
333 tprintf("base_addr:%#08lx, "
334 "limit:%d, "
335 "seg_32bit:%d, "
336 "contents:%d, "
337 "read_exec_only:%d, "
338 "limit_in_pages:%d, "
339 "seg_not_present:%d, "
340 "useable:%d}",
341 copy.base_addr,
342 copy.limit,
343 copy.seg_32bit,
344 copy.contents,
345 copy.read_exec_only,
346 copy.limit_in_pages,
347 copy.seg_not_present,
348 copy.useable);
349 }
350 }
351 tprintf(", %lu", tcp->u_arg[2]);
352 }
353 return 0;
354}
355#endif /* LINUX && __i386__ */
356