futex.c revision 3e0e10532dd5cdb79c710dd43822bbb5fa162cb9
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 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "defs.h"
32
33#ifdef HAVE_LINUX_FUTEX_H
34# include <linux/futex.h>
35#endif
36
37#ifndef FUTEX_PRIVATE_FLAG
38# define FUTEX_PRIVATE_FLAG 128
39#endif
40#ifndef FUTEX_CLOCK_REALTIME
41# define FUTEX_CLOCK_REALTIME 256
42#endif
43
44#include "xlat/futexops.h"
45#include "xlat/futexwakeops.h"
46#include "xlat/futexwakecmps.h"
47
48SYS_FUNC(futex)
49{
50	const long uaddr = tcp->u_arg[0];
51	const int op = tcp->u_arg[1];
52	const int cmd = op & 127;
53	const long timeout = tcp->u_arg[3];
54	const long 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
59	printaddr(uaddr);
60	tprints(", ");
61	printxval(futexops, op, "FUTEX_???");
62	tprintf(", %u", val);
63	switch (cmd) {
64	case FUTEX_WAIT:
65	case FUTEX_LOCK_PI:
66		tprints(", ");
67		print_timespec(tcp, timeout);
68		break;
69	case FUTEX_WAIT_BITSET:
70		tprints(", ");
71		print_timespec(tcp, timeout);
72		tprintf(", %#x", val3);
73		break;
74	case FUTEX_WAKE_BITSET:
75		tprintf(", %#x", val3);
76		break;
77	case FUTEX_REQUEUE:
78		tprintf(", %u, ", val2);
79		printaddr(uaddr2);
80		break;
81	case FUTEX_CMP_REQUEUE:
82	case FUTEX_CMP_REQUEUE_PI:
83		tprintf(", %u, ", val2);
84		printaddr(uaddr2);
85		tprintf(", %u", val3);
86		break;
87	case FUTEX_WAKE_OP:
88		tprintf(", %u, ", val2);
89		printaddr(uaddr2);
90		tprints(", {");
91		if ((val3 >> 28) & 8)
92			tprints("FUTEX_OP_OPARG_SHIFT|");
93		printxval(futexwakeops, (val3 >> 28) & 0x7, "FUTEX_OP_???");
94		tprintf(", %u, ", (val3 >> 12) & 0xfff);
95		printxval(futexwakecmps, (val3 >> 24) & 0xf, "FUTEX_OP_CMP_???");
96		tprintf(", %u}", val3 & 0xfff);
97		break;
98	case FUTEX_WAIT_REQUEUE_PI:
99		tprints(", ");
100		print_timespec(tcp, timeout);
101		tprints(", ");
102		printaddr(uaddr2);
103		break;
104	case FUTEX_FD:
105	case FUTEX_WAKE:
106	case FUTEX_UNLOCK_PI:
107	case FUTEX_TRYLOCK_PI:
108		break;
109	default:
110		tprintf(", %lx, %lx, %x", timeout, uaddr2, val3);
111		break;
112	}
113
114	return RVAL_DECODED;
115}
116