libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
SystemCallItem.hxx
1#pragma once
2
3// C++
4#include <iosfwd>
5#include <string_view>
6#include <type_traits>
7
8// cosmos
9#include <cosmos/BitMask.hxx>
10#include <cosmos/utils.hxx>
11
12// clues
13#include <clues/types.hxx>
14
15namespace clues {
16
17class SystemCall;
18class Tracee;
19
27
29
33class CLUES_API SystemCallItem {
34 friend SystemCall;
35public: // types
36
37
38 enum class Flag {
40
44 DEFER_FILL = 1 << 0
45 };
46
47 using Flags = cosmos::BitMask<Flag>;
48
49public: // functions
50
52
61 const ItemType type,
62 const std::string_view short_name = {},
63 const std::string_view long_name = {}) :
64 m_type{type},
65 m_short_name{short_name},
66 m_long_name{long_name}
67 {}
68
69 virtual ~SystemCallItem() {}
70
71 auto type() const { return m_type; }
72
73 bool isIn() const { return m_type == ItemType::PARAM_IN; }
74 bool isOut() const { return m_type == ItemType::PARAM_OUT; }
75 bool isInOut() const { return m_type == ItemType::PARAM_IN_OUT; }
76 bool isReturnValue() const { return m_type == ItemType::RETVAL; }
77
79 void fill(const Tracee &proc, const Word word);
80
82 bool needsUpdate() const { return m_type != ItemType::PARAM_IN; }
83
85 std::string_view shortName() const { return m_short_name; }
87 std::string_view longName() const {
88 return m_long_name.empty() ? shortName() : m_long_name; }
89
90 auto hasLongName() const { return !m_long_name.empty(); }
91
93
98 virtual std::string str() const;
99
101 bool isZero() const {
102 return value() == Word::ZERO;
103 }
104
106 Word value() const { return m_val; }
107
109
116 template <typename OTHER>
117 OTHER valueAs() const {
118 const auto baseval = cosmos::to_integral(m_val);
119 if constexpr (std::is_enum_v<OTHER>) {
120 const auto baseret = static_cast<typename std::underlying_type<OTHER>::type>(baseval);
121 return OTHER{baseret};
122 }
123
124 if constexpr (std::is_pointer_v<OTHER>) {
125 return reinterpret_cast<OTHER>(baseval);
126 }
127
128 if constexpr (!std::is_enum_v<OTHER> && !std::is_pointer_v<OTHER>) {
129 return static_cast<OTHER>(baseval);
130 }
131 }
132
133 ForeignPtr asPtr() const {
134 return valueAs<ForeignPtr>();
135 }
136
137 Flags flags() const {
138 return m_flags;
139 }
140
141 bool deferFill() const {
142 return m_flags[Flag::DEFER_FILL];
143 }
144
145protected: // functions
146
148
156 virtual void processValue(const Tracee &) {}
157
159
173 virtual void updateData(const Tracee &t) {
174 processValue(t);
175 }
176
178 void setSystemCall(const SystemCall &sc) { m_call = &sc; }
179
180protected: // data
181
183 const SystemCall *m_call = nullptr;
187 std::string_view m_short_name;
189 std::string_view m_long_name;
193 Flags m_flags;
194};
195
196} // end ns
197
198CLUES_API std::ostream& operator<<(
199 std::ostream &o,
200 const clues::SystemCallItem &value
201);
Base class for any kind of system call parameter or return value.
const SystemCall * m_call
The system call context this item part of.
std::string_view m_short_name
A human readable short name for the item, should be one word only.
bool isZero() const
Returns whether the parameter is set to 0 / NULL.
bool needsUpdate() const
Returns whether the item needs to be updated after the system call is finished.
void setSystemCall(const SystemCall &sc)
Sets the system call context this item is a part of.
Word value() const
Returns the currently stored raw value of the item.
virtual void processValue(const Tracee &)
Processes the value stored in m_val acc. to the actual item type.
std::string_view longName() const
Returns the friendly long name for this item, if available, else the short name.
Flags m_flags
Flags influencing the processing of the item.
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
Word m_val
The raw register value for the item.
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
std::string_view m_long_name
A human readable longer name for the item.
virtual void updateData(const Tracee &t)
Called upon exit of the system call to update possible out parameters.
std::string_view shortName() const
Returns the friendly short name for this item.
const ItemType m_type
The type of item.
@ DEFER_FILL
Only fill in this item after all other items have been filled.
Access to System Call Data.
Base class for traced processes.
Definition Tracee.hxx:39
ItemType
Basic type of a SystemCallItem.
@ PARAM_OUT
An output parameter filled by in by the system call.
@ PARAM_IN
An input parameter to the system call.
@ RETVAL
A system call return value.
@ PARAM_IN_OUT
Both an input and output parameter.
ForeignPtr
Strongly typed opaque pointer to tracee memory.
Definition types.hxx:140
Word
An integer that is able to hold a word for the current architecture.
Definition types.hxx:38