gem5  v20.1.0.0
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 class EmulatedDriver;
44 
49 class FDEntry : public Serializable
50 {
51  public:
52  FDEntry(bool close_on_exec = false)
53  : _closeOnExec(close_on_exec)
54  { }
55 
56  virtual std::shared_ptr<FDEntry> clone() const = 0;
57 
58  bool getCOE() const { return _closeOnExec; }
59 
60  void setCOE(bool close_on_exec) { _closeOnExec = close_on_exec; }
61 
62  virtual void serialize(CheckpointOut &cp) const;
63  virtual void unserialize(CheckpointIn &cp);
64 
65  protected:
67 };
68 
74 class HBFDEntry: public FDEntry
75 {
76  public:
77  HBFDEntry(int flags, int sim_fd, bool close_on_exec = false)
78  : FDEntry(close_on_exec), _flags(flags), _simFD(sim_fd)
79  { }
80 
81  HBFDEntry(HBFDEntry const& reg, bool close_on_exec = false)
82  : FDEntry(close_on_exec), _flags(reg._flags), _simFD(reg._simFD)
83  { }
84 
85  std::shared_ptr<FDEntry>
86  clone() const override
87  {
88  return std::make_shared<HBFDEntry>(*this);
89  }
90 
91  int getFlags() const { return _flags; }
92  int getSimFD() const { return _simFD; }
93 
94  void setFlags(int flags) { _flags = flags; }
95  void setSimFD(int sim_fd) { _simFD = sim_fd; }
96 
97  protected:
98  int _flags;
99  int _simFD;
100 };
101 
110 class FileFDEntry: public HBFDEntry
111 {
112  public:
113  FileFDEntry(int sim_fd, int flags, std::string const& file_name,
114  uint64_t file_offset, bool close_on_exec = false)
115  : HBFDEntry(flags, sim_fd, close_on_exec),
116  _fileName(file_name), _fileOffset(file_offset)
117  { }
118 
119  FileFDEntry(FileFDEntry const& reg, bool close_on_exec = false)
120  : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
122  { }
123 
124  std::shared_ptr<FDEntry>
125  clone() const override
126  {
127  return std::make_shared<FileFDEntry>(*this);
128  }
129 
130  std::string const& getFileName() const { return _fileName; }
131  uint64_t getFileOffset() const { return _fileOffset; }
132 
133  void setFileName(std::string const& file_name) { _fileName = file_name; }
134  void setFileOffset(uint64_t f_off) { _fileOffset = f_off; }
135 
136  void serialize(CheckpointOut &cp) const override;
137  void unserialize(CheckpointIn &cp) override;
138 
139  private:
140  std::string _fileName;
141  uint64_t _fileOffset;
142 };
143 
148 class PipeFDEntry: public HBFDEntry
149 {
150  public:
151  enum EndType {
152  read = 0,
153  write = 1
154  };
155 
156  PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type,
157  bool close_on_exec = false)
158  : HBFDEntry(flags, sim_fd, close_on_exec), _pipeReadSource(-1),
159  _pipeEndType(pipe_end_type)
160  { }
161 
162  PipeFDEntry(PipeFDEntry const& pipe, bool close_on_exec = false)
163  : HBFDEntry(pipe._flags, pipe._simFD, close_on_exec),
166  { }
167 
168  std::shared_ptr<FDEntry>
169  clone() const override
170  {
171  return std::make_shared<PipeFDEntry>(*this);
172  }
173 
174  EndType getEndType() const { return _pipeEndType; }
175  int getPipeReadSource() const { return _pipeReadSource; }
176 
177  void setPipeReadSource(int tgt_fd) { _pipeReadSource = tgt_fd; }
179 
180  void serialize(CheckpointOut &cp) const override;
181  void unserialize(CheckpointIn &cp) override;
182 
183  private:
186 };
187 
192 class DeviceFDEntry : public FDEntry
193 {
194  public:
195  DeviceFDEntry(EmulatedDriver *driver, std::string const& file_name,
196  bool close_on_exec = false)
197  : FDEntry(close_on_exec), _driver(driver), _fileName(file_name)
198  { }
199 
200  DeviceFDEntry(DeviceFDEntry const& dev, bool close_on_exec = false)
201  : FDEntry(close_on_exec), _driver(dev._driver),
202  _fileName(dev._fileName)
203  { }
204 
205  std::shared_ptr<FDEntry>
206  clone() const override
207  {
208  return std::make_shared<DeviceFDEntry>(*this);
209  }
210 
211  EmulatedDriver *getDriver() const { return _driver; }
212  std::string const& getFileName() const { return _fileName; }
213 
214  void serialize(CheckpointOut &cp) const override;
215  void unserialize(CheckpointIn &cp) override;
216 
217  private:
219  std::string _fileName;
220 };
221 
223 {
224  public:
225  SocketFDEntry(int sim_fd, int domain, int type, int protocol,
226  bool close_on_exec = false)
227  : HBFDEntry(0, sim_fd, close_on_exec),
228  _domain(domain), _type(type), _protocol(protocol)
229  { }
230 
231  SocketFDEntry(SocketFDEntry const& reg, bool close_on_exec = false)
232  : HBFDEntry(reg._flags, reg._simFD, close_on_exec),
234  { }
235 
236  std::shared_ptr<FDEntry>
237  clone() const override
238  {
239  return std::make_shared<SocketFDEntry>(*this);
240  }
241 
242  int _domain;
243  int _type;
245 };
246 
247 #endif // __FD_ENTRY_HH__
SocketFDEntry::_protocol
int _protocol
Definition: fd_entry.hh:244
PipeFDEntry
Holds the metadata needed to maintain the mappings for file descriptors allocated with the pipe() sys...
Definition: fd_entry.hh:148
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:113
FileFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:125
SocketFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:237
FDEntry::serialize
virtual void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: fd_entry.cc:39
PipeFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:77
DeviceFDEntry::DeviceFDEntry
DeviceFDEntry(EmulatedDriver *driver, std::string const &file_name, bool close_on_exec=false)
Definition: fd_entry.hh:195
serialize.hh
PipeFDEntry::setPipeReadSource
void setPipeReadSource(int tgt_fd)
Definition: fd_entry.hh:177
DeviceFDEntry::getDriver
EmulatedDriver * getDriver() const
Definition: fd_entry.hh:211
FileFDEntry::setFileName
void setFileName(std::string const &file_name)
Definition: fd_entry.hh:133
SocketFDEntry::_type
int _type
Definition: fd_entry.hh:243
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
DeviceFDEntry::_fileName
std::string _fileName
Definition: fd_entry.hh:219
SocketFDEntry::_domain
int _domain
Definition: fd_entry.hh:242
type
uint8_t type
Definition: inet.hh:421
HBFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:86
DeviceFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:85
HBFDEntry::getFlags
int getFlags() const
Definition: fd_entry.hh:91
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
SocketFDEntry::SocketFDEntry
SocketFDEntry(int sim_fd, int domain, int type, int protocol, bool close_on_exec=false)
Definition: fd_entry.hh:225
DeviceFDEntry
Holds file descriptors needed to simulate devices opened with pseudo files (commonly with calls to io...
Definition: fd_entry.hh:192
PipeFDEntry::_pipeReadSource
int _pipeReadSource
Definition: fd_entry.hh:184
PipeFDEntry::EndType
EndType
Definition: fd_entry.hh:151
FileFDEntry::_fileOffset
uint64_t _fileOffset
Definition: fd_entry.hh:141
EmulatedDriver
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
FDEntry::setCOE
void setCOE(bool close_on_exec)
Definition: fd_entry.hh:60
cp
Definition: cprintf.cc:40
PipeFDEntry::PipeFDEntry
PipeFDEntry(PipeFDEntry const &pipe, bool close_on_exec=false)
Definition: fd_entry.hh:162
DeviceFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:206
PipeFDEntry::write
@ write
Definition: fd_entry.hh:153
HBFDEntry::setSimFD
void setSimFD(int sim_fd)
Definition: fd_entry.hh:95
PipeFDEntry::setEndType
void setEndType(EndType type)
Definition: fd_entry.hh:178
PipeFDEntry::_pipeEndType
EndType _pipeEndType
Definition: fd_entry.hh:185
FDEntry::FDEntry
FDEntry(bool close_on_exec=false)
Definition: fd_entry.hh:52
PipeFDEntry::read
@ read
Definition: fd_entry.hh:152
HBFDEntry::setFlags
void setFlags(int flags)
Definition: fd_entry.hh:94
FDEntry::unserialize
virtual void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: fd_entry.cc:45
FDEntry::getCOE
bool getCOE() const
Definition: fd_entry.hh:58
FDEntry::clone
virtual std::shared_ptr< FDEntry > clone() const =0
FileFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:60
DeviceFDEntry::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_entry.cc:93
HBFDEntry::_simFD
int _simFD
Definition: fd_entry.hh:99
FDEntry::_closeOnExec
bool _closeOnExec
Definition: fd_entry.hh:66
FileFDEntry::getFileOffset
uint64_t getFileOffset() const
Definition: fd_entry.hh:131
HBFDEntry::_flags
int _flags
Definition: fd_entry.hh:98
FDEntry
Holds a single file descriptor mapping and that mapping's data for processes running in syscall emula...
Definition: fd_entry.hh:49
DeviceFDEntry::DeviceFDEntry
DeviceFDEntry(DeviceFDEntry const &dev, bool close_on_exec=false)
Definition: fd_entry.hh:200
HBFDEntry
Extends the base class to include a host-backed file descriptor field that records the integer used t...
Definition: fd_entry.hh:74
SocketFDEntry::SocketFDEntry
SocketFDEntry(SocketFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:231
FileFDEntry::getFileName
std::string const & getFileName() const
Definition: fd_entry.hh:130
PipeFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:69
FileFDEntry::FileFDEntry
FileFDEntry(FileFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:119
FileFDEntry
Holds file descriptors for host-backed files; host-backed files are files which were opened on the ph...
Definition: fd_entry.hh:110
FileFDEntry::setFileOffset
void setFileOffset(uint64_t f_off)
Definition: fd_entry.hh:134
ArmISA::domain
Bitfield< 7, 4 > domain
Definition: miscregs_types.hh:418
HBFDEntry::getSimFD
int getSimFD() const
Definition: fd_entry.hh:92
FileFDEntry::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_entry.cc:51
SocketFDEntry
Definition: fd_entry.hh:222
PipeFDEntry::getPipeReadSource
int getPipeReadSource() const
Definition: fd_entry.hh:175
HBFDEntry::HBFDEntry
HBFDEntry(HBFDEntry const &reg, bool close_on_exec=false)
Definition: fd_entry.hh:81
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
HBFDEntry::HBFDEntry
HBFDEntry(int flags, int sim_fd, bool close_on_exec=false)
Definition: fd_entry.hh:77
PipeFDEntry::clone
std::shared_ptr< FDEntry > clone() const override
Definition: fd_entry.hh:169
CheckpointIn
Definition: serialize.hh:67
FileFDEntry::_fileName
std::string _fileName
Definition: fd_entry.hh:140
PipeFDEntry::PipeFDEntry
PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type, bool close_on_exec=false)
Definition: fd_entry.hh:156
DeviceFDEntry::getFileName
std::string const & getFileName() const
Definition: fd_entry.hh:212
DeviceFDEntry::_driver
EmulatedDriver * _driver
Definition: fd_entry.hh:218
PipeFDEntry::getEndType
EndType getEndType() const
Definition: fd_entry.hh:174

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17