Apply the gem5 namespace to the codebase. Some anonymous namespaces could theoretically be removed, but since this change's main goal was to keep conflicts at a minimum, it was decided not to modify much the general shape of the files. A few missing comments of the form "// namespace X" that occurred before the newly added "} // namespace gem5" have been added for consistency. std out should not be included in the gem5 namespace, so they weren't. ProtoMessage has not been included in the gem5 namespace, since I'm not familiar with how proto works. Regarding the SystemC files, although they belong to gem5, they actually perform integration between gem5 and SystemC; therefore, it deserved its own separate namespace. Files that are automatically generated have been included in the gem5 namespace. The .isa files currently are limited to a single namespace. This limitation should be later removed to make it easier to accomodate a better API. Regarding the files in util, gem5:: was prepended where suitable. Notice that this patch was tested as much as possible given that most of these were already not previously compiling. Change-Id: Ia53d404ec79c46edaa98f654e23bc3b0e179fe2d Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46323 Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Matthew Poremba <matthew.poremba@amd.com> Tested-by: kokoro <noreply+kokoro@google.com>
273 lines
8.1 KiB
C++
273 lines
8.1 KiB
C++
/*
|
|
* Copyright (c) 2016 Advanced Micro Devices, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* For use for simulation and test purposes only
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
* contributors may be used to endorse or promote products derived from this
|
|
* software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef __FD_ENTRY_HH__
|
|
#define __FD_ENTRY_HH__
|
|
|
|
#include <memory>
|
|
#include <ostream>
|
|
#include <string>
|
|
|
|
#include "sim/serialize.hh"
|
|
|
|
namespace gem5
|
|
{
|
|
|
|
class EmulatedDriver;
|
|
|
|
|
|
/**
|
|
* Holds a single file descriptor mapping and that mapping's data for
|
|
* processes running in syscall emulation mode.
|
|
*/
|
|
class FDEntry : public Serializable
|
|
{
|
|
public:
|
|
|
|
enum FDClass
|
|
{
|
|
fd_base,
|
|
fd_hb,
|
|
fd_file,
|
|
fd_pipe,
|
|
fd_device,
|
|
fd_socket,
|
|
fd_null
|
|
};
|
|
|
|
FDEntry(bool close_on_exec = false)
|
|
: _closeOnExec(close_on_exec)
|
|
{ _class = FDClass::fd_base; }
|
|
|
|
virtual std::shared_ptr<FDEntry> clone() const = 0;
|
|
|
|
bool getCOE() const { return _closeOnExec; }
|
|
|
|
FDClass getClass() const { return _class; }
|
|
|
|
void setCOE(bool close_on_exec) { _closeOnExec = close_on_exec; }
|
|
|
|
virtual void serialize(CheckpointOut &cp) const;
|
|
virtual void unserialize(CheckpointIn &cp);
|
|
|
|
protected:
|
|
bool _closeOnExec;
|
|
FDClass _class;
|
|
};
|
|
|
|
/**
|
|
* Extends the base class to include a host-backed file descriptor field
|
|
* that records the integer used to represent the file descriptor on the host
|
|
* and the file's flags.
|
|
*/
|
|
class HBFDEntry: public FDEntry
|
|
{
|
|
public:
|
|
HBFDEntry(int flags, int sim_fd, bool close_on_exec = false)
|
|
: FDEntry(close_on_exec), _flags(flags), _simFD(sim_fd)
|
|
{ _class = FDClass::fd_hb; }
|
|
|
|
HBFDEntry(HBFDEntry const& reg, bool close_on_exec = false)
|
|
: FDEntry(close_on_exec), _flags(reg._flags), _simFD(reg._simFD)
|
|
{ _class = FDClass::fd_hb; }
|
|
|
|
std::shared_ptr<FDEntry>
|
|
clone() const override
|
|
{
|
|
return std::make_shared<HBFDEntry>(*this);
|
|
}
|
|
|
|
int getFlags() const { return _flags; }
|
|
int getSimFD() const { return _simFD; }
|
|
|
|
void setFlags(int flags) { _flags = flags; }
|
|
void setSimFD(int sim_fd) { _simFD = sim_fd; }
|
|
|
|
protected:
|
|
int _flags;
|
|
int _simFD;
|
|
};
|
|
|
|
/**
|
|
* Holds file descriptors for host-backed files; host-backed files are
|
|
* files which were opened on the physical machine where the simulation
|
|
* is running (probably the thing on/under your desk). All regular files
|
|
* are redirected to make it appear that the file descriptor assignment
|
|
* starts at file descriptor '3' (not including stdin, stdout, stderr) and
|
|
* then grows upward.
|
|
*/
|
|
class FileFDEntry: public HBFDEntry
|
|
{
|
|
public:
|
|
FileFDEntry(int sim_fd, int flags, std::string const& file_name,
|
|
uint64_t file_offset, bool close_on_exec = false)
|
|
: HBFDEntry(flags, sim_fd, close_on_exec),
|
|
_fileName(file_name), _fileOffset(file_offset)
|
|
{ _class = FDClass::fd_file; }
|
|
|
|
FileFDEntry(FileFDEntry const& reg, bool close_on_exec = false)
|
|
: HBFDEntry(reg._flags, reg._simFD, close_on_exec),
|
|
_fileName(reg._fileName), _fileOffset(reg._fileOffset)
|
|
{ _class = FDClass::fd_file; }
|
|
|
|
std::shared_ptr<FDEntry>
|
|
clone() const override
|
|
{
|
|
return std::make_shared<FileFDEntry>(*this);
|
|
}
|
|
|
|
std::string const& getFileName() const { return _fileName; }
|
|
uint64_t getFileOffset() const { return _fileOffset; }
|
|
mode_t getFileMode() const { return _mode; }
|
|
|
|
void setFileName(std::string const& file_name) { _fileName = file_name; }
|
|
void setFileOffset(uint64_t f_off) { _fileOffset = f_off; }
|
|
void setFileMode(mode_t mode) { _mode = mode; }
|
|
|
|
void serialize(CheckpointOut &cp) const override;
|
|
void unserialize(CheckpointIn &cp) override;
|
|
|
|
private:
|
|
std::string _fileName;
|
|
uint64_t _fileOffset;
|
|
mode_t _mode;
|
|
};
|
|
|
|
/**
|
|
* Holds the metadata needed to maintain the mappings for file descriptors
|
|
* allocated with the pipe() system calls and its variants.
|
|
*/
|
|
class PipeFDEntry: public HBFDEntry
|
|
{
|
|
public:
|
|
enum EndType
|
|
{
|
|
read = 0,
|
|
write = 1
|
|
};
|
|
|
|
PipeFDEntry(int sim_fd, int flags, EndType pipe_end_type,
|
|
bool close_on_exec = false)
|
|
: HBFDEntry(flags, sim_fd, close_on_exec), _pipeReadSource(-1),
|
|
_pipeEndType(pipe_end_type)
|
|
{ _class = FDClass::fd_pipe; }
|
|
|
|
PipeFDEntry(PipeFDEntry const& pipe, bool close_on_exec = false)
|
|
: HBFDEntry(pipe._flags, pipe._simFD, close_on_exec),
|
|
_pipeReadSource(pipe._pipeReadSource),
|
|
_pipeEndType(pipe._pipeEndType)
|
|
{ _class = FDClass::fd_pipe; }
|
|
|
|
std::shared_ptr<FDEntry>
|
|
clone() const override
|
|
{
|
|
return std::make_shared<PipeFDEntry>(*this);
|
|
}
|
|
|
|
EndType getEndType() const { return _pipeEndType; }
|
|
int getPipeReadSource() const { return _pipeReadSource; }
|
|
|
|
void setPipeReadSource(int tgt_fd) { _pipeReadSource = tgt_fd; }
|
|
void setEndType(EndType type) { _pipeEndType = type; }
|
|
|
|
void serialize(CheckpointOut &cp) const override;
|
|
void unserialize(CheckpointIn &cp) override;
|
|
|
|
private:
|
|
int _pipeReadSource;
|
|
EndType _pipeEndType;
|
|
};
|
|
|
|
/**
|
|
* Holds file descriptors needed to simulate devices opened with pseudo
|
|
* files (commonly with calls to ioctls).
|
|
*/
|
|
class DeviceFDEntry : public FDEntry
|
|
{
|
|
public:
|
|
DeviceFDEntry(EmulatedDriver *driver, std::string const& file_name,
|
|
bool close_on_exec = false)
|
|
: FDEntry(close_on_exec), _driver(driver), _fileName(file_name)
|
|
{ _class = FDClass::fd_device; }
|
|
|
|
DeviceFDEntry(DeviceFDEntry const& dev, bool close_on_exec = false)
|
|
: FDEntry(close_on_exec), _driver(dev._driver),
|
|
_fileName(dev._fileName)
|
|
{ _class = FDClass::fd_device; }
|
|
|
|
std::shared_ptr<FDEntry>
|
|
clone() const override
|
|
{
|
|
return std::make_shared<DeviceFDEntry>(*this);
|
|
}
|
|
|
|
EmulatedDriver *getDriver() const { return _driver; }
|
|
std::string const& getFileName() const { return _fileName; }
|
|
|
|
void serialize(CheckpointOut &cp) const override;
|
|
void unserialize(CheckpointIn &cp) override;
|
|
|
|
private:
|
|
EmulatedDriver *_driver;
|
|
std::string _fileName;
|
|
};
|
|
|
|
class SocketFDEntry: public HBFDEntry
|
|
{
|
|
public:
|
|
SocketFDEntry(int sim_fd, int domain, int type, int protocol,
|
|
bool close_on_exec = false)
|
|
: HBFDEntry(0, sim_fd, close_on_exec),
|
|
_domain(domain), _type(type), _protocol(protocol)
|
|
{ _class = FDClass::fd_socket; }
|
|
|
|
SocketFDEntry(SocketFDEntry const& reg, bool close_on_exec = false)
|
|
: HBFDEntry(reg._flags, reg._simFD, close_on_exec),
|
|
_domain(reg._domain), _type(reg._type), _protocol(reg._protocol)
|
|
{ _class = FDClass::fd_socket; }
|
|
|
|
std::shared_ptr<FDEntry>
|
|
clone() const override
|
|
{
|
|
return std::make_shared<SocketFDEntry>(*this);
|
|
}
|
|
|
|
int _domain;
|
|
int _type;
|
|
int _protocol;
|
|
};
|
|
|
|
} // namespace gem5
|
|
|
|
#endif // __FD_ENTRY_HH__
|