libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::item::TimeSpecParameter Class Reference

The struct timespec used for various timing and timeout operations in system calls. More...

#include <time.hxx>

+ Inheritance diagram for clues::item::TimeSpecParameter:

Public Member Functions

 TimeSpecParameter (const std::string_view short_name, const std::string_view long_name={}, const ItemType type=ItemType::PARAM_IN, const bool remain_semantics=false)
 
std::string str () const override
 Returns a human readable string representation of the item.
 
const std::optional< struct timespec > & spec () const
 
- Public Member Functions inherited from clues::SystemCallItem
 SystemCallItem (const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
 Constructs a new SystemCallItem.
 
auto type () const
 
bool isIn () const
 
bool isOut () const
 
bool isInOut () const
 
bool isReturnValue () const
 
void fill (const Tracee &proc, const Word word)
 Fills the item from the given register data.
 
bool needsUpdate () const
 Returns whether the item needs to be updated after the system call is finished.
 
std::string_view shortName () const
 Returns the friendly short name for this item.
 
std::string_view longName () const
 Returns the friendly long name for this item, if available, else the short name.
 
auto hasLongName () const
 
bool isZero () const
 Returns whether the parameter is set to 0 / NULL.
 
Word value () const
 Returns the currently stored raw value of the item.
 
template<typename OTHER>
OTHER valueAs () const
 Helper to cast the strongly typed Word m_val to other strong enum types.
 
ForeignPtr asPtr () const
 
Flags flags () const
 
bool deferFill () const
 

Protected Member Functions

void processValue (const Tracee &proc) override
 Processes the value stored in m_val acc. to the actual item type.
 
void updateData (const Tracee &proc) override
 Called upon exit of the system call to update possible out parameters.
 
void fetch (const Tracee &proc)
 
bool needTime32Conversion () const
 Checks whether the current ABI context requires conversion of 32 bit to 64 bit.
 
- Protected Member Functions inherited from clues::SystemCallItem
void setSystemCall (const SystemCall &sc)
 Sets the system call context this item is a part of.
 

Protected Attributes

std::optional< struct timespec > m_timespec
 
bool m_remain_semantics = false
 
- Protected Attributes inherited from clues::SystemCallItem
const SystemCallm_call = nullptr
 The system call context this item part of.
 
const ItemType m_type
 The type of item.
 
std::string_view m_short_name
 A human readable short name for the item, should be one word only.
 
std::string_view m_long_name
 A human readable longer name for the item.
 
Word m_val
 The raw register value for the item.
 
Flags m_flags
 Flags influencing the processing of the item.
 

Additional Inherited Members

- Public Types inherited from clues::SystemCallItem
enum class  Flag { DEFER_FILL = 1 << 0 }
 
using Flags = cosmos::BitMask<Flag>
 

Detailed Description

The struct timespec used for various timing and timeout operations in system calls.

Definition at line 16 of file time.hxx.

Constructor & Destructor Documentation

◆ TimeSpecParameter()

clues::item::TimeSpecParameter::TimeSpecParameter ( const std::string_view short_name,
const std::string_view long_name = {},
const ItemType type = ItemType::PARAM_IN,
const bool remain_semantics = false )
inlineexplicit

Definition at line 19 of file time.hxx.

21 {},
22 const ItemType type = ItemType::PARAM_IN,
23 const bool remain_semantics = false) :
24 SystemCallItem{type, short_name, long_name},
25 m_remain_semantics{remain_semantics} {
26 }
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
ItemType
Basic type of a SystemCallItem.
@ PARAM_IN
An input parameter to the system call.

Member Function Documentation

◆ fetch()

void clues::item::TimeSpecParameter::fetch ( const Tracee & proc)
protected

Definition at line 60 of file time.cxx.

60 {
61 if (!m_timespec) {
62 m_timespec = timespec{};
63 }
64
66 struct timespec32 ts32;
67 if (!proc.readStruct(asPtr(), ts32)) {
68 m_timespec.reset();
69 return;
70 }
71
72 m_timespec->tv_sec = ts32.tv_sec;
73 m_timespec->tv_nsec = ts32.tv_nsec;
74 } else if (!proc.readStruct(asPtr(), *m_timespec)) {
75 m_timespec.reset();
76 }
77}
bool needTime32Conversion() const
Checks whether the current ABI context requires conversion of 32 bit to 64 bit.
Definition time.cxx:43

◆ needTime32Conversion()

bool clues::item::TimeSpecParameter::needTime32Conversion ( ) const
protected

Checks whether the current ABI context requires conversion of 32 bit to 64 bit.

Definition at line 43 of file time.cxx.

43 {
44 /*
45 * currently we only cover 32-bit emulation binaries on X86-64.
46 */
47
48 if (!m_call->is32BitEmulationABI()) {
49 return false;
50 }
51
52 /* now we need to check which system call we're on */
53 return cosmos::in_list(m_call->callNr(), {
54 SystemCallNr::CLOCK_NANOSLEEP,
55 SystemCallNr::FUTEX,
56 SystemCallNr::NANOSLEEP
57 });
58}
const SystemCall * m_call
The system call context this item part of.

◆ processValue()

void clues::item::TimeSpecParameter::processValue ( const Tracee & )
inlineoverrideprotectedvirtual

Processes the value stored in m_val acc. to the actual item type.

This function is called for all parameter types upon entry to a system call, and for ItemType::RETVAL upon exit from a system call.

For parameters of ItemType::PARAM_OUT this callback can be used to reset any stored data to be filled in later when updateData() is called.

Reimplemented from clues::SystemCallItem.

Definition at line 36 of file time.hxx.

36 {
37 if (this->isOut())
38 m_timespec.reset();
39 else
40 fetch(proc);
41 }

◆ spec()

const std::optional< struct timespec > & clues::item::TimeSpecParameter::spec ( ) const
inline

Definition at line 30 of file time.hxx.

30 {
31 return m_timespec;
32 }

◆ str()

std::string clues::item::TimeSpecParameter::str ( ) const
overridevirtual

Returns a human readable string representation of the item.

This member function should be specialized in derived classes to output the item's data in a fashion suitable for the concrete item type.

Reimplemented from clues::SystemCallItem.

Definition at line 79 of file time.cxx.

79 {
80 if (!m_timespec) {
81 if (m_remain_semantics) {
82 /* still show that a pointer was passed */
83 return format::pointer(asPtr());
84 } else {
85 return "NULL";
86 }
87 }
88
89 return format::timespec(*m_timespec);
90}

◆ updateData()

void clues::item::TimeSpecParameter::updateData ( const Tracee & t)
overrideprotectedvirtual

Called upon exit of the system call to update possible out parameters.

This function is called for parameters of ItemType::PARAM_OUT and ItemType::PARAM_IN_OUT upon system call exit to update the data from the values returned from the system call.

The default implementation calls processValue() to allow to share the same data processing code for input and output for item types that support both.

This function is called regardless of system call success or error, so it can happen that there is no valid data returned by the kernel or pointers in userspace are broken. Implementations should take this into consideration when operating on the data.

Reimplemented from clues::SystemCallItem.

Definition at line 18 of file time.cxx.

18 {
19 if (m_remain_semantics) {
20 /*
21 * special logic for clock_nanosleep remain semantics &
22 * similar cases:
23 *
24 * - on success, remaining time is not updated
25 * - on special kernel error code, transparent restart will
26 * happen
27 * - otherwise only if EINTR is observed will the time be
28 * updated
29 */
30 if (m_call->hasResultValue())
31 return;
32
33 const auto error = *m_call->error();
34
35 if (!error.hasErrorCode() || error.errorCode() != cosmos::Errno::INTERRUPTED) {
36 return;
37 }
38 }
39
40 fetch(proc);
41}

Member Data Documentation

◆ m_remain_semantics

bool clues::item::TimeSpecParameter::m_remain_semantics = false
protected

Definition at line 53 of file time.hxx.

◆ m_timespec

std::optional<struct timespec> clues::item::TimeSpecParameter::m_timespec
protected

Definition at line 52 of file time.hxx.


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