blob: e4dfa08605e426040a6edd500a8cb089c464ef87 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
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>
Elliott Hughes03a418e2018-06-15 13:11:40 -07006 * Copyright (c) 2014-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00007 * 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
Dmitry V. Levine314f802014-12-11 19:25:02 +000032#include "defs.h"
33
Dmitry V. Levine314f802014-12-11 19:25:02 +000034#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
Elliott Hughes03a418e2018-06-15 13:11:40 -070040#ifndef FUTEX_OP_OPARG_SHIFT
41# define FUTEX_OP_OPARG_SHIFT 8
42#endif
Dmitry V. Levin003cc9f2015-06-17 19:00:17 +000043
Elliott Hughesc1873762018-12-19 15:13:36 -080044#include "xlat/futexbitset.h"
Dmitry V. Levine314f802014-12-11 19:25:02 +000045#include "xlat/futexops.h"
Dmitry V. Levine314f802014-12-11 19:25:02 +000046#include "xlat/futexwakeops.h"
47#include "xlat/futexwakecmps.h"
48
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000049SYS_FUNC(futex)
Dmitry V. Levine314f802014-12-11 19:25:02 +000050{
Elliott Hughesd35df492017-02-15 15:19:05 -080051 const kernel_ulong_t uaddr = tcp->u_arg[0];
Dmitry V. Levinb5821092015-07-20 13:15:51 +000052 const int op = tcp->u_arg[1];
53 const int cmd = op & 127;
Elliott Hughesd35df492017-02-15 15:19:05 -080054 const kernel_ulong_t timeout = tcp->u_arg[3];
55 const kernel_ulong_t uaddr2 = tcp->u_arg[4];
Dmitry V. Levinb5821092015-07-20 13:15:51 +000056 const unsigned int val = tcp->u_arg[2];
57 const unsigned int val2 = tcp->u_arg[3];
58 const unsigned int val3 = tcp->u_arg[5];
Elliott Hughes39bac052017-05-25 16:56:11 -070059 const char *comment;
Dmitry V. Levinb5821092015-07-20 13:15:51 +000060
61 printaddr(uaddr);
62 tprints(", ");
63 printxval(futexops, op, "FUTEX_???");
Dmitry V. Levinb5821092015-07-20 13:15:51 +000064 switch (cmd) {
65 case FUTEX_WAIT:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030066 tprintf(", %u", val);
67 tprints(", ");
68 print_timespec(tcp, timeout);
69 break;
Dmitry V. Levinb5821092015-07-20 13:15:51 +000070 case FUTEX_LOCK_PI:
71 tprints(", ");
Dmitry V. Levin59385262015-09-18 15:16:11 +000072 print_timespec(tcp, timeout);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000073 break;
74 case FUTEX_WAIT_BITSET:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030075 tprintf(", %u", val);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000076 tprints(", ");
Dmitry V. Levin59385262015-09-18 15:16:11 +000077 print_timespec(tcp, timeout);
Elliott Hughesc1873762018-12-19 15:13:36 -080078 tprints(", ");
79 printxval(futexbitset, val3, NULL);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000080 break;
81 case FUTEX_WAKE_BITSET:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030082 tprintf(", %u", val);
Elliott Hughesc1873762018-12-19 15:13:36 -080083 tprints(", ");
84 printxval(futexbitset, val3, NULL);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000085 break;
86 case FUTEX_REQUEUE:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030087 tprintf(", %u", val);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000088 tprintf(", %u, ", val2);
89 printaddr(uaddr2);
90 break;
91 case FUTEX_CMP_REQUEUE:
92 case FUTEX_CMP_REQUEUE_PI:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030093 tprintf(", %u", val);
Dmitry V. Levinb5821092015-07-20 13:15:51 +000094 tprintf(", %u, ", val2);
95 printaddr(uaddr2);
96 tprintf(", %u", val3);
97 break;
98 case FUTEX_WAKE_OP:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +030099 tprintf(", %u", val);
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000100 tprintf(", %u, ", val2);
101 printaddr(uaddr2);
Elliott Hughesd35df492017-02-15 15:19:05 -0800102 tprints(", ");
Elliott Hughes03a418e2018-06-15 13:11:40 -0700103 if ((val3 >> 28) & FUTEX_OP_OPARG_SHIFT) {
104 print_xlat(FUTEX_OP_OPARG_SHIFT);
105 tprints("<<28|");
106 }
Elliott Hughes39bac052017-05-25 16:56:11 -0700107 comment = printxval(futexwakeops, (val3 >> 28) & 0x7, NULL)
108 ? NULL : "FUTEX_OP_???";
109 tprints("<<28");
110 tprints_comment(comment);
Elliott Hughesd35df492017-02-15 15:19:05 -0800111 tprintf("|%#x<<12|", (val3 >> 12) & 0xfff);
Elliott Hughes39bac052017-05-25 16:56:11 -0700112 comment = printxval(futexwakecmps, (val3 >> 24) & 0xf, NULL)
113 ? NULL : "FUTEX_OP_CMP_???";
114 tprints("<<24");
115 tprints_comment(comment);
Elliott Hughesd35df492017-02-15 15:19:05 -0800116 tprintf("|%#x", val3 & 0xfff);
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000117 break;
118 case FUTEX_WAIT_REQUEUE_PI:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +0300119 tprintf(", %u", val);
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000120 tprints(", ");
Dmitry V. Levin59385262015-09-18 15:16:11 +0000121 print_timespec(tcp, timeout);
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000122 tprints(", ");
123 printaddr(uaddr2);
124 break;
Eugene Syromyatnikov3e0e1052016-08-29 23:57:38 +0300125 case FUTEX_FD:
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000126 case FUTEX_WAKE:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +0300127 tprintf(", %u", val);
128 break;
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000129 case FUTEX_UNLOCK_PI:
130 case FUTEX_TRYLOCK_PI:
131 break;
132 default:
Eugene Syromyatnikov110da332016-08-30 00:01:45 +0300133 tprintf(", %u", val);
Elliott Hughesd35df492017-02-15 15:19:05 -0800134 tprints(", ");
135 printaddr(timeout);
Eugene Syromyatnikovebeae242016-08-29 23:59:01 +0300136 tprints(", ");
137 printaddr(uaddr2);
138 tprintf(", %#x", val3);
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000139 break;
Dmitry V. Levine314f802014-12-11 19:25:02 +0000140 }
Dmitry V. Levinb5821092015-07-20 13:15:51 +0000141
142 return RVAL_DECODED;
Dmitry V. Levine314f802014-12-11 19:25:02 +0000143}