libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
memory.hxx
1#pragma once
2
3// clues
4#include <clues/SystemCall.hxx>
5#include <clues/items/fs.hxx>
6#include <clues/items/items.hxx>
7#include <clues/items/mmap.hxx>
8#include <clues/sysnrs/generic.hxx>
9
10namespace clues {
11
12/* note that this is called brk() in man pages and some other spots, while
13 * `man break` refers to an unsupported system call */
14struct CLUES_API BreakSystemCall :
15 public SystemCall {
16 BreakSystemCall() :
17 SystemCall{SystemCallNr::BREAK},
18 req_addr{"req_addr", "requested data segment end"},
19 ret_addr{"ret_addr", "actual data segment end", ItemType::RETVAL} {
20 setReturnItem(ret_addr);
21 setParameters(req_addr);
22 }
23
26};
27
29
48struct CLUES_API MmapSystemCall :
49 public SystemCall {
50
51public: // functions
52
53 explicit MmapSystemCall(const SystemCallNr nr) :
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 }
61
62 bool isOldMmap() const {
63 return old_args.has_value();
64 }
65
66protected: // functions
67
68 void prepareNewSystemCall() override;
69
70 bool implementsOldMmap() const;
71
72 bool check2ndPass(const Tracee&) override;
73
74public: // data
75
76 /* parameters for new mmap() / mmap2() */
78 item::SizeValue length;
82 item::OffsetValue offset;
83
84 /* parameters for old mmap() */
85 std::optional<item::OldMmapArgs> old_args;
86
87 /* return value */
89};
90
91struct CLUES_API MunmapSystemCall :
92 public SystemCall {
93
94 MunmapSystemCall() :
95 SystemCall{SystemCallNr::MUNMAP},
96 addr{"addr", "address to unmap"},
97 length{"len", "length"} {
98 setReturnItem(result);
99 setParameters(addr, length);
100 }
101
102 /* parameters */
104 item::SizeValue length;
105
106 /* return value */
107 item::SuccessResult result;
108};
109
110struct CLUES_API MprotectSystemCall :
111 public SystemCall {
112
113 MprotectSystemCall() :
114 SystemCall{SystemCallNr::MPROTECT},
115 addr{"addr"},
116 length{"length"} {
117 setReturnItem(result);
118 setParameters(addr, length, protection);
119 }
120
121 /* parameters */
123 item::SizeValue length;
125
126 /* return value */
127 item::SuccessResult result;
128};
129
130} // 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
Base class for file descriptor system call items.
Definition fs.hxx:28
Memory protection used e.g. in mprotect().
Definition mmap.hxx:13
An always-success return value.
Definition error.hxx:15
@ RETVAL
A system call return value.
SystemCallNr
Abstract system call number usable across architectures and ABIs.
Definition generic.hxx:29
bool check2ndPass(const Tracee &) override
Check whether a second pass needs to be made processing parameters.
Definition memory.cxx:26
void prepareNewSystemCall() override
Perform any necessary actions before processing a new system call entry event.
Definition memory.cxx:13