Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org> |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2015-2017 The strace developers. |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 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 | |
Dmitry V. Levin | a6ebdb1 | 2015-11-15 02:22:44 +0000 | [diff] [blame] | 29 | #include "defs.h" |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 30 | #include "print_fields.h" |
Dmitry V. Levin | a6ebdb1 | 2015-11-15 02:22:44 +0000 | [diff] [blame] | 31 | #include <fcntl.h> |
| 32 | |
| 33 | #include "xlat/uffd_flags.h" |
| 34 | |
| 35 | SYS_FUNC(userfaultfd) |
| 36 | { |
| 37 | printflags(uffd_flags, tcp->u_arg[0], "UFFD_???"); |
| 38 | |
| 39 | return RVAL_DECODED | RVAL_FD; |
| 40 | } |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 41 | |
| 42 | #ifdef HAVE_LINUX_USERFAULTFD_H |
| 43 | # include <linux/ioctl.h> |
| 44 | # include <linux/userfaultfd.h> |
| 45 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 46 | # include "xlat/uffd_api_features.h" |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 47 | # include "xlat/uffd_api_flags.h" |
| 48 | # include "xlat/uffd_copy_flags.h" |
| 49 | # include "xlat/uffd_register_ioctl_flags.h" |
| 50 | # include "xlat/uffd_register_mode_flags.h" |
| 51 | # include "xlat/uffd_zeropage_flags.h" |
| 52 | |
| 53 | static void |
| 54 | tprintf_uffdio_range(const struct uffdio_range *range) |
| 55 | { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 56 | PRINT_FIELD_X("{", *range, start); |
| 57 | PRINT_FIELD_X(", ", *range, len); |
| 58 | tprints("}"); |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 61 | #define PRINT_FIELD_UFFDIO_RANGE(prefix_, where_, field_) \ |
| 62 | do { \ |
| 63 | STRACE_PRINTF("%s%s=", (prefix_), #field_); \ |
| 64 | tprintf_uffdio_range(&(where_).field_); \ |
| 65 | } while (0) |
| 66 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 67 | int |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 68 | uffdio_ioctl(struct tcb *const tcp, const unsigned int code, |
| 69 | const kernel_ulong_t arg) |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 70 | { |
| 71 | switch (code) { |
| 72 | case UFFDIO_API: { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 73 | uint64_t *entering_features; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 74 | struct uffdio_api ua; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 75 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 76 | if (entering(tcp)) { |
| 77 | tprints(", "); |
| 78 | if (umove_or_printaddr(tcp, arg, &ua)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 79 | break; |
| 80 | PRINT_FIELD_X("{", ua, api); |
| 81 | PRINT_FIELD_FLAGS(", ", ua, features, uffd_api_features, |
| 82 | "UFFD_FEATURE_???"); |
| 83 | entering_features = malloc(sizeof(*entering_features)); |
| 84 | if (entering_features) { |
| 85 | *entering_features = ua.features; |
| 86 | set_tcb_priv_data(tcp, entering_features, free); |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 87 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 88 | |
| 89 | return 0; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 90 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 91 | |
| 92 | if (!syserror(tcp) && !umove(tcp, arg, &ua)) { |
| 93 | entering_features = get_tcb_priv_data(tcp); |
| 94 | |
| 95 | if (!entering_features |
| 96 | || *entering_features != ua.features) { |
| 97 | PRINT_FIELD_FLAGS(" => ", ua, features, |
| 98 | uffd_api_features, |
| 99 | "UFFD_FEATURE_???"); |
| 100 | } |
| 101 | |
| 102 | PRINT_FIELD_FLAGS(", ", ua, ioctls, uffd_api_flags, |
| 103 | "_UFFDIO_???"); |
| 104 | } |
| 105 | |
| 106 | tprints("}"); |
| 107 | |
| 108 | break; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | case UFFDIO_COPY: { |
| 112 | struct uffdio_copy uc; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 113 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 114 | if (entering(tcp)) { |
| 115 | tprints(", "); |
| 116 | if (umove_or_printaddr(tcp, arg, &uc)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 117 | return RVAL_IOCTL_DECODED; |
| 118 | PRINT_FIELD_X("{", uc, dst); |
| 119 | PRINT_FIELD_X(", ", uc, src); |
| 120 | PRINT_FIELD_X(", ", uc, len); |
| 121 | PRINT_FIELD_FLAGS(", ", uc, mode, uffd_copy_flags, |
| 122 | "UFFDIO_COPY_???"); |
| 123 | |
| 124 | return 0; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 125 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 126 | |
| 127 | if (!syserror(tcp) && !umove(tcp, arg, &uc)) |
| 128 | PRINT_FIELD_X(", ", uc, copy); |
| 129 | |
| 130 | tprints("}"); |
| 131 | |
| 132 | break; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | case UFFDIO_REGISTER: { |
| 136 | struct uffdio_register ur; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 137 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 138 | if (entering(tcp)) { |
| 139 | tprints(", "); |
| 140 | if (umove_or_printaddr(tcp, arg, &ur)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 141 | return RVAL_IOCTL_DECODED; |
| 142 | PRINT_FIELD_UFFDIO_RANGE("{", ur, range); |
| 143 | PRINT_FIELD_FLAGS(", ", ur, mode, |
| 144 | uffd_register_mode_flags, |
| 145 | "UFFDIO_REGISTER_MODE_???"); |
| 146 | |
| 147 | return 0; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 148 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 149 | |
| 150 | if (!syserror(tcp) && !umove(tcp, arg, &ur)) { |
| 151 | PRINT_FIELD_FLAGS(", ", ur, ioctls, |
| 152 | uffd_register_ioctl_flags, |
| 153 | "UFFDIO_???"); |
| 154 | } |
| 155 | |
| 156 | tprints("}"); |
| 157 | |
| 158 | break; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | case UFFDIO_UNREGISTER: |
| 162 | case UFFDIO_WAKE: { |
| 163 | struct uffdio_range ura; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 164 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 165 | tprints(", "); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 166 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 167 | if (!umove_or_printaddr(tcp, arg, &ura)) |
| 168 | tprintf_uffdio_range(&ura); |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 169 | |
| 170 | break; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | case UFFDIO_ZEROPAGE: { |
| 174 | struct uffdio_zeropage uz; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 175 | |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 176 | if (entering(tcp)) { |
| 177 | tprints(", "); |
| 178 | if (umove_or_printaddr(tcp, arg, &uz)) |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 179 | return RVAL_IOCTL_DECODED; |
| 180 | PRINT_FIELD_UFFDIO_RANGE("{", uz, range); |
| 181 | PRINT_FIELD_FLAGS(", ", uz, mode, uffd_zeropage_flags, |
| 182 | "UFFDIO_ZEROPAGE_???"); |
| 183 | |
| 184 | return 0; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 185 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 186 | |
| 187 | if (!syserror(tcp) && !umove(tcp, arg, &uz)) |
| 188 | PRINT_FIELD_X(", ", uz, zeropage); |
| 189 | |
| 190 | tprints("}"); |
| 191 | |
| 192 | break; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | default: |
| 196 | return RVAL_DECODED; |
| 197 | } |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 198 | |
| 199 | return RVAL_IOCTL_DECODED; |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame] | 200 | } |
| 201 | #endif /* HAVE_LINUX_USERFAULTFD_H */ |