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>
8 * Copyright (c) 1999-2018 The strace developers.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <linux/mman.h>
41 static unsigned long pagesize;
44 long ret = sysconf(_SC_PAGESIZE);
47 perror_func_msg_and_die("sysconf(_SC_PAGESIZE)");
49 error_func_msg_and_die("sysconf(_SC_PAGESIZE) "
52 pagesize = (unsigned long) ret;
60 printaddr(tcp->u_arg[0]);
62 return RVAL_DECODED | RVAL_HEX;
65 #include "xlat/mmap_prot.h"
66 #include "xlat/mmap_flags.h"
68 #ifndef MAP_HUGE_SHIFT
69 # define MAP_HUGE_SHIFT 26
73 # define MAP_HUGE_MASK 0x3f
77 print_mmap_flags(kernel_ulong_t flags)
79 printxval64(mmap_flags, flags & MAP_TYPE, "MAP_???");
82 const unsigned int mask = MAP_HUGE_MASK << MAP_HUGE_SHIFT;
83 const unsigned int hugetlb_value = flags & mask;
88 printflags64(mmap_flags, flags, NULL);
92 tprintf("|%u<<MAP_HUGE_SHIFT",
93 hugetlb_value >> MAP_HUGE_SHIFT);
97 print_mmap(struct tcb *tcp, kernel_ulong_t *u_arg, unsigned long long offset)
99 const kernel_ulong_t addr = u_arg[0];
100 const kernel_ulong_t len = u_arg[1];
101 const kernel_ulong_t prot = u_arg[2];
102 const kernel_ulong_t flags = u_arg[3];
103 const int fd = u_arg[4];
106 tprintf(", %" PRI_klu ", ", len);
107 printflags64(mmap_prot, prot, "PROT_???");
109 print_mmap_flags(flags);
112 tprintf(", %#llx", offset);
115 /* Syscall name<->function correspondence is messed up on many arches.
117 * i386 has __NR_mmap == 90, and it is "old mmap", and
118 * also it has __NR_mmap2 == 192, which is a "new mmap with page offsets".
119 * But x86_64 has just one __NR_mmap == 9, a "new mmap with byte offsets".
123 #if HAVE_ARCH_OLD_MMAP
124 /* Params are pointed to by u_arg[0], offset is in bytes */
127 kernel_ulong_t *args =
128 fetch_indirect_syscall_args(tcp, tcp->u_arg[0], 6);
131 print_mmap(tcp, args, args[5]);
133 printaddr(tcp->u_arg[0]);
135 return RVAL_DECODED | RVAL_HEX;
138 # if HAVE_ARCH_OLD_MMAP_PGOFF
139 /* Params are pointed to by u_arg[0], offset is in pages */
140 SYS_FUNC(old_mmap_pgoff)
142 kernel_ulong_t *args =
143 fetch_indirect_syscall_args(tcp, tcp->u_arg[0], 6);
146 unsigned long long offset;
149 offset *= get_pagesize();
151 print_mmap(tcp, args, offset);
153 printaddr(tcp->u_arg[0]);
156 return RVAL_DECODED | RVAL_HEX;
158 # endif /* HAVE_ARCH_OLD_MMAP_PGOFF */
159 #endif /* HAVE_ARCH_OLD_MMAP */
161 /* Params are passed directly, offset is in bytes */
164 /* Example of kernel-side handling of this variety of mmap:
165 * arch/x86/kernel/sys_x86_64.c::SYSCALL_DEFINE6(mmap, ...) calls
166 * sys_mmap_pgoff(..., off >> PAGE_SHIFT); i.e. off is in bytes,
167 * since the above code converts off to pages.
169 print_mmap(tcp, tcp->u_arg, tcp->u_arg[5]);
171 return RVAL_DECODED | RVAL_HEX;
174 /* Params are passed directly, offset is in pages */
177 /* Try test/mmap_offset_decode.c */
178 unsigned long long offset;
179 offset = tcp->u_arg[5];
180 offset *= get_pagesize();
181 print_mmap(tcp, tcp->u_arg, offset);
183 return RVAL_DECODED | RVAL_HEX;
186 /* Params are passed directly, offset is in 4k units */
189 unsigned long long offset;
190 offset = tcp->u_arg[5];
192 print_mmap(tcp, tcp->u_arg, offset);
194 return RVAL_DECODED | RVAL_HEX;
199 printaddr(tcp->u_arg[0]);
200 tprintf(", %" PRI_klu, tcp->u_arg[1]);
206 do_mprotect(struct tcb *tcp, bool has_pkey)
208 printaddr(tcp->u_arg[0]);
209 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
210 printflags64(mmap_prot, tcp->u_arg[2], "PROT_???");
213 tprintf(", %d", (int) tcp->u_arg[3]);
220 return do_mprotect(tcp, false);
223 SYS_FUNC(pkey_mprotect)
225 return do_mprotect(tcp, true);
228 #include "xlat/mremap_flags.h"
232 printaddr(tcp->u_arg[0]);
233 tprintf(", %" PRI_klu ", %" PRI_klu ", ", tcp->u_arg[1], tcp->u_arg[2]);
234 printflags64(mremap_flags, tcp->u_arg[3], "MREMAP_???");
236 if ((tcp->u_arg[3] & (MREMAP_MAYMOVE | MREMAP_FIXED)) ==
237 (MREMAP_MAYMOVE | MREMAP_FIXED)) {
239 printaddr(tcp->u_arg[4]);
242 return RVAL_DECODED | RVAL_HEX;
245 #include "xlat/madvise_cmds.h"
249 printaddr(tcp->u_arg[0]);
250 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
251 printxval(madvise_cmds, tcp->u_arg[2], "MADV_???");
256 #include "xlat/mlockall_flags.h"
260 printflags(mlockall_flags, tcp->u_arg[0], "MCL_???");
265 #include "xlat/mctl_sync.h"
270 printaddr(tcp->u_arg[0]);
272 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
274 printflags(mctl_sync, tcp->u_arg[2], "MS_???");
279 #include "xlat/mlock_flags.h"
283 printaddr(tcp->u_arg[0]);
284 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
285 printflags(mlock_flags, tcp->u_arg[2], "MLOCK_???");
293 printaddr(tcp->u_arg[0]);
294 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
296 const unsigned long page_size = get_pagesize();
297 const unsigned long page_mask = page_size - 1;
298 unsigned long len = tcp->u_arg[1];
299 unsigned char *vec = NULL;
301 len = len / page_size + (len & page_mask ? 1 : 0);
302 if (syserror(tcp) || !verbose(tcp) ||
303 !tcp->u_arg[2] || !(vec = malloc(len)) ||
304 umoven(tcp, tcp->u_arg[2], len, vec) < 0)
305 printaddr(tcp->u_arg[2]);
309 for (i = 0; i < len; i++) {
312 if (abbrev(tcp) && i >= max_strlen) {
316 tprints((vec[i] & 1) ? "1" : "0");
325 SYS_FUNC(remap_file_pages)
327 const kernel_ulong_t addr = tcp->u_arg[0];
328 const kernel_ulong_t size = tcp->u_arg[1];
329 const kernel_ulong_t prot = tcp->u_arg[2];
330 const kernel_ulong_t pgoff = tcp->u_arg[3];
331 const kernel_ulong_t flags = tcp->u_arg[4];
334 tprintf(", %" PRI_klu ", ", size);
335 printflags64(mmap_prot, prot, "PROT_???");
336 tprintf(", %" PRI_klu ", ", pgoff);
337 print_mmap_flags(flags);
344 print_protmap_entry(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
346 tprintf("%#08x", *(unsigned int *) elem_buf);
351 SYS_FUNC(subpage_prot)
353 kernel_ulong_t addr = tcp->u_arg[0];
354 kernel_ulong_t len = tcp->u_arg[1];
355 kernel_ulong_t nmemb = len >> 16;
356 kernel_ulong_t map = tcp->u_arg[2];
359 tprintf(", %" PRI_klu ", ", len);
362 print_array(tcp, map, nmemb, &entry, sizeof(entry),
363 umoven_or_printaddr, print_protmap_entry, 0);