libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::FutexSystemCall Struct Reference

futex() system call with context-sensitive parameters and return values. More...

#include <thread.hxx>

+ Inheritance diagram for clues::FutexSystemCall:

Public Attributes

item::GenericPointerValue futex_addr
 
item::FutexOperation operation
 
std::optional< item::Uint32Valuevalue
 ! the value expected at futex_addr (WAIT, WAIT_REQUEUE_PI).
 
std::optional< item::Uint32Valuewake_count
 ! number of waiters to wake up (WAKE, REQUEUE, CMP_REQUEUE, WAKE_OP, CMD_REQUEUE_PI).
 
std::optional< item::SignalNumberfd_sig
 ! signal used for asynchronous notifications (CREATE_FD).
 
std::optional< item::TimeSpecParametertimeout
 ! optional relative timeout (WAIT) or absolute timeout (WAIT_BITSET, LOCK_PI, LOCK_PI2).
 
std::optional< item::GenericPointerValuefutex2_addr
 ! "uaddr2" requeue address (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI, WAIT_REQUEUE_PI) or additional futex (WAKE_OP).
 
std::optional< item::Uint32Valuerequeue_value
 ! "val3" used for comparison in CMP_REQUEUE, CMP_REQUEUE_PI.
 
std::optional< item::Uint32Valuerequeue_limit
 ! "val2", upper limit on waiters to be requeued to addr2 (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI).
 
std::optional< item::Uint32Valuewake_count2
 ! "val2", number of waiters at futex2_addr to wakeup (WAKE_OP).
 
std::optional< item::FutexWakeOperationwake_op
 ! instructions for how to perform the wake operation (WAKE_OP).
 
std::optional< item::GenericPointerValuebitset
 ! bitset to restrict wait/wakeup (FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET).
 
std::optional< item::ReturnValuenum_woken_up
 ! number of waiters woken up (WAKE, WAKE_OP).
 
std::optional< item::FileDescriptornew_fd
 ! new file descriptor (CREATE_FD).
 
std::optional< item::SuccessResultresult
 ! success status (all remaining operations).
 

Protected Member Functions

bool check2ndPass (const Tracee &) override
 Check whether a second pass needs to be made processing parameters.
 
void prepareNewSystemCall () override
 Perform any necessary actions before processing a new system call entry event.
 
void updateFDTracking (const Tracee &proc) override
 Update file descriptor tracking.
 
- Protected Member Functions inherited from clues::SystemCall
void fillParameters (const Tracee &proc, const SystemCallInfo &info)
 
void setReturnItem (SystemCallItem &ret)
 Sets the return value system call item.
 
void addParameters ()
 
template<typename T, typename... Targs>
void addParameters (T &par, Targs &...rest)
 
template<typename... Targs>
void setParameters (Targs &...args)
 
void dropFD (const Tracee &proc, const cosmos::FileNum num)
 
void trackFD (const Tracee &proc, FDInfo &&info)
 

Additional Inherited Members

- Public Types inherited from clues::SystemCall
using ParameterVector = std::vector<SystemCallItemPtr>
 Vector of the parameters required for a system call.
 
- Public Member Functions inherited from clues::SystemCall
 SystemCall (const SystemCallNr nr)
 Instantiates a new SystemCall object with given properties.
 
 SystemCall (const SystemCall &other)=delete
 
SystemCalloperator= (const SystemCall &other)=delete
 
void setEntryInfo (const Tracee &proc, const SystemCallInfo &info)
 Update the stored parameter values from the given tracee.
 
void setExitInfo (const Tracee &proc, const SystemCallInfo &info)
 Update possible out and return parameter values from the given tracee.
 
std::string_view name () const
 Returns the system call's human readable name.
 
size_t numPars () const
 Returns the number of parameters for this system call.
 
SystemCallNr callNr () const
 Returns the system call table number for this system call.
 
const ParameterVectorparameters () const
 Access to the parameters associated with this system call.
 
SystemCallItemPtr result () const
 Access to the return value parameter associated with this system call.
 
std::optional< ErrnoResulterror () const
 Access to the errno result seen for this system call.
 
bool hasOutParameter () const
 
bool hasResultValue () const
 
bool hasErrorCode () const
 
ABI abi () const
 Returns the system call ABi seen during system call entry.
 
bool is32BitEmulationABI () const
 
const SystemCallInfocurrentInfo () const
 Access the current SystemCallInfo if currently processing syscall entry/exit.
 
- Static Public Member Functions inherited from clues::SystemCall
static const char * name (const SystemCallNr nr)
 Returns the name of the given system call or "<unknown>" if unknown.
 
static bool validNr (const SystemCallNr nr)
 Returns whether the given system call number is in a valid range.
 
- Protected Attributes inherited from clues::SystemCall
SystemCallNr m_nr
 The raw system call number of the system call.
 
const std::string_view m_name
 The basic name of the system call.
 
const SystemCallInfom_info = nullptr
 Current system call info during entry/exit processing, nullptr otherwise.
 
SystemCallItemPtr m_return
 The return value of the system call.
 
std::optional< ErrnoResultm_error
 If the system call fails, this is the error code.
 
ParameterVector m_pars
 The array of system call parameters, if any.
 
ABI m_abi = ABI::UNKNOWN
 The current system call ABI which is in effect.
 

Detailed Description

futex() system call with context-sensitive parameters and return values.

This is an ioctl() style system call or high complexity.

Definition at line 83 of file thread.hxx.

Constructor & Destructor Documentation

◆ FutexSystemCall()

clues::FutexSystemCall::FutexSystemCall ( )
inline

Definition at line 86 of file thread.hxx.

86 :
87 SystemCall{SystemCallNr::FUTEX},
88 futex_addr{"addr", "pointer to futex word"},
89 result{item::SuccessResult{}} {
90 /*
91 * minimal default setup, the actual parameters and return
92 * values are setup in the member functions in a
93 * context-sensitive manner.
94 */
96 setParameters(futex_addr, operation);
97 }
void setReturnItem(SystemCallItem &ret)
Sets the return value system call item.
SystemCall(const SystemCallNr nr)
Instantiates a new SystemCall object with given properties.
std::optional< item::SuccessResult > result
! success status (all remaining operations).
Definition thread.hxx:135

Member Function Documentation

◆ check2ndPass()

bool clues::FutexSystemCall::check2ndPass ( const Tracee & )
overrideprotectedvirtual

Check whether a second pass needs to be made processing parameters.

This function can be overridden by the actual system call implementation to perform context-sensitive evaluation of system call parameters (e.g. for ioctl() style system calls) upon system call entry.

The implementation of this function is allowed to modify the amount and types of system call parameters and return parameter. In this case true must be returned to let the base class implementation reevaluate all system call parameters.

Reimplemented from clues::SystemCall.

Definition at line 31 of file thread.cxx.

31 {
32 using enum item::FutexOperation::Command;
33
34 auto setNewReturnItem = [this](auto &new_ret) {
35 result.reset();
36 setReturnItem(new_ret);
37 };
38
39 auto setWokenUpReturnValue = [this, setNewReturnItem]() {
40 num_woken_up.emplace(item::ReturnValue{"nwokenup", "number of waiters woken up"});
41 setNewReturnItem(*num_woken_up);
42 };
43
44 const auto command = operation.command();
45
46 switch (command) {
47 case WAIT: [[fallthrough]];
48 case WAIT_BITSET:
49 value.emplace(item::Uint32Value{"value"});
50 timeout.emplace(item::TimeSpecParameter{"timeout"});
51 if (command == WAIT) {
52 addParameters(*value, *timeout);
53 } else {
54 bitset.emplace(item::GenericPointerValue{"bitset"});
55 addParameters(*value, *timeout, item::unused, *bitset);
56 }
57 break;
58 case WAKE: [[fallthrough]];
59 case WAKE_BITSET:
60 wake_count.emplace(item::Uint32Value{"nwakeup", "number of waiters to wake up"});
61 if (command == WAKE) {
62 addParameters(*wake_count);
63 } else {
64 bitset.emplace(item::GenericPointerValue{"bitset"});
65 addParameters(*wake_count, item::unused, item::unused, *bitset);
66 }
67
68 setWokenUpReturnValue();
69 break;
70 case CREATE_FD:
71 /*
72 * this operation is not supported anymore, but we model it
73 * anyway
74 */
75 fd_sig.emplace(item::SignalNumber{});
76 new_fd.emplace(item::FileDescriptor{});
77 addParameters(*fd_sig);
78 new_fd.emplace(item::FileDescriptor{ItemType::RETVAL});
79 setNewReturnItem(*new_fd);
80 break;
81 case REQUEUE: [[fallthrough]];
82 case CMP_REQUEUE: [[fallthrough]];
83 case CMP_REQUEUE_PI:
84 wake_count.emplace(item::Uint32Value{"nwakeup", "number of waiters to wake up"});
85 requeue_limit.emplace(item::Uint32Value{"val2", "max number of waiters to requeue"});
86 futex2_addr.emplace(item::GenericPointerValue{"addr2", "requeue address"});
87 if (command == REQUEUE) {
88 addParameters(*wake_count, *requeue_limit, *futex2_addr);
89 } else {
90 requeue_value.emplace(item::Uint32Value{"val3", "comparison value"});
92 }
93
94 setWokenUpReturnValue();
95 break;
96 case WAKE_OP:
97 wake_count.emplace(item::Uint32Value{"nwakeup", "number of waiters to wake up at addr1"});
98 wake_count2.emplace(item::Uint32Value{"nwakeup2", "number of waiters to wake up at addr2"});
99 futex2_addr.emplace(item::GenericPointerValue{"addr2", "op-futex"});
100 wake_op.emplace(item::FutexWakeOperation{});
101 addParameters(*wake_count, *wake_count2, *futex2_addr, *wake_op);
102
103 setWokenUpReturnValue();
104 break;
105 case LOCK_PI: [[fallthrough]];
106 case LOCK_PI2:
107 // absolute timeout measured against CLOCK_REALTIME (or
108 // MONOTONIC in case of LOCK_PI2, if the CLOCK_REALTIME flag
109 // is not passed in `operation`.
110 timeout.emplace(item::TimeSpecParameter{"timeout"});
111 addParameters(item::unused, *timeout);
112 break;
113 case TRYLOCK_PI: [[fallthrough]];
114 case UNLOCK_PI:
115 // none of the extra arguments are used in these cases
116 break;
117 case WAIT_REQUEUE_PI:
118 value.emplace(item::Uint32Value{"value"});
119 // absolute timeout
120 timeout.emplace(item::TimeSpecParameter{"timeout"});
121 futex2_addr.emplace(item::GenericPointerValue{"addr2", "requeue address"});
122 addParameters(*value, *timeout, *futex2_addr);
123 break;
124 default:
125 /* unknown operation? keep defaults. */
126 break;
127 }
128
129 return true;
130}
@ RETVAL
A system call return value.
std::optional< item::Uint32Value > wake_count2
! "val2", number of waiters at futex2_addr to wakeup (WAKE_OP).
Definition thread.hxx:122
std::optional< item::Uint32Value > requeue_limit
! "val2", upper limit on waiters to be requeued to addr2 (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI).
Definition thread.hxx:120
std::optional< item::FileDescriptor > new_fd
! new file descriptor (CREATE_FD).
Definition thread.hxx:133
std::optional< item::FutexWakeOperation > wake_op
! instructions for how to perform the wake operation (WAKE_OP).
Definition thread.hxx:124
std::optional< item::Uint32Value > requeue_value
! "val3" used for comparison in CMP_REQUEUE, CMP_REQUEUE_PI.
Definition thread.hxx:118
std::optional< item::GenericPointerValue > bitset
! bitset to restrict wait/wakeup (FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET).
Definition thread.hxx:126
std::optional< item::Uint32Value > wake_count
! number of waiters to wake up (WAKE, REQUEUE, CMP_REQUEUE, WAKE_OP, CMD_REQUEUE_PI).
Definition thread.hxx:110
std::optional< item::Uint32Value > value
! the value expected at futex_addr (WAIT, WAIT_REQUEUE_PI).
Definition thread.hxx:108
std::optional< item::TimeSpecParameter > timeout
! optional relative timeout (WAIT) or absolute timeout (WAIT_BITSET, LOCK_PI, LOCK_PI2).
Definition thread.hxx:114
std::optional< item::SignalNumber > fd_sig
! signal used for asynchronous notifications (CREATE_FD).
Definition thread.hxx:112
std::optional< item::GenericPointerValue > futex2_addr
! "uaddr2" requeue address (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI, WAIT_REQUEUE_PI) or additional fute...
Definition thread.hxx:116
std::optional< item::ReturnValue > num_woken_up
! number of waiters woken up (WAKE, WAKE_OP).
Definition thread.hxx:131

◆ prepareNewSystemCall()

void clues::FutexSystemCall::prepareNewSystemCall ( )
overrideprotectedvirtual

Perform any necessary actions before processing a new system call entry event.

Reimplemented from clues::SystemCall.

Definition at line 6 of file thread.cxx.

6 {
7 /* drop all but the fixed initial two parameters */
8 m_pars.erase(m_pars.begin() + 2, m_pars.end());
9
10 /* args */
11 value.reset();
12 wake_count.reset();
13 fd_sig.reset();
14 timeout.reset();
15 futex2_addr.reset();
16 requeue_value.reset();
17 requeue_limit.reset();
18 wake_count2.reset();
19 wake_op.reset();
20 bitset.reset();
21
22 /* retvals */
23 num_woken_up.reset();
24 new_fd.reset();
25
26 // setup the default return value
27 result.emplace(item::SuccessResult{});
29}
ParameterVector m_pars
The array of system call parameters, if any.

◆ updateFDTracking()

void clues::FutexSystemCall::updateFDTracking ( const Tracee & proc)
overrideprotectedvirtual

Update file descriptor tracking.

This function is called upon successful system call exit to track any potential new file descriptors or stop tracking of existing file descriptors.

Specializations of SystemCall that create or close file descriptors need to overwrite this function and call proc.trackFD() or proc.dropFD() accordingly.

Reimplemented from clues::SystemCall.

Definition at line 132 of file thread.cxx.

132 {
133 if (new_fd) {
134 // we don't even have a type for this, because this feature
135 // was dropped in kernel 2.6.26, so I guess it doesn't make
136 // sense to track anything here.
137 (void)proc;
138 }
139}

Member Data Documentation

◆ bitset

std::optional<item::GenericPointerValue> clues::FutexSystemCall::bitset

! bitset to restrict wait/wakeup (FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET).

Definition at line 126 of file thread.hxx.

◆ fd_sig

std::optional<item::SignalNumber> clues::FutexSystemCall::fd_sig

! signal used for asynchronous notifications (CREATE_FD).

Definition at line 112 of file thread.hxx.

◆ futex2_addr

std::optional<item::GenericPointerValue> clues::FutexSystemCall::futex2_addr

! "uaddr2" requeue address (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI, WAIT_REQUEUE_PI) or additional futex (WAKE_OP).

Definition at line 116 of file thread.hxx.

◆ futex_addr

item::GenericPointerValue clues::FutexSystemCall::futex_addr

Definition at line 102 of file thread.hxx.

◆ new_fd

std::optional<item::FileDescriptor> clues::FutexSystemCall::new_fd

! new file descriptor (CREATE_FD).

Definition at line 133 of file thread.hxx.

◆ num_woken_up

std::optional<item::ReturnValue> clues::FutexSystemCall::num_woken_up

! number of waiters woken up (WAKE, WAKE_OP).

Definition at line 131 of file thread.hxx.

◆ operation

item::FutexOperation clues::FutexSystemCall::operation

Definition at line 103 of file thread.hxx.

◆ requeue_limit

std::optional<item::Uint32Value> clues::FutexSystemCall::requeue_limit

! "val2", upper limit on waiters to be requeued to addr2 (REQUEUE, CMP_REQUEUE, CMP_REQUEUE_PI).

Definition at line 120 of file thread.hxx.

◆ requeue_value

std::optional<item::Uint32Value> clues::FutexSystemCall::requeue_value

! "val3" used for comparison in CMP_REQUEUE, CMP_REQUEUE_PI.

Definition at line 118 of file thread.hxx.

◆ result

std::optional<item::SuccessResult> clues::FutexSystemCall::result

! success status (all remaining operations).

Definition at line 135 of file thread.hxx.

◆ timeout

std::optional<item::TimeSpecParameter> clues::FutexSystemCall::timeout

! optional relative timeout (WAIT) or absolute timeout (WAIT_BITSET, LOCK_PI, LOCK_PI2).

Definition at line 114 of file thread.hxx.

◆ value

std::optional<item::Uint32Value> clues::FutexSystemCall::value

! the value expected at futex_addr (WAIT, WAIT_REQUEUE_PI).

Definition at line 108 of file thread.hxx.

◆ wake_count

std::optional<item::Uint32Value> clues::FutexSystemCall::wake_count

! number of waiters to wake up (WAKE, REQUEUE, CMP_REQUEUE, WAKE_OP, CMD_REQUEUE_PI).

Definition at line 110 of file thread.hxx.

◆ wake_count2

std::optional<item::Uint32Value> clues::FutexSystemCall::wake_count2

! "val2", number of waiters at futex2_addr to wakeup (WAKE_OP).

Definition at line 122 of file thread.hxx.

◆ wake_op

std::optional<item::FutexWakeOperation> clues::FutexSystemCall::wake_op

! instructions for how to perform the wake operation (WAKE_OP).

Definition at line 124 of file thread.hxx.


The documentation for this struct was generated from the following files: