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.
40 static unsigned long pagesize;
43 pagesize = sysconf(_SC_PAGESIZE);
49 printaddr(tcp->u_arg[0]);
51 return RVAL_DECODED | RVAL_HEX;
54 #include "xlat/mmap_prot.h"
55 #include "xlat/mmap_flags.h"
58 print_mmap(struct tcb *tcp, long *u_arg, unsigned long long offset)
60 const unsigned long addr = u_arg[0];
61 const unsigned long len = u_arg[1];
62 const unsigned long prot = u_arg[2];
63 const unsigned long flags = u_arg[3];
64 const int fd = u_arg[4];
67 tprintf(", %lu, ", len);
68 printflags_long(mmap_prot, prot, "PROT_???");
71 printxval_long(mmap_flags, flags & MAP_TYPE, "MAP_???");
72 addflags(mmap_flags, flags & ~MAP_TYPE);
74 printflags_long(mmap_flags, flags, "MAP_???");
78 tprintf(", %#llx", offset);
81 /* Syscall name<->function correspondence is messed up on many arches.
83 * i386 has __NR_mmap == 90, and it is "old mmap", and
84 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
85 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
89 #if defined AARCH64 || defined ARM \
90 || defined I386 || defined X86_64 || defined X32 \
92 || defined S390 || defined S390X
93 /* Params are pointed to by u_arg[0], offset is in bytes */
97 # if defined AARCH64 || defined X86_64
98 /* We are here only in a 32-bit personality. */
99 unsigned int narrow_arg[6];
100 if (umove_or_printaddr(tcp, tcp->u_arg[0], &narrow_arg))
101 return RVAL_DECODED | RVAL_HEX;
103 for (i = 0; i < 6; i++)
104 u_arg[i] = narrow_arg[i];
106 if (umove_or_printaddr(tcp, tcp->u_arg[0], &u_arg))
107 return RVAL_DECODED | RVAL_HEX;
109 print_mmap(tcp, u_arg, (unsigned long) u_arg[5]);
111 return RVAL_DECODED | RVAL_HEX;
113 #endif /* old_mmap architectures */
116 /* Params are pointed to by u_arg[0], offset is in pages */
117 SYS_FUNC(old_mmap_pgoff)
121 unsigned narrow_arg[6];
122 unsigned long long offset;
123 if (umoven(tcp, tcp->u_arg[0], sizeof(narrow_arg), narrow_arg) == -1)
125 for (i = 0; i < 5; i++)
126 u_arg[i] = (unsigned long) narrow_arg[i];
127 offset = narrow_arg[5];
128 offset *= get_pagesize();
129 print_mmap(tcp, u_arg, offset);
131 return RVAL_DECODED | RVAL_HEX;
135 /* Params are passed directly, offset is in bytes */
138 unsigned long long offset = (unsigned long) tcp->u_arg[5];
139 #if defined(LINUX_MIPSN32) || defined(X32)
140 /* Try test/x32_mmap.c */
141 offset = tcp->ext_arg[5];
143 /* Example of kernel-side handling of this variety of mmap:
144 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
145 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
146 * since the above code converts off to pages.
148 print_mmap(tcp, tcp->u_arg, offset);
150 return RVAL_DECODED | RVAL_HEX;
153 /* Params are passed directly, offset is in pages */
156 /* Try test/mmap_offset_decode.c */
157 unsigned long long offset;
158 offset = (unsigned long) tcp->u_arg[5];
159 offset *= get_pagesize();
160 print_mmap(tcp, tcp->u_arg, offset);
162 return RVAL_DECODED | RVAL_HEX;
165 /* Params are passed directly, offset is in 4k units */
168 unsigned long long offset;
169 offset = (unsigned long) tcp->u_arg[5];
171 print_mmap(tcp, tcp->u_arg, offset);
173 return RVAL_DECODED | RVAL_HEX;
178 printaddr(tcp->u_arg[0]);
179 tprintf(", %lu", tcp->u_arg[1]);
186 printaddr(tcp->u_arg[0]);
187 tprintf(", %lu, ", tcp->u_arg[1]);
188 printflags_long(mmap_prot, tcp->u_arg[2], "PROT_???");
193 #include "xlat/mremap_flags.h"
197 printaddr(tcp->u_arg[0]);
198 tprintf(", %lu, %lu, ", tcp->u_arg[1], tcp->u_arg[2]);
199 printflags_long(mremap_flags, tcp->u_arg[3], "MREMAP_???");
201 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
202 (MREMAP_MAYMOVE | MREMAP_FIXED)) {
204 printaddr(tcp->u_arg[4]);
207 return RVAL_DECODED | RVAL_HEX;
210 #include "xlat/madvise_cmds.h"
214 printaddr(tcp->u_arg[0]);
215 tprintf(", %lu, ", tcp->u_arg[1]);
216 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
221 #include "xlat/mlockall_flags.h"
225 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
230 #include "xlat/mctl_sync.h"
235 printaddr(tcp->u_arg[0]);
237 tprintf(", %lu, ", tcp->u_arg[1]);
239 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
244 #include "xlat/mlock_flags.h"
248 printaddr(tcp->u_arg[0]);
249 tprintf(", %lu, ", tcp->u_arg[1]);
250 printflags(mlock_flags, tcp->u_arg[2], "MLOCK_???");
258 printaddr(tcp->u_arg[0]);
259 tprintf(", %lu, ", tcp->u_arg[1]);
261 const unsigned long page_size = get_pagesize();
262 const unsigned long page_mask = page_size - 1;
263 unsigned long len = tcp->u_arg[1];
264 unsigned char *vec = NULL;
266 len = len / page_size + (len & page_mask ? 1 : 0);
267 if (syserror(tcp) || !verbose(tcp) ||
268 !tcp->u_arg[2] || !(vec = malloc(len)) ||
269 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
270 printaddr(tcp->u_arg[2]);
274 for (i = 0; i < len; i++) {
275 if (abbrev(tcp) && i >= max_strlen) {
279 tprints((vec[i] & 1) ? "1" : "0");
288 #if defined ALPHA || defined IA64 || defined M68K \
289 || defined SPARC || defined SPARC64
290 SYS_FUNC(getpagesize)
292 return RVAL_DECODED | RVAL_HEX;
296 SYS_FUNC(remap_file_pages)
298 const unsigned long addr = tcp->u_arg[0];
299 const unsigned long size = tcp->u_arg[1];
300 const unsigned long prot = tcp->u_arg[2];
301 const unsigned long pgoff = tcp->u_arg[3];
302 const unsigned long flags = tcp->u_arg[4];
305 tprintf(", %lu, ", size);
306 printflags_long(mmap_prot, prot, "PROT_???");
307 tprintf(", %lu, ", pgoff);
309 printxval_long(mmap_flags, flags & MAP_TYPE, "MAP_???");
310 addflags(mmap_flags, flags & ~MAP_TYPE);
312 printflags_long(mmap_flags, flags, "MAP_???");
320 print_protmap_entry(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
322 tprintf("%#08x", * (unsigned int *) elem_buf);
327 SYS_FUNC(subpage_prot)
329 unsigned long addr = tcp->u_arg[0];
330 unsigned long len = tcp->u_arg[1];
331 unsigned long nmemb = len >> 16;
332 unsigned long map = tcp->u_arg[2];
335 tprintf(", %lu, ", len);
338 print_array(tcp, map, nmemb, &entry, sizeof(entry),
339 umoven_or_printaddr, print_protmap_entry, 0);