libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::FcntlSystemCall Struct Reference
+ Inheritance diagram for clues::FcntlSystemCall:

Public Member Functions

 FcntlSystemCall (const SystemCallNr sysnr)
 
- Public Member Functions inherited from clues::SystemCall
 SystemCall (const SystemCallNr nr)
 Instantiates a new SystemCall object with given properties.
 
 SystemCall (const SystemCall &other)=delete
 
SystemCalloperator= (const SystemCall &other)=delete
 
void setEntryInfo (const Tracee &proc, const SystemCallInfo &info)
 Update the stored parameter values from the given tracee.
 
void setExitInfo (const Tracee &proc, const SystemCallInfo &info)
 Update possible out and return parameter values from the given tracee.
 
std::string_view name () const
 Returns the system call's human readable name.
 
size_t numPars () const
 Returns the number of parameters for this system call.
 
SystemCallNr callNr () const
 Returns the system call table number for this system call.
 
const ParameterVectorparameters () const
 Access to the parameters associated with this system call.
 
SystemCallItemPtr result () const
 Access to the return value parameter associated with this system call.
 
std::optional< ErrnoResulterror () const
 Access to the errno result seen for this system call.
 
bool hasOutParameter () const
 
bool hasResultValue () const
 
bool hasErrorCode () const
 
ABI abi () const
 Returns the system call ABi seen during system call entry.
 
bool is32BitEmulationABI () const
 
const SystemCallInfocurrentInfo () const
 Access the current SystemCallInfo if currently processing syscall entry/exit.
 

Public Attributes

item::FileDescriptor fd
 
item::FcntlOperation operation
 
std::optional< item::FileDescriptordup_lowest
 for DUPFD, DUPFD_CLOEXEC
 
std::optional< item::FileDescFlagsValuefd_flags_arg
 for SETFD
 
std::optional< item::OpenFlagsValuestatus_flags_arg
 for SETFL
 
std::optional< item::FLockParameterflock_arg
 for F_SETLK, F_SETLKW, F_GETLK
 
std::optional< item::FileDescOwnerowner_arg
 for SETOWN
 
std::optional< item::ExtFileDescOwnerext_owner_arg
 for SETOWN_EX, GETOWN_EX
 
std::optional< item::SignalNumberio_signal_arg
 for SETSIG
 
std::optional< item::LeaseTypelease_arg
 for SETLEASE
 
std::optional< item::DNotifySettingsdnotify_arg
 for NOTIFY
 
std::optional< item::IntValuepipe_size_arg
 for SETPIPE_SZ
 
std::optional< item::FileSealSettingsfile_seals_arg
 for ADD_SEALS
 
std::optional< item::ReadWriteHintrw_hint_arg
 for {GET,SET}_[FILE]_RW_HINT
 
std::optional< item::SuccessResultresult
 for all other cases
 
std::optional< item::FileDescriptorret_dupfd
 for DUPFD, DUPFD_CLOEXEC
 
std::optional< item::FileDescFlagsValueret_fd_flags
 for GETFD
 
std::optional< item::OpenFlagsValueret_status_flags
 for GETFL
 
std::optional< item::FileDescOwnerret_owner
 for GET_OWNER
 
std::optional< item::SignalNumberret_io_signal
 for GETSIG
 
std::optional< item::LeaseTyperet_lease
 for GETLEASE
 
std::optional< item::IntValueret_pipe_size
 for GETPIPE_SZ, SETPIPE_SZ
 
std::optional< item::FileSealSettingsret_seals
 for GET_SEALS
 

Protected Member Functions

void clear ()
 
bool check2ndPass (const Tracee &) override
 Check whether a second pass needs to be made processing parameters.
 
void prepareNewSystemCall () override
 Perform any necessary actions before processing a new system call entry event.
 
void updateFDTracking (const Tracee &proc) override
 Update file descriptor tracking.
 
- Protected Member Functions inherited from clues::SystemCall
void fillParameters (const Tracee &proc, const SystemCallInfo &info)
 
void setReturnItem (SystemCallItem &ret)
 Sets the return value system call item.
 
void addParameters ()
 
template<typename T, typename... Targs>
void addParameters (T &par, Targs &...rest)
 
template<typename... Targs>
void setParameters (Targs &...args)
 
void dropFD (const Tracee &proc, const cosmos::FileNum num)
 
void trackFD (const Tracee &proc, FDInfo &&info)
 

Additional Inherited Members

- Public Types inherited from clues::SystemCall
using ParameterVector = std::vector<SystemCallItemPtr>
 Vector of the parameters required for a system call.
 
- Static Public Member Functions inherited from clues::SystemCall
static const char * name (const SystemCallNr nr)
 Returns the name of the given system call or "<unknown>" if unknown.
 
static bool validNr (const SystemCallNr nr)
 Returns whether the given system call number is in a valid range.
 
- Protected Attributes inherited from clues::SystemCall
SystemCallNr m_nr
 The raw system call number of the system call.
 
const std::string_view m_name
 The basic name of the system call.
 
const SystemCallInfom_info = nullptr
 Current system call info during entry/exit processing, nullptr otherwise.
 
SystemCallItemPtr m_return
 The return value of the system call.
 
std::optional< ErrnoResultm_error
 If the system call fails, this is the error code.
 
ParameterVector m_pars
 The array of system call parameters, if any.
 
ABI m_abi = ABI::UNKNOWN
 The current system call ABI which is in effect.
 

Detailed Description

Definition at line 57 of file fs.hxx.

Constructor & Destructor Documentation

◆ FcntlSystemCall()

clues::FcntlSystemCall::FcntlSystemCall ( const SystemCallNr sysnr)
inlineexplicit

Definition at line 60 of file fs.hxx.

60 :
61 SystemCall{sysnr} {
62 // these two parameters are always present
63 setParameters(fd, operation);
64 }
SystemCall(const SystemCallNr nr)
Instantiates a new SystemCall object with given properties.

Member Function Documentation

◆ check2ndPass()

bool clues::FcntlSystemCall::check2ndPass ( const Tracee & )
overrideprotectedvirtual

Check whether a second pass needs to be made processing parameters.

This function can be overridden by the actual system call implementation to perform context-sensitive evaluation of system call parameters (e.g. for ioctl() style system calls) upon system call entry.

The implementation of this function is allowed to modify the amount and types of system call parameters and return parameter. In this case true must be returned to let the base class implementation reevaluate all system call parameters.

Reimplemented from clues::SystemCall.

Definition at line 41 of file fs.cxx.

41 {
42 auto setExtraParameter = [this](auto &extra_par) {
43 addParameters(extra_par);
44 };
45 auto setNewReturnItem = [this](auto &new_ret) {
46 result.reset();
47 setReturnItem(new_ret);
48 };
49
50 using Oper = item::FcntlOperation::Oper;
51 switch (operation.operation()) {
52 case Oper::DUPFD: [[fallthrough]];
53 case Oper::DUPFD_CLOEXEC: {
54 dup_lowest.emplace(item::FileDescriptor{ItemType::PARAM_IN, item::AtSemantics{false},
55 "lowest_fd", "lowest dup file descriptor number"});
56 ret_dupfd.emplace(item::FileDescriptor{ItemType::RETVAL, item::AtSemantics{false},
57 "dupfd", "duplicated file descriptor"});
58 setNewReturnItem(*ret_dupfd);
59 setExtraParameter(*dup_lowest);
60 break;
61 } case Oper::GETFD: {
62 ret_fd_flags.emplace(item::FileDescFlagsValue{ItemType::RETVAL});
63 setNewReturnItem(*ret_fd_flags);
64 break;
65 } case Oper::SETFD: {
66 fd_flags_arg.emplace(item::FileDescFlagsValue{ItemType::PARAM_IN});
67 setExtraParameter(*fd_flags_arg);
68 break;
69 } case Oper::GETFL: {
70 ret_status_flags.emplace(item::OpenFlagsValue{ItemType::RETVAL});
71 setNewReturnItem(*ret_status_flags);
72 break;
73 } case Oper::SETFL: {
74 status_flags_arg.emplace(item::OpenFlagsValue{ItemType::PARAM_IN});
75 setExtraParameter(*status_flags_arg);
76 break;
77 } case Oper::SETLK: [[fallthrough]];
78 case Oper::SETLKW: [[fallthrough]];
79 case Oper::GETLK: [[fallthrough]];
80 case Oper::SETLK64: [[fallthrough]];
81 case Oper::SETLKW64: [[fallthrough]];
82 case Oper::GETLK64: [[fallthrough]];
83 case Oper::OFD_SETLK: [[fallthrough]];
84 case Oper::OFD_SETLKW: [[fallthrough]];
85 case Oper::OFD_GETLK: {
86 /*
87 * OFD locks and old style locks use the same API
88 * details
89 */
90 flock_arg.emplace(item::FLockParameter{});
91 setExtraParameter(*flock_arg);
92 break;
93 } case Oper::GETOWN: {
94 ret_owner.emplace(item::FileDescOwner{ItemType::RETVAL});
95 setNewReturnItem(*ret_owner);
96 break;
97 } case Oper::SETOWN: {
98 owner_arg.emplace(item::FileDescOwner{ItemType::PARAM_IN});
99 setExtraParameter(*owner_arg);
100 break;
101 } case Oper::GETOWN_EX: {
102 ext_owner_arg.emplace(item::ExtFileDescOwner{ItemType::PARAM_OUT});
103 setExtraParameter(*ext_owner_arg);
104 break;
105 } case Oper::SETOWN_EX: {
106 ext_owner_arg.emplace(item::ExtFileDescOwner{ItemType::PARAM_IN});
107 setExtraParameter(*ext_owner_arg);
108 break;
109 } case Oper::GETSIG: {
110 ret_io_signal.emplace(item::SignalNumber{ItemType::RETVAL});
111 setNewReturnItem(*ret_io_signal);
112 break;
113 } case Oper::SETSIG: {
114 io_signal_arg.emplace(item::SignalNumber{});
115 setExtraParameter(*io_signal_arg);
116 break;
117 } case Oper::GETLEASE: {
118 ret_lease.emplace(item::LeaseType{ItemType::RETVAL});
119 setNewReturnItem(*ret_lease);
120 break;
121 } case Oper::SETLEASE: {
122 lease_arg.emplace(item::LeaseType{ItemType::PARAM_IN});
123 setExtraParameter(*lease_arg);
124 break;
125 } case Oper::NOTIFY: {
126 dnotify_arg.emplace(item::DNotifySettings{});
127 setExtraParameter(*dnotify_arg);
128 break;
129 } case Oper::SETPIPE_SZ: {
130 pipe_size_arg.emplace(item::IntValue{"pipe size", "pipe buffer size"});
131 setExtraParameter(*pipe_size_arg);
132 /*
133 * SET and GET both return the current pipe size
134 */
135 [[fallthrough]];
136 } case Oper::GETPIPE_SZ: {
137 ret_pipe_size.emplace(item::IntValue{"pipe size", "pipe buffer size", ItemType::RETVAL});
138 setNewReturnItem(*ret_pipe_size);
139 break;
140 } case Oper::ADD_SEALS: {
141 file_seals_arg.emplace(item::FileSealSettings{ItemType::PARAM_IN});
142 setExtraParameter(*file_seals_arg);
143 break;
144 } case Oper::GET_SEALS: {
145 ret_seals.emplace(item::FileSealSettings{ItemType::RETVAL});
146 setNewReturnItem(*ret_seals);
147 break;
148 } case Oper::GET_RW_HINT: [[fallthrough]];
149 case Oper::GET_FILE_RW_HINT: {
150 rw_hint_arg.emplace(item::ReadWriteHint{ItemType::PARAM_OUT});
151 setExtraParameter(*rw_hint_arg);
152 break;
153 } case Oper::SET_RW_HINT: [[fallthrough]];
154 case Oper::SET_FILE_RW_HINT: {
155 rw_hint_arg.emplace(item::ReadWriteHint{ItemType::PARAM_IN});
156 setExtraParameter(*rw_hint_arg);
157 break;
158 } default: {
159 /* unknown operation? keep defaults */
160 break;
161 }
162 }
163
164 return true;
165}
void setReturnItem(SystemCallItem &ret)
Sets the return value system call item.
Oper
All possible arguments for the op parameter to fcntl(2).
Definition fcntl.hxx:26
@ 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.
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
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
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
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

◆ prepareNewSystemCall()

void clues::FcntlSystemCall::prepareNewSystemCall ( )
overrideprotectedvirtual

Perform any necessary actions before processing a new system call entry event.

Reimplemented from clues::SystemCall.

Definition at line 8 of file fs.cxx.

8 {
9 /* drop all but the fixed initial two parameters */
10 m_pars.erase(m_pars.begin() + 2, m_pars.end());
11
12 // setup the default return value
13 result.emplace(item::SuccessResult{});
15
16 /* args */
17 dup_lowest.reset();
18 fd_flags_arg.reset();
19 status_flags_arg.reset();
20 flock_arg.reset();
21 owner_arg.reset();
22 ext_owner_arg.reset();
23 io_signal_arg.reset();
24 lease_arg.reset();
25 dnotify_arg.reset();
26 pipe_size_arg.reset();
27 file_seals_arg.reset();
28 rw_hint_arg.reset();
29
30 /* retvals */
31 ret_dupfd.reset();
32 ret_fd_flags.reset();
33 ret_status_flags.reset();
34 ret_owner.reset();
35 ret_io_signal.reset();
36 ret_lease.reset();
37 ret_pipe_size.reset();
38 ret_seals.reset();
39}
ParameterVector m_pars
The array of system call parameters, if any.

◆ updateFDTracking()

void clues::FcntlSystemCall::updateFDTracking ( const Tracee & proc)
overrideprotectedvirtual

Update file descriptor tracking.

This function is called upon successful system call exit to track any potential new file descriptors or stop tracking of existing file descriptors.

Specializations of SystemCall that create or close file descriptors need to overwrite this function and call proc.trackFD() or proc.dropFD() accordingly.

Reimplemented from clues::SystemCall.

Definition at line 167 of file fs.cxx.

167 {
169
170 if (cosmos::in_list(operation.operation(), {DUPFD, DUPFD_CLOEXEC})) {
171 auto &info_map = proc.fdInfoMap();
172 if (auto it = info_map.find(fd.fd()); it != info_map.end()) {
173 auto info = it->second;
174 info.fd = ret_dupfd->fd();
175 trackFD(proc, std::move(info));
176 } else {
177 LOG_WARN("[" << cosmos::to_integral(proc.pid()) << "]"
178 << "Couldn't find dup source FD "
179 << cosmos::to_integral(fd.fd())
180 << " for tracking");
181 }
182 }
183}

Member Data Documentation

◆ dnotify_arg

std::optional<item::DNotifySettings> clues::FcntlSystemCall::dnotify_arg

for NOTIFY

Definition at line 79 of file fs.hxx.

◆ dup_lowest

std::optional<item::FileDescriptor> clues::FcntlSystemCall::dup_lowest

for DUPFD, DUPFD_CLOEXEC

Definition at line 71 of file fs.hxx.

◆ ext_owner_arg

std::optional<item::ExtFileDescOwner> clues::FcntlSystemCall::ext_owner_arg

for SETOWN_EX, GETOWN_EX

Definition at line 76 of file fs.hxx.

◆ fd

item::FileDescriptor clues::FcntlSystemCall::fd

Definition at line 67 of file fs.hxx.

◆ fd_flags_arg

std::optional<item::FileDescFlagsValue> clues::FcntlSystemCall::fd_flags_arg

for SETFD

Definition at line 72 of file fs.hxx.

◆ file_seals_arg

std::optional<item::FileSealSettings> clues::FcntlSystemCall::file_seals_arg

for ADD_SEALS

Definition at line 81 of file fs.hxx.

◆ flock_arg

std::optional<item::FLockParameter> clues::FcntlSystemCall::flock_arg

for F_SETLK, F_SETLKW, F_GETLK

Definition at line 74 of file fs.hxx.

◆ io_signal_arg

std::optional<item::SignalNumber> clues::FcntlSystemCall::io_signal_arg

for SETSIG

Definition at line 77 of file fs.hxx.

◆ lease_arg

std::optional<item::LeaseType> clues::FcntlSystemCall::lease_arg

for SETLEASE

Definition at line 78 of file fs.hxx.

◆ operation

item::FcntlOperation clues::FcntlSystemCall::operation

Definition at line 68 of file fs.hxx.

◆ owner_arg

std::optional<item::FileDescOwner> clues::FcntlSystemCall::owner_arg

for SETOWN

Definition at line 75 of file fs.hxx.

◆ pipe_size_arg

std::optional<item::IntValue> clues::FcntlSystemCall::pipe_size_arg

for SETPIPE_SZ

Definition at line 80 of file fs.hxx.

◆ result

std::optional<item::SuccessResult> clues::FcntlSystemCall::result

for all other cases

Definition at line 85 of file fs.hxx.

◆ ret_dupfd

std::optional<item::FileDescriptor> clues::FcntlSystemCall::ret_dupfd

for DUPFD, DUPFD_CLOEXEC

Definition at line 86 of file fs.hxx.

◆ ret_fd_flags

std::optional<item::FileDescFlagsValue> clues::FcntlSystemCall::ret_fd_flags

for GETFD

Definition at line 87 of file fs.hxx.

◆ ret_io_signal

std::optional<item::SignalNumber> clues::FcntlSystemCall::ret_io_signal

for GETSIG

Definition at line 90 of file fs.hxx.

◆ ret_lease

std::optional<item::LeaseType> clues::FcntlSystemCall::ret_lease

for GETLEASE

Definition at line 91 of file fs.hxx.

◆ ret_owner

std::optional<item::FileDescOwner> clues::FcntlSystemCall::ret_owner

for GET_OWNER

Definition at line 89 of file fs.hxx.

◆ ret_pipe_size

std::optional<item::IntValue> clues::FcntlSystemCall::ret_pipe_size

for GETPIPE_SZ, SETPIPE_SZ

Definition at line 92 of file fs.hxx.

◆ ret_seals

std::optional<item::FileSealSettings> clues::FcntlSystemCall::ret_seals

for GET_SEALS

Definition at line 93 of file fs.hxx.

◆ ret_status_flags

std::optional<item::OpenFlagsValue> clues::FcntlSystemCall::ret_status_flags

for GETFL

Definition at line 88 of file fs.hxx.

◆ rw_hint_arg

std::optional<item::ReadWriteHint> clues::FcntlSystemCall::rw_hint_arg

for {GET,SET}_[FILE]_RW_HINT

Definition at line 82 of file fs.hxx.

◆ status_flags_arg

std::optional<item::OpenFlagsValue> clues::FcntlSystemCall::status_flags_arg

for SETFL

Definition at line 73 of file fs.hxx.


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