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

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13