]> granicus.if.org Git - strace/blob - term.c
Automatically replace kernel_(scno|ureg)_t with kernel_ulong_t
[strace] / term.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "defs.h"
29 /*
30  * The C library's definition of struct termios might differ from
31  * the kernel one, and we need to use the kernel layout.
32  */
33 #include <linux/termios.h>
34
35 #include "xlat/tcxonc_options.h"
36 #include "xlat/tcflsh_options.h"
37 #include "xlat/baud_options.h"
38 #include "xlat/modem_flags.h"
39
40 static void
41 decode_termios(struct tcb *const tcp, const kernel_ulong_t addr)
42 {
43         struct termios tios;
44         int i;
45
46         if (!verbose(tcp))
47                 return;
48
49         tprints(", ");
50         if (umove_or_printaddr(tcp, addr, &tios))
51                 return;
52         if (abbrev(tcp)) {
53                 tprints("{");
54                 printxval(baud_options, tios.c_cflag & CBAUD, "B???");
55                 tprintf(" %sopost %sisig %sicanon %secho ...}",
56                         (tios.c_oflag & OPOST) ? "" : "-",
57                         (tios.c_lflag & ISIG) ? "" : "-",
58                         (tios.c_lflag & ICANON) ? "" : "-",
59                         (tios.c_lflag & ECHO) ? "" : "-");
60                 return;
61         }
62         tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
63                 (long) tios.c_iflag, (long) tios.c_oflag);
64         tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
65                 (long) tios.c_cflag, (long) tios.c_lflag);
66         tprintf("c_line=%u, ", tios.c_line);
67         if (!(tios.c_lflag & ICANON))
68                 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
69                         tios.c_cc[VMIN], tios.c_cc[VTIME]);
70         tprints("c_cc=\"");
71         for (i = 0; i < NCCS; i++)
72                 tprintf("\\x%02x", tios.c_cc[i]);
73         tprints("\"}");
74 }
75
76 static void
77 decode_termio(struct tcb *const tcp, const kernel_ulong_t addr)
78 {
79         struct termio tio;
80         int i;
81
82         if (!verbose(tcp))
83                 return;
84
85         tprints(", ");
86         if (umove_or_printaddr(tcp, addr, &tio))
87                 return;
88         if (abbrev(tcp)) {
89                 tprints("{");
90                 printxval(baud_options, tio.c_cflag & CBAUD, "B???");
91                 tprintf(" %sopost %sisig %sicanon %secho ...}",
92                         (tio.c_oflag & OPOST) ? "" : "-",
93                         (tio.c_lflag & ISIG) ? "" : "-",
94                         (tio.c_lflag & ICANON) ? "" : "-",
95                         (tio.c_lflag & ECHO) ? "" : "-");
96                 return;
97         }
98         tprintf("{c_iflags=%#lx, c_oflags=%#lx, ",
99                 (long) tio.c_iflag, (long) tio.c_oflag);
100         tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
101                 (long) tio.c_cflag, (long) tio.c_lflag);
102         tprintf("c_line=%u, ", tio.c_line);
103 #ifdef _VMIN
104         if (!(tio.c_lflag & ICANON))
105                 tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
106                         tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
107 #else /* !_VMIN */
108         if (!(tio.c_lflag & ICANON))
109                 tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
110                         tio.c_cc[VMIN], tio.c_cc[VTIME]);
111 #endif /* !_VMIN */
112         tprints("c_cc=\"");
113         for (i = 0; i < NCC; i++)
114                 tprintf("\\x%02x", tio.c_cc[i]);
115         tprints("\"}");
116 }
117
118 static void
119 decode_winsize(struct tcb *const tcp, const kernel_ulong_t addr)
120 {
121         struct winsize ws;
122
123         if (!verbose(tcp))
124                 return;
125
126         tprints(", ");
127         if (umove_or_printaddr(tcp, addr, &ws))
128                 return;
129         tprintf("{ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
130                 ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
131 }
132
133 #ifdef TIOCGSIZE
134 static void
135 decode_ttysize(struct tcb *const tcp, const kernel_ulong_t addr)
136 {
137         struct ttysize ts;
138
139         if (!verbose(tcp))
140                 return;
141
142         tprints(", ");
143         if (umove_or_printaddr(tcp, addr, &ts))
144                 return;
145         tprintf("{ts_lines=%d, ts_cols=%d}",
146                 ts.ts_lines, ts.ts_cols);
147 }
148 #endif
149
150 static void
151 decode_modem_flags(struct tcb *const tcp, const kernel_ulong_t addr)
152 {
153         int i;
154
155         if (!verbose(tcp))
156                 return;
157
158         tprints(", ");
159         if (umove_or_printaddr(tcp, addr, &i))
160                 return;
161         tprints("[");
162         printflags(modem_flags, i, "TIOCM_???");
163         tprints("]");
164 }
165
166 int
167 term_ioctl(struct tcb *const tcp, const unsigned int code,
168            const kernel_ulong_t arg)
169 {
170         switch (code) {
171         /* struct termios */
172         case TCGETS:
173 #ifdef TCGETS2
174         case TCGETS2:
175 #endif
176         case TIOCGLCKTRMIOS:
177                 if (entering(tcp))
178                         return 0;
179         case TCSETS:
180 #ifdef TCSETS2
181         case TCSETS2:
182 #endif
183         case TCSETSW:
184 #ifdef TCSETSW2
185         case TCSETSW2:
186 #endif
187         case TCSETSF:
188 #ifdef TCSETSF2
189         case TCSETSF2:
190 #endif
191         case TIOCSLCKTRMIOS:
192                 decode_termios(tcp, arg);
193                 break;
194
195         /* struct termio */
196         case TCGETA:
197                 if (entering(tcp))
198                         return 0;
199         case TCSETA:
200         case TCSETAW:
201         case TCSETAF:
202                 decode_termio(tcp, arg);
203                 break;
204
205         /* struct winsize */
206         case TIOCGWINSZ:
207                 if (entering(tcp))
208                         return 0;
209         case TIOCSWINSZ:
210                 decode_winsize(tcp, arg);
211                 break;
212
213         /* struct ttysize */
214 #ifdef TIOCGSIZE
215         case TIOCGSIZE:
216                 if (entering(tcp))
217                         return 0;
218         case TIOCSSIZE:
219                 decode_ttysize(tcp, arg);
220                 break;
221 #endif
222
223         /* ioctls with a direct decodable arg */
224         case TCXONC:
225                 tprints(", ");
226                 printxval64(tcxonc_options, arg, "TC???");
227                 break;
228         case TCFLSH:
229                 tprints(", ");
230                 printxval64(tcflsh_options, arg, "TC???");
231                 break;
232         case TCSBRK:
233         case TCSBRKP:
234         case TIOCSCTTY:
235                 tprintf(", %d", (int) arg);
236                 break;
237
238         /* ioctls with an indirect parameter displayed as modem flags */
239         case TIOCMGET:
240                 if (entering(tcp))
241                         return 0;
242         case TIOCMBIS:
243         case TIOCMBIC:
244         case TIOCMSET:
245                 decode_modem_flags(tcp, arg);
246                 break;
247
248         /* ioctls with an indirect parameter displayed in decimal */
249         case TIOCGPGRP:
250         case TIOCGSID:
251         case TIOCGETD:
252         case TIOCGSOFTCAR:
253         case TIOCGPTN:
254         case FIONREAD:
255         case TIOCOUTQ:
256 #ifdef TIOCGEXCL
257         case TIOCGEXCL:
258 #endif
259 #ifdef TIOCGDEV
260         case TIOCGDEV:
261 #endif
262                 if (entering(tcp))
263                         return 0;
264         case TIOCSPGRP:
265         case TIOCSETD:
266         case FIONBIO:
267         case FIOASYNC:
268         case TIOCPKT:
269         case TIOCSSOFTCAR:
270         case TIOCSPTLCK:
271                 tprints(", ");
272                 printnum_int(tcp, arg, "%d");
273                 break;
274
275         /* ioctls with an indirect parameter displayed as a char */
276         case TIOCSTI:
277                 tprints(", ");
278                 printstrn(tcp, arg, 1);
279                 break;
280
281         /* ioctls with no parameters */
282
283         case TIOCSBRK:
284         case TIOCCBRK:
285         case TIOCCONS:
286         case TIOCNOTTY:
287         case TIOCEXCL:
288         case TIOCNXCL:
289         case FIOCLEX:
290         case FIONCLEX:
291 #ifdef TIOCVHANGUP
292         case TIOCVHANGUP:
293 #endif
294 #ifdef TIOCSSERIAL
295         case TIOCSSERIAL:
296 #endif
297                 break;
298
299         /* ioctls which are unknown */
300
301         default:
302                 return RVAL_DECODED;
303         }
304
305         return RVAL_DECODED | 1;
306 }