libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
io.hxx
1#pragma once
2
3// clues
4#include <clues/SystemCall.hxx>
5#include <clues/items/fs.hxx>
6#include <clues/items/io.hxx>
7#include <clues/sysnrs/generic.hxx>
8
9namespace clues {
10
11struct CLUES_API WriteSystemCall :
12 public SystemCall {
13 WriteSystemCall() :
14 SystemCall{SystemCallNr::WRITE},
15 fd{},
16 buf{count, ItemType::PARAM_IN, "buf", "source buffer"},
17 count{"count", "buffer length"},
18 written{"bytes", "bytes written", ItemType::RETVAL} {
19 setReturnItem(written);
20 setParameters(fd, buf, count);
21 }
22
25 item::SizeValue count;
26 item::SizeValue written;
27};
28
29struct CLUES_API ReadSystemCall :
30 public SystemCall {
31 ReadSystemCall() :
32 SystemCall{SystemCallNr::READ},
33 fd{},
34 buf{read, ItemType::PARAM_OUT, "buf", "target buffer"},
35 count{"count", "buffer length"},
36 read{"bytes", "bytes read", ItemType::RETVAL} {
37 setReturnItem(read);
38 setParameters(fd, buf, count);
39 }
40
43 item::SizeValue count;
44 item::SizeValue read;
45};
46
47// TODO: the number of parameters can vary here.
48// can we find out during runtime if additional parameters
49// have been passed?
50// some well-known commands could be interpreted, but we don't
51// know of what type a file descriptor is, or do we?
52//
53// the request integer can be interpreted in a generic way by use of some
54// macros (e.g.: in/out/in-out operation, size of next parameter), but the man
55// page says that this is unreliable, due to legacy APIs.
56//
57// combined with file descriptor tracking we could route to specializations
58// for file descriptor specific operations. But this might not always work
59// perfectly (e.g. when attaching to a ForeignTracee).
60struct CLUES_API IoCtlSystemCall :
61 public SystemCall {
62
63 IoCtlSystemCall() :
64 SystemCall{SystemCallNr::IOCTL},
65 request{"request", "ioctl request number"} {
66 setReturnItem(result);
67 setParameters(fd, request);
68 }
69
71 // this should be a 32-bit `int`, but many request codes set the
72 // highest bit, making it signed, causing comparison against
73 // preproessor defines to fail. Thus make it unsigned.
74 item::UintValue request;
75 /*
76 * operation-specific parameters to be done
77 */
79};
80
82struct CLUES_API PipeSystemCall :
83 public SystemCall {
84
85 explicit PipeSystemCall(const SystemCallNr nr = SystemCallNr::PIPE) :
86 SystemCall{nr} {
87 setReturnItem(result);
88 setParameters(ends);
89 /*
90 * XXX: some architectures like IA64, Alpha, MIPS, Sparc,
91 * SuperH return the two file descriptors as return values in
92 * two registers. This still needs to be covered once one of
93 * the respective ABIs is supported.
94 */
95 }
96
97 item::PipeEnds ends;
99
100protected: // functions
101
102 void updateFDTracking(const Tracee &proc) override;
103};
104
105struct CLUES_API Pipe2SystemCall :
106 public PipeSystemCall {
107
108 explicit Pipe2SystemCall() :
109 PipeSystemCall{SystemCallNr::PIPE2} {
110 addParameters(flags);
111 }
112
113 item::PipeFlags flags;
114};
115
116} // 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
Pointer to a buffer of a certain size containing arbitrary data.
Definition items.hxx:153
Base class for file descriptor system call items.
Definition fs.hxx:28
Pointer to pipefd[2] array in pipe() system calls.
Definition io.hxx:22
Flags used in Pipe2SystemCall.
Definition io.hxx:69
An always-success return value.
Definition error.hxx:15
@ PARAM_OUT
An output parameter filled by in by the system call.
@ PARAM_IN
An input parameter to the system call.
@ RETVAL
A system call return value.
SystemCallNr
Abstract system call number usable across architectures and ABIs.
Definition generic.hxx:29
void updateFDTracking(const Tracee &proc) override
Update file descriptor tracking.
Definition io.cxx:6