libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
fs.hxx
1#pragma once
2
3// clues
4#include <clues/SystemCall.hxx>
5#include <clues/items/fs.hxx>
6#include <clues/items/signal.hxx>
7#include <clues/items/strings.hxx>
8#include <clues/sysnrs/generic.hxx>
9
10namespace clues {
11
12struct CLUES_API AccessSystemCall :
13 public SystemCall {
14
15 AccessSystemCall() :
16 SystemCall{SystemCallNr::ACCESS},
17 path{"path"} {
18 setReturnItem(result);
19 setParameters(path, mode);
20 }
21
25};
26
27// this is an earlier variant of faccessat() which doesn't take a flags argument
28struct CLUES_API FAccessAtSystemCall :
29 public SystemCall {
30
31 explicit FAccessAtSystemCall(const SystemCallNr nr = SystemCallNr::FACCESSAT) :
32 SystemCall{nr},
33 dirfd{ItemType::PARAM_IN, item::AtSemantics{true}},
34 path{"path"} {
35 setReturnItem(result);
36 setParameters(dirfd, path, mode);
37 }
38
43};
44
45// follow-up variant of faccessat() supporting an additional flags argument, introduced in Linux 5.8
46struct CLUES_API FAccessAt2SystemCall :
47 public FAccessAtSystemCall {
48
49 FAccessAt2SystemCall() :
50 FAccessAtSystemCall{SystemCallNr::FACCESSAT2} {
51 addParameters(flags);
52 }
53
55};
56
57struct CLUES_API FcntlSystemCall :
58 public SystemCall {
59
60 explicit FcntlSystemCall(const SystemCallNr sysnr) :
61 SystemCall{sysnr} {
62 // these two parameters are always present
63 setParameters(fd, operation);
64 }
65
66 /* fixed parameters */
68 item::FcntlOperation operation;
69
70 /* context dependent parameters */
71 std::optional<item::FileDescriptor> dup_lowest;
72 std::optional<item::FileDescFlagsValue> fd_flags_arg;
73 std::optional<item::OpenFlagsValue> status_flags_arg;
74 std::optional<item::FLockParameter> flock_arg;
75 std::optional<item::FileDescOwner> owner_arg;
76 std::optional<item::ExtFileDescOwner> ext_owner_arg;
77 std::optional<item::SignalNumber> io_signal_arg;
78 std::optional<item::LeaseType> lease_arg;
79 std::optional<item::DNotifySettings> dnotify_arg;
80 std::optional<item::IntValue> pipe_size_arg;
81 std::optional<item::FileSealSettings> file_seals_arg;
82 std::optional<item::ReadWriteHint> rw_hint_arg;
83
84 /* context dependent return values */
85 std::optional<item::SuccessResult> result;
86 std::optional<item::FileDescriptor> ret_dupfd;
87 std::optional<item::FileDescFlagsValue> ret_fd_flags;
88 std::optional<item::OpenFlagsValue> ret_status_flags;
89 std::optional<item::FileDescOwner> ret_owner;
90 std::optional<item::SignalNumber> ret_io_signal;
91 std::optional<item::LeaseType> ret_lease;
92 std::optional<item::IntValue> ret_pipe_size;
93 std::optional<item::FileSealSettings> ret_seals;
94
95protected: // functions
96
97 void clear();
98
99 bool check2ndPass(const Tracee&) override;
100
101 void prepareNewSystemCall() override;
102
103 void updateFDTracking(const Tracee &proc) override;
104};
105
106struct CLUES_API FstatSystemCall :
107 public SystemCall {
108
109 explicit FstatSystemCall(const SystemCallNr nr) :
110 SystemCall{nr} {
111 setReturnItem(result);
112 setParameters(fd, statbuf);
113 }
114
116 item::StatParameter statbuf;
117 item::SuccessResult result;
118};
119
120struct CLUES_API FstatAtSystemCall :
121 public SystemCall {
122
123 explicit FstatAtSystemCall(const SystemCallNr nr) :
124 SystemCall{nr},
125 dirfd{ItemType::PARAM_IN, item::AtSemantics{true}} {
126 setReturnItem(result);
127 setParameters(dirfd, path, statbuf, flags);
128 }
129
131 item::StringData path;
132 item::StatParameter statbuf;
133 item::AtFlagsValue flags;
134 item::SuccessResult result;
135};
136
137// This covers both stat() and lstat(), they only differ in semantics
138struct StatSystemCallT :
139 public SystemCall {
140
141 explicit StatSystemCallT(const SystemCallNr nr) :
142 SystemCall{nr},
143 path{"path"} {
144 setReturnItem(result);
145 setParameters(path, statbuf);
146 }
147
148 item::StringData path;
149 item::StatParameter statbuf;
150 item::SuccessResult result;
151};
152
153using StatSystemCall = StatSystemCallT;
154using LstatSystemCall = StatSystemCallT;
155
156struct CLUES_API OpenSystemCall :
157 public SystemCall {
158
159 OpenSystemCall() :
160 SystemCall{SystemCallNr::OPEN},
161 filename{"filename"},
162 new_fd{ItemType::RETVAL} {
163 setReturnItem(new_fd);
164 setParameters(filename, flags);
165 }
166
167 /* parameters */
168 item::StringData filename;
170 std::optional<item::FileModeParameter> mode;
171
172 /* return value */
174
175protected: // functions
176
177 bool check2ndPass(const Tracee&) override;
178
179 void prepareNewSystemCall() override;
180
181 void updateFDTracking(const Tracee &) override;
182};
183
184struct CLUES_API OpenAtSystemCall :
185 public SystemCall {
186
187 OpenAtSystemCall() :
188 SystemCall{SystemCallNr::OPENAT},
189 fd{ItemType::PARAM_IN, item::AtSemantics{true}},
190 filename{"filename"},
191 new_fd{ItemType::RETVAL} {
192 setReturnItem(new_fd);
193 setParameters(fd, filename, flags);
194 }
195
196 /* parameters */
198 item::StringData filename;
200 std::optional<item::FileModeParameter> mode;
201
202 /* return value */
204
205protected: // functions
206
207 bool check2ndPass(const Tracee&) override;
208
209 void prepareNewSystemCall() override;
210
211 void updateFDTracking(const Tracee &) override;
212};
213
214struct CLUES_API CloseSystemCall :
215 public SystemCall {
216
217 CloseSystemCall() :
218 SystemCall{SystemCallNr::CLOSE} {
219 setReturnItem(result);
220 setParameters(fd);
221 }
222
224 item::SuccessResult result;
225
226protected: // functions
227
228 void updateFDTracking(const Tracee &) override;
229};
230
231struct CLUES_API GetDentsSystemCall :
232 public SystemCall {
233
234 GetDentsSystemCall(const SystemCallNr nr) :
235 SystemCall{nr},
236 size{"size", "dirent size in bytes"},
237 ret_bytes{"bytes", "bytes returned in dirent", ItemType::RETVAL} {
239 setParameters(fd, dirent, size);
240 }
241
244 item::UintValue size;
245 item::SizeValue ret_bytes;
246};
247
248} // end ns
void setReturnItem(SystemCallItem &ret)
Sets the return value system call item.
SystemCall(const SystemCallNr nr)
Instantiates a new SystemCall object with given properties.
Base class for traced processes.
Definition Tracee.hxx:39
The mode parameter in access().
Definition fs.hxx:141
Flags for system calls with at semantics like linkat(), faccessat().
Definition fs.hxx:104
A range of directory entries from getdents().
Definition fs.hxx:231
Base class for file descriptor system call items.
Definition fs.hxx:28
The flags passed to calls like open().
Definition fs.hxx:76
The stat structure used in stat() & friends.
Definition fs.hxx:190
c-string style system call data.
Definition strings.hxx:11
An always-success return value.
Definition error.hxx:15
@ PARAM_IN
An input parameter to the system call.
@ RETVAL
A system call return value.
SystemCallNr
Abstract system call number usable across architectures and ABIs.
Definition generic.hxx:29
void updateFDTracking(const Tracee &) override
Update file descriptor tracking.
Definition fs.cxx:236
std::optional< item::FileDescriptor > dup_lowest
for DUPFD, DUPFD_CLOEXEC
Definition fs.hxx:71
std::optional< item::IntValue > pipe_size_arg
for SETPIPE_SZ
Definition fs.hxx:80
bool check2ndPass(const Tracee &) override
Check whether a second pass needs to be made processing parameters.
Definition fs.cxx:41
std::optional< item::OpenFlagsValue > ret_status_flags
for GETFL
Definition fs.hxx:88
std::optional< item::FileDescFlagsValue > ret_fd_flags
for GETFD
Definition fs.hxx:87
std::optional< item::FileDescFlagsValue > fd_flags_arg
for SETFD
Definition fs.hxx:72
void prepareNewSystemCall() override
Perform any necessary actions before processing a new system call entry event.
Definition fs.cxx:8
std::optional< item::SuccessResult > result
for all other cases
Definition fs.hxx:85
std::optional< item::FileDescOwner > owner_arg
for SETOWN
Definition fs.hxx:75
std::optional< item::LeaseType > ret_lease
for GETLEASE
Definition fs.hxx:91
std::optional< item::IntValue > ret_pipe_size
for GETPIPE_SZ, SETPIPE_SZ
Definition fs.hxx:92
std::optional< item::FileDescriptor > ret_dupfd
for DUPFD, DUPFD_CLOEXEC
Definition fs.hxx:86
std::optional< item::ReadWriteHint > rw_hint_arg
for {GET,SET}_[FILE]_RW_HINT
Definition fs.hxx:82
std::optional< item::FLockParameter > flock_arg
for F_SETLK, F_SETLKW, F_GETLK
Definition fs.hxx:74
std::optional< item::FileDescOwner > ret_owner
for GET_OWNER
Definition fs.hxx:89
std::optional< item::DNotifySettings > dnotify_arg
for NOTIFY
Definition fs.hxx:79
std::optional< item::FileSealSettings > file_seals_arg
for ADD_SEALS
Definition fs.hxx:81
std::optional< item::SignalNumber > io_signal_arg
for SETSIG
Definition fs.hxx:77
std::optional< item::SignalNumber > ret_io_signal
for GETSIG
Definition fs.hxx:90
std::optional< item::FileSealSettings > ret_seals
for GET_SEALS
Definition fs.hxx:93
void updateFDTracking(const Tracee &proc) override
Update file descriptor tracking.
Definition fs.cxx:167
std::optional< item::ExtFileDescOwner > ext_owner_arg
for SETOWN_EX, GETOWN_EX
Definition fs.hxx:76
std::optional< item::OpenFlagsValue > status_flags_arg
for SETFL
Definition fs.hxx:73
std::optional< item::LeaseType > lease_arg
for SETLEASE
Definition fs.hxx:78
item::FileDescriptor fd
directory FD.
Definition fs.hxx:242
item::SizeValue ret_bytes
number of bytes filled in dirent buffer.
Definition fs.hxx:245
item::DirEntries dirent
struct linux_dirent*.
Definition fs.hxx:243
item::UintValue size
size of dirent buffer provided by tracee.
Definition fs.hxx:244
bool check2ndPass(const Tracee &) override
Check whether a second pass needs to be made processing parameters.
Definition fs.cxx:216
void updateFDTracking(const Tracee &) override
Update file descriptor tracking.
Definition fs.cxx:228
void prepareNewSystemCall() override
Perform any necessary actions before processing a new system call entry event.
Definition fs.cxx:211
void updateFDTracking(const Tracee &) override
Update file descriptor tracking.
Definition fs.cxx:203
bool check2ndPass(const Tracee &) override
Check whether a second pass needs to be made processing parameters.
Definition fs.cxx:191
void prepareNewSystemCall() override
Perform any necessary actions before processing a new system call entry event.
Definition fs.cxx:185