63 #include "config/the_isa.hh" 67 #include "params/Process.hh" 86 static LoaderList loaders;
94 process_loaders().emplace_back(
this);
100 for (
auto &loader: process_loaders()) {
101 Process *
p = loader->load(params, obj_file);
112 if (directory.back() !=
'/')
120 useArchPT(params->useArchPT),
121 kvmInSE(params->kvmInSE),
124 initVirtMem(
system->getSystemPort(), this,
127 argv(params->cmd), envp(params->env),
128 executable(params->executable),
130 hostCwd(checkPathRedirect(tgtCwd)),
131 release(params->release),
132 _uid(params->uid), _euid(params->euid),
133 _gid(params->gid), _egid(params->egid),
134 _pid(params->pid), _ppid(params->ppid),
135 _pgid(params->pgid), drivers(params->drivers),
136 fds(make_shared<
FDArray>(params->input, params->
output, params->errout)),
143 if (!ret_pair.second)
184 #define CLONE_FILES 0 187 #define CLONE_THREAD 0 211 for (
auto map : mappings) {
235 std::shared_ptr<FDArray> nfds = np->
fds;
236 for (
int tgt_fd = 0; tgt_fd <
fds->getSize(); tgt_fd++) {
237 std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
239 nfds->setFDEntry(tgt_fd,
nullptr);
242 nfds->setFDEntry(tgt_fd, this_fde->clone());
244 auto this_hbfd = std::dynamic_pointer_cast<
HBFDEntry>(this_fde);
248 int this_sim_fd = this_hbfd->
getSimFD();
249 if (this_sim_fd <= 2)
252 int np_sim_fd = dup(this_sim_fd);
253 assert(np_sim_fd != -1);
255 auto nhbfd = std::dynamic_pointer_cast<
HBFDEntry>((*nfds)[tgt_fd]);
275 using namespace Stats;
279 .
desc(
"Number of system calls")
288 if (*it == context_id) {
293 warn(
"Unable to find thread context to revoke");
310 fatal(
"Process %s is not associated with any HW contexts!\n",
name());
328 fds->updateFileOffsets();
370 if (vaddr >= stack_min && vaddr < stack_base) {
377 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
378 while (vaddr < stack_min) {
380 if (stack_base - stack_min > max_stack_size)
381 fatal(
"Maximum stack size exceeded\n");
383 inform(
"Increasing stack size by one page.");
401 warn(
"Checkpoints for file descriptors currently do not work.");
413 warn(
"Checkpoints for file descriptors currently do not work.");
436 fatal(
"Syscall %d out of range", callnum);
451 if (
d->match(filename))
470 std::string tail = abs_path.substr(
path->appPath().size());
474 for (
auto host_path :
path->hostPaths()) {
475 if (access((host_path + tail).c_str(), R_OK) == 0) {
477 return host_path + tail;
483 return path->hostPaths()[0] + tail;
511 mmap_end =
mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
542 if (filename.empty() ||
startswith(filename,
"/"))
548 auto path_base = std::string();
549 if (host_filesystem) {
561 auto absolute_path = path_base + filename;
563 return absolute_path;
567 ProcessParams::create()
579 fatal_if(!process,
"Unknown error creating process object.");
virtual SyscallDesc * getDesc(int callnum)=0
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)
Maps a virtual memory region to a physical memory region.
virtual bool relocatable() const
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.
DrainState
Object drain/handover states.
std::vector< RedirectPath * > redirectPaths
bool write(const PortProxy &proxy) const
static std::stack< std::string > path
std::vector< ContextID > contextIds
ObjectFile * createObjectFile(const std::string &fname, bool raw)
void doSyscall(int callnum, ThreadContext *tc, Fault *fault)
Interface for invoking the system call funcion pointer.
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
virtual ObjectFile * getInterpreter() const
SETranslatingPortProxy initVirtMem
void regStats() override
Callback to set stat parameters.
Stats::Scalar numSyscalls
virtual PortProxy & getVirtProxy()=0
void setPageTable(EmulationPageTable *p)
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
virtual void regStats()
Callback to set stat parameters.
virtual Addr mapSize() const
void setSimFD(int sim_fd)
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
Overload hash function for BasicBlockRange type.
void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault)
ObjectFile * getInterpreter()
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
static Process * tryLoaders(ProcessParams *params, 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.
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)
virtual void updateBias(Addr bias_addr)
virtual MemoryImage buildImage() const =0
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)
virtual RegVal getSyscallArg(ThreadContext *tc, int &i)=0
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
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...
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
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.
Draining buffers pending serialization/handover.
virtual const std::string name() const
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
virtual Addr bias() const
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.
This class provides the wrapper interface for the system call implementations which are defined in th...
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
bool fixupStackFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
EmulationPageTable * pTable
Declarations of a non-full system Page Table.
std::ostream CheckpointOut
Process(ProcessParams *params, EmulationPageTable *pTable, ObjectFile *obj_file)
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.
T divCeil(const T &a, const U &b)
TranslatingPortProxy Object Declaration for SE.
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
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::shared_ptr< FaultBase > Fault
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=MaxAddr)
Abstract superclass for simulation objects.
std::shared_ptr< FDArray > fds
std::vector< EmulatedDriver * > drivers