libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
clues::MmapSystemCall Struct Reference

Type for mmap() / mmap2() system calls. More...

#include <memory.hxx>

+ Inheritance diagram for clues::MmapSystemCall:

Public Member Functions

 MmapSystemCall (const SystemCallNr nr)
 
bool isOldMmap () const
 
- 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::GenericPointerValue hint
 
item::SizeValue length
 
item::MemoryProtectionParameter protection
 
item::MapFlagsParameter flags
 
item::FileDescriptor fd
 
item::OffsetValue offset
 
std::optional< item::OldMmapArgsold_args
 
item::GenericPointerValue addr
 

Protected Member Functions

void prepareNewSystemCall () override
 Perform any necessary actions before processing a new system call entry event.
 
bool implementsOldMmap () const
 
bool check2ndPass (const Tracee &) override
 Check whether a second pass needs to be made processing parameters.
 
- 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)
 
virtual void updateFDTracking (const Tracee &proc)
 Update file descriptor tracking.
 
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

Type for mmap() / mmap2() system calls.

SYS_mmap and SYS_mmap2 are unfortunate with regards to tracing. SYS_mmap can refer to two different variants of mmap() depending on ABI.

The well-known modern mmap() call taking six parameters is found in SYS_mmap on modern systems and in SYS_mmap2 on older ABIs.

SYS_mmap on older ABIs like I386 takes a single struct mmap_args parameter. Thus when SYS_mmap occurs during tracing, in an abstract application not considering the ABI, it can be either the modern mmap() or the legacy mmap(). To ease handling these differences, this type covers both SYS_mmap and SYS_mmap2 on all ABIs. Even on older ABIs the six members corresponding to the modern mmap() system call will be filled. This way applications can process both types of mmap system calls in a unified way.

For completeness, in case of the legacy SYS_mmap() the isOldMmap() member function will return true and the original data structure passed to the kernel is available in old_args.

Definition at line 48 of file memory.hxx.

Constructor & Destructor Documentation

◆ MmapSystemCall()

clues::MmapSystemCall::MmapSystemCall ( const SystemCallNr nr)
inlineexplicit

Definition at line 53 of file memory.hxx.

53 :
54 SystemCall{nr},
55 hint{"hint", "address placement hint"},
56 length{"len", "length"},
57 offset{"offset"},
58 addr{"addr", "mapped memory address", ItemType::RETVAL} {
59 setReturnItem(addr);
60 }
void setReturnItem(SystemCallItem &ret)
Sets the return value system call item.
SystemCall(const SystemCallNr nr)
Instantiates a new SystemCall object with given properties.
@ RETVAL
A system call return value.

Member Function Documentation

◆ check2ndPass()

bool clues::MmapSystemCall::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 26 of file memory.cxx.

26 {
27 /*
28 * we use this callback not for rearranging the parameters, but for
29 * synchronizing the regular mmap arguments with the legacy struct
30 * mmap data.
31 */
32 if (isOldMmap()) {
33 const auto &args = *old_args;
34 hint.fill(proc, Word{cosmos::to_integral(args.addr())});
35 length.fill(proc, Word{args.length()});
36 protection.fill(proc, Word{static_cast<elf_greg_t>(args.prot().raw())});
37 flags.fill(proc, Word{static_cast<elf_greg_t>(cosmos::to_integral(args.type()) | args.flags().raw())});
38 fd.fill(proc, Word{static_cast<elf_greg_t>(cosmos::to_integral(args.fd()))});
39 offset.fill(proc, Word{args.offset()});
40 }
41 return false;
42}
Word
An integer that is able to hold a word for the current architecture.
Definition types.hxx:38

◆ implementsOldMmap()

bool clues::MmapSystemCall::implementsOldMmap ( ) const
protected

Definition at line 6 of file memory.cxx.

6 {
7 switch (abi()) {
8 case ABI::I386: return true;
9 default: return false;
10 }
11}
ABI abi() const
Returns the system call ABi seen during system call entry.

◆ isOldMmap()

bool clues::MmapSystemCall::isOldMmap ( ) const
inline

Definition at line 62 of file memory.hxx.

62 {
63 return old_args.has_value();
64 }

◆ prepareNewSystemCall()

void clues::MmapSystemCall::prepareNewSystemCall ( )
overrideprotectedvirtual

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

Reimplemented from clues::SystemCall.

Definition at line 13 of file memory.cxx.

13 {
14 /*
15 * setup parameters for legacy / new variant of mmap()
16 */
17 if (callNr() == SystemCallNr::MMAP2 || !implementsOldMmap()) {
18 old_args.reset();
19 setParameters(hint, length, protection, flags, fd, offset);
20 } else {
21 old_args.emplace(item::OldMmapArgs{});
22 setParameters(*old_args);
23 }
24}
SystemCallNr callNr() const
Returns the system call table number for this system call.

Member Data Documentation

◆ addr

item::GenericPointerValue clues::MmapSystemCall::addr

Definition at line 88 of file memory.hxx.

◆ fd

item::FileDescriptor clues::MmapSystemCall::fd

Definition at line 81 of file memory.hxx.

◆ flags

item::MapFlagsParameter clues::MmapSystemCall::flags

Definition at line 80 of file memory.hxx.

◆ hint

item::GenericPointerValue clues::MmapSystemCall::hint

Definition at line 77 of file memory.hxx.

◆ length

item::SizeValue clues::MmapSystemCall::length

Definition at line 78 of file memory.hxx.

◆ offset

item::OffsetValue clues::MmapSystemCall::offset

Definition at line 82 of file memory.hxx.

◆ old_args

std::optional<item::OldMmapArgs> clues::MmapSystemCall::old_args

Definition at line 85 of file memory.hxx.

◆ protection

item::MemoryProtectionParameter clues::MmapSystemCall::protection

Definition at line 79 of file memory.hxx.


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