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) 2005-2007 Roland McGrath <roland@redhat.com>
7 * Copyright (c) 2006-2007 Ulrich Drepper <drepper@redhat.com>
8 * Copyright (c) 2009-2013 Denys Vlasenko <dvlasenk@redhat.com>
9 * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
10 * Copyright (c) 2014-2019 The strace developers.
11 * All rights reserved.
13 * SPDX-License-Identifier: LGPL-2.1-or-later
19 #include <asm/fcntl.h>
21 /* some libcs are guilty of messing up with O_ACCMODE */
26 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
31 #include "xlat/open_access_modes.h"
32 #include "xlat/open_mode_flags.h"
35 # define AT_FDCWD -100
38 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
39 * extension to get the right value. We do this by declaring fd as int here.
42 print_dirfd(struct tcb *tcp, int fd)
45 print_xlat_d(AT_FDCWD);
51 * low bits of the open(2) flags define access mode,
52 * other bits are real flags.
55 sprint_open_modes(unsigned int flags)
57 static char outstr[sizeof("flags O_ACCMODE")];
63 p = stpcpy(outstr, "flags");
64 str = xlookup(open_access_modes, flags & 3);
75 return sprintflags_ex(outstr, open_mode_flags, flags, sep,
76 XLAT_STYLE_ABBREV) ?: outstr;
80 tprint_open_modes(unsigned int flags)
82 print_xlat_ex(flags, sprint_open_modes(flags) + sizeof("flags"),
87 decode_open(struct tcb *tcp, int offset)
89 printpath(tcp, tcp->u_arg[offset]);
92 tprint_open_modes(tcp->u_arg[offset + 1]);
93 if (tcp->u_arg[offset + 1] & (O_CREAT | __O_TMPFILE)) {
96 print_numeric_umode_t(tcp->u_arg[offset + 2]);
99 return RVAL_DECODED | RVAL_FD;
104 return decode_open(tcp, 0);
109 print_dirfd(tcp, tcp->u_arg[0]);
111 return decode_open(tcp, 1);
116 printpath(tcp, tcp->u_arg[0]);
118 print_numeric_umode_t(tcp->u_arg[1]);
120 return RVAL_DECODED | RVAL_FD;