gem5
v20.1.0.0
|
#include <fd_array.hh>
Public Member Functions | |
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 passed in with the process params. More... | |
void | updateFileOffsets () |
Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process. More... | |
void | restoreFileOffsets () |
Restore all offsets for currently open files during the unserialize phase for the owning process class. More... | |
void | setFDEntry (int tgt_fd, std::shared_ptr< FDEntry > fdep) |
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd. More... | |
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. More... | |
int | getSize () const |
Return the size of the _fdArray field. More... | |
int | allocFD (std::shared_ptr< FDEntry > fdp) |
Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'. More... | |
int | closeFDEntry (int tgt_fd) |
Try to close the host file descriptor. More... | |
Private Member Functions | |
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. More... | |
int | openInputFile (std::string const &file_name) const |
int | openOutputFile (std::string const &file_name) const |
std::shared_ptr< FDEntry > | getFDEntry (int tgt_fd) |
Return the file descriptor entry object associated with the index provided. More... | |
Private Attributes | |
std::array< std::shared_ptr< FDEntry >, _numFDs > | _fdArray |
std::string | _input |
Hold param strings passed from the Process class which indicate the filename for each of the corresponding files or some keyword indicating the use of standard file descriptors. More... | |
std::string | _output |
std::string | _errout |
std::map< std::string, int > | _imap |
Hold strings which represent the default values which are checked against to initialize the standard file descriptors. More... | |
std::map< std::string, int > | _oemap |
Static Private Attributes | |
static constexpr size_t | _numFDs {1024} |
Hold pointers to the file descriptor entries. More... | |
Definition at line 43 of file fd_array.hh.
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 passed in with the process params.
input | Used to initialize the stdin file descriptor |
output | Used to initialize the stdout file descriptor |
errout | Used to initialize the stderr file descriptor |
Search through the input options and setup the default fd if match is found; otherwise, open an input file and seek to location.
Search through the output/error options and setup the default fd if match is found; otherwise, open an output file and seek to location.
Definition at line 48 of file fd_array.cc.
int FDArray::allocFD | ( | std::shared_ptr< FDEntry > | fdp | ) |
Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'.
That file descriptor entry is the new target file descriptor entry that we return as the return parameter.
fdp | Allocated beforehand and passed into this method; the fdp is meant to be a generic pointer capable of pointing to different types of file descriptors. Must cast the pointer to the correct type before dereferencing to access the needed fields. |
Definition at line 283 of file fd_array.cc.
int FDArray::closeFDEntry | ( | int | tgt_fd | ) |
Try to close the host file descriptor.
If successful, set the specified file descriptor entry object pointer to nullptr. Used to "close" the target file descriptor.
tgt_fd | Use target file descriptors to index the array. |
Definition at line 332 of file fd_array.cc.
References _fdArray, and ArmISA::status.
|
private |
Return the file descriptor entry object associated with the index provided.
(The index is protected with bounds checking on the array size without the use of the array's at operator.)
tgt_fd | Use target file descriptors to index the array. |
Definition at line 318 of file fd_array.cc.
References _fdArray.
Referenced by operator[]().
|
inline |
Return the size of the _fdArray field.
Definition at line 91 of file fd_array.hh.
References _fdArray.
|
private |
Help clarify our intention when opening files in the init and restoration code.
These are helper functions which are not meant to be exposed to other objects or files.
Definition at line 296 of file fd_array.cc.
References fatal, and ArmISA::mode.
Referenced by openInputFile(), openOutputFile(), and restoreFileOffsets().
|
private |
Definition at line 305 of file fd_array.cc.
References openFile().
Referenced by restoreFileOffsets().
|
private |
Definition at line 311 of file fd_array.cc.
References openFile(), OutputDirectory::resolve(), and simout.
Referenced by restoreFileOffsets().
|
inline |
Treat this object like a normal array in using the subscript operator to pull entries out of it.
tgt_fd | Use target file descriptors to index the array. |
Definition at line 83 of file fd_array.hh.
References getFDEntry().
void FDArray::restoreFileOffsets | ( | ) |
Restore all offsets for currently open files during the unserialize phase for the owning process class.
Use this lambda to highlight what we mean to do with the seek. Notice that this either seeks correctly (sets the file location on the host) or it fails with a fatal. The error is fatal because it's not possible to guarantee that the simulation will proceed as it should have in the same way that it would have proceeded sans checkpoints.
Search through the input options and set fd if match is found; otherwise, open an input file and seek to location. Check if user has specified a different input file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Search through the output options and set fd if match is found; otherwise, open an output file and seek to location. Check if user has specified a different output file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Search through the error options and set fd if match is found; otherwise, open an error file and seek to location. Check if user has specified a different error file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Check which end of the pipe we are looking at; we only want to setup the pipe once so we arbitrarily choose the read end to be the end that sets up the pipe.
Reconstruct the ends of the pipe by reassigning the pipe that we created on the host. This one is the read end.
Grab the write end by referencing the read ends source and using that tgt_fd to index the array.
Yeah, how does one retain the entire driver state from this particular set of code? If you figure it out, add some code here to rectify the issue.
Assume that this has the mode of an output file so there's no need to worry about properly recording the mode. If you're reading this and this happens to be your issue, at least be happy that you've discovered the issue (and not mad at me). Onward ho!
Definition at line 124 of file fd_array.cc.
References _errout, _fdArray, _imap, _input, _oemap, _output, fatal, openFile(), openInputFile(), openOutputFile(), and warn.
void FDArray::setFDEntry | ( | int | tgt_fd, |
std::shared_ptr< FDEntry > | fdep | ||
) |
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.
tgt_fd | Use target file descriptors to index the array. |
fdep | Incoming pointer used to set the entry pointed to by tgt_fd. |
Definition at line 325 of file fd_array.cc.
References _fdArray.
void FDArray::updateFileOffsets | ( | ) |
Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process.
It only makes sense to check the offsets if the file descriptor type is 'File' (which indicates that this file is backed by a file on the host). If the type is File, then record the offset.
Use lseek with SEEK_CUR with offset 0 to figure out where the offset currently resides and pass that back to our setter.
Definition at line 101 of file fd_array.cc.
References _fdArray.
|
private |
Definition at line 145 of file fd_array.hh.
Referenced by restoreFileOffsets().
Definition at line 136 of file fd_array.hh.
Referenced by allocFD(), closeFDEntry(), getFDEntry(), getSize(), restoreFileOffsets(), setFDEntry(), and updateFileOffsets().
|
private |
Hold strings which represent the default values which are checked against to initialize the standard file descriptors.
If the string provided doesn't hit against these maps, then a file is opened on the host instead of using the host's standard file descriptors.
Definition at line 153 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
private |
Hold param strings passed from the Process class which indicate the filename for each of the corresponding files or some keyword indicating the use of standard file descriptors.
Definition at line 143 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
staticconstexprprivate |
Hold pointers to the file descriptor entries.
The array size is statically defined by the operating system.
Definition at line 135 of file fd_array.hh.
|
private |
Definition at line 154 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
private |
Definition at line 144 of file fd_array.hh.
Referenced by restoreFileOffsets().