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 * Copyright (c) 1999-2017 The strace developers.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
35 #include "xlat/f_owner_types.h"
36 #include "xlat/f_seals.h"
37 #include "xlat/fcntlcmds.h"
38 #include "xlat/fcntl64cmds.h"
39 #include "xlat/fdflags.h"
40 #include "xlat/lockfcmds.h"
41 #include "xlat/notifyflags.h"
44 print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk)
47 printxval(lockfcmds, (unsigned short) fl->l_type, "F_???");
48 tprints(", l_whence=");
49 printxval(whence_codes, (unsigned short) fl->l_whence, "SEEK_???");
50 tprintf(", l_start=%" PRId64 ", l_len=%" PRId64,
51 (int64_t) fl->l_start, (int64_t) fl->l_len);
53 tprintf(", l_pid=%lu", (unsigned long) fl->l_pid);
58 printflock64(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
60 struct_kernel_flock64 fl;
62 if (fetch_struct_flock64(tcp, addr, &fl))
63 print_struct_flock64(&fl, getlk);
67 printflock(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
69 struct_kernel_flock64 fl;
71 if (fetch_struct_flock(tcp, addr, &fl))
72 print_struct_flock64(&fl, getlk);
76 print_f_owner_ex(struct tcb *const tcp, const kernel_ulong_t addr)
78 struct { int type, pid; } owner;
80 if (umove_or_printaddr(tcp, addr, &owner))
84 printxval(f_owner_types, owner.type, "F_OWNER_???");
85 tprintf(", pid=%d}", owner.pid);
89 print_fcntl(struct tcb *tcp)
91 const unsigned int cmd = tcp->u_arg[1];
96 printflags(fdflags, tcp->u_arg[2], "FD_???");
100 tprintf(", %" PRI_kld, tcp->u_arg[2]);
103 case F_DUPFD_CLOEXEC:
104 tprintf(", %" PRI_kld, tcp->u_arg[2]);
105 return RVAL_DECODED | RVAL_FD;
108 tprint_open_modes(tcp->u_arg[2]);
113 printflock(tcp, tcp->u_arg[2], 0);
118 printflock64(tcp, tcp->u_arg[2], 0);
122 print_f_owner_ex(tcp, tcp->u_arg[2]);
126 printflags64(notifyflags, tcp->u_arg[2], "DN_???");
130 printxval64(lockfcmds, tcp->u_arg[2], "F_???");
134 printflags64(f_seals, tcp->u_arg[2], "F_SEAL_???");
138 tprints(signame(tcp->u_arg[2]));
144 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
146 tcp->auxstr = sprintflags("flags ", fdflags,
147 (kernel_ulong_t) tcp->u_rval);
148 return RVAL_HEX | RVAL_STR;
150 if (entering(tcp) || syserror(tcp))
152 tcp->auxstr = sprint_open_modes(tcp->u_rval);
153 return RVAL_HEX | RVAL_STR;
158 printflock(tcp, tcp->u_arg[2], 1);
164 printflock64(tcp, tcp->u_arg[2], 1);
170 print_f_owner_ex(tcp, tcp->u_arg[2]);
173 if (entering(tcp) || syserror(tcp))
175 tcp->auxstr = xlookup(lockfcmds, (kernel_ulong_t) tcp->u_rval);
176 return RVAL_HEX | RVAL_STR;
178 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
180 tcp->auxstr = sprintflags("seals ", f_seals,
181 (kernel_ulong_t) tcp->u_rval);
182 return RVAL_HEX | RVAL_STR;
184 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
186 tcp->auxstr = signame(tcp->u_rval);
189 tprintf(", %#" PRI_klx, tcp->u_arg[2]);
198 printfd(tcp, tcp->u_arg[0]);
200 const unsigned int cmd = tcp->u_arg[1];
201 const char *str = xlookup(fcntlcmds, cmd);
206 * fcntl syscall does not recognize these
207 * constants, but we would like to show them
208 * for better debugging experience.
210 printxval(fcntl64cmds, cmd, "F_???");
213 return print_fcntl(tcp);
218 const unsigned int cmd = tcp->u_arg[1];
220 printfd(tcp, tcp->u_arg[0]);
222 const char *str = xlookup(fcntl64cmds, cmd);
226 printxval(fcntlcmds, cmd, "F_???");
233 printflock64(tcp, tcp->u_arg[2], 0);
238 printflock64(tcp, tcp->u_arg[2], 1);
242 return print_fcntl(tcp);