libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::item::ResourceLimit Class Reference
+ Inheritance diagram for clues::item::ResourceLimit:

Public Member Functions

 ResourceLimit (const ItemType type, const std::string_view name={})
 
std::string str () const override
 Returns a human readable string representation of the item.
 
std::optional< cosmos::LimitSpec > limit () const
 
- 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 updateData (const Tracee &proc) override
 Called upon exit of the system call to update possible out parameters.
 
void processValue (const Tracee &proc) override
 Processes the value stored in m_val acc. to the actual item type.
 
bool isCompatSyscall () const
 Checks whether the current context involves a 32-bit struct rlimit.
 
- 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< cosmos::LimitSpec > m_limit
 
- 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

Definition at line 41 of file limits.hxx.

Constructor & Destructor Documentation

◆ ResourceLimit()

clues::item::ResourceLimit::ResourceLimit ( const ItemType type,
const std::string_view name = {} )
inlineexplicit

Definition at line 44 of file limits.hxx.

44 {}) :
45 PointerValue{type, name.empty() ? "limit" : name, ""} {
46 }

Member Function Documentation

◆ isCompatSyscall()

bool clues::item::ResourceLimit::isCompatSyscall ( ) const
protected

Checks whether the current context involves a 32-bit struct rlimit.

On older 32-bit ABIs like I386, getrlimit() and setrlimit() use struct compat_rlimit in the kernel, with only 32-bit unsigned integer members.

Definition at line 91 of file limits.cxx.

91 {
92 if (m_call->callNr() == SystemCallNr::PRLIMIT64)
93 // prlimit64() always uses 64-bit wide fields
94 return false;
95
96 const auto abi = m_call->abi();
97
98 return abi == ABI::I386;
99}
const SystemCall * m_call
The system call context this item part of.

◆ limit()

std::optional< cosmos::LimitSpec > clues::item::ResourceLimit::limit ( ) const
inline

Definition at line 50 of file limits.hxx.

50 {
51 return m_limit;
52 }

◆ processValue()

void clues::item::ResourceLimit::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 58 of file limits.hxx.

58 {
59 if (isOut()) {
60 m_limit.reset();
61 } else {
62 // the same logic on input as on output
63 return updateData(proc);
64 }
65 }
void updateData(const Tracee &proc) override
Called upon exit of the system call to update possible out parameters.
Definition limits.cxx:55

◆ str()

std::string clues::item::ResourceLimit::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 42 of file limits.cxx.

42 {
43 if (!m_limit) {
44 return isZero() ? "NULL" : "<invalid>";
45 }
46 std::stringstream ss;
47
48 ss
49 << "{rlim_cur=" << format::limit(m_limit->rlim_cur) << ", rlim_max="
50 << format::limit(m_limit->rlim_max) << "}";
51
52 return ss.str();
53}
bool isZero() const
Returns whether the parameter is set to 0 / NULL.

◆ updateData()

void clues::item::ResourceLimit::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 55 of file limits.cxx.

55 {
56 auto update_rlimit = [this, &proc]<typename RLIM_T>() {
57 RLIM_T rlim;
58
59 if (!proc.readStruct(asPtr(), rlim)) {
60 m_limit.reset();
61 return;
62 }
63
64 m_limit = cosmos::LimitSpec{};
65
66 /*
67 * RLIM_INFINITY is simply the maximum of unsigned long, thus
68 * check the ABI-specific maximum value here and translate it
69 * into the native RLIM_INFINITY;
70 */
71 constexpr auto RLIM_T_INFINITY = std::numeric_limits<decltype(rlim.rlim_cur)>::max();
72 if (rlim.rlim_cur == RLIM_T_INFINITY)
73 m_limit->rlim_cur = RLIM_INFINITY;
74 else
75 m_limit->rlim_cur = rlim.rlim_cur;
76
77 if (rlim.rlim_max == RLIM_T_INFINITY)
78 m_limit->rlim_max = RLIM_INFINITY;
79 else
80 m_limit->rlim_max = rlim.rlim_max;
81 };
82
83 if (isCompatSyscall()) {
84 update_rlimit.operator()<struct rlimit32>();
85 } else {
86 update_rlimit.operator()<struct rlimit64>();
87 }
88
89}
bool isCompatSyscall() const
Checks whether the current context involves a 32-bit struct rlimit.
Definition limits.cxx:91

Member Data Documentation

◆ m_limit

std::optional<cosmos::LimitSpec> clues::item::ResourceLimit::m_limit
protected

Definition at line 77 of file limits.hxx.


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