gem5  v22.1.0.0
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  * 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_ARRAY_HH__
33 #define __FD_ARRAY_HH__
34 
35 #include <array>
36 #include <map>
37 #include <memory>
38 #include <string>
39 
40 #include "sim/fd_entry.hh"
41 #include "sim/serialize.hh"
42 
43 namespace gem5
44 {
45 
46 class FDArray : public Serializable
47 {
48  public:
57  FDArray(std::string const& input, std::string const& output,
58  std::string const& errout);
59 
64  void updateFileOffsets();
65 
70  void restoreFileOffsets();
71 
78  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
79 
85  std::shared_ptr<FDEntry>
86  operator[](int tgt_fd)
87  {
88  return getFDEntry(tgt_fd);
89  }
90 
94  int getSize() const { return _fdArray.size(); }
95 
106  int allocFD(std::shared_ptr<FDEntry> fdp);
107 
114  int closeFDEntry(int tgt_fd);
115 
116  /*
117  * Serialization methods for file descriptors
118  */
119  void serialize(CheckpointOut &cp) const override;
120  void unserialize(CheckpointIn &cp) override;
121 
122  private:
128  int openFile(std::string const& file_name, int flags, mode_t mode) const;
129  int openInputFile(std::string const& file_name) const;
130  int openOutputFile(std::string const& file_name) const;
131 
138  std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
139 
144  static constexpr size_t _numFDs {1024};
145  std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
146 
152  std::string _input;
153  std::string _output;
154  std::string _errout;
155 
162  std::map<std::string, int> _imap;
163  std::map<std::string, int> _oemap;
164 };
165 
166 } // namespace gem5
167 
168 #endif // __FD_ARRAY_HH__
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition: fd_array.cc:333
std::string _errout
Definition: fd_array.hh:154
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:102
std::string _input
Hold param strings passed from the Process class which indicate the filename for each of the correspo...
Definition: fd_array.hh:152
std::map< std::string, int > _oemap
Definition: fd_array.hh:163
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:162
std::string _output
Definition: fd_array.hh:153
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:86
int openInputFile(std::string const &file_name) const
Definition: fd_array.cc:306
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_array.cc:370
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:49
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:297
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_array.cc:354
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition: fd_array.hh:145
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:284
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:326
int openOutputFile(std::string const &file_name) const
Definition: fd_array.cc:312
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
Definition: fd_array.cc:319
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:144
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:94
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition: fd_array.cc:125
Basic support for object serialization.
Definition: serialize.hh:170
uint8_t flags
Definition: helpers.cc:66
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
Definition: serialize.hh:66
static void output(const char *filename)
Definition: debug.cc:60

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1