libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
futex.hxx
1#pragma once
2
3// Linux
4#include <linux/futex.h> // futex(2)
5
6// cosmos
7#include <cosmos/BitMask.hxx>
8
9// clues
10#include <clues/items/items.hxx>
11
12namespace clues::item {
13
15
18class CLUES_API FutexOperation :
19 public ValueInParameter {
20public: // types
21
22 enum class Command : int {
23 WAIT = FUTEX_WAIT, /* wait for `val` to be changed */
24 WAKE = FUTEX_WAKE, /* wake given number of waiters */
25 WAIT_REQUEUE_PI = FUTEX_WAIT_REQUEUE_PI, /* wait on a non-PI futex, potentially being requeued to a PI futex on addr2 */
26 CREATE_FD = FUTEX_FD, /* create a futex FD, dropped in Linux 2.6.25 */
27 REQUEUE = FUTEX_REQUEUE, /* wakeup some waiters, requeue others */
28 CMP_REQUEUE = FUTEX_CMP_REQUEUE, /* additionally compare futex value */
29 CMP_REQUEUE_PI = FUTEX_CMP_REQUEUE_PI, /* CMP_REQUEUE with priority-inheritance semantics. `val1` must be 1. */
30 WAKE_OP = FUTEX_WAKE_OP, /* wake up waiters based on provided criteria */
31 WAIT_BITSET = FUTEX_WAIT_BITSET, /* wait based on a 32-bit bitset limiting wakeups */
32 WAKE_BITSET = FUTEX_WAKE_BITSET, /* wake up waiters with matching bits in a 32-bit bitset */
33 LOCK_PI = FUTEX_LOCK_PI, /* priority-inheritance lock operation */
34 LOCK_PI2 = FUTEX_LOCK_PI2, /* save as above, but supports Flag::REALTIME on top */
35 TRYLOCK_PI = FUTEX_TRYLOCK_PI, /* try to lock the futex based on extra kernel information, does not block */
36 UNLOCK_PI = FUTEX_UNLOCK_PI, /* unlock with priority inheritance semantics */
37 };
38
39 enum class Flag : int {
40 PRIVATE_FLAG = FUTEX_PRIVATE_FLAG, /* futex between threads only */
41 REALTIME = FUTEX_CLOCK_REALTIME, /* for wait related operations, use CLOCK_REALTIME instead of MONOTONIC */
42 };
43
44 using Flags = cosmos::BitMask<Flag>;
45
46public: // functions
47
48 explicit FutexOperation() :
49 ValueInParameter{"op", "futex operation"} {
50 }
51
52 std::string str() const override;
53
54 void processValue(const Tracee &) override;
55
56 auto command() const {
57 return m_cmd;
58 }
59
60 auto flags() const {
61 return m_flags;
62 }
63
64protected: // data
65
66 Command m_cmd = Command{0};
67 Flags m_flags;
68};
69
71
89class CLUES_API FutexWakeOperation :
90 public ValueInParameter {
91public: // types
92
94 enum class Operation : uint32_t {
95 SET = FUTEX_OP_SET,
96 ADD = FUTEX_OP_ADD,
97 OR = FUTEX_OP_OR,
98 ANDN = FUTEX_OP_ANDN,
99 XOR = FUTEX_OP_XOR,
100 };
101
102 enum class Comparator : uint32_t {
103 EQUAL = FUTEX_OP_CMP_EQ,
104 UNEQUAL = FUTEX_OP_CMP_NE,
105 LESS_THAN = FUTEX_OP_CMP_LT,
106 LESS_EQUAL = FUTEX_OP_CMP_LE,
107 GREATER_THAN = FUTEX_OP_CMP_GT,
108 GREATER_EQUAL = FUTEX_OP_CMP_GE,
109 };
110
111public: // functions
112
113 explicit FutexWakeOperation() :
114 ValueInParameter{"wake_op", "wake operation settings"} {
115 }
116
117 std::string str() const override;
118
119 void processValue(const Tracee &) override;
120
121 auto operation() const {
122 return m_op;
123 }
124
125 auto comparator() const {
126 return m_comp;
127 }
128
129 bool doShiftArg() const {
130 return m_shift_arg;
131 }
132
133 uint32_t oparg() const {
134 return m_oparg;
135 }
136
137 uint32_t cmparg() const {
138 return m_cmparg;
139 }
140
141protected: // data
142
143 Operation m_op = Operation{0};
144 Comparator m_comp = Comparator{0};
146 bool m_shift_arg = false;
148 uint32_t m_oparg = 0;
150 uint32_t m_cmparg = 0;
151};
152
153} // end ns
Base class for traced processes.
Definition Tracee.hxx:39
std::string str() const override
Returns a human readable string representation of the item.
Definition futex.cxx:11
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition futex.cxx:54
Composite bit values used in val3 for futex() operation FUTEX_WAKE_OP.
Definition futex.hxx:90
Operation
Atomic operation to be carried out on futex value.
Definition futex.hxx:94
@ OR
bitwise or uaddr2 |= oparg
Definition futex.hxx:97
@ SET
assignment uaddr2 = oparg
Definition futex.hxx:95
@ XOR
bitwise XOR uaddr ^= oparg
Definition futex.hxx:99
@ ADD
addition uaddr2 += oparg
Definition futex.hxx:96
@ ANDN
bitwise and of negated value uaddr2 &= ~oparg
Definition futex.hxx:98
uint32_t m_oparg
! The operation argument used in uaddr2 OP oparg.
Definition futex.hxx:148
uint32_t m_cmparg
! The comparison argument used in oldval CMP cmparg.
Definition futex.hxx:150
bool m_shift_arg
! Whether oparg is additionally replaced by 1 << oparg.
Definition futex.hxx:146
Specialization of ValueParameter for PARAM_IN parameters.
Definition items.hxx:47