61#include "params/Process.hh"
81 static LoaderList loaders;
89 process_loaders().emplace_back(
this);
96 for (
auto &loader_it : process_loaders()) {
108 if (directory.back() !=
'/')
109 return directory +
'/';
135 "Number of system calls")
141 fatal_if(!ret_pair.second,
"_pid %d is already used",
_pid);
177#define CLONE_THREAD 0
201 for (
auto map : mappings) {
225 std::shared_ptr<FDArray> nfds = np->
fds;
226 for (
int tgt_fd = 0; tgt_fd <
fds->getSize(); tgt_fd++) {
227 std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
229 nfds->setFDEntry(tgt_fd,
nullptr);
232 nfds->setFDEntry(tgt_fd, this_fde->clone());
234 auto this_hbfd = std::dynamic_pointer_cast<HBFDEntry>(this_fde);
238 int this_sim_fd = this_hbfd->getSimFD();
239 if (this_sim_fd <= 2)
242 int np_sim_fd = dup(this_sim_fd);
243 assert(np_sim_fd != -1);
245 auto nhbfd = std::dynamic_pointer_cast<HBFDEntry>((*nfds)[tgt_fd]);
246 nhbfd->setSimFD(np_sim_fd);
269 if (*it == context_id) {
274 warn(
"Unable to find thread context to revoke");
291 fatal(
"Process %s is not associated with any HW contexts!\n",
name());
312 fds->updateFileOffsets();
333 warn(
"Process::allocateMem: addr %#x already mapped\n",
vaddr);
338 const int npages =
divCeil(size, page_size);
340 const Addr pages_size = npages * page_size;
341 pTable->
map(page_addr, paddr, pages_size,
382 warn(
"Checkpoints for pipes, device drivers and sockets do not work.");
390 fds->unserialize(cp,
this);
396 warn(
"Checkpoints for pipes, device drivers and sockets do not work.");
416 if (
d->match(filename))
435 std::string tail = abs_path.substr(
path->appPath().size());
439 for (
auto host_path :
path->hostPaths()) {
440 if (access((host_path + tail).c_str(), R_OK) == 0) {
442 return host_path + tail;
448 return path->hostPaths()[0] + tail;
461 if (!interp || !interp->relocatable())
476 mmap_end =
mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
479 interp->updateBias(ld_bias);
507 if (filename.empty() ||
startswith(filename,
"/"))
513 auto path_base = std::string();
514 if (host_filesystem) {
526 auto absolute_path = path_base + filename;
528 return absolute_path;
532ProcessParams::create()
const
536 const std::string &exec = (executable ==
"") ? cmd[0] : executable;
539 fatal_if(!obj_file,
"Cannot load object file %s.", exec);
542 fatal_if(!process,
"Unknown error creating process object.");
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)
Maps a virtual memory region to a physical memory region.
const Entry * lookup(Addr vaddr)
Lookup function.
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool translate(Addr vaddr, Addr &paddr)
Translate function.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void getMappings(std::vector< std::pair< Addr, Addr > > *addr_mappings)
virtual std::string name() const
void readBlob(Addr addr, void *p, uint64_t size) const
Higher level interfaces based on the above.
void writeBlob(Addr addr, const void *p, uint64_t size) const
Same as tryWriteBlob, but insists on success.
loader::MemoryImage image
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward,...
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
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...
std::unique_ptr< SETranslatingPortProxy > initVirtMem
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::shared_ptr< MemState > memState
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
std::vector< std::string > argv
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
std::shared_ptr< FDArray > fds
bool map(Addr vaddr, Addr paddr, int64_t size, bool cacheable=true)
Maps a contiguous range of virtual addresses in this process's address space to a contiguous range of...
loader::ObjectFile * getInterpreter()
loader::MemoryImage interpImage
std::vector< ContextID > vforkContexts
std::vector< ContextID > contextIds
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::vector< std::string > envp
std::string tgtCwd
The cwd members are used to track changes to the current working directory for the purpose of executi...
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Process(const ProcessParams ¶ms, EmulationPageTable *pTable, loader::ObjectFile *obj_file)
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext.
loader::ObjectFile * objFile
statistics::Scalar numSyscalls
static Process * tryLoaders(const ProcessParams ¶ms, loader::ObjectFile *obj_file)
std::vector< EmulatedDriver * > drivers
EmulationPageTable * pTable
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Addr allocPhysPages(int npages, int pool_id=0)
static std::stack< std::string > path
Abstract superclass for simulation objects.
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
std::vector< RedirectPath * > redirectPaths
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void activate()=0
Set the status to Active.
virtual ContextID contextId() const =0
virtual MemoryImage buildImage() const =0
bool write(const PortProxy &proxy) const
virtual ObjectFile * getInterpreter() const
virtual Addr bias() const
const SymbolTable & symtab() const
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
static constexpr T divCeil(const T &a, const U &b)
static constexpr T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
static constexpr T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
DrainState
Object drain/handover states.
@ Drained
Buffers drained, ready for serialization/handover.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define fatal(...)
This implements a cprintf based fatal() function.
const Params & params() const
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
std::ostream CheckpointOut
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
static void output(const char *filename)
static std::string normalize(const std::string &directory)
Overload hash function for BasicBlockRange type.
Declarations of a non-full system Page Table.
Declaration of Statistics objects.