gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
process.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
3  * Copyright (c) 2001-2005 The Regents of The University of Michigan
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __PROCESS_HH__
31 #define __PROCESS_HH__
32 
33 #include <inttypes.h>
34 
35 #include <map>
36 #include <memory>
37 #include <string>
38 #include <vector>
39 
40 #include "arch/registers.hh"
42 #include "base/statistics.hh"
43 #include "base/types.hh"
44 #include "config/the_isa.hh"
46 #include "sim/fd_array.hh"
47 #include "sim/fd_entry.hh"
48 #include "sim/mem_state.hh"
49 #include "sim/sim_object.hh"
50 
51 namespace Loader
52 {
53 class ObjectFile;
54 } // namespace Loader
55 
56 struct ProcessParams;
57 
58 class EmulatedDriver;
59 class EmulationPageTable;
60 class SyscallDesc;
61 class SyscallReturn;
62 class System;
63 class ThreadContext;
64 
65 class Process : public SimObject
66 {
67  public:
68  Process(const ProcessParams &params, EmulationPageTable *pTable,
69  ::Loader::ObjectFile *obj_file);
70 
71  void serialize(CheckpointOut &cp) const override;
72  void unserialize(CheckpointIn &cp) override;
73 
74  void init() override;
75  void initState() override;
76  DrainState drain() override;
77 
78  virtual void syscall(ThreadContext *tc) { numSyscalls++; }
79 
80  inline uint64_t uid() { return _uid; }
81  inline uint64_t euid() { return _euid; }
82  inline uint64_t gid() { return _gid; }
83  inline uint64_t egid() { return _egid; }
84  inline uint64_t pid() { return _pid; }
85  inline uint64_t ppid() { return _ppid; }
86  inline uint64_t pgid() { return _pgid; }
87  inline void pgid(uint64_t pgid) { _pgid = pgid; }
88  inline uint64_t tgid() { return _tgid; }
89 
90  const char *progName() const { return executable.c_str(); }
91 
98  EmulatedDriver *findDriver(std::string filename);
99 
100  // This function acts as a callback to update the bias value in
101  // the object file because the parameters needed to calculate the
102  // bias are not available when the object file is created.
103  void updateBias();
104  Addr getBias();
105  Addr getStartPC();
107 
108  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
109 
112  bool fixupFault(Addr vaddr);
113 
114  // After getting registered with system object, tell process which
115  // system-wide context id it is assigned.
116  void
118  {
119  contextIds.push_back(context_id);
120  }
121 
126  void revokeThreadContext(int context_id);
127 
133  virtual bool mmapGrowsDown() const { return true; }
134 
148  bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
149 
150  void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
151  ThreadContext *new_tc, bool alloc_page);
152 
153  virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
154  Process *new_p, RegVal flags);
155 
156  // thread contexts associated with this process
158 
159  // system object which owns this process
161 
162  // flag for using architecture specific page table
163  bool useArchPT;
164  // running KVM requires special initialization
165  bool kvmInSE;
166  // flag for using the process as a thread which shares page tables
168 
170 
171  // Memory proxy for initial image load.
172  std::unique_ptr<SETranslatingPortProxy> initVirtMem;
173 
180  class Loader
181  {
182  public:
183  Loader();
184 
185  /* Loader instances are singletons. */
186  Loader(const Loader &) = delete;
187  void operator=(const Loader &) = delete;
188 
189  virtual ~Loader() {}
190 
199  virtual Process *load(const ProcessParams &params,
200  ::Loader::ObjectFile *obj_file) = 0;
201  };
202 
203  // Try all the Loader instance's "load" methods one by one until one is
204  // successful. If none are, complain and fail.
205  static Process *tryLoaders(const ProcessParams &params,
206  ::Loader::ObjectFile *obj_file);
207 
213  std::string executable;
214 
228  std::string absolutePath(const std::string &path, bool host_fs);
229 
238  std::string checkPathRedirect(const std::string &filename);
239 
250  std::string tgtCwd;
251  std::string hostCwd;
252 
253  // Syscall emulation uname release.
254  std::string release;
255 
256  // Id of the owner of the process
257  uint64_t _uid;
258  uint64_t _euid;
259  uint64_t _gid;
260  uint64_t _egid;
261 
262  // pid of the process and it's parent
263  uint64_t _pid;
264  uint64_t _ppid;
265  uint64_t _pgid;
266  uint64_t _tgid;
267 
268  // Emulated drivers available to this process
270 
271  std::shared_ptr<FDArray> fds;
272 
273  bool *exitGroup;
274  std::shared_ptr<MemState> memState;
275 
280  uint64_t childClearTID;
281 
282  // Process was forked with SIGCHLD set.
283  bool *sigchld;
284 
285  Stats::Scalar numSyscalls; // track how many system calls are executed
286 };
287 
288 #endif // __PROCESS_HH__
Process::_egid
uint64_t _egid
Definition: process.hh:260
Process::kvmInSE
bool kvmInSE
Definition: process.hh:165
Process::updateBias
void updateBias()
Definition: process.cc:437
Process::tgtCwd
std::string tgtCwd
The cwd members are used to track changes to the current working directory for the purpose of executi...
Definition: process.hh:250
Process::pgid
uint64_t pgid()
Definition: process.hh:86
Process::envp
std::vector< std::string > envp
Definition: process.hh:212
fd_entry.hh
Process::useForClone
bool useForClone
Definition: process.hh:167
Process::fds
std::shared_ptr< FDArray > fds
Definition: process.hh:271
Process::assignThreadContext
void assignThreadContext(ContextID context_id)
Definition: process.hh:117
Process::gid
uint64_t gid()
Definition: process.hh:82
Process::Loader::~Loader
virtual ~Loader()
Definition: process.hh:189
Process
Definition: process.hh:65
Process::executable
std::string executable
Definition: process.hh:213
Process::ppid
uint64_t ppid()
Definition: process.hh:85
Process::_gid
uint64_t _gid
Definition: process.hh:259
ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:237
Process::argv
std::vector< std::string > argv
Definition: process.hh:211
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:169
std::vector< ContextID >
Process::initVirtMem
std::unique_ptr< SETranslatingPortProxy > initVirtMem
Definition: process.hh:172
fd_array.hh
Process::exitGroup
bool * exitGroup
Definition: process.hh:273
Process::egid
uint64_t egid()
Definition: process.hh:83
Process::syscall
virtual void syscall(ThreadContext *tc)
Definition: process.hh:78
mem_state.hh
Process::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: process.cc:368
Loader::MemoryImage
Definition: memory_image.hh:48
Process::numSyscalls
Stats::Scalar numSyscalls
Definition: process.hh:285
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1933
Process::getInterpreter
::Loader::ObjectFile * getInterpreter()
Definition: process.cc:463
Loader
Definition: process.hh:34
Process::revokeThreadContext
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext.
Definition: process.cc:254
Loader::ObjectFile
Definition: object_file.hh:74
Process::tgid
uint64_t tgid()
Definition: process.hh:88
EmulatedDriver
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
cp
Definition: cprintf.cc:37
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
Process::clone
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
Definition: process.cc:163
EmulationPageTable
Definition: page_table.hh:49
sim_object.hh
System
Definition: system.hh:73
Process::checkPathRedirect
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
Definition: process.cc:404
Process::tryLoaders
static Process * tryLoaders(const ProcessParams &params, ::Loader::ObjectFile *obj_file)
Definition: process.cc:90
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
Process::allocateMem
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition: process.cc:306
statistics.hh
Process::sigchld
bool * sigchld
Definition: process.hh:283
Process::Loader::Loader
Loader()
Definition: process.cc:84
Process::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: process.cc:267
Process::hostCwd
std::string hostCwd
Definition: process.hh:251
Process::_euid
uint64_t _euid
Definition: process.hh:258
Process::Loader::operator=
void operator=(const Loader &)=delete
Process::image
::Loader::MemoryImage image
Definition: process.hh:209
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Process::objFile
::Loader::ObjectFile * objFile
Definition: process.hh:208
Process::getBias
Addr getBias()
Definition: process.cc:469
Process::_uid
uint64_t _uid
Definition: process.hh:257
SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:52
Process::progName
const char * progName() const
Definition: process.hh:90
Process::contextIds
std::vector< ContextID > contextIds
Definition: process.hh:157
Process::interpImage
::Loader::MemoryImage interpImage
Definition: process.hh:210
Process::drivers
std::vector< EmulatedDriver * > drivers
Definition: process.hh:269
Process::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: process.cc:299
Process::mmapGrowsDown
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward,...
Definition: process.hh:133
Process::absolutePath
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...
Definition: process.cc:485
types.hh
Process::useArchPT
bool useArchPT
Definition: process.hh:163
Process::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:277
Process::Loader::load
virtual Process * load(const ProcessParams &params, ::Loader::ObjectFile *obj_file)=0
Each subclass needs to implement this method.
Process::_pid
uint64_t _pid
Definition: process.hh:263
Process::map
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...
Definition: process.cc:384
Process::release
std::string release
Definition: process.hh:254
Process::euid
uint64_t euid()
Definition: process.hh:81
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
Process::getStartPC
Addr getStartPC()
Definition: process.cc:477
Process::replicatePage
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition: process.cc:331
se_translating_port_proxy.hh
Process::fixupFault
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Definition: process.cc:349
SimObject::params
const Params & params() const
Definition: sim_object.hh:168
Process::system
System * system
Definition: process.hh:160
Process::uid
uint64_t uid()
Definition: process.hh:80
Process::pgid
void pgid(uint64_t pgid)
Definition: process.hh:87
Process::_pgid
uint64_t _pgid
Definition: process.hh:265
CheckpointIn
Definition: serialize.hh:68
Process::_tgid
uint64_t _tgid
Definition: process.hh:266
Process::_ppid
uint64_t _ppid
Definition: process.hh:264
Process::findDriver
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition: process.cc:393
memory_image.hh
Serializable::path
static std::stack< std::string > path
Definition: serialize.hh:321
Process::childClearTID
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:280
Process::memState
std::shared_ptr< MemState > memState
Definition: process.hh:274
RegVal
uint64_t RegVal
Definition: types.hh:174
Process::pid
uint64_t pid()
Definition: process.hh:84
SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66
Process::Process
Process(const ProcessParams &params, EmulationPageTable *pTable, ::Loader::ObjectFile *obj_file)
Definition: process.cc:110
Process::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: process.cc:355
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:20 for gem5 by doxygen 1.8.17