]> granicus.if.org Git - strace/blob - stream.c
Fix time syscall decoding for some personalities
[strace] / stream.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "defs.h"
30
31 /* Who has STREAMS syscalls?
32  * Linux hasn't. Solaris has (had?).
33  * Just in case I miss something, retain in for Sparc...
34  */
35 #if (defined SPARC || defined SPARC64) \
36  && (defined SYS_putpmsg || defined SYS_getpmsg)
37
38 # ifdef HAVE_STROPTS_H
39 #  include <stropts.h>
40 # else
41 struct strbuf {
42         int     maxlen;                 /* no. of bytes in buffer */
43         int     len;                    /* no. of bytes returned */
44         const char *buf;                /* pointer to data */
45 };
46 #  define MORECTL 1
47 #  define MOREDATA 2
48 # endif
49
50 static void
51 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
52 {
53         if (sbp->maxlen == -1 && getting)
54                 tprints("{maxlen=-1}");
55         else {
56                 tprints("{");
57                 if (getting)
58                         tprintf("maxlen=%d, ", sbp->maxlen);
59                 tprintf("len=%d, buf=", sbp->len);
60                 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
61                 tprints("}");
62         }
63 }
64
65 static void
66 printstrbufarg(struct tcb *tcp, long arg, int getting)
67 {
68         struct strbuf buf;
69
70         if (arg == 0)
71                 tprints("NULL");
72         else if (umove(tcp, arg, &buf) < 0)
73                 tprints("{...}");
74         else
75                 printstrbuf(tcp, &buf, getting);
76         tprints(", ");
77 }
78
79 # include "xlat/pmsgflags.h"
80 # ifdef SYS_putpmsg
81 SYS_FUNC(putpmsg)
82 {
83         int i;
84
85         if (entering(tcp)) {
86                 /* fd */
87                 tprintf("%ld, ", tcp->u_arg[0]);
88                 /* control and data */
89                 for (i = 1; i < 3; i++)
90                         printstrbufarg(tcp, tcp->u_arg[i], 0);
91                 /* band */
92                 tprintf("%ld, ", tcp->u_arg[3]);
93                 /* flags */
94                 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
95         }
96         return 0;
97 }
98 # endif
99 # ifdef SYS_getpmsg
100 SYS_FUNC(getpmsg)
101 {
102         int i, flags;
103
104         if (entering(tcp)) {
105                 /* fd */
106                 tprintf("%lu, ", tcp->u_arg[0]);
107         } else {
108                 if (syserror(tcp)) {
109                         tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
110                                 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
111                         return 0;
112                 }
113                 /* control and data */
114                 for (i = 1; i < 3; i++)
115                         printstrbufarg(tcp, tcp->u_arg[i], 1);
116                 /* pointer to band */
117                 printnum_int(tcp, tcp->u_arg[3], "%d");
118                 tprints(", ");
119                 /* pointer to flags */
120                 if (tcp->u_arg[4] == 0)
121                         tprints("NULL");
122                 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
123                         tprints("[?]");
124                 else {
125                         tprints("[");
126                         printflags(pmsgflags, flags, "MSG_???");
127                         tprints("]");
128                 }
129                 /* decode return value */
130                 switch (tcp->u_rval) {
131                 case MORECTL:
132                         tcp->auxstr = "MORECTL";
133                         break;
134                 case MORECTL|MOREDATA:
135                         tcp->auxstr = "MORECTL|MOREDATA";
136                         break;
137                 case MOREDATA:
138                         tcp->auxstr = "MORECTL";
139                         break;
140                 default:
141                         tcp->auxstr = NULL;
142                         break;
143                 }
144         }
145         return RVAL_HEX | RVAL_STR;
146 }
147 # endif
148 #endif /* STREAMS syscalls support */