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

Generated on Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17