61#include "params/Process.hh"
76typedef std::vector<Process::Loader *> LoaderList;
81 static LoaderList loaders;
89 process_loaders().emplace_back(
this);
96 for (
auto &loader_it : process_loaders()) {
108 if (directory.back() !=
'/')
109 return directory +
'/';
136 "Number of system calls")
142 fatal_if(!ret_pair.second,
"_pid %d is already used",
_pid);
178#define CLONE_THREAD 0
200 pTable->getMappings(&mappings);
202 for (
auto map : mappings) {
226 std::shared_ptr<FDArray> nfds = np->
fds;
227 for (
int tgt_fd = 0; tgt_fd <
fds->getSize(); tgt_fd++) {
228 std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
230 nfds->setFDEntry(tgt_fd,
nullptr);
233 nfds->setFDEntry(tgt_fd, this_fde->clone());
235 auto this_hbfd = std::dynamic_pointer_cast<HBFDEntry>(this_fde);
239 int this_sim_fd = this_hbfd->getSimFD();
240 if (this_sim_fd <= 2)
243 int np_sim_fd = dup(this_sim_fd);
244 assert(np_sim_fd != -1);
246 auto nhbfd = std::dynamic_pointer_cast<HBFDEntry>((*nfds)[tgt_fd]);
247 nhbfd->setSimFD(np_sim_fd);
270 if (*it == context_id) {
275 warn(
"Unable to find thread context to revoke");
292 fatal(
"Process %s is not associated with any HW contexts!\n",
name());
313 fds->updateFileOffsets();
320 const auto page_size =
pTable->pageSize();
334 warn(
"Process::allocateMem: addr %#x already mapped\n",
vaddr);
339 const int npages =
divCeil(size, page_size);
341 const Addr pages_size = npages * page_size;
342 pTable->map(page_addr, paddr, pages_size,
350 const auto page_size =
pTable->pageSize();
353 const int npages = (page_vend - page_vbase) / page_size;
357 for (
int i = 0;
i < npages; ++
i) {
358 const Addr page_vaddr = page_vbase + page_size *
i;
360 if (
pTable->translate(page_vaddr, page_paddr)) {
373 virt_mem.
writeBlob(page_vaddr, zero_page.data(), page_size);
377 pTable->unmap(page_vaddr, page_size);
393 const size_t buf_size =
pTable->pageSize();
394 auto buf_p = std::make_unique<uint8_t[]>(buf_size);
422 warn(
"Checkpoints for pipes, device drivers and sockets do not work.");
430 fds->unserialize(
cp,
this);
436 warn(
"Checkpoints for pipes, device drivers and sockets do not work.");
456 if (
d->match(filename))
475 std::string tail = abs_path.substr(
path->appPath().size());
479 for (
auto host_path :
path->hostPaths()) {
480 if (access((host_path + tail).c_str(), R_OK) == 0) {
482 return host_path + tail;
488 return path->hostPaths()[0] + tail;
499 auto *interp =
objFile->getInterpreter();
501 if (!interp || !interp->relocatable())
516 mmap_end =
mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
519 interp->updateBias(ld_bias);
525 return objFile->getInterpreter();
533 return interp ? interp->bias() :
objFile->bias();
541 return interp ? interp->entryPoint() :
objFile->entryPoint();
547 if (filename.empty() ||
startswith(filename,
"/"))
553 auto path_base = std::string();
554 if (host_filesystem) {
566 auto absolute_path = path_base + filename;
568 return absolute_path;
572ProcessParams::create()
const
576 const std::string &exec = (executable ==
"") ? cmd[0] : executable;
579 fatal_if(!obj_file,
"Cannot load object file %s.", exec);
582 fatal_if(!process,
"Unknown error creating process object.");
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
bool translate(Addr vaddr, Addr &paddr)
Translate function.
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?
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.
void deallocateMem(Addr vaddr, int64_t size)
Unmap the given virtual address range and deallocate any physical pages that it mapped to.
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
bool zeroPages
Whether to ensure that all newly allocated pages are zero-filled.
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.
static std::stack< std::string > path
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
#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
SimObject(const Params &p)
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Copyright (c) 2024 Arm Limited 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.