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

Pointer to pipefd[2] array in pipe() system calls. More...

#include <io.hxx>

+ Inheritance diagram for clues::item::PipeEnds:

Public Member Functions

std::string str () const override
 Returns a human readable string representation of the item.
 
cosmos::FileNum readEnd () const
 
cosmos::FileNum writeEnd () const
 
bool haveEnds () const
 Returns whether valid read and write end file numbers are stored.
 
- Public Member Functions inherited from clues::item::PointerOutValue
 PointerOutValue (const std::string_view short_name, const std::string_view long_name={}, const ItemType type=ItemType::PARAM_OUT)
 
- Public Member Functions inherited from clues::item::PointerValue
 PointerValue (const ItemType type, const std::string_view short_name, const std::string_view long_name)
 
- 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 reset ()
 
void processValue (const Tracee &) 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.
 
- 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

cosmos::FileNum m_read_end = cosmos::FileNum::INVALID
 
cosmos::FileNum m_write_end = cosmos::FileNum::INVALID
 
- 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

Pointer to pipefd[2] array in pipe() system calls.

Definition at line 21 of file io.hxx.

Constructor & Destructor Documentation

◆ PipeEnds()

clues::item::PipeEnds::PipeEnds ( )
inlineexplicit

Definition at line 25 of file io.hxx.

25 :
26 PointerOutValue{"pipefd", "pointer to array pipefd[2]"} {
27 }

Member Function Documentation

◆ haveEnds()

bool clues::item::PipeEnds::haveEnds ( ) const
inline

Returns whether valid read and write end file numbers are stored.

On failed system calls or sudden Tracee death these can have invalid values.

Definition at line 44 of file io.hxx.

44 {
45 return m_read_end != cosmos::FileNum::INVALID && m_write_end != cosmos::FileNum::INVALID;
46 }

◆ processValue()

void clues::item::PipeEnds::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 55 of file io.hxx.

55 {
56 reset();
57 }

◆ readEnd()

cosmos::FileNum clues::item::PipeEnds::readEnd ( ) const
inline

Definition at line 31 of file io.hxx.

31 {
32 return m_read_end;
33 }

◆ reset()

void clues::item::PipeEnds::reset ( )
inlineprotected

Definition at line 50 of file io.hxx.

50 {
51 m_read_end = cosmos::FileNum::INVALID;
52 m_write_end = cosmos::FileNum::INVALID;
53 }

◆ str()

std::string clues::item::PipeEnds::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 26 of file io.cxx.

26 {
27 if (haveEnds()) {
28 const auto ends_array = cosmos::sprintf("%d, %d",
29 cosmos::to_integral(m_read_end),
30 cosmos::to_integral(m_write_end));
31 return clues::format::pointer(asPtr(), ends_array);
32 } else {
33 return clues::format::pointer(asPtr());
34 }
35}
bool haveEnds() const
Returns whether valid read and write end file numbers are stored.
Definition io.hxx:44

◆ updateData()

void clues::item::PipeEnds::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 13 of file io.cxx.

13 {
14 int ends[2];
15
16 if (!proc.readStruct(asPtr(), ends)) {
17 // probably bad userspace address or Tracee died
18 reset();
19 return;
20 }
21
22 m_read_end = cosmos::FileNum{ends[0]};
23 m_write_end = cosmos::FileNum{ends[1]};
24}

◆ writeEnd()

cosmos::FileNum clues::item::PipeEnds::writeEnd ( ) const
inline

Definition at line 35 of file io.hxx.

35 {
36 return m_write_end;
37 }

Member Data Documentation

◆ m_read_end

cosmos::FileNum clues::item::PipeEnds::m_read_end = cosmos::FileNum::INVALID
protected

Definition at line 63 of file io.hxx.

◆ m_write_end

cosmos::FileNum clues::item::PipeEnds::m_write_end = cosmos::FileNum::INVALID
protected

Definition at line 64 of file io.hxx.


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