2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-2018 The strace developers.
6 * SPDX-License-Identifier: LGPL-2.1-or-later
11 * The C library's definition of struct termios might differ from
12 * the kernel one, and we need to use the kernel layout.
14 #include <linux/termios.h>
16 #include "xlat/tcxonc_options.h"
17 #include "xlat/tcflsh_options.h"
18 #include "xlat/baud_options.h"
19 #include "xlat/modem_flags.h"
22 decode_termios(struct tcb *const tcp, const kernel_ulong_t addr)
27 if (umove_or_printaddr(tcp, addr, &tios))
31 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
32 tprintf(" %sopost %sisig %sicanon %secho ...}",
33 (tios.c_oflag & OPOST) ? "" : "-",
34 (tios.c_lflag & ISIG) ? "" : "-",
35 (tios.c_lflag & ICANON) ? "" : "-",
36 (tios.c_lflag & ECHO) ? "" : "-");
39 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
40 (long) tios.c_iflag, (long) tios.c_oflag);
41 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
42 (long) tios.c_cflag, (long) tios.c_lflag);
43 tprintf("c_line=%u, ", tios.c_line);
44 if (!(tios.c_lflag & ICANON))
45 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
46 tios.c_cc[VMIN], tios.c_cc[VTIME]);
48 print_quoted_string((char *) tios.c_cc, NCCS, QUOTE_FORCE_HEX);
53 decode_termio(struct tcb *const tcp, const kernel_ulong_t addr)
59 if (umove_or_printaddr(tcp, addr, &tio))
63 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
64 tprintf(" %sopost %sisig %sicanon %secho ...}",
65 (tio.c_oflag & OPOST) ? "" : "-",
66 (tio.c_lflag & ISIG) ? "" : "-",
67 (tio.c_lflag & ICANON) ? "" : "-",
68 (tio.c_lflag & ECHO) ? "" : "-");
71 tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
72 (long) tio.c_iflag, (long) tio.c_oflag);
73 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
74 (long) tio.c_cflag, (long) tio.c_lflag);
75 tprintf("c_line=%u, ", tio.c_line);
77 if (!(tio.c_lflag & ICANON))
78 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
79 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
81 if (!(tio.c_lflag & ICANON))
82 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
83 tio.c_cc[VMIN], tio.c_cc[VTIME]);
86 for (i = 0; i < NCC; i++)
87 tprintf("\\x%02x", tio.c_cc[i]);
92 decode_winsize(struct tcb *const tcp, const kernel_ulong_t addr)
97 if (umove_or_printaddr(tcp, addr, &ws))
99 tprintf("{ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
100 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
105 decode_ttysize(struct tcb *const tcp, const kernel_ulong_t addr)
110 if (umove_or_printaddr(tcp, addr, &ts))
112 tprintf("{ts_lines=%d, ts_cols=%d}",
113 ts.ts_lines, ts.ts_cols);
118 decode_modem_flags(struct tcb *const tcp, const kernel_ulong_t addr)
123 if (umove_or_printaddr(tcp, addr, &i))
126 printflags(modem_flags, i, "TIOCM_???");
131 term_ioctl(struct tcb *const tcp, const unsigned int code,
132 const kernel_ulong_t arg)
143 ATTRIBUTE_FALLTHROUGH;
157 decode_termios(tcp, arg);
164 ATTRIBUTE_FALLTHROUGH;
168 decode_termio(tcp, arg);
175 ATTRIBUTE_FALLTHROUGH;
177 decode_winsize(tcp, arg);
185 ATTRIBUTE_FALLTHROUGH;
187 decode_ttysize(tcp, arg);
191 /* ioctls with a direct decodable arg */
194 printxval64(tcxonc_options, arg, "TC???");
198 printxval64(tcflsh_options, arg, "TC???");
203 tprintf(", %d", (int) arg);
206 /* ioctls with an indirect parameter displayed as modem flags */
210 ATTRIBUTE_FALLTHROUGH;
214 decode_modem_flags(tcp, arg);
217 /* ioctls with an indirect parameter displayed in decimal */
233 ATTRIBUTE_FALLTHROUGH;
242 printnum_int(tcp, arg, "%d");
245 /* ioctls with an indirect parameter displayed as a char */
248 printstrn(tcp, arg, 1);
251 /* ioctls with no parameters */
269 /* ioctls which are unknown */
275 return RVAL_IOCTL_DECODED;