gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Author: 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  private:
48  static const int NUM_FDS = 1024;
49 
50  public:
59  FDArray(std::string const& input, std::string const& output,
60  std::string const& errout);
61 
62  std::string _input;
63  std::string _output;
64  std::string _errout;
65 
70  void updateFileOffsets();
71 
76  void restoreFileOffsets();
77 
83  inline std::shared_ptr<FDEntry>
84  operator[](int tgt_fd)
85  {
86  return getFDEntry(tgt_fd);
87  }
88 
99  int allocFD(std::shared_ptr<FDEntry> fdp);
100 
104  int getSize() const { return _fdArray.size(); }
105 
112  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
113 
120  int closeFDEntry(int tgt_fd);
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  std::array<std::shared_ptr<FDEntry>, NUM_FDS> _fdArray;
145 
152  std::map<std::string, int> imap;
153  std::map<std::string, int> oemap;
154 };
155 
156 #endif // __FD_ARRAY_HH__
std::string _output
Definition: fd_array.hh:63
int openOutputFile(std::string const &file_name) const
static void output(const char *filename)
Definition: debug.cc:63
void setFDEntry(int tgt_fd, std::shared_ptr< FDEntry > fdep)
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:104
std::array< std::shared_ptr< FDEntry >, NUM_FDS > _fdArray
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:144
int openInputFile(std::string const &file_name) const
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
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:84
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.
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...
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
std::string _input
Definition: fd_array.hh:62
std::map< std::string, int > oemap
Definition: fd_array.hh:153
void updateFileOffsets()
Figure out the file offsets for all currently open files and save them the offsets during the calls t...
std::string _errout
Definition: fd_array.hh:64
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:152
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
static const int NUM_FDS
Definition: fd_array.hh:48

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6