gem5 v24.0.0.0
Loading...
Searching...
No Matches
fd_entry.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __FD_ENTRY_HH__
33#define __FD_ENTRY_HH__
34
35#include <memory>
36#include <ostream>
37#include <string>
38
39#include "sim/serialize.hh"
40
41namespace gem5
42{
43
44class EmulatedDriver;
45
46
51class FDEntry : public Serializable
52{
53 public:
54
65
66 FDEntry(bool close_on_exec = false)
67 : _closeOnExec(close_on_exec)
69
70 virtual std::shared_ptr<FDEntry> clone() const = 0;
71
72 bool getCOE() const { return _closeOnExec; }
73
74 FDClass getClass() const { return _class; }
75
76 void setCOE(bool close_on_exec) { _closeOnExec = close_on_exec; }
77
78 virtual void serialize(CheckpointOut &cp) const;
79 virtual void unserialize(CheckpointIn &cp);
80
81 protected:
84};
85
91class HBFDEntry: public FDEntry
92{
93 public:
94 HBFDEntry(int flags, int sim_fd, bool close_on_exec = false)
95 : FDEntry(close_on_exec), _flags(flags), _simFD(sim_fd)
97
98 HBFDEntry(HBFDEntry const& reg, bool close_on_exec = false)
99 : FDEntry(close_on_exec), _flags(reg._flags), _simFD(reg._simFD)
101
102 std::shared_ptr<FDEntry>
103 clone() const override
104 {
105 return std::make_shared<HBFDEntry>(*this);
106 }
107
108 int getFlags() const { return _flags; }
109 int getSimFD() const { return _simFD; }
110
111 void setFlags(int flags) { _flags = flags; }
112 void setSimFD(int sim_fd) { _simFD = sim_fd; }
113
114 protected:
117};
118
128{
129 public:
130 FileFDEntry(int sim_fd, int flags, std::string const& file_name,
131 uint64_t file_offset, bool close_on_exec = false)
132 : HBFDEntry(flags, sim_fd, close_on_exec),
133 _fileName(file_name), _fileOffset(file_offset)
135
136 FileFDEntry(FileFDEntry const& reg, bool close_on_exec = false)
137 : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
140
141 std::shared_ptr<FDEntry>
142 clone() const override
143 {
144 return std::make_shared<FileFDEntry>(*this);
145 }
146
147 std::string const& getFileName() const { return _fileName; }
148 uint64_t getFileOffset() const { return _fileOffset; }
149 mode_t getFileMode() const { return _mode; }
150
151 void setFileName(std::string const& file_name) { _fileName = file_name; }
152 void setFileOffset(uint64_t f_off) { _fileOffset = f_off; }
153 void setFileMode(mode_t mode) { _mode = mode; }
154
155 void serialize(CheckpointOut &cp) const override;
156 void unserialize(CheckpointIn &cp) override;
157
158 private:
159 std::string _fileName;
160 uint64_t _fileOffset;
161 mode_t _mode;
162};
163
169{
170 public:
172 {
173 read = 0,
174 write = 1
175 };
176
177 PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type,
178 bool close_on_exec = false)
179 : HBFDEntry(flags, sim_fd, close_on_exec), _pipeReadSource(-1),
180 _pipeEndType(pipe_end_type)
182
183 PipeFDEntry(PipeFDEntry const& pipe, bool close_on_exec = false)
184 : HBFDEntry(pipe._flags, pipe._simFD, close_on_exec),
188
189 std::shared_ptr<FDEntry>
190 clone() const override
191 {
192 return std::make_shared<PipeFDEntry>(*this);
193 }
194
195 EndType getEndType() const { return _pipeEndType; }
196 int getPipeReadSource() const { return _pipeReadSource; }
197
198 void setPipeReadSource(int tgt_fd) { _pipeReadSource = tgt_fd; }
200
201 void serialize(CheckpointOut &cp) const override;
202 void unserialize(CheckpointIn &cp) override;
203
204 private:
207};
208
213class DeviceFDEntry : public FDEntry
214{
215 public:
216 DeviceFDEntry(EmulatedDriver *driver, std::string const& file_name,
217 bool close_on_exec = false)
218 : FDEntry(close_on_exec), _driver(driver), _fileName(file_name)
220
221 DeviceFDEntry(DeviceFDEntry const& dev, bool close_on_exec = false)
222 : FDEntry(close_on_exec), _driver(dev._driver),
225
226 std::shared_ptr<FDEntry>
227 clone() const override
228 {
229 return std::make_shared<DeviceFDEntry>(*this);
230 }
231
232 EmulatedDriver *getDriver() const { return _driver; }
233 std::string const& getFileName() const { return _fileName; }
234
235 void serialize(CheckpointOut &cp) const override;
236 void unserialize(CheckpointIn &cp) override;
237
238 private:
240 std::string _fileName;
241};
242
244{
245 public:
246 SocketFDEntry(int sim_fd, int domain, int type, int protocol,
247 bool close_on_exec = false)
248 : HBFDEntry(0, sim_fd, close_on_exec),
249 _domain(domain), _type(type), _protocol(protocol)
251
252 SocketFDEntry(SocketFDEntry const& reg, bool close_on_exec = false)
253 : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
256
257 std::shared_ptr<FDEntry>
258 clone() const override
259 {
260 return std::make_shared<SocketFDEntry>(*this);
261 }
262
264 int _type;
266};
267
268} // namespace gem5
269
270#endif // __FD_ENTRY_HH__
Holds file descriptors needed to simulate devices opened with pseudo files (commonly with calls to io...
Definition fd_entry.hh:214
EmulatedDriver * getDriver() const
Definition fd_entry.hh:232
EmulatedDriver * _driver
Definition fd_entry.hh:239
std::string const & getFileName() const
Definition fd_entry.hh:233
std::string _fileName
Definition fd_entry.hh:240
std::shared_ptr< FDEntry > clone() const override
Definition fd_entry.hh:227
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition fd_entry.cc:88
DeviceFDEntry(EmulatedDriver *driver, std::string const &file_name, bool close_on_exec=false)
Definition fd_entry.hh:216
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition fd_entry.cc:96
DeviceFDEntry(DeviceFDEntry const &dev, bool close_on_exec=false)
Definition fd_entry.hh:221
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Holds a single file descriptor mapping and that mapping's data for processes running in syscall emula...
Definition fd_entry.hh:52
virtual std::shared_ptr< FDEntry > clone() const =0
void setCOE(bool close_on_exec)
Definition fd_entry.hh:76
FDClass _class
Definition fd_entry.hh:83
FDClass getClass() const
Definition fd_entry.hh:74
FDEntry(bool close_on_exec=false)
Definition fd_entry.hh:66
bool _closeOnExec
Definition fd_entry.hh:82
bool getCOE() const
Definition fd_entry.hh:72
virtual void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition fd_entry.cc:46
virtual void serialize(CheckpointOut &cp) const
Serialize an object.
Definition fd_entry.cc:40
Holds file descriptors for host-backed files; host-backed files are files which were opened on the ph...
Definition fd_entry.hh:128
void setFileMode(mode_t mode)
Definition fd_entry.hh:153
FileFDEntry(int sim_fd, int flags, std::string const &file_name, uint64_t file_offset, bool close_on_exec=false)
Definition fd_entry.hh:130
std::string const & getFileName() const
Definition fd_entry.hh:147
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition fd_entry.cc:52
void setFileName(std::string const &file_name)
Definition fd_entry.hh:151
mode_t getFileMode() const
Definition fd_entry.hh:149
FileFDEntry(FileFDEntry const &reg, bool close_on_exec=false)
Definition fd_entry.hh:136
void setFileOffset(uint64_t f_off)
Definition fd_entry.hh:152
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition fd_entry.cc:62
uint64_t _fileOffset
Definition fd_entry.hh:160
std::shared_ptr< FDEntry > clone() const override
Definition fd_entry.hh:142
uint64_t getFileOffset() const
Definition fd_entry.hh:148
std::string _fileName
Definition fd_entry.hh:159
Extends the base class to include a host-backed file descriptor field that records the integer used t...
Definition fd_entry.hh:92
void setSimFD(int sim_fd)
Definition fd_entry.hh:112
std::shared_ptr< FDEntry > clone() const override
Definition fd_entry.hh:103
HBFDEntry(HBFDEntry const &reg, bool close_on_exec=false)
Definition fd_entry.hh:98
HBFDEntry(int flags, int sim_fd, bool close_on_exec=false)
Definition fd_entry.hh:94
void setFlags(int flags)
Definition fd_entry.hh:111
int getSimFD() const
Definition fd_entry.hh:109
int getFlags() const
Definition fd_entry.hh:108
Holds the metadata needed to maintain the mappings for file descriptors allocated with the pipe() sys...
Definition fd_entry.hh:169
int getPipeReadSource() const
Definition fd_entry.hh:196
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition fd_entry.cc:72
std::shared_ptr< FDEntry > clone() const override
Definition fd_entry.hh:190
void setEndType(EndType type)
Definition fd_entry.hh:199
EndType _pipeEndType
Definition fd_entry.hh:206
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition fd_entry.cc:80
EndType getEndType() const
Definition fd_entry.hh:195
PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type, bool close_on_exec=false)
Definition fd_entry.hh:177
void setPipeReadSource(int tgt_fd)
Definition fd_entry.hh:198
PipeFDEntry(PipeFDEntry const &pipe, bool close_on_exec=false)
Definition fd_entry.hh:183
Basic support for object serialization.
Definition serialize.hh:170
SocketFDEntry(int sim_fd, int domain, int type, int protocol, bool close_on_exec=false)
Definition fd_entry.hh:246
SocketFDEntry(SocketFDEntry const &reg, bool close_on_exec=false)
Definition fd_entry.hh:252
std::shared_ptr< FDEntry > clone() const override
Definition fd_entry.hh:258
uint8_t flags
Definition helpers.cc:87
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 7, 4 > domain
Bitfield< 5, 3 > reg
Definition types.hh:92
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0