]> granicus.if.org Git - strace/blob - futex.c
xlat: add ability to specify a default string to print_xlat_ex
[strace] / futex.c
1 /*
2  * Copyright (c) 2002-2003 Roland McGrath  <roland@redhat.com>
3  * Copyright (c) 2007-2008 Ulrich Drepper <drepper@redhat.com>
4  * Copyright (c) 2009 Andreas Schwab <schwab@redhat.com>
5  * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
6  * Copyright (c) 2014-2018 The strace developers.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
19  *
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.
30  */
31
32 #include "defs.h"
33
34 #ifndef FUTEX_PRIVATE_FLAG
35 # define FUTEX_PRIVATE_FLAG 128
36 #endif
37 #ifndef FUTEX_CLOCK_REALTIME
38 # define FUTEX_CLOCK_REALTIME 256
39 #endif
40 #ifndef FUTEX_OP_OPARG_SHIFT
41 # define FUTEX_OP_OPARG_SHIFT 8
42 #endif
43
44 #include "xlat/futexops.h"
45 #include "xlat/futexwakeops.h"
46 #include "xlat/futexwakecmps.h"
47
48 SYS_FUNC(futex)
49 {
50         const kernel_ulong_t uaddr = tcp->u_arg[0];
51         const int op = tcp->u_arg[1];
52         const int cmd = op & 127;
53         const kernel_ulong_t timeout = tcp->u_arg[3];
54         const kernel_ulong_t uaddr2 = tcp->u_arg[4];
55         const unsigned int val = tcp->u_arg[2];
56         const unsigned int val2 = tcp->u_arg[3];
57         const unsigned int val3 = tcp->u_arg[5];
58         const char *comment;
59
60         printaddr(uaddr);
61         tprints(", ");
62         printxval(futexops, op, "FUTEX_???");
63         switch (cmd) {
64         case FUTEX_WAIT:
65                 tprintf(", %u", val);
66                 tprints(", ");
67                 print_timespec(tcp, timeout);
68                 break;
69         case FUTEX_LOCK_PI:
70                 tprints(", ");
71                 print_timespec(tcp, timeout);
72                 break;
73         case FUTEX_WAIT_BITSET:
74                 tprintf(", %u", val);
75                 tprints(", ");
76                 print_timespec(tcp, timeout);
77                 tprintf(", %#x", val3);
78                 break;
79         case FUTEX_WAKE_BITSET:
80                 tprintf(", %u", val);
81                 tprintf(", %#x", val3);
82                 break;
83         case FUTEX_REQUEUE:
84                 tprintf(", %u", val);
85                 tprintf(", %u, ", val2);
86                 printaddr(uaddr2);
87                 break;
88         case FUTEX_CMP_REQUEUE:
89         case FUTEX_CMP_REQUEUE_PI:
90                 tprintf(", %u", val);
91                 tprintf(", %u, ", val2);
92                 printaddr(uaddr2);
93                 tprintf(", %u", val3);
94                 break;
95         case FUTEX_WAKE_OP:
96                 tprintf(", %u", val);
97                 tprintf(", %u, ", val2);
98                 printaddr(uaddr2);
99                 tprints(", ");
100                 if ((val3 >> 28) & FUTEX_OP_OPARG_SHIFT) {
101                         print_xlat(FUTEX_OP_OPARG_SHIFT);
102                         tprints("<<28|");
103                 }
104                 comment = printxval(futexwakeops, (val3 >> 28) & 0x7, NULL)
105                         ? NULL : "FUTEX_OP_???";
106                 tprints("<<28");
107                 tprints_comment(comment);
108                 tprintf("|%#x<<12|", (val3 >> 12) & 0xfff);
109                 comment = printxval(futexwakecmps, (val3 >> 24) & 0xf, NULL)
110                         ? NULL : "FUTEX_OP_CMP_???";
111                 tprints("<<24");
112                 tprints_comment(comment);
113                 tprintf("|%#x", val3 & 0xfff);
114                 break;
115         case FUTEX_WAIT_REQUEUE_PI:
116                 tprintf(", %u", val);
117                 tprints(", ");
118                 print_timespec(tcp, timeout);
119                 tprints(", ");
120                 printaddr(uaddr2);
121                 break;
122         case FUTEX_FD:
123         case FUTEX_WAKE:
124                 tprintf(", %u", val);
125                 break;
126         case FUTEX_UNLOCK_PI:
127         case FUTEX_TRYLOCK_PI:
128                 break;
129         default:
130                 tprintf(", %u", val);
131                 tprints(", ");
132                 printaddr(timeout);
133                 tprints(", ");
134                 printaddr(uaddr2);
135                 tprintf(", %#x", val3);
136                 break;
137         }
138
139         return RVAL_DECODED;
140 }