gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Brandon Potter
34  */
35 
36 #ifndef __FD_ARRAY_HH__
37 #define __FD_ARRAY_HH__
38 
39 #include <array>
40 #include <memory>
41 #include <string>
42 
43 #include "sim/fd_entry.hh"
44 
45 class FDArray
46 {
47  public:
56  FDArray(std::string const& input, std::string const& output,
57  std::string const& errout);
58 
63  void updateFileOffsets();
64 
69  void restoreFileOffsets();
70 
77  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
78 
84  std::shared_ptr<FDEntry>
85  operator[](int tgt_fd)
86  {
87  return getFDEntry(tgt_fd);
88  }
89 
93  int getSize() const { return _fdArray.size(); }
94 
105  int allocFD(std::shared_ptr<FDEntry> fdp);
106 
113  int closeFDEntry(int tgt_fd);
114 
115  private:
121  int openFile(std::string const& file_name, int flags, mode_t mode) const;
122  int openInputFile(std::string const& file_name) const;
123  int openOutputFile(std::string const& file_name) const;
124 
131  std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
132 
137  static constexpr size_t _numFDs {1024};
138  std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
139 
145  std::string _input;
146  std::string _output;
147  std::string _errout;
148 
155  std::map<std::string, int> _imap;
156  std::map<std::string, int> _oemap;
157 };
158 
159 #endif // __FD_ARRAY_HH__
std::string _output
Definition: fd_array.hh:146
int openInputFile(std::string const &file_name) const
Definition: fd_array.cc:307
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
Definition: fd_array.cc:320
static void output(const char *filename)
Definition: debug.cc:63
int openOutputFile(std::string const &file_name) const
Definition: fd_array.cc:313
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:327
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:298
Bitfield< 4, 0 > mode
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition: fd_array.cc:334
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition: fd_array.cc:126
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:85
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:285
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:50
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:155
std::string _input
Hold param strings passed from the Process class which indicate the filename for each of the correspo...
Definition: fd_array.hh:145
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:137
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:93
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:103
std::map< std::string, int > _oemap
Definition: fd_array.hh:156
std::string _errout
Definition: fd_array.hh:147
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition: fd_array.hh:138

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