libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
fcntl.hxx
1#pragma once
2
3// C++
4#include <limits>
5#include <optional>
6
7// cosmos
8#include <cosmos/fs/FileDescriptor.hxx>
9#include <cosmos/fs/FileLock.hxx>
10#include <cosmos/utils.hxx>
11
12// clues
13#include <clues/items/items.hxx>
14
15namespace clues::item {
16
17class CLUES_API FcntlOperation :
19public: // types
20
21 FcntlOperation() :
22 ValueInParameter{"op", "operation"} {
23 }
24
26 enum class Oper : int {
27 DUPFD = F_DUPFD,
28 DUPFD_CLOEXEC = F_DUPFD_CLOEXEC,
29 GETFD = F_GETFD,
30 SETFD = F_SETFD,
31 GETFL = F_GETFL,
32 SETFL = F_SETFL,
33 /*
34 * We cannot rely on the preprocessor definitions exported by
35 * the userspace headers due to a lot of magic going on. See
36 * the implementation of the str() method and FLockParameter
37 * for more details.
38 */
39 GETLK = 5, /* F_GETLK */
40 SETLK = 6, /* F_SETLK */
41 SETLKW = 7, /* F_SETLKW */
42 GETLK64 = 12, /* F_GETLK64 */
43 SETLK64 = 13, /* F_SETLK64 */
44 SETLKW64 = 14, /* F_SETLKW64 */
45 OFD_SETLK = F_OFD_SETLK,
46 OFD_SETLKW = F_OFD_SETLKW,
47 OFD_GETLK = F_OFD_GETLK,
48 GETOWN = F_GETOWN,
49 SETOWN = F_SETOWN,
50 GETOWN_EX = F_GETOWN_EX,
51 SETOWN_EX = F_SETOWN_EX,
52 GETSIG = F_GETSIG,
53 SETSIG = F_SETSIG,
54 SETLEASE = F_SETLEASE,
55 GETLEASE = F_GETLEASE,
56 NOTIFY = F_NOTIFY,
57 SETPIPE_SZ = F_SETPIPE_SZ,
58 GETPIPE_SZ = F_GETPIPE_SZ,
59 ADD_SEALS = F_ADD_SEALS,
60 GET_SEALS = F_GET_SEALS,
61 GET_RW_HINT = F_GET_RW_HINT,
62 SET_RW_HINT = F_SET_RW_HINT,
63 GET_FILE_RW_HINT = F_GET_FILE_RW_HINT,
64 SET_FILE_RW_HINT = F_SET_FILE_RW_HINT,
65 // DUPFD is already 0, thus we need a different invalid value
66 INVALID = std::numeric_limits<int>::max()
67 };
68
69 using enum Oper;
70
71public: // functions
72
73 std::string str() const override;
74
75 Oper operation() const {
76 return m_op;
77 }
78
80 bool isLock64() const {
81 return cosmos::in_list(m_op, {Oper::GETLK64, Oper::SETLK64, Oper::SETLKW64});
82 }
83
84protected: // functions
85
86 void processValue(const Tracee &proc) override;
87
88protected: // data
89
90 Oper m_op = INVALID;
91};
92
94struct CLUES_API FileDescFlagsValue :
95 public SystemCallItem {
96 explicit FileDescFlagsValue(ItemType type) :
97 SystemCallItem{type, "fdflags", "file descriptor flags"} {
98 }
99
100 std::string str() const override;
101
102 cosmos::FileDescriptor::DescFlags flags() const {
103 return m_flags;
104 }
105
106protected: // functions
107
108 void processValue(const Tracee &proc) override;
109
110protected: // data
111
112 cosmos::FileDescriptor::DescFlags m_flags;
113};
114
116class CLUES_API FLockParameter :
117 public PointerValue {
118public: // functions
119 explicit FLockParameter() :
120 // this can be PARAM_IN and PARAM_IN_OUT, but we
121 // simply claim it's always IN_OUT
122 PointerValue{ItemType::PARAM_IN_OUT, "flock", "struct flock"} {
123 }
124
125 std::string str() const override;
126
128
132 const std::optional<cosmos::FileLock>& lock() const {
133 return m_lock;
134 }
135
136protected: // functions
137
138 void processValue(const Tracee &proc) override;
139
140 void updateData(const Tracee &proc) override;
141
142protected: // data
143
144 std::optional<cosmos::FileLock> m_lock;
145};
146
148
153class CLUES_API FileDescOwner :
154 public SystemCallItem {
155public: // functions
156
157 explicit FileDescOwner(const ItemType type) :
158 SystemCallItem{type} {
159 }
160
161 std::string str() const override;
162
163 std::optional<cosmos::ProcessID> pid() const {
164 return m_pid;
165 }
166
167 std::optional<cosmos::ProcessGroupID> pgid() const {
168 return m_pgid;
169 }
170
171 bool isPid() const {
172 return m_pid.has_value();
173 }
174
175 bool isPgid() const {
176 return m_pgid.has_value();
177 }
178
179protected: // functions
180
181 void processValue(const Tracee &proc) override;
182
183protected: // data
184
185 std::optional<cosmos::ProcessID> m_pid;
186 std::optional<cosmos::ProcessGroupID> m_pgid;
187};
188
190class CLUES_API ExtFileDescOwner :
191 public SystemCallItem {
192public: // functions
193 explicit ExtFileDescOwner(const ItemType type) :
194 SystemCallItem{type, "owner_ex", "struct f_owner_ex"} {
195 }
196
197 std::string str() const override;
198
199 const std::optional<cosmos::FileDescriptor::Owner>& owner() const {
200 return m_owner;
201 }
202
203protected: // functions
204
205 void processValue(const Tracee &proc) override;
206
207protected: // data
208
209 std::optional<cosmos::FileDescriptor::Owner> m_owner;
210};
211
213class CLUES_API LeaseType :
214 public SystemCallItem {
215public: // functions
216
217 explicit LeaseType(const ItemType type) :
218 SystemCallItem{type, "lease", "lease type"} {
219 }
220
221 std::string str() const override;
222
223 auto& lease() const {
224 return m_lease;
225 }
226
227protected: // functions
228
229 void processValue(const Tracee &proc) override;
230
231protected: // data
232
233 cosmos::FileDescriptor::LeaseType m_lease{std::numeric_limits<int>::max()};
234};
235
237class CLUES_API DNotifySettings :
238 public ValueInParameter {
239public: // types
240
241 enum class Setting : int {
242 ACCESS = DN_ACCESS,
243 MODIFY = DN_MODIFY,
244 CREATE = DN_CREATE,
245 DELETE = DN_DELETE,
246 RENAME = DN_RENAME,
247 ATTRIB = DN_ATTRIB
248 };
249
250 using enum Setting;
251
252 using Settings = cosmos::BitMask<Setting>;
253
254public: // functions
255
256 explicit DNotifySettings() :
257 ValueInParameter{"events", "dnotify event bitmask"} {
258 }
259
260 auto settings() const {
261 return m_settings;
262 }
263
264 std::string str() const override;
265
266protected: // functions
267
268 void processValue(const Tracee &proc) override;
269
270protected: // data
271
272 Settings m_settings;
273};
274
276class CLUES_API FileSealSettings :
277 public ValueParameter {
278public: // functions
279
280 explicit FileSealSettings(const ItemType type) :
281 ValueParameter{type, "flags", "seal flags"} {
282 }
283
285 auto flags() const {
286 return m_flags;
287 }
288
289 std::string str() const override;
290
291protected: // functions
292
293 void processValue(const Tracee &proc) override;
294
295protected: // data
296
297 cosmos::FileDescriptor::SealFlags m_flags;
298};
299
301
308class CLUES_API ReadWriteHint :
309 public SystemCallItem {
310public: // types
311
312 using Hint = cosmos::FileDescriptor::ReadWriteHint;
313
314public: // functions
315
316 explicit ReadWriteHint(const ItemType type) :
317 SystemCallItem{type, "rw_hint", "read/write lifetime hint"} {
318 }
319
320 Hint hint() const {
321 return m_hint;
322 }
323
324 std::string str() const override;
325
326protected: // functions
327
328 void processValue(const Tracee &proc) override;
329
330protected:
331
332 Hint m_hint = Hint::LIFE_NOT_SET;
333};
334
335} // end ns
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
Base class for traced processes.
Definition Tracee.hxx:39
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:365
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:361
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:345
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:326
const std::optional< cosmos::FileLock > & lock() const
Access to the extracted FileLock data.
Definition fcntl.hxx:132
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:280
bool isLock64() const
Returns whether the operation is one of the LK64 operations.
Definition fcntl.hxx:80
Oper
All possible arguments for the op parameter to fcntl(2).
Definition fcntl.hxx:26
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:319
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:303
auto flags() const
Returns the currently stored SealFlags.
Definition fcntl.hxx:285
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:357
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:353
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:395
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:407
Specialization of ValueParameter for PARAM_IN parameters.
Definition items.hxx:47
ItemType
Basic type of a SystemCallItem.
@ PARAM_IN_OUT
Both an input and output parameter.
std::string str() const override
Returns a human readable string representation of the item.
Definition fcntl.cxx:17
void processValue(const Tracee &proc) override
Processes the value stored in m_val acc. to the actual item type.
Definition fcntl.cxx:25