Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2003-2007 Ulrich Drepper <drepper@redhat.com> |
| 3 | * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 31 | static bool |
| 32 | print_node(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
| 33 | { |
| 34 | if (elem_size < sizeof(long)) { |
| 35 | tprintf("%#0*x", (int) elem_size * 2 + 2, |
| 36 | * (unsigned int *) elem_buf); |
| 37 | } else { |
| 38 | tprintf("%#0*lx", (int) elem_size * 2 + 2, |
| 39 | * (unsigned long *) elem_buf); |
| 40 | } |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 45 | static void |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 46 | print_nodemask(struct tcb *tcp, unsigned long addr, unsigned long maxnodes) |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 47 | { |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 48 | const unsigned long nmemb = |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 49 | (maxnodes + 8 * current_wordsize - 2) / (8 * current_wordsize); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 50 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 51 | if (nmemb < maxnodes / (8 * current_wordsize) || |
| 52 | (maxnodes && !nmemb)) { |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 53 | printaddr(addr); |
| 54 | return; |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 55 | } |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 56 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 57 | unsigned long buf; |
| 58 | print_array(tcp, addr, nmemb, &buf, current_wordsize, |
| 59 | umoven_or_printaddr, print_node, 0); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | SYS_FUNC(migrate_pages) |
| 63 | { |
Dmitry V. Levin | c8c7a53 | 2016-04-28 01:19:19 +0000 | [diff] [blame] | 64 | tprintf("%d, %lu, ", (int) tcp->u_arg[0], tcp->u_arg[1]); |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 65 | print_nodemask(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
Dmitry V. Levin | c8c7a53 | 2016-04-28 01:19:19 +0000 | [diff] [blame] | 66 | tprints(", "); |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 67 | print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[1]); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 68 | |
| 69 | return RVAL_DECODED; |
| 70 | } |
| 71 | |
| 72 | #include "xlat/policies.h" |
| 73 | #include "xlat/mbindflags.h" |
| 74 | |
| 75 | SYS_FUNC(mbind) |
| 76 | { |
| 77 | printaddr(tcp->u_arg[0]); |
| 78 | tprintf(", %lu, ", tcp->u_arg[1]); |
Dmitry V. Levin | 3a0fa5c | 2016-05-16 23:13:04 +0000 | [diff] [blame] | 79 | printxval_long(policies, tcp->u_arg[2], "MPOL_???"); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 80 | tprints(", "); |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 81 | print_nodemask(tcp, tcp->u_arg[3], tcp->u_arg[4]); |
| 82 | tprintf(", %lu, ", tcp->u_arg[4]); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 83 | printflags(mbindflags, tcp->u_arg[5], "MPOL_???"); |
| 84 | |
| 85 | return RVAL_DECODED; |
| 86 | } |
| 87 | |
| 88 | SYS_FUNC(set_mempolicy) |
| 89 | { |
| 90 | printxval(policies, tcp->u_arg[0], "MPOL_???"); |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 91 | tprints(", "); |
| 92 | print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 93 | tprintf(", %lu", tcp->u_arg[2]); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 94 | |
| 95 | return RVAL_DECODED; |
| 96 | } |
| 97 | |
| 98 | #include "xlat/mempolicyflags.h" |
| 99 | |
| 100 | SYS_FUNC(get_mempolicy) |
| 101 | { |
| 102 | if (exiting(tcp)) { |
| 103 | int pol; |
Dmitry V. Levin | fb1ae07 | 2016-04-27 22:36:07 +0000 | [diff] [blame] | 104 | if (!umove_or_printaddr(tcp, tcp->u_arg[0], &pol)) { |
| 105 | tprints("["); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 106 | printxval(policies, pol, "MPOL_???"); |
Dmitry V. Levin | fb1ae07 | 2016-04-27 22:36:07 +0000 | [diff] [blame] | 107 | tprints("]"); |
| 108 | } |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 109 | tprints(", "); |
Dmitry V. Levin | 9547c45 | 2016-04-27 22:02:26 +0000 | [diff] [blame] | 110 | print_nodemask(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 111 | tprintf(", %lu, ", tcp->u_arg[2]); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 112 | printaddr(tcp->u_arg[3]); |
| 113 | tprints(", "); |
Dmitry V. Levin | 0da9b0e | 2016-05-16 23:15:06 +0000 | [diff] [blame] | 114 | printflags_long(mempolicyflags, tcp->u_arg[4], "MPOL_???"); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 115 | } |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | #include "xlat/move_pages_flags.h" |
| 120 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 121 | static bool |
| 122 | print_addr(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 123 | { |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 124 | unsigned long addr; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 125 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 126 | if (elem_size < sizeof(long)) { |
| 127 | addr = * (unsigned int *) elem_buf; |
| 128 | } else { |
| 129 | addr = * (unsigned long *) elem_buf; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 130 | } |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 131 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 132 | printaddr(addr); |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 133 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 134 | return true; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 137 | static bool |
| 138 | print_status(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 139 | { |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 140 | const int status = * (int *) elem_buf; |
| 141 | |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 142 | if (status < 0 && (unsigned) -status < nerrnos) |
| 143 | tprintf("%s", errnoent[-status]); |
| 144 | else |
| 145 | tprintf("%d", status); |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 146 | |
| 147 | return true; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 150 | static bool |
| 151 | print_int(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 152 | { |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 153 | tprintf("%d", * (int *) elem_buf); |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 154 | |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 155 | return true; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 158 | SYS_FUNC(move_pages) |
| 159 | { |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 160 | const unsigned long npages = tcp->u_arg[1]; |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 161 | long buf; |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 162 | |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 163 | if (entering(tcp)) { |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 164 | tprintf("%d, %lu, ", (int) tcp->u_arg[0], npages); |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 165 | print_array(tcp, tcp->u_arg[2], npages, &buf, current_wordsize, |
| 166 | umoven_or_printaddr, print_addr, 0); |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 167 | tprints(", "); |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 168 | print_array(tcp, tcp->u_arg[3], npages, &buf, sizeof(int), |
| 169 | umoven_or_printaddr, print_int, 0); |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 170 | tprints(", "); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 171 | } else { |
Dmitry V. Levin | 636b8c1 | 2016-05-07 23:02:36 +0000 | [diff] [blame] | 172 | print_array(tcp, tcp->u_arg[4], npages, &buf, sizeof(int), |
| 173 | umoven_or_printaddr, print_status, 0); |
Dmitry V. Levin | e212a15 | 2016-04-29 17:26:56 +0000 | [diff] [blame] | 174 | tprints(", "); |
Dmitry V. Levin | a4da0c8 | 2016-04-27 05:06:06 +0000 | [diff] [blame] | 175 | printflags(move_pages_flags, tcp->u_arg[5], "MPOL_???"); |
| 176 | } |
| 177 | return 0; |
| 178 | } |