libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
types.hxx
1#pragma once
2
3// Linux
4#include <sys/procfs.h> // the elf_greg_t & friends are in here
5
6// C++
7#include <cstdint>
8#include <map>
9#include <memory>
10#include <optional>
11#include <string>
12
13// cosmos
14#include <cosmos/utils.hxx>
15#include <cosmos/fs/types.hxx>
16
17namespace clues {
18
19/*
20 * some general types used across Clues
21 */
22
24using FollowChildren = cosmos::NamedBool<struct follow_children_t, true>;
25
27using AttachThreads = cosmos::NamedBool<struct attach_threads_t, true>;
28
29class Tracee;
30
31using TraceePtr = std::shared_ptr<Tracee>;
32
33class ProcessData;
34
35using ProcessDataPtr = std::shared_ptr<ProcessData>;
36
38enum class Word : elf_greg_t {
39 ZERO = 0
40};
41
43
49enum class KernelErrno : int {
50 RESTART_SYS = 512, /* transparent restart if SA_RESTART is set, otherwise EINTR return */
51 RESTART_NOINTR = 513, /* always transparent restart */
52 RESTART_NOHAND = 514, /* restart if no handler.. */
53 RESTART_RESTARTBLOCK = 516, /* restart by calling sys_restart_syscall */
54};
55
57
62enum class ABI {
63 UNKNOWN,
64 X86_64,
65 I386,
67 AARCH64
68};
69
71
75struct FDInfo {
76public: // types
77
79
86 enum class Type {
87 INVALID,
99 PERF_EVENT,
100 UNKNOWN
101 };
102
103public: // functions
104
105 FDInfo() = default;
106
107 explicit FDInfo(const Type _type, const cosmos::FileNum _fd) :
108 type{_type}, fd{_fd} {
109 }
110
111 bool valid() const {
112 return type != Type::INVALID;
113 }
114
115public: // data
116
117 Type type = Type::INVALID;
118 cosmos::FileNum fd = cosmos::FileNum::INVALID;
119 std::string path;
120 std::optional<cosmos::OpenMode> mode;
121 std::optional<cosmos::OpenFlags> flags;
122 std::optional<cosmos::Inode> inode;
123};
124
126using FDInfoMap = std::map<cosmos::FileNum, FDInfo>;
127
129enum class Base {
130 OCT,
131 DEC,
132 HEX
133};
134
136
140enum class ForeignPtr : uintptr_t {
141 NO_POINTER = 0
142};
143
144} // end ns
145
147inline clues::ForeignPtr operator++(clues::ForeignPtr &p, int) {
148 auto ret = p;
149 p = clues::ForeignPtr{static_cast<uintptr_t>(p) + sizeof(void*)};
150 return ret;
151}
This type contains data that is shared between tracees of the same thread group.
Base class for traced processes.
Definition Tracee.hxx:39
KernelErrno
Errno values that can appear in tracing context.
Definition types.hxx:49
cosmos::NamedBool< struct attach_threads_t, true > AttachThreads
A strong boolean type denoting whether to automatically all other threads of a process.
Definition types.hxx:27
ABI
System Call ABI.
Definition types.hxx:62
@ X32
X86_64 with 32-bit pointers.
Definition types.hxx:66
std::map< cosmos::FileNum, FDInfo > FDInfoMap
A mapping of file descriptor numbers to their file system paths or other human readable description o...
Definition types.hxx:126
Base
Integer number display base for formatting purposes.
Definition types.hxx:129
cosmos::NamedBool< struct follow_children_t, true > FollowChildren
A strong boolean type denoting whether to automatically attach to newly created child processes.
Definition types.hxx:24
ForeignPtr
Strongly typed opaque pointer to tracee memory.
Definition types.hxx:140
Word
An integer that is able to hold a word for the current architecture.
Definition types.hxx:38
Contextual information about a file descriptor in a Tracee.
Definition types.hxx:75
cosmos::FileNum fd
the actual file descriptor number.
Definition types.hxx:118
Type
Different types of file descriptors.
Definition types.hxx:86
@ BPF_PROG
refers to a BPF program validated and loaded
Definition types.hxx:98
@ SIGNAL_FD
created by signalfd()
Definition types.hxx:91
@ INOTIFY
created by inotify_init()
Definition types.hxx:95
@ TIMER_FD
created by timerfd()
Definition types.hxx:90
@ PID_FD
created by pidfd_open(), clone(), ...
Definition types.hxx:96
@ PIPE
created by pipe()
Definition types.hxx:94
@ SOCKET
created by socket()
Definition types.hxx:92
@ EVENT_FD
created by eventfd()
Definition types.hxx:89
@ FS_PATH
a path opened on the file system (this can still be a device special file, named pipe,...
Definition types.hxx:88
@ EPOLL
an epoll() file descriptor
Definition types.hxx:93
@ BPF_MAP
refers to a BPF type map
Definition types.hxx:97
std::string path
path to the file, if applicable
Definition types.hxx:119
std::optional< cosmos::Inode > inode
inode of the file, only filled by utils::get_fd_infos().
Definition types.hxx:122