gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
43namespace gem5
44{
45
46class Process;
47
48class FDArray : public Serializable
49{
50 public:
59 FDArray(std::string const& input, std::string const& output,
60 std::string const& errout);
61
66 void updateFileOffsets();
67
72 void restoreFileOffsets();
73
80 void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
81
87 std::shared_ptr<FDEntry>
88 operator[](int tgt_fd)
89 {
90 return getFDEntry(tgt_fd);
91 }
92
96 int getSize() const { return _fdArray.size(); }
97
108 int allocFD(std::shared_ptr<FDEntry> fdp);
109
116 int closeFDEntry(int tgt_fd);
117
118 /*
119 * Serialization methods for file descriptors
120 */
121 void serialize(CheckpointOut &cp) const override;
122 void unserialize(CheckpointIn &cp, Process* process_ptr );
123 void unserialize(CheckpointIn &cp) override {
124 unserialize(cp, nullptr);
125 };
126
127
128 private:
134 int openFile(std::string const& file_name, int flags, mode_t mode) const;
135 int openInputFile(std::string const& file_name) const;
136 int openOutputFile(std::string const& file_name) const;
137
144 std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
145
150 static constexpr size_t _numFDs {1024};
151 std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
152
158 std::string _input;
159 std::string _output;
160 std::string _errout;
161
168 std::map<std::string, int> _imap;
169 std::map<std::string, int> _oemap;
170};
171
172} // namespace gem5
173
174#endif // __FD_ARRAY_HH__
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition fd_array.cc:334
std::string _errout
Definition fd_array.hh:160
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::string _input
Hold param strings passed from the Process class which indicate the filename for each of the correspo...
Definition fd_array.hh:158
std::map< std::string, int > _oemap
Definition fd_array.hh:169
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:168
std::string _output
Definition fd_array.hh:159
int openInputFile(std::string const &file_name) const
Definition fd_array.cc:307
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition fd_array.hh:123
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:88
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
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
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition fd_array.cc:355
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition fd_array.hh:151
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
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 openOutputFile(std::string const &file_name) const
Definition fd_array.cc:313
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
Definition fd_array.cc:320
void unserialize(CheckpointIn &cp, Process *process_ptr)
Definition fd_array.cc:371
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition fd_array.hh:150
int getSize() const
Return the size of the _fdArray field.
Definition fd_array.hh:96
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition fd_array.cc:126
Basic support for object serialization.
Definition serialize.hh:170
uint8_t flags
Definition helpers.cc:87
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
static void output(const char *filename)
Definition debug.cc:60

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0