gem5  v21.1.0.2
fd_array.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_ARRAY_HH__
35 #define __FD_ARRAY_HH__
36 
37 #include <array>
38 #include <map>
39 #include <memory>
40 #include <string>
41 
42 #include "sim/fd_entry.hh"
43 #include "sim/serialize.hh"
44 
45 namespace gem5
46 {
47 
48 class FDArray : public Serializable
49 {
50  public:
59  FDArray(std::string const& input, std::string const& output,
60  std::string const& errout);
61 
66  void updateFileOffsets();
67 
72  void restoreFileOffsets();
73 
80  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
81 
87  std::shared_ptr<FDEntry>
88  operator[](int tgt_fd)
89  {
90  return getFDEntry(tgt_fd);
91  }
92 
96  int getSize() const { return _fdArray.size(); }
97 
108  int allocFD(std::shared_ptr<FDEntry> fdp);
109 
116  int closeFDEntry(int tgt_fd);
117 
118  /*
119  * Serialization methods for file descriptors
120  */
121  void serialize(CheckpointOut &cp) const override;
122  void unserialize(CheckpointIn &cp) override;
123 
124  private:
130  int openFile(std::string const& file_name, int flags, mode_t mode) const;
131  int openInputFile(std::string const& file_name) const;
132  int openOutputFile(std::string const& file_name) const;
133 
140  std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
141 
146  static constexpr size_t _numFDs {1024};
147  std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
148 
154  std::string _input;
155  std::string _output;
156  std::string _errout;
157 
164  std::map<std::string, int> _imap;
165  std::map<std::string, int> _oemap;
166 };
167 
168 } // namespace gem5
169 
170 #endif // __FD_ARRAY_HH__
gem5::FDArray::restoreFileOffsets
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition: fd_array.cc:127
gem5::FDArray::allocFD
int allocFD(std::shared_ptr< FDEntry > fdp)
Step through the file descriptor array and find the first available entry which is denoted as being f...
Definition: fd_array.cc:286
gem5::FDArray::FDArray
FDArray(std::string const &input, std::string const &output, std::string const &errout)
Initialize the file descriptor array and set the standard file descriptors to defaults or values pass...
Definition: fd_array.cc:51
fd_entry.hh
serialize.hh
gem5::output
static void output(const char *filename)
Definition: debug.cc:66
gem5::FDArray::_imap
std::map< std::string, int > _imap
Hold strings which represent the default values which are checked against to initialize the standard ...
Definition: fd_array.hh:164
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::FDArray::setFDEntry
void setFDEntry(int tgt_fd, std::shared_ptr< FDEntry > fdep)
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.
Definition: fd_array.cc:328
gem5::FDArray::_output
std::string _output
Definition: fd_array.hh:155
gem5::FDArray::openOutputFile
int openOutputFile(std::string const &file_name) const
Definition: fd_array.cc:314
gem5::FDArray::openFile
int openFile(std::string const &file_name, int flags, mode_t mode) const
Help clarify our intention when opening files in the init and restoration code.
Definition: fd_array.cc:299
gem5::FDArray::getSize
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:96
gem5::FDArray::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_array.cc:372
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::FDArray::_fdArray
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition: fd_array.hh:147
gem5::FDArray::_input
std::string _input
Hold param strings passed from the Process class which indicate the filename for each of the correspo...
Definition: fd_array.hh:154
gem5::FDArray::closeFDEntry
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition: fd_array.cc:335
gem5::FDArray::_oemap
std::map< std::string, int > _oemap
Definition: fd_array.hh:165
gem5::FDArray::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_array.cc:356
gem5::FDArray::updateFileOffsets
void updateFileOffsets()
Figure out the file offsets for all currently open files and save them the offsets during the calls t...
Definition: fd_array.cc:104
gem5::FDArray::_numFDs
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:146
gem5::FDArray
Definition: fd_array.hh:48
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::FDArray::getFDEntry
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
Definition: fd_array.cc:321
gem5::FDArray::openInputFile
int openInputFile(std::string const &file_name) const
Definition: fd_array.cc:308
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::FDArray::_errout
std::string _errout
Definition: fd_array.hh:156
gem5::FDArray::operator[]
std::shared_ptr< FDEntry > operator[](int tgt_fd)
Treat this object like a normal array in using the subscript operator to pull entries out of it.
Definition: fd_array.hh:88
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