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 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
7 * port by Greg Banks <gbanks@pocketpenguins.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #if defined(LINUX) && defined(I386)
44 # ifdef HAVE_STRUCT_USER_DESC
45 # define modify_ldt_ldt_s user_desc
48 #if defined(LINUX) && defined(SH64)
49 #include <asm/page.h> /* for PAGE_SHIFT */
52 #ifdef HAVE_LONG_LONG_OFF_T
54 * Ugly hacks for systems that have a long long off_t
56 #define sys_mmap64 sys_mmap
64 tprintf("%#lx", tcp->u_arg[0]);
78 tprintf("%lu", tcp->u_arg[0]);
83 static const struct xlat mmap_prot[] = {
84 { PROT_NONE, "PROT_NONE", },
85 { PROT_READ, "PROT_READ" },
86 { PROT_WRITE, "PROT_WRITE" },
87 { PROT_EXEC, "PROT_EXEC" },
89 { PROT_SEM, "PROT_SEM" },
92 { PROT_GROWSDOWN,"PROT_GROWSDOWN"},
95 { PROT_GROWSUP, "PROT_GROWSUP" },
100 static const struct xlat mmap_flags[] = {
101 { MAP_SHARED, "MAP_SHARED" },
102 { MAP_PRIVATE, "MAP_PRIVATE" },
103 { MAP_FIXED, "MAP_FIXED" },
105 { MAP_ANONYMOUS,"MAP_ANONYMOUS" },
108 { MAP_RENAME, "MAP_RENAME" },
111 { MAP_NORESERVE,"MAP_NORESERVE" },
114 { MAP_POPULATE, "MAP_POPULATE" },
117 { MAP_NONBLOCK, "MAP_NONBLOCK" },
120 * XXX - this was introduced in SunOS 4.x to distinguish between
121 * the old pre-4.x "mmap()", which:
123 * only let you map devices with an "mmap" routine (e.g.,
126 * required you to specify the mapping address;
128 * returned 0 on success and -1 on failure;
130 * memory and which, and the 4.x "mmap()" which:
132 * can map plain files;
134 * can be asked to pick where to map the file;
136 * returns the address where it mapped the file on success
139 * It's not actually used in source code that calls "mmap()"; the
140 * "mmap()" routine adds it for you.
142 * It'd be nice to come up with some way of eliminating it from
143 * the flags, e.g. reporting calls *without* it as "old_mmap()"
144 * and calls with it as "mmap()".
147 { _MAP_NEW, "_MAP_NEW" },
150 { MAP_GROWSDOWN,"MAP_GROWSDOWN" },
153 { MAP_DENYWRITE,"MAP_DENYWRITE" },
155 #ifdef MAP_EXECUTABLE
156 { MAP_EXECUTABLE,"MAP_EXECUTABLE"},
159 { MAP_INHERIT,"MAP_INHERIT" },
162 { MAP_FILE,"MAP_FILE"},
165 { MAP_LOCKED,"MAP_LOCKED"},
169 { MAP_ANON, "MAP_ANON" },
171 #ifdef MAP_HASSEMAPHORE
172 { MAP_HASSEMAPHORE, "MAP_HASSEMAPHORE" },
175 { MAP_STACK, "MAP_STACK" },
178 { MAP_NOSYNC, "MAP_NOSYNC" },
181 { MAP_NOCORE, "MAP_NOCORE" },
186 #if !HAVE_LONG_LONG_OFF_T
189 print_mmap(tcp,u_arg)
198 tprintf("%#lx, ", u_arg[0]);
200 tprintf("%lu, ", u_arg[1]);
202 printflags(mmap_prot, u_arg[2]);
206 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
207 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
209 printflags(mmap_flags, u_arg[3]);
211 /* fd (is always int, not long) */
212 tprintf(", %d, ", (int)u_arg[4]);
214 tprintf("%#lx", u_arg[5]);
220 int sys_old_mmap(tcp)
228 * IA64 processes never call this routine, they only use the
229 * new `sys_mmap' interface. This code converts the integer
230 * arguments that the IA32 process pushed onto the stack into
233 * Note that addresses with bit 31 set will be sign extended.
234 * Fortunately, those addresses are not currently being generated
235 * for IA32 processes so it's not a problem.
237 for (i = 0; i < 6; i++)
238 if (umove(tcp, tcp->u_arg[0] + (i * sizeof(int)), &v) == -1)
242 #elif defined(SH) || defined(SH64)
243 /* SH has always passed the args in registers */
246 u_arg[i] = tcp->u_arg[i];
248 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg, (char *) u_arg) == -1)
250 #endif // defined(IA64)
251 return print_mmap(tcp, u_arg);
260 #if defined(LINUX) && defined(SH64)
262 * Old mmap differs from new mmap in specifying the
263 * offset in units of bytes rather than pages. We
264 * pretend it's in byte units so the user only ever
265 * sees bytes in the printout.
267 tcp->u_arg[5] <<= PAGE_SHIFT;
269 return print_mmap(tcp, tcp->u_arg);
271 #endif /* !HAVE_LONG_LONG_OFF_T */
273 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
280 long *u_arg = tcp->u_arg;
285 long *u_arg = tcp->u_arg;
291 if (umoven(tcp, tcp->u_arg[0], sizeof u_arg,
292 (char *) u_arg) == -1)
296 ALIGN64 (tcp, 5); /* FreeBSD wierdies */
299 tprintf("%#lx, ", u_arg[0]);
301 tprintf("%lu, ", u_arg[1]);
303 printflags(mmap_prot, u_arg[2]);
307 printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
308 addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
310 printflags(mmap_flags, u_arg[3]);
313 tprintf(", %ld, ", u_arg[4]);
315 tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
328 tcp->u_arg[0], tcp->u_arg[1]);
338 tprintf("%#lx, %lu, ",
339 tcp->u_arg[0], tcp->u_arg[1]);
340 if (!printflags(mmap_prot, tcp->u_arg[2]))
348 static const struct xlat mremap_flags[] = {
349 { MREMAP_MAYMOVE, "MREMAP_MAYMOVE" },
358 tprintf("%#lx, %lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1],
360 printflags(mremap_flags, tcp->u_arg[3]);
365 static const struct xlat madvise_flags[] = {
367 { MADV_NORMAL, "MADV_NORMAL" },
370 { MADV_RANDOM, "MADV_RANDOM" },
372 #ifdef MADV_SEQUENTIAL
373 { MADV_SEQUENTIAL, "MADV_SEQUENTIAL" },
376 { MADV_WILLNEED, "MADV_WILLNEED" },
379 { MADV_DONTNEED, "MADV_DONTNEED" },
390 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
391 printflags(madvise_flags, tcp->u_arg[2]);
397 static const struct xlat mlockall_flags[] = {
399 { MCL_CURRENT, "MCL_CURRENT" },
402 { MCL_FUTURE, "MCL_FUTURE" },
412 printflags(mlockall_flags, tcp->u_arg[0]);
422 static const struct xlat mctl_sync[] = {
424 { MS_SYNC, "MS_SYNC" },
426 { MS_ASYNC, "MS_ASYNC" },
427 { MS_INVALIDATE,"MS_INVALIDATE" },
437 tprintf("%#lx", tcp->u_arg[0]);
439 tprintf(", %lu, ", tcp->u_arg[1]);
441 if (!printflags(mctl_sync, tcp->u_arg[2]))
447 #endif /* MS_ASYNC */
451 static const struct xlat mctl_funcs[] = {
452 { MC_LOCK, "MC_LOCK" },
453 { MC_LOCKAS, "MC_LOCKAS" },
454 { MC_SYNC, "MC_SYNC" },
455 { MC_UNLOCK, "MC_UNLOCK" },
456 { MC_UNLOCKAS, "MC_UNLOCKAS" },
460 static const struct xlat mctl_lockas[] = {
461 { MCL_CURRENT, "MCL_CURRENT" },
462 { MCL_FUTURE, "MCL_FUTURE" },
474 tprintf("%#lx", tcp->u_arg[0]);
476 tprintf(", %lu, ", tcp->u_arg[1]);
478 function = tcp->u_arg[2];
479 if (!printflags(mctl_funcs, function))
486 if (!printflags(mctl_sync, arg))
490 if (!printflags(mctl_lockas, arg))
511 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
514 if (syserror(tcp) || tcp->u_arg[2] == 0 ||
515 (vec = malloc((u_int)len)) == NULL ||
516 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
517 tprintf("%#lx", tcp->u_arg[2]);
520 for (i = 0; i < len; i++) {
521 if (abbrev(tcp) && i >= max_strlen) {
525 tprintf((vec[i] & 1) ? "1" : "0");
544 #if defined(LINUX) && defined(__i386__)
546 print_ldt_entry (ldt_entry)
547 struct modify_ldt_ldt_s *ldt_entry;
549 tprintf("base_addr:%#08lx, "
553 "read_exec_only:%d, "
554 "limit_in_pages:%d, "
555 "seg_not_present:%d, "
557 ldt_entry->base_addr,
559 ldt_entry->seg_32bit,
561 ldt_entry->read_exec_only,
562 ldt_entry->limit_in_pages,
563 ldt_entry->seg_not_present,
572 struct modify_ldt_ldt_s copy;
573 tprintf("%ld", tcp->u_arg[0]);
574 if (tcp->u_arg[1] == 0
575 || tcp->u_arg[2] != sizeof (struct modify_ldt_ldt_s)
576 || umove(tcp, tcp->u_arg[1], ©) == -1)
577 tprintf(", %lx", tcp->u_arg[1]);
579 tprintf(", {entry_number:%d, ", copy.entry_number);
583 print_ldt_entry(©);
586 tprintf(", %lu", tcp->u_arg[2]);
592 sys_set_thread_area(tcp)
595 struct modify_ldt_ldt_s copy;
597 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
598 if (copy.entry_number == -1)
599 tprintf("{entry_number:%d -> ",
602 tprintf("{entry_number:");
605 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
606 tprintf("%d, ", copy.entry_number);
610 print_ldt_entry(©);
613 tprintf("%lx", tcp->u_arg[0]);
621 sys_get_thread_area(tcp)
624 struct modify_ldt_ldt_s copy;
626 if (umove(tcp, tcp->u_arg[0], ©) != -1) {
627 tprintf("{entry_number:%d, ", copy.entry_number);
631 print_ldt_entry(©);
634 tprintf("%lx", tcp->u_arg[0]);
640 #endif /* LINUX && __i386__ */
644 sys_remap_file_pages(tcp)
648 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
649 printflags(mmap_prot, tcp->u_arg[2]);
650 tprintf(", %lu, ", tcp->u_arg[3]);
652 printxval(mmap_flags, tcp->u_arg[4] & MAP_TYPE, "MAP_???");
653 addflags(mmap_flags, tcp->u_arg[4] & ~MAP_TYPE);
655 printflags(mmap_flags, tcp->u_arg[4]);