2 * Check decoding of remap_file_pages syscall.
4 * Copyright (c) 2016-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016-2018 The strace developers.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
32 #include <asm/unistd.h>
35 #ifdef __NR_remap_file_pages
40 # include <linux/mman.h>
42 static const char *errstr;
45 k_remap_file_pages(const kernel_ulong_t addr,
46 const kernel_ulong_t size,
47 const kernel_ulong_t prot,
48 const kernel_ulong_t pgoff,
49 const kernel_ulong_t flags)
51 const long rc = syscall(__NR_remap_file_pages,
52 addr, size, prot, pgoff, flags);
53 errstr = sprintrc(rc);
60 kernel_ulong_t addr = (kernel_ulong_t) 0xfacefeeddeadbeefULL;
61 kernel_ulong_t size = (kernel_ulong_t) 0xdefaced1bad2f00dULL;
62 kernel_ulong_t prot = PROT_READ|PROT_WRITE|PROT_EXEC;
63 kernel_ulong_t pgoff = (kernel_ulong_t) 0xcaf3babebad4deedULL;
64 kernel_ulong_t flags = MAP_PRIVATE|MAP_ANONYMOUS;
65 # define prot1_str "PROT_READ|PROT_WRITE|PROT_EXEC"
66 # define flags1_str "MAP_PRIVATE|MAP_ANONYMOUS"
68 k_remap_file_pages(addr, size, prot, pgoff, flags);
70 printf("remap_file_pages(%#jx, %ju, %#jx, %ju, %#jx) = %s\n",
71 (uintmax_t) addr, (uintmax_t) size, (uintmax_t) prot,
72 (uintmax_t) pgoff, (uintmax_t) flags, errstr);
74 printf("remap_file_pages(%#jx, %ju, %#jx /* %s */, %ju, %#jx /* %s */)"
76 (uintmax_t) addr, (uintmax_t) size, (uintmax_t) prot, prot1_str,
77 (uintmax_t) pgoff, (uintmax_t) flags,
79 # else /* XLAT_ABBREV */
80 printf("remap_file_pages(%#jx, %ju, %s, %ju, %s) = %s\n",
81 (uintmax_t) addr, (uintmax_t) size, prot1_str,
82 (uintmax_t) pgoff, flags1_str, errstr);
87 # ifndef MAP_HUGE_SHIFT
88 # define MAP_HUGE_SHIFT 26
90 # define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT)
91 # endif /* !MAP_HUGE_2MB */
92 addr = (kernel_ulong_t) 0xfacefeeddeadf00dULL;
93 size = (kernel_ulong_t) 0xdefaced1bad2beefULL;
94 prot = (kernel_ulong_t) 0xdefaced00000000ULL | PROT_NONE;
95 flags = MAP_TYPE | MAP_FIXED | MAP_NORESERVE | MAP_HUGETLB | MAP_HUGE_2MB;
97 k_remap_file_pages(addr, size, prot, pgoff, flags);
100 * HP PA-RISC is the only architecture that has MAP_TYPE defined to 0x3, which
101 * is also used for MAP_SHARED_VALIDATE since Linux commit v4.15-rc1~71^2^2~23.
104 # define MAP_TYPE_str "MAP_SHARED_VALIDATE"
106 # define MAP_TYPE_str "0xf /* MAP_??? */"
108 # define flags2_str \
109 MAP_TYPE_str "|MAP_FIXED|MAP_NORESERVE|MAP_HUGETLB|21<<MAP_HUGE_SHIFT"
112 printf("remap_file_pages(%#jx, %ju, %#jx, %ju, %#jx) = %s\n",
113 (uintmax_t) addr, (uintmax_t) size, (uintmax_t) prot,
114 (uintmax_t) pgoff, (uintmax_t) flags, errstr);
116 printf("remap_file_pages(%#jx, %ju, %#jx /* %s */, %ju, %#jx /* %s */)"
118 (uintmax_t) addr, (uintmax_t) size, (uintmax_t) prot,
119 prot == PROT_NONE ? "PROT_NONE" : "PROT_???",
120 (uintmax_t) pgoff, (uintmax_t) flags, flags2_str, errstr);
121 # else /* XLAT_ABBREV */
122 printf("remap_file_pages(%#jx, %ju, %s, %ju, %s) = %s\n",
123 (uintmax_t) addr, (uintmax_t) size,
124 prot == PROT_NONE ? "PROT_NONE" :
125 "0xdefaced00000000 /* PROT_??? */",
126 (uintmax_t) pgoff, flags2_str, errstr);
128 #endif /* MAP_HUGETLB */
130 puts("+++ exited with 0 +++");
136 SKIP_MAIN_UNDEFINED("__NR_remap_file_pages")