blob: 973684e16ffe4bd08c8f4f565022ecb1a0ff0c6f [file] [log] [blame]
Dmitry V. Levin25120032015-10-01 12:24:01 +00001/*
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>
Elliott Hughes03a418e2018-06-15 13:11:40 -07006 * Copyright (c) 1999-2018 The strace developers.
Dmitry V. Levin25120032015-10-01 12:24:01 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "defs.h"
Dmitry V. Levin6250e6c2015-10-09 01:38:07 +000033#include "flock.h"
Dmitry V. Levin25120032015-10-01 12:24:01 +000034
Dmitry V. Levinc7c52702015-10-09 21:08:43 +000035#include "xlat/f_owner_types.h"
36#include "xlat/f_seals.h"
Dmitry V. Levin25120032015-10-01 12:24:01 +000037#include "xlat/fcntlcmds.h"
38#include "xlat/fdflags.h"
39#include "xlat/lockfcmds.h"
40#include "xlat/notifyflags.h"
41
Dmitry V. Levin25120032015-10-01 12:24:01 +000042static void
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000043print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk)
Dmitry V. Levin25120032015-10-01 12:24:01 +000044{
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000045 tprints("{l_type=");
Dmitry V. Levina734a972016-05-16 21:57:08 +000046 printxval(lockfcmds, (unsigned short) fl->l_type, "F_???");
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000047 tprints(", l_whence=");
Dmitry V. Levina734a972016-05-16 21:57:08 +000048 printxval(whence_codes, (unsigned short) fl->l_whence, "SEEK_???");
Elliott Hughesd35df492017-02-15 15:19:05 -080049 tprintf(", l_start=%" PRId64 ", l_len=%" PRId64,
50 (int64_t) fl->l_start, (int64_t) fl->l_len);
Dmitry V. Levin25120032015-10-01 12:24:01 +000051 if (getlk)
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000052 tprintf(", l_pid=%lu", (unsigned long) fl->l_pid);
53 tprints("}");
Dmitry V. Levin25120032015-10-01 12:24:01 +000054}
Dmitry V. Levin25120032015-10-01 12:24:01 +000055
56static void
Elliott Hughesd35df492017-02-15 15:19:05 -080057printflock64(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
Dmitry V. Levin25120032015-10-01 12:24:01 +000058{
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000059 struct_kernel_flock64 fl;
Dmitry V. Levin25120032015-10-01 12:24:01 +000060
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000061 if (fetch_struct_flock64(tcp, addr, &fl))
62 print_struct_flock64(&fl, getlk);
63}
64
65static void
Elliott Hughesd35df492017-02-15 15:19:05 -080066printflock(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
Dmitry V. Levin1a713d92015-09-19 23:48:56 +000067{
68 struct_kernel_flock64 fl;
69
70 if (fetch_struct_flock(tcp, addr, &fl))
71 print_struct_flock64(&fl, getlk);
Dmitry V. Levin25120032015-10-01 12:24:01 +000072}
73
Dmitry V. Levinc7c52702015-10-09 21:08:43 +000074static void
Elliott Hughesd35df492017-02-15 15:19:05 -080075print_f_owner_ex(struct tcb *const tcp, const kernel_ulong_t addr)
Dmitry V. Levinc7c52702015-10-09 21:08:43 +000076{
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 Khabirova211d6ef2015-12-05 00:42:58 +030087static int
88print_fcntl(struct tcb *tcp)
Dmitry V. Levin25120032015-10-01 12:24:01 +000089{
Dmitry V. Levin77086592016-05-16 21:01:43 +000090 const unsigned int cmd = tcp->u_arg[1];
91
92 switch (cmd) {
Dmitry V. Levin03202da2015-12-05 17:54:26 +000093 case F_SETFD:
94 tprints(", ");
95 printflags(fdflags, tcp->u_arg[2], "FD_???");
96 break;
97 case F_SETOWN:
98 case F_SETPIPE_SZ:
Elliott Hughesd35df492017-02-15 15:19:05 -080099 tprintf(", %" PRI_kld, tcp->u_arg[2]);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000100 break;
101 case F_DUPFD:
102 case F_DUPFD_CLOEXEC:
Elliott Hughesd35df492017-02-15 15:19:05 -0800103 tprintf(", %" PRI_kld, tcp->u_arg[2]);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000104 return RVAL_DECODED | RVAL_FD;
105 case F_SETFL:
106 tprints(", ");
107 tprint_open_modes(tcp->u_arg[2]);
108 break;
109 case F_SETLK:
110 case F_SETLKW:
111 tprints(", ");
112 printflock(tcp, tcp->u_arg[2], 0);
113 break;
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000114 case F_OFD_SETLK:
115 case F_OFD_SETLKW:
116 tprints(", ");
117 printflock64(tcp, tcp->u_arg[2], 0);
118 break;
119 case F_SETOWN_EX:
120 tprints(", ");
121 print_f_owner_ex(tcp, tcp->u_arg[2]);
122 break;
123 case F_NOTIFY:
124 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800125 printflags64(notifyflags, tcp->u_arg[2], "DN_???");
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000126 break;
127 case F_SETLEASE:
128 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800129 printxval64(lockfcmds, tcp->u_arg[2], "F_???");
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000130 break;
131 case F_ADD_SEALS:
132 tprints(", ");
Elliott Hughesd35df492017-02-15 15:19:05 -0800133 printflags64(f_seals, tcp->u_arg[2], "F_SEAL_???");
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000134 break;
135 case F_SETSIG:
136 tprints(", ");
137 tprints(signame(tcp->u_arg[2]));
138 break;
139 case F_GETOWN:
140 case F_GETPIPE_SZ:
141 break;
142 case F_GETFD:
143 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
144 return 0;
Dmitry V. Levin6274ecc2016-05-15 14:23:06 +0000145 tcp->auxstr = sprintflags("flags ", fdflags,
Elliott Hughesd35df492017-02-15 15:19:05 -0800146 (kernel_ulong_t) tcp->u_rval);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000147 return RVAL_HEX | RVAL_STR;
148 case F_GETFL:
149 if (entering(tcp) || syserror(tcp))
150 return 0;
151 tcp->auxstr = sprint_open_modes(tcp->u_rval);
152 return RVAL_HEX | RVAL_STR;
153 case F_GETLK:
154 if (entering(tcp))
155 return 0;
156 tprints(", ");
157 printflock(tcp, tcp->u_arg[2], 1);
158 break;
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000159 case F_OFD_GETLK:
160 if (entering(tcp))
161 return 0;
162 tprints(", ");
163 printflock64(tcp, tcp->u_arg[2], 1);
164 break;
165 case F_GETOWN_EX:
166 if (entering(tcp))
167 return 0;
168 tprints(", ");
169 print_f_owner_ex(tcp, tcp->u_arg[2]);
170 break;
171 case F_GETLEASE:
172 if (entering(tcp) || syserror(tcp))
173 return 0;
Elliott Hughesd35df492017-02-15 15:19:05 -0800174 tcp->auxstr = xlookup(lockfcmds, (kernel_ulong_t) tcp->u_rval);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000175 return RVAL_HEX | RVAL_STR;
176 case F_GET_SEALS:
177 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
178 return 0;
Dmitry V. Levin6274ecc2016-05-15 14:23:06 +0000179 tcp->auxstr = sprintflags("seals ", f_seals,
Elliott Hughesd35df492017-02-15 15:19:05 -0800180 (kernel_ulong_t) tcp->u_rval);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000181 return RVAL_HEX | RVAL_STR;
182 case F_GETSIG:
183 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
184 return 0;
185 tcp->auxstr = signame(tcp->u_rval);
186 return RVAL_STR;
187 default:
Elliott Hughesd35df492017-02-15 15:19:05 -0800188 tprintf(", %#" PRI_klx, tcp->u_arg[2]);
Dmitry V. Levin03202da2015-12-05 17:54:26 +0000189 break;
190 }
191 return RVAL_DECODED;
Dmitry V. Levin25120032015-10-01 12:24:01 +0000192}
Elvira Khabirova211d6ef2015-12-05 00:42:58 +0300193
194SYS_FUNC(fcntl)
195{
Dmitry V. Levin21547022015-12-05 00:52:01 +0000196 if (entering(tcp)) {
197 printfd(tcp, tcp->u_arg[0]);
198 tprints(", ");
Elliott Hughes03a418e2018-06-15 13:11:40 -0700199 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
Dmitry V. Levin21547022015-12-05 00:52:01 +0000200 }
Elvira Khabirova211d6ef2015-12-05 00:42:58 +0300201 return print_fcntl(tcp);
202}
203
204SYS_FUNC(fcntl64)
205{
Dmitry V. Levin77086592016-05-16 21:01:43 +0000206 const unsigned int cmd = tcp->u_arg[1];
Dmitry V. Levin21547022015-12-05 00:52:01 +0000207 if (entering(tcp)) {
208 printfd(tcp, tcp->u_arg[0]);
209 tprints(", ");
Elliott Hughes03a418e2018-06-15 13:11:40 -0700210 printxval(fcntlcmds, cmd, "F_???");
Dmitry V. Levin21547022015-12-05 00:52:01 +0000211 }
Dmitry V. Levin77086592016-05-16 21:01:43 +0000212 switch (cmd) {
Dmitry V. Levin21547022015-12-05 00:52:01 +0000213 case F_SETLK64:
214 case F_SETLKW64:
215 tprints(", ");
216 printflock64(tcp, tcp->u_arg[2], 0);
217 return RVAL_DECODED;
218 case F_GETLK64:
219 if (exiting(tcp)) {
220 tprints(", ");
221 printflock64(tcp, tcp->u_arg[2], 1);
222 }
223 return 0;
224 }
Elvira Khabirova211d6ef2015-12-05 00:42:58 +0300225 return print_fcntl(tcp);
226}