58 #include "config/the_isa.hh" 62 #include "params/Process.hh" 81 static LoaderList loaders;
89 process_loaders().emplace_back(
this);
95 for (
auto &loader: process_loaders()) {
96 Process *
p = loader->load(params, obj_file);
107 if (directory.back() !=
'/')
115 useArchPT(params->useArchPT),
116 kvmInSE(params->kvmInSE),
120 argv(params->cmd), envp(params->env),
121 executable(params->executable),
123 hostCwd(checkPathRedirect(tgtCwd)),
124 release(params->release),
125 _uid(params->uid), _euid(params->euid),
126 _gid(params->gid), _egid(params->egid),
127 _pid(params->pid), _ppid(params->ppid),
128 _pgid(params->pgid), drivers(params->drivers),
129 fds(make_shared<
FDArray>(params->input, params->
output, params->errout)),
136 if (!ret_pair.second)
175 #define CLONE_FILES 0 178 #define CLONE_THREAD 0 199 for (
auto map : mappings) {
223 std::shared_ptr<FDArray> nfds = np->
fds;
224 for (
int tgt_fd = 0; tgt_fd <
fds->getSize(); tgt_fd++) {
225 std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
227 nfds->setFDEntry(tgt_fd,
nullptr);
230 nfds->setFDEntry(tgt_fd, this_fde->clone());
232 auto this_hbfd = std::dynamic_pointer_cast<
HBFDEntry>(this_fde);
236 int this_sim_fd = this_hbfd->
getSimFD();
237 if (this_sim_fd <= 2)
240 int np_sim_fd = dup(this_sim_fd);
241 assert(np_sim_fd != -1);
243 auto nhbfd = std::dynamic_pointer_cast<
HBFDEntry>((*nfds)[tgt_fd]);
263 using namespace Stats;
267 .
desc(
"Number of system calls")
276 if (*it == context_id) {
281 warn(
"Unable to find thread context to revoke");
298 fatal(
"Process %s is not associated with any HW contexts!\n",
name());
319 fds->updateFileOffsets();
368 warn(
"Checkpoints for file descriptors currently do not work.");
380 warn(
"Checkpoints for file descriptors currently do not work.");
400 if (
d->match(filename))
419 std::string tail = abs_path.substr(
path->appPath().size());
423 for (
auto host_path :
path->hostPaths()) {
424 if (access((host_path + tail).c_str(), R_OK) == 0) {
426 return host_path + tail;
432 return path->hostPaths()[0] + tail;
445 if (!interp || !interp->relocatable())
460 mmap_end =
mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
463 interp->updateBias(ld_bias);
491 if (filename.empty() ||
startswith(filename,
"/"))
497 auto path_base = std::string();
498 if (host_filesystem) {
510 auto absolute_path = path_base + filename;
512 return absolute_path;
516 ProcessParams::create()
528 fatal_if(!process,
"Unknown error creating process object.");
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Process(ProcessParams *params, EmulationPageTable *pTable, ::Loader::ObjectFile *obj_file)
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)
Maps a virtual memory region to a physical memory region.
ObjectFile * createObjectFile(const std::string &fname, bool raw)
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
#define fatal(...)
This implements a cprintf based fatal() function.
static void output(const char *filename)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
std::vector< RedirectPath * > redirectPaths
static std::stack< std::string > path
std::unique_ptr< SETranslatingPortProxy > initVirtMem
std::vector< ContextID > contextIds
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
virtual MemoryImage buildImage() const =0
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void regStats() override
Callback to set stat parameters.
Stats::Scalar numSyscalls
virtual PortProxy & getVirtProxy()=0
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
void setSimFD(int sim_fd)
Overload hash function for BasicBlockRange type.
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
static Process * tryLoaders(ProcessParams *params, ::Loader::ObjectFile *obj_file)
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
DrainState
Object drain/handover states.
ThreadContext * getThreadContext(ContextID tid) const
DrainState drain() override
Notify an object that it needs to drain its state.
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
bool write(const PortProxy &proxy) const
Draining buffers pending serialization/handover.
std::string absolutePath(const std::string &path, bool host_fs)
Return an absolute path given a relative path paired with the current working directory of the proces...
bool translate(Addr vaddr, Addr &paddr)
Translate function.
bool map(Addr vaddr, Addr paddr, int size, bool cacheable=true)
Maps a contiguous range of virtual addresses in this process's address space to a contiguous range of...
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
static std::string normalize(std::string &directory)
Extends the base class to include a host-backed file descriptor field that records the integer used t...
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
std::string tgtCwd
The cwd members are used to track changes to the current working directory for the purpose of executi...
std::vector< std::string > envp
virtual void activate()=0
Set the status to Active.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
virtual const std::string name() const
::Loader::ObjectFile * getInterpreter()
EmulationPageTable * pTable
Declarations of a non-full system Page Table.
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
virtual ObjectFile * getInterpreter() const
::Loader::MemoryImage image
std::ostream CheckpointOut
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
::Loader::MemoryImage interpImage
T divCeil(const T &a, const U &b)
virtual Addr bias() const
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward, but a few (such as Alpha) grow upward instead, so they can override this method to return false.
void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
void serialize(CheckpointOut &cp) const override
Serialize an object.
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::vector< std::string > argv
virtual void regStats()
Callback to set stat parameters.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Abstract superclass for simulation objects.
::Loader::ObjectFile * objFile
std::shared_ptr< FDArray > fds
std::vector< EmulatedDriver * > drivers