Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Dmitry V. Levin | a6ebdb1 | 2015-11-15 02:22:44 +0000 | [diff] [blame] | 28 | #include "defs.h" |
| 29 | #include <fcntl.h> |
| 30 | |
| 31 | #include "xlat/uffd_flags.h" |
| 32 | |
| 33 | SYS_FUNC(userfaultfd) |
| 34 | { |
| 35 | printflags(uffd_flags, tcp->u_arg[0], "UFFD_???"); |
| 36 | |
| 37 | return RVAL_DECODED | RVAL_FD; |
| 38 | } |
Dr. David Alan Gilbert | 5d1216a | 2016-05-10 11:49:02 +0100 | [diff] [blame^] | 39 | |
| 40 | #ifdef HAVE_LINUX_USERFAULTFD_H |
| 41 | # include <linux/ioctl.h> |
| 42 | # include <linux/userfaultfd.h> |
| 43 | |
| 44 | # include "xlat/uffd_api_flags.h" |
| 45 | # include "xlat/uffd_copy_flags.h" |
| 46 | # include "xlat/uffd_register_ioctl_flags.h" |
| 47 | # include "xlat/uffd_register_mode_flags.h" |
| 48 | # include "xlat/uffd_zeropage_flags.h" |
| 49 | |
| 50 | static void |
| 51 | tprintf_uffdio_range(const struct uffdio_range *range) |
| 52 | { |
| 53 | tprintf("{start=%#" PRI__x64 ", len=%#" PRI__x64 "}", |
| 54 | range->start, range->len); |
| 55 | } |
| 56 | |
| 57 | int |
| 58 | uffdio_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
| 59 | { |
| 60 | switch (code) { |
| 61 | case UFFDIO_API: { |
| 62 | struct uffdio_api ua; |
| 63 | if (entering(tcp)) { |
| 64 | tprints(", "); |
| 65 | if (umove_or_printaddr(tcp, arg, &ua)) |
| 66 | return RVAL_DECODED | 1; |
| 67 | /* Features is intended to contain some flags, but |
| 68 | * there aren't any defined yet. |
| 69 | */ |
| 70 | tprintf("{api=%#" PRI__x64 |
| 71 | ", features=%#" PRI__x64, |
| 72 | ua.api, ua.features); |
| 73 | } else { |
| 74 | if (!syserror(tcp) && !umove(tcp, arg, &ua)) { |
| 75 | tprintf(", features.out=%#" PRI__x64 |
| 76 | ", ioctls=", ua.features); |
| 77 | printflags64(uffd_api_flags, ua.ioctls, |
| 78 | "_UFFDIO_???"); |
| 79 | } |
| 80 | tprintf("}"); |
| 81 | } |
| 82 | return 1; |
| 83 | } |
| 84 | |
| 85 | case UFFDIO_COPY: { |
| 86 | struct uffdio_copy uc; |
| 87 | if (entering(tcp)) { |
| 88 | tprints(", "); |
| 89 | if (umove_or_printaddr(tcp, arg, &uc)) |
| 90 | return RVAL_DECODED | 1; |
| 91 | tprintf("{dst=%#" PRI__x64 ", src=%#" PRI__x64 |
| 92 | ", len=%#" PRI__x64 ", mode=", |
| 93 | uc.dst, uc.src, uc.len); |
| 94 | printflags64(uffd_copy_flags, uc.mode, |
| 95 | "UFFDIO_COPY_???"); |
| 96 | } else { |
| 97 | if (!syserror(tcp) && !umove(tcp, arg, &uc)) |
| 98 | tprintf(", copy=%#" PRI__x64, uc.copy); |
| 99 | tprints("}"); |
| 100 | } |
| 101 | return 1; |
| 102 | } |
| 103 | |
| 104 | case UFFDIO_REGISTER: { |
| 105 | struct uffdio_register ur; |
| 106 | if (entering(tcp)) { |
| 107 | tprints(", "); |
| 108 | if (umove_or_printaddr(tcp, arg, &ur)) |
| 109 | return RVAL_DECODED | 1; |
| 110 | tprintf("{range="); |
| 111 | tprintf_uffdio_range(&ur.range); |
| 112 | tprintf(", mode="); |
| 113 | printflags64(uffd_register_mode_flags, ur.mode, |
| 114 | "UFFDIO_REGISTER_MODE_???"); |
| 115 | } else { |
| 116 | if (!syserror(tcp) && !umove(tcp, arg, &ur)) { |
| 117 | tprintf(", ioctls="); |
| 118 | printflags64(uffd_register_ioctl_flags, |
| 119 | ur.ioctls, "UFFDIO_???"); |
| 120 | } |
| 121 | tprints("}"); |
| 122 | } |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | case UFFDIO_UNREGISTER: |
| 127 | case UFFDIO_WAKE: { |
| 128 | struct uffdio_range ura; |
| 129 | tprints(", "); |
| 130 | if (!umove_or_printaddr(tcp, arg, &ura)) |
| 131 | tprintf_uffdio_range(&ura); |
| 132 | return RVAL_DECODED | 1; |
| 133 | } |
| 134 | |
| 135 | case UFFDIO_ZEROPAGE: { |
| 136 | struct uffdio_zeropage uz; |
| 137 | if (entering(tcp)) { |
| 138 | tprints(", "); |
| 139 | if (umove_or_printaddr(tcp, arg, &uz)) |
| 140 | return RVAL_DECODED | 1; |
| 141 | tprintf("{range="); |
| 142 | tprintf_uffdio_range(&uz.range); |
| 143 | tprintf(", mode="); |
| 144 | printflags64(uffd_zeropage_flags, uz.mode, |
| 145 | "UFFDIO_ZEROPAGE_???"); |
| 146 | } else { |
| 147 | if (!syserror(tcp) && !umove(tcp, arg, &uz)) |
| 148 | tprintf(", zeropage=%#" PRI__x64, uz.zeropage); |
| 149 | tprints("}"); |
| 150 | } |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | default: |
| 155 | return RVAL_DECODED; |
| 156 | } |
| 157 | } |
| 158 | #endif /* HAVE_LINUX_USERFAULTFD_H */ |