2 * Check decoding of get_mempolicy syscall.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
31 #include <asm/unistd.h>
33 #ifdef __NR_get_mempolicy
39 # include "xlat/policies.h"
42 # define NLONGS(n) ((n + 8 * sizeof(long) - 2) \
46 print_nodes(unsigned long maxnode)
48 unsigned long *const nodemask =
49 tail_alloc(sizeof(*nodemask) * NLONGS(maxnode));
51 if (syscall(__NR_get_mempolicy, 0, nodemask, maxnode, 0, 0)) {
52 printf("get_mempolicy(NULL, %p, %lu, NULL, 0) = -1 %s (%m)\n",
53 nodemask, maxnode, errno2name());
57 printf("get_mempolicy(NULL, [");
59 unsigned int nlongs = NLONGS(maxnode);
61 for (i = 0; i < nlongs; ++i) {
64 if (i >= MAX_STRLEN) {
68 printf("%#0*lx", (int) sizeof(*nodemask) * 2 + 2, nodemask[i]);
71 printf("], %lu, NULL, 0) = 0\n", maxnode);
79 if (syscall(__NR_get_mempolicy, 0, 0, 0, 0, 0))
80 perror_msg_and_skip("get_mempolicy");
81 puts("get_mempolicy(NULL, NULL, 0, NULL, 0) = 0");
83 int *mode = (void *) 0xdefaced1baddeed2;
84 unsigned long maxnode = (unsigned long) 0xcafef00dbadc0dedULL;
85 const unsigned long *nodemask = (void *) 0xfacedad3bebefed4ULL;
86 const unsigned long addr = (unsigned long) 0xfacefeeddeadbeefULL;
87 const unsigned long flags = -1U;
88 rc = syscall(__NR_get_mempolicy, mode, nodemask, maxnode, addr, flags);
89 printf("get_mempolicy(%p, %p, %lu, %#lx, %s|%#lx) = %ld %s (%m)\n",
90 mode, nodemask, maxnode, addr,
91 "MPOL_F_NODE|MPOL_F_ADDR",
92 flags & ~3, rc, errno2name());
94 mode = tail_alloc(sizeof(*mode));
96 rc = syscall(__NR_get_mempolicy, mode, 0, 0, 0, 0);
97 printf("get_mempolicy([");
98 printxval(policies, (unsigned) *mode, "MPOL_???");
99 printf("], NULL, 0, NULL, 0) = %ld\n", rc);
102 rc = syscall(__NR_get_mempolicy, mode, 0, 0, mode - 1, 2);
103 printf("get_mempolicy([");
104 printxval(policies, (unsigned) *mode, "MPOL_???");
105 printf("], NULL, 0, %p, MPOL_F_ADDR) = %ld\n", mode - 1, rc);
107 maxnode = get_page_size() * 8;
109 print_nodes(maxnode);
110 print_nodes(maxnode + 1);
111 print_nodes(maxnode + 2);
113 maxnode = sizeof(*nodemask) * 8;
114 print_nodes(maxnode - 1);
115 print_nodes(maxnode );
116 print_nodes(maxnode + 1);
117 print_nodes(maxnode + 2);
118 print_nodes(maxnode * 2 - 1);
119 print_nodes(maxnode * 2 );
120 print_nodes(maxnode * 2 + 1);
121 print_nodes(maxnode * 2 + 2);
122 print_nodes(maxnode * 3 - 1);
123 print_nodes(maxnode * 3 );
124 print_nodes(maxnode * 3 + 1);
125 print_nodes(maxnode * 3 + 2);
127 puts("+++ exited with 0 +++");
133 SKIP_MAIN_UNDEFINED("__NR_get_mempolicy")