libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
mmap.cxx
1// C++
2#include <sstream>
3
4// cosmos
5#include <cosmos/proc/mman.hxx>
6
7// clues
8#include <clues/items/mmap.hxx>
9#include <clues/private/kernel/mmap.hxx>
10#include <clues/private/utils.hxx>
11#include <clues/syscalls/memory.hxx>
12#include <clues/Tracee.hxx>
13
14namespace clues::item {
15
16std::string MemoryProtectionParameter::str() const {
17 if (m_prot.none())
18 // this is just zero
19 return "PROT_NONE";
20
21 BITFLAGS_FORMAT_START(m_prot);
22
23 BITFLAGS_ADD(PROT_READ);
24 BITFLAGS_ADD(PROT_WRITE);
25 BITFLAGS_ADD(PROT_EXEC);
26 BITFLAGS_ADD(PROT_SEM);
27 BITFLAGS_ADD(PROT_SAO);
28
29 return BITFLAGS_STR();
30}
31
32std::string MapFlagsParameter::str() const {
33 const auto raw = valueAs<int>();
34 BITFLAGS_FORMAT_START_COMBINED(m_flags, raw);
35
36 using enum cosmos::mem::MapType;
37
38 switch (m_type) {
39 default: BITFLAGS_STREAM() << "MAP_???"; break;
40 case SHARED: BITFLAGS_STREAM() << "MAP_SHARED"; break;
41 case SHARED_VALIDATE: BITFLAGS_STREAM() << "MAP_SHARED_VALIDATE"; break;
42 case PRIVATE: BITFLAGS_STREAM() << "MAP_PRIVATE"; break;
43 }
44
45 BITFLAGS_STREAM() << '|';
46
47#ifdef MAP_32BIT
48 BITFLAGS_ADD(MAP_32BIT);
49#endif
50 BITFLAGS_ADD(MAP_ANONYMOUS);
51 BITFLAGS_ADD(MAP_FIXED);
52 BITFLAGS_ADD(MAP_FIXED_NOREPLACE);
53 BITFLAGS_ADD(MAP_GROWSDOWN);
54 BITFLAGS_ADD(MAP_HUGETLB);
55 BITFLAGS_ADD(MAP_LOCKED);
56 BITFLAGS_ADD(MAP_NONBLOCK);
57 BITFLAGS_ADD(MAP_NORESERVE);
58 BITFLAGS_ADD(MAP_POPULATE);
59 BITFLAGS_ADD(MAP_STACK);
60 BITFLAGS_ADD(MAP_SYNC);
61 BITFLAGS_ADD(MAP_UNINITIALIZED);
62
63 const auto huge_shift = (raw >> MAP_HUGE_SHIFT) & 0x3f;
64
65 if (huge_shift != 0) {
66 /* there's also the TLB page size encoded into the bit mask */
67 BITFLAGS_STREAM() << huge_shift << "<<MAP_HUGE_SHIFT|";
68 }
69
70 return BITFLAGS_STR();
71}
72
74 struct mmap_arg_struct args;
75
76 if (!proc.readStruct(asPtr(), args)) {
77 m_valid = false;
78 return;
79 }
80
81 m_addr = ForeignPtr{static_cast<uintptr_t>(args.addr)};
82 m_length = args.len;
83 m_offset = args.offset;
84 m_prot = cosmos::mem::AccessFlags{static_cast<int>(args.prot)};
85 m_fd = cosmos::FileNum{static_cast<int>(args.fd)};
86 const auto raw_flags = static_cast<int>(args.flags);
87 m_flags = cosmos::mem::MapFlags{raw_flags & ~0x3};
88 m_type = cosmos::mem::MapType{raw_flags & 0x3};
89
90 m_valid = true;
91}
92
93std::string OldMmapArgs::str() const {
94 auto &mmap_call = dynamic_cast<const MmapSystemCall&>(*m_call);
95
96 std::stringstream ss;
97 ss << "{hint=" << mmap_call.hint.str()
98 << ", length=" << mmap_call.length.str()
99 << ", prot=" << mmap_call.protection.str()
100 << ", flags=" << mmap_call.flags.str()
101 << ", fd=" << mmap_call.fd.str()
102 << ", offset=" << mmap_call.offset.str()
103 << "}";
104
105 return ss.str();
106}
107
108} // end ns
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
Base class for traced processes.
Definition Tracee.hxx:39
bool readStruct(const ForeignPtr addr, T &out) const
Reads a system call struct from the tracee's address space into out.
Definition Tracee.hxx:221
std::string str() const override
Returns a human readable string representation of the item.
Definition mmap.cxx:32
std::string str() const override
Returns a human readable string representation of the item.
Definition mmap.cxx:16
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition mmap.cxx:73
std::string str() const override
Returns a human readable string representation of the item.
Definition mmap.cxx:93
ForeignPtr
Strongly typed opaque pointer to tracee memory.
Definition types.hxx:140
Type for mmap() / mmap2() system calls.
Definition memory.hxx:49
Old mmap() parameter on 32-bit ABIs like I386.
Definition mmap.hxx:11