Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 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. |
| 18 | * |
| 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. |
| 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Dmitry V. Levin | 6250e6c | 2015-10-09 01:38:07 +0000 | [diff] [blame] | 32 | #include "flock.h" |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 33 | |
Dmitry V. Levin | c7c5270 | 2015-10-09 21:08:43 +0000 | [diff] [blame] | 34 | #include "xlat/f_owner_types.h" |
| 35 | #include "xlat/f_seals.h" |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 36 | #include "xlat/fcntlcmds.h" |
Dmitry V. Levin | 2154702 | 2015-12-05 00:52:01 +0000 | [diff] [blame] | 37 | #include "xlat/fcntl64cmds.h" |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 38 | #include "xlat/fdflags.h" |
| 39 | #include "xlat/lockfcmds.h" |
| 40 | #include "xlat/notifyflags.h" |
| 41 | |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 42 | static void |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 43 | print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk) |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 44 | { |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 45 | tprints("{l_type="); |
| 46 | printxval(lockfcmds, fl->l_type, "F_???"); |
| 47 | tprints(", l_whence="); |
| 48 | printxval(whence_codes, fl->l_whence, "SEEK_???"); |
Dmitry V. Levin | e67c8e4 | 2015-12-16 00:07:16 +0000 | [diff] [blame] | 49 | tprintf(", l_start=%lld, l_len=%lld", |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 50 | (long long) fl->l_start, (long long) fl->l_len); |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 51 | if (getlk) |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 52 | tprintf(", l_pid=%lu", (unsigned long) fl->l_pid); |
| 53 | tprints("}"); |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 54 | } |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 55 | |
| 56 | static void |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 57 | printflock64(struct tcb *tcp, const long addr, const int getlk) |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 58 | { |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 59 | struct_kernel_flock64 fl; |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 60 | |
Dmitry V. Levin | 1a713d9 | 2015-09-19 23:48:56 +0000 | [diff] [blame] | 61 | if (fetch_struct_flock64(tcp, addr, &fl)) |
| 62 | print_struct_flock64(&fl, getlk); |
| 63 | } |
| 64 | |
| 65 | static void |
| 66 | printflock(struct tcb *tcp, const long addr, const int getlk) |
| 67 | { |
| 68 | struct_kernel_flock64 fl; |
| 69 | |
| 70 | if (fetch_struct_flock(tcp, addr, &fl)) |
| 71 | print_struct_flock64(&fl, getlk); |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Dmitry V. Levin | c7c5270 | 2015-10-09 21:08:43 +0000 | [diff] [blame] | 74 | static void |
| 75 | print_f_owner_ex(struct tcb *tcp, const long addr) |
| 76 | { |
| 77 | struct { int type, pid; } owner; |
| 78 | |
| 79 | if (umove_or_printaddr(tcp, addr, &owner)) |
| 80 | return; |
| 81 | |
| 82 | tprints("{type="); |
| 83 | printxval(f_owner_types, owner.type, "F_OWNER_???"); |
| 84 | tprintf(", pid=%d}", owner.pid); |
| 85 | } |
| 86 | |
Elvira Khabirova | 211d6ef | 2015-12-05 00:42:58 +0300 | [diff] [blame] | 87 | static int |
| 88 | print_fcntl(struct tcb *tcp) |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 89 | { |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 90 | switch (tcp->u_arg[1]) { |
| 91 | case F_SETFD: |
| 92 | tprints(", "); |
| 93 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
| 94 | break; |
| 95 | case F_SETOWN: |
| 96 | case F_SETPIPE_SZ: |
| 97 | tprintf(", %ld", tcp->u_arg[2]); |
| 98 | break; |
| 99 | case F_DUPFD: |
| 100 | case F_DUPFD_CLOEXEC: |
| 101 | tprintf(", %ld", tcp->u_arg[2]); |
| 102 | return RVAL_DECODED | RVAL_FD; |
| 103 | case F_SETFL: |
| 104 | tprints(", "); |
| 105 | tprint_open_modes(tcp->u_arg[2]); |
| 106 | break; |
| 107 | case F_SETLK: |
| 108 | case F_SETLKW: |
| 109 | tprints(", "); |
| 110 | printflock(tcp, tcp->u_arg[2], 0); |
| 111 | break; |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 112 | case F_OFD_SETLK: |
| 113 | case F_OFD_SETLKW: |
| 114 | tprints(", "); |
| 115 | printflock64(tcp, tcp->u_arg[2], 0); |
| 116 | break; |
| 117 | case F_SETOWN_EX: |
| 118 | tprints(", "); |
| 119 | print_f_owner_ex(tcp, tcp->u_arg[2]); |
| 120 | break; |
| 121 | case F_NOTIFY: |
| 122 | tprints(", "); |
| 123 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 124 | break; |
| 125 | case F_SETLEASE: |
| 126 | tprints(", "); |
| 127 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 128 | break; |
| 129 | case F_ADD_SEALS: |
| 130 | tprints(", "); |
| 131 | printflags(f_seals, tcp->u_arg[2], "F_SEAL_???"); |
| 132 | break; |
| 133 | case F_SETSIG: |
| 134 | tprints(", "); |
| 135 | tprints(signame(tcp->u_arg[2])); |
| 136 | break; |
| 137 | case F_GETOWN: |
| 138 | case F_GETPIPE_SZ: |
| 139 | break; |
| 140 | case F_GETFD: |
| 141 | if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0) |
| 142 | return 0; |
Dmitry V. Levin | 6274ecc | 2016-05-15 14:23:06 +0000 | [diff] [blame^] | 143 | tcp->auxstr = sprintflags("flags ", fdflags, |
| 144 | (unsigned long) tcp->u_rval); |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 145 | return RVAL_HEX | RVAL_STR; |
| 146 | case F_GETFL: |
| 147 | if (entering(tcp) || syserror(tcp)) |
| 148 | return 0; |
| 149 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
| 150 | return RVAL_HEX | RVAL_STR; |
| 151 | case F_GETLK: |
| 152 | if (entering(tcp)) |
| 153 | return 0; |
| 154 | tprints(", "); |
| 155 | printflock(tcp, tcp->u_arg[2], 1); |
| 156 | break; |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 157 | case F_OFD_GETLK: |
| 158 | if (entering(tcp)) |
| 159 | return 0; |
| 160 | tprints(", "); |
| 161 | printflock64(tcp, tcp->u_arg[2], 1); |
| 162 | break; |
| 163 | case F_GETOWN_EX: |
| 164 | if (entering(tcp)) |
| 165 | return 0; |
| 166 | tprints(", "); |
| 167 | print_f_owner_ex(tcp, tcp->u_arg[2]); |
| 168 | break; |
| 169 | case F_GETLEASE: |
| 170 | if (entering(tcp) || syserror(tcp)) |
| 171 | return 0; |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 172 | tcp->auxstr = xlookup(lockfcmds, (unsigned long) tcp->u_rval); |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 173 | return RVAL_HEX | RVAL_STR; |
| 174 | case F_GET_SEALS: |
| 175 | if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0) |
| 176 | return 0; |
Dmitry V. Levin | 6274ecc | 2016-05-15 14:23:06 +0000 | [diff] [blame^] | 177 | tcp->auxstr = sprintflags("seals ", f_seals, |
| 178 | (unsigned long) tcp->u_rval); |
Dmitry V. Levin | 03202da | 2015-12-05 17:54:26 +0000 | [diff] [blame] | 179 | return RVAL_HEX | RVAL_STR; |
| 180 | case F_GETSIG: |
| 181 | if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0) |
| 182 | return 0; |
| 183 | tcp->auxstr = signame(tcp->u_rval); |
| 184 | return RVAL_STR; |
| 185 | default: |
| 186 | tprintf(", %#lx", tcp->u_arg[2]); |
| 187 | break; |
| 188 | } |
| 189 | return RVAL_DECODED; |
Dmitry V. Levin | 2512003 | 2015-10-01 12:24:01 +0000 | [diff] [blame] | 190 | } |
Elvira Khabirova | 211d6ef | 2015-12-05 00:42:58 +0300 | [diff] [blame] | 191 | |
| 192 | SYS_FUNC(fcntl) |
| 193 | { |
Dmitry V. Levin | 2154702 | 2015-12-05 00:52:01 +0000 | [diff] [blame] | 194 | if (entering(tcp)) { |
| 195 | printfd(tcp, tcp->u_arg[0]); |
| 196 | tprints(", "); |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 197 | const char *str = |
| 198 | xlookup(fcntlcmds, (unsigned long) tcp->u_arg[1]); |
Dmitry V. Levin | 2154702 | 2015-12-05 00:52:01 +0000 | [diff] [blame] | 199 | if (str) { |
| 200 | tprints(str); |
| 201 | } else { |
| 202 | /* |
| 203 | * fcntl syscall does not recognize these |
| 204 | * constants, but we would like to show them |
| 205 | * for better debugging experience. |
| 206 | */ |
| 207 | printxval(fcntl64cmds, tcp->u_arg[1], "F_???"); |
| 208 | } |
| 209 | } |
Elvira Khabirova | 211d6ef | 2015-12-05 00:42:58 +0300 | [diff] [blame] | 210 | return print_fcntl(tcp); |
| 211 | } |
| 212 | |
| 213 | SYS_FUNC(fcntl64) |
| 214 | { |
Dmitry V. Levin | 2154702 | 2015-12-05 00:52:01 +0000 | [diff] [blame] | 215 | if (entering(tcp)) { |
| 216 | printfd(tcp, tcp->u_arg[0]); |
| 217 | tprints(", "); |
Dmitry V. Levin | 9134aab | 2016-05-14 21:46:05 +0000 | [diff] [blame] | 218 | const char *str = |
| 219 | xlookup(fcntl64cmds, (unsigned long) tcp->u_arg[1]); |
Dmitry V. Levin | 2154702 | 2015-12-05 00:52:01 +0000 | [diff] [blame] | 220 | if (str) { |
| 221 | tprints(str); |
| 222 | } else { |
| 223 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 224 | } |
| 225 | } |
| 226 | switch (tcp->u_arg[1]) { |
| 227 | case F_SETLK64: |
| 228 | case F_SETLKW64: |
| 229 | tprints(", "); |
| 230 | printflock64(tcp, tcp->u_arg[2], 0); |
| 231 | return RVAL_DECODED; |
| 232 | case F_GETLK64: |
| 233 | if (exiting(tcp)) { |
| 234 | tprints(", "); |
| 235 | printflock64(tcp, tcp->u_arg[2], 1); |
| 236 | } |
| 237 | return 0; |
| 238 | } |
Elvira Khabirova | 211d6ef | 2015-12-05 00:42:58 +0300 | [diff] [blame] | 239 | return print_fcntl(tcp); |
| 240 | } |