libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
time.cxx
1// Linux
2#include <time.h>
3
4// cosmos
5#include <cosmos/formatting.hxx>
6
7// clues
8#include <clues/format.hxx>
9#include <clues/items/time.hxx>
10#include <clues/macros.h>
11#include <clues/private/kernel/time.hxx>
12#include <clues/sysnrs/generic.hxx>
13#include <clues/Tracee.hxx>
14#include <clues/utils.hxx>
15
16namespace clues::item {
17
19 if (m_remain_semantics) {
20 /*
21 * special logic for clock_nanosleep remain semantics &
22 * similar cases:
23 *
24 * - on success, remaining time is not updated
25 * - on special kernel error code, transparent restart will
26 * happen
27 * - otherwise only if EINTR is observed will the time be
28 * updated
29 */
30 if (m_call->hasResultValue())
31 return;
32
33 const auto error = *m_call->error();
34
35 if (!error.hasErrorCode() || error.errorCode() != cosmos::Errno::INTERRUPTED) {
36 return;
37 }
38 }
39
40 fetch(proc);
41}
42
44 /*
45 * currently we only cover 32-bit emulation binaries on X86-64.
46 */
47
48 if (!m_call->is32BitEmulationABI()) {
49 return false;
50 }
51
52 /* now we need to check which system call we're on */
53 return cosmos::in_list(m_call->callNr(), {
54 SystemCallNr::CLOCK_NANOSLEEP,
55 SystemCallNr::FUTEX,
56 SystemCallNr::NANOSLEEP
57 });
58}
59
60void TimeSpecParameter::fetch(const Tracee &proc) {
61 if (!m_timespec) {
62 m_timespec = timespec{};
63 }
64
66 struct timespec32 ts32;
67 if (!proc.readStruct(asPtr(), ts32)) {
68 m_timespec.reset();
69 return;
70 }
71
72 m_timespec->tv_sec = ts32.tv_sec;
73 m_timespec->tv_nsec = ts32.tv_nsec;
74 } else if (!proc.readStruct(asPtr(), *m_timespec)) {
75 m_timespec.reset();
76 }
77}
78
79std::string TimeSpecParameter::str() const {
80 if (!m_timespec) {
81 if (m_remain_semantics) {
82 /* still show that a pointer was passed */
83 return format::pointer(asPtr());
84 } else {
85 return "NULL";
86 }
87 }
88
89 return format::timespec(*m_timespec);
90}
91
92std::string ClockID::str() const {
93 switch (valueAs<clockid_t>()) {
94 CASE_ENUM_TO_STR(CLOCK_REALTIME);
95 CASE_ENUM_TO_STR(CLOCK_REALTIME_COARSE);
96 CASE_ENUM_TO_STR(CLOCK_TAI);
97 CASE_ENUM_TO_STR(CLOCK_MONOTONIC);
98 CASE_ENUM_TO_STR(CLOCK_MONOTONIC_RAW);
99 CASE_ENUM_TO_STR(CLOCK_MONOTONIC_COARSE);
100 CASE_ENUM_TO_STR(CLOCK_BOOTTIME);
101 CASE_ENUM_TO_STR(CLOCK_PROCESS_CPUTIME_ID);
102 CASE_ENUM_TO_STR(CLOCK_THREAD_CPUTIME_ID);
103 default: return cosmos::sprintf("unknown (%d)", valueAs<clockid_t>());
104 }
105}
106
107std::string ClockNanoSleepFlags::str() const {
108 switch (valueAs<int>()) {
109 CASE_ENUM_TO_STR(TIMER_ABSTIME);
110 case 0: return "<relative-time>";
111 default: return cosmos::sprintf("unknown (%d)", valueAs<clockid_t>());
112 }
113}
114
115} // end ns
const SystemCall * m_call
The system call context this item part of.
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 time.cxx:92
std::string str() const override
Returns a human readable string representation of the item.
Definition time.cxx:107
void updateData(const Tracee &proc) override
Called upon exit of the system call to update possible out parameters.
Definition time.cxx:18
bool needTime32Conversion() const
Checks whether the current ABI context requires conversion of 32 bit to 64 bit.
Definition time.cxx:43
std::string str() const override
Returns a human readable string representation of the item.
Definition time.cxx:79