gem5  v20.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  * 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 <memory>
39 #include <string>
40 
41 #include "sim/fd_entry.hh"
42 
43 class FDArray
44 {
45  public:
54  FDArray(std::string const& input, std::string const& output,
55  std::string const& errout);
56 
61  void updateFileOffsets();
62 
67  void restoreFileOffsets();
68 
75  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
76 
82  std::shared_ptr<FDEntry>
83  operator[](int tgt_fd)
84  {
85  return getFDEntry(tgt_fd);
86  }
87 
91  int getSize() const { return _fdArray.size(); }
92 
103  int allocFD(std::shared_ptr<FDEntry> fdp);
104 
111  int closeFDEntry(int tgt_fd);
112 
113  private:
119  int openFile(std::string const& file_name, int flags, mode_t mode) const;
120  int openInputFile(std::string const& file_name) const;
121  int openOutputFile(std::string const& file_name) const;
122 
129  std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
130 
135  static constexpr size_t _numFDs {1024};
136  std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
137 
143  std::string _input;
144  std::string _output;
145  std::string _errout;
146 
153  std::map<std::string, int> _imap;
154  std::map<std::string, int> _oemap;
155 };
156 
157 #endif // __FD_ARRAY_HH__
output
static void output(const char *filename)
Definition: debug.cc:60
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:296
FDArray::_output
std::string _output
Definition: fd_array.hh:144
fd_entry.hh
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:83
FDArray
Definition: fd_array.hh:43
FDArray::_numFDs
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:135
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:48
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:143
FDArray::_fdArray
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition: fd_array.hh:136
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
FDArray::_errout
std::string _errout
Definition: fd_array.hh:145
FDArray::openInputFile
int openInputFile(std::string const &file_name) const
Definition: fd_array.cc:305
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:101
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:283
FDArray::_oemap
std::map< std::string, int > _oemap
Definition: fd_array.hh:154
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:325
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:153
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:318
FDArray::getSize
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:91
FDArray::restoreFileOffsets
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition: fd_array.cc:124
FDArray::closeFDEntry
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition: fd_array.cc:332
FDArray::openOutputFile
int openOutputFile(std::string const &file_name) const
Definition: fd_array.cc:311

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