gem5  v22.0.0.2
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 
41 namespace gem5
42 {
43 
44 class EmulatedDriver;
45 
46 
51 class FDEntry : public Serializable
52 {
53  public:
54 
55  enum FDClass
56  {
64  };
65 
66  FDEntry(bool close_on_exec = false)
67  : _closeOnExec(close_on_exec)
68  { _class = FDClass::fd_base; }
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 
91 class 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)
96  { _class = FDClass::fd_hb; }
97 
98  HBFDEntry(HBFDEntry const& reg, bool close_on_exec = false)
99  : FDEntry(close_on_exec), _flags(reg._flags), _simFD(reg._simFD)
100  { _class = FDClass::fd_hb; }
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:
115  int _flags;
116  int _simFD;
117 };
118 
127 class FileFDEntry: public HBFDEntry
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)
134  { _class = FDClass::fd_file; }
135 
136  FileFDEntry(FileFDEntry const& reg, bool close_on_exec = false)
137  : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
139  { _class = FDClass::fd_file; }
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 
168 class PipeFDEntry: public HBFDEntry
169 {
170  public:
171  enum EndType
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)
181  { _class = FDClass::fd_pipe; }
182 
183  PipeFDEntry(PipeFDEntry const& pipe, bool close_on_exec = false)
184  : HBFDEntry(pipe._flags, pipe._simFD, close_on_exec),
187  { _class = FDClass::fd_pipe; }
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 
213 class 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)
219  { _class = FDClass::fd_device; }
220 
221  DeviceFDEntry(DeviceFDEntry const& dev, bool close_on_exec = false)
222  : FDEntry(close_on_exec), _driver(dev._driver),
223  _fileName(dev._fileName)
224  { _class = FDClass::fd_device; }
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)
250  { _class = FDClass::fd_socket; }
251 
252  SocketFDEntry(SocketFDEntry const& reg, bool close_on_exec = false)
253  : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
255  { _class = FDClass::fd_socket; }
256 
257  std::shared_ptr<FDEntry>
258  clone() const override
259  {
260  return std::make_shared<SocketFDEntry>(*this);
261  }
262 
263  int _domain;
264  int _type;
266 };
267 
268 } // namespace gem5
269 
270 #endif // __FD_ENTRY_HH__
gem5::PipeFDEntry::read
@ read
Definition: fd_entry.hh:173
gem5::SocketFDEntry
Definition: fd_entry.hh:243
gem5::FDEntry::fd_device
@ fd_device
Definition: fd_entry.hh:61
gem5::PipeFDEntry::getPipeReadSource
int getPipeReadSource() const
Definition: fd_entry.hh:196
gem5::PipeFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:72
gem5::FileFDEntry::setFileName
void setFileName(std::string const &file_name)
Definition: fd_entry.hh:151
gem5::PipeFDEntry::EndType
EndType
Definition: fd_entry.hh:171
serialize.hh
gem5::FDEntry::unserialize
virtual void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: fd_entry.cc:46
gem5::FDEntry::serialize
virtual void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: fd_entry.cc:40
gem5::SocketFDEntry::_type
int _type
Definition: fd_entry.hh:264
gem5::FDEntry::setCOE
void setCOE(bool close_on_exec)
Definition: fd_entry.hh:76
gem5::ArmISA::domain
Bitfield< 7, 4 > domain
Definition: misc_types.hh:424
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::HBFDEntry::HBFDEntry
HBFDEntry(HBFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:98
gem5::FDEntry::fd_socket
@ fd_socket
Definition: fd_entry.hh:62
gem5::FileFDEntry::getFileOffset
uint64_t getFileOffset() const
Definition: fd_entry.hh:148
gem5::FileFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:52
gem5::DeviceFDEntry::getDriver
EmulatedDriver * getDriver() const
Definition: fd_entry.hh:232
gem5::DeviceFDEntry::_fileName
std::string _fileName
Definition: fd_entry.hh:240
gem5::FileFDEntry::getFileName
std::string const & getFileName() const
Definition: fd_entry.hh:147
gem5::HBFDEntry::_flags
int _flags
Definition: fd_entry.hh:115
gem5::FileFDEntry::getFileMode
mode_t getFileMode() const
Definition: fd_entry.hh:149
gem5::PipeFDEntry::PipeFDEntry
PipeFDEntry(PipeFDEntry const &pipe, bool close_on_exec=false)
Definition: fd_entry.hh:183
gem5::FileFDEntry::setFileOffset
void setFileOffset(uint64_t f_off)
Definition: fd_entry.hh:152
gem5::FDEntry::_class
FDClass _class
Definition: fd_entry.hh:83
gem5::PipeFDEntry::_pipeReadSource
int _pipeReadSource
Definition: fd_entry.hh:205
gem5::HBFDEntry::HBFDEntry
HBFDEntry(int flags, int sim_fd, bool close_on_exec=false)
Definition: fd_entry.hh:94
gem5::HBFDEntry
Extends the base class to include a host-backed file descriptor field that records the integer used t...
Definition: fd_entry.hh:91
gem5::FDEntry::clone
virtual std::shared_ptr< FDEntry > clone() const =0
gem5::PipeFDEntry::PipeFDEntry
PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type, bool close_on_exec=false)
Definition: fd_entry.hh:177
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::FDEntry::getClass
FDClass getClass() const
Definition: fd_entry.hh:74
gem5::DeviceFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:227
gem5::HBFDEntry::setSimFD
void setSimFD(int sim_fd)
Definition: fd_entry.hh:112
gem5::SocketFDEntry::_protocol
int _protocol
Definition: fd_entry.hh:265
gem5::HBFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:103
gem5::DeviceFDEntry::DeviceFDEntry
DeviceFDEntry(DeviceFDEntry const &dev, bool close_on_exec=false)
Definition: fd_entry.hh:221
gem5::PipeFDEntry::_pipeEndType
EndType _pipeEndType
Definition: fd_entry.hh:206
gem5::SocketFDEntry::_domain
int _domain
Definition: fd_entry.hh:263
gem5::FDEntry::fd_null
@ fd_null
Definition: fd_entry.hh:63
gem5::DeviceFDEntry::getFileName
std::string const & getFileName() const
Definition: fd_entry.hh:233
gem5::DeviceFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:96
gem5::FileFDEntry::FileFDEntry
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
gem5::FileFDEntry::_mode
mode_t _mode
Definition: fd_entry.hh:161
gem5::X86ISA::type
type
Definition: misc.hh:727
gem5::FileFDEntry::FileFDEntry
FileFDEntry(FileFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:136
gem5::FDEntry
Holds a single file descriptor mapping and that mapping's data for processes running in syscall emula...
Definition: fd_entry.hh:51
gem5::FDEntry::fd_base
@ fd_base
Definition: fd_entry.hh:57
gem5::PipeFDEntry::setPipeReadSource
void setPipeReadSource(int tgt_fd)
Definition: fd_entry.hh:198
gem5::PipeFDEntry::write
@ write
Definition: fd_entry.hh:174
flags
uint8_t flags
Definition: helpers.cc:66
gem5::FileFDEntry::_fileName
std::string _fileName
Definition: fd_entry.hh:159
gem5::FileFDEntry::_fileOffset
uint64_t _fileOffset
Definition: fd_entry.hh:160
gem5::HBFDEntry::setFlags
void setFlags(int flags)
Definition: fd_entry.hh:111
gem5::FDEntry::getCOE
bool getCOE() const
Definition: fd_entry.hh:72
gem5::DeviceFDEntry
Holds file descriptors needed to simulate devices opened with pseudo files (commonly with calls to io...
Definition: fd_entry.hh:213
gem5::DeviceFDEntry::_driver
EmulatedDriver * _driver
Definition: fd_entry.hh:239
gem5::FDEntry::FDClass
FDClass
Definition: fd_entry.hh:55
gem5::HBFDEntry::getFlags
int getFlags() const
Definition: fd_entry.hh:108
gem5::PipeFDEntry::getEndType
EndType getEndType() const
Definition: fd_entry.hh:195
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
gem5::FDEntry::FDEntry
FDEntry(bool close_on_exec=false)
Definition: fd_entry.hh:66
gem5::EmulatedDriver
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:55
gem5::FileFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:142
gem5::HBFDEntry::getSimFD
int getSimFD() const
Definition: fd_entry.hh:109
gem5::FDEntry::_closeOnExec
bool _closeOnExec
Definition: fd_entry.hh:82
gem5::FDEntry::fd_hb
@ fd_hb
Definition: fd_entry.hh:58
gem5::HBFDEntry::_simFD
int _simFD
Definition: fd_entry.hh:116
gem5::FileFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:62
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::PipeFDEntry::setEndType
void setEndType(EndType type)
Definition: fd_entry.hh:199
gem5::DeviceFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:88
gem5::FDEntry::fd_pipe
@ fd_pipe
Definition: fd_entry.hh:60
gem5::PipeFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:190
gem5::FDEntry::fd_file
@ fd_file
Definition: fd_entry.hh:59
gem5::DeviceFDEntry::DeviceFDEntry
DeviceFDEntry(EmulatedDriver *driver, std::string const &file_name, bool close_on_exec=false)
Definition: fd_entry.hh:216
gem5::FileFDEntry::setFileMode
void setFileMode(mode_t mode)
Definition: fd_entry.hh:153
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::FileFDEntry
Holds file descriptors for host-backed files; host-backed files are files which were opened on the ph...
Definition: fd_entry.hh:127
gem5::SocketFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:258
gem5::SocketFDEntry::SocketFDEntry
SocketFDEntry(int sim_fd, int domain, int type, int protocol, bool close_on_exec=false)
Definition: fd_entry.hh:246
gem5::PipeFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:80
gem5::PipeFDEntry
Holds the metadata needed to maintain the mappings for file descriptors allocated with the pipe() sys...
Definition: fd_entry.hh:168
gem5::SocketFDEntry::SocketFDEntry
SocketFDEntry(SocketFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:252
gem5::ArmISA::mode
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74

Generated on Thu Jul 28 2022 13:32:36 for gem5 by doxygen 1.8.17