gem5  v20.1.0.0
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(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  // override of virtual SimObject method: register statistics
109  void regStats() override;
110 
111  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
112 
115  bool fixupFault(Addr vaddr);
116 
117  // After getting registered with system object, tell process which
118  // system-wide context id it is assigned.
119  void
121  {
122  contextIds.push_back(context_id);
123  }
124 
129  void revokeThreadContext(int context_id);
130 
136  virtual bool mmapGrowsDown() const { return true; }
137 
151  bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
152 
153  void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
154  ThreadContext *new_tc, bool alloc_page);
155 
156  virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
157  Process *new_p, RegVal flags);
158 
159  // thread contexts associated with this process
161 
162  // system object which owns this process
164 
165  Stats::Scalar numSyscalls; // track how many system calls are executed
166 
167  // flag for using architecture specific page table
168  bool useArchPT;
169  // running KVM requires special initialization
170  bool kvmInSE;
171  // flag for using the process as a thread which shares page tables
173 
175 
176  // Memory proxy for initial image load.
177  std::unique_ptr<SETranslatingPortProxy> initVirtMem;
178 
185  class Loader
186  {
187  public:
188  Loader();
189 
190  /* Loader instances are singletons. */
191  Loader(const Loader &) = delete;
192  void operator=(const Loader &) = delete;
193 
194  virtual ~Loader() {}
195 
204  virtual Process *load(ProcessParams *params,
205  ::Loader::ObjectFile *obj_file) = 0;
206  };
207 
208  // Try all the Loader instance's "load" methods one by one until one is
209  // successful. If none are, complain and fail.
210  static Process *tryLoaders(ProcessParams *params,
211  ::Loader::ObjectFile *obj_file);
212 
218  std::string executable;
219 
233  std::string absolutePath(const std::string &path, bool host_fs);
234 
243  std::string checkPathRedirect(const std::string &filename);
244 
255  std::string tgtCwd;
256  std::string hostCwd;
257 
258  // Syscall emulation uname release.
259  std::string release;
260 
261  // Id of the owner of the process
262  uint64_t _uid;
263  uint64_t _euid;
264  uint64_t _gid;
265  uint64_t _egid;
266 
267  // pid of the process and it's parent
268  uint64_t _pid;
269  uint64_t _ppid;
270  uint64_t _pgid;
271  uint64_t _tgid;
272 
273  // Emulated drivers available to this process
275 
276  std::shared_ptr<FDArray> fds;
277 
278  bool *exitGroup;
279  std::shared_ptr<MemState> memState;
280 
285  uint64_t childClearTID;
286 
287  // Process was forked with SIGCHLD set.
288  bool *sigchld;
289 };
290 
291 #endif // __PROCESS_HH__
Process::_egid
uint64_t _egid
Definition: process.hh:265
Process::kvmInSE
bool kvmInSE
Definition: process.hh:170
Process::updateBias
void updateBias()
Definition: process.cc:436
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:255
Process::pgid
uint64_t pgid()
Definition: process.hh:86
Process::envp
std::vector< std::string > envp
Definition: process.hh:217
fd_entry.hh
Process::useForClone
bool useForClone
Definition: process.hh:172
Process::fds
std::shared_ptr< FDArray > fds
Definition: process.hh:276
Process::assignThreadContext
void assignThreadContext(ContextID context_id)
Definition: process.hh:120
Process::gid
uint64_t gid()
Definition: process.hh:82
Process::Loader::~Loader
virtual ~Loader()
Definition: process.hh:194
Process
Definition: process.hh:65
Process::executable
std::string executable
Definition: process.hh:218
Process::ppid
uint64_t ppid()
Definition: process.hh:85
Process::_gid
uint64_t _gid
Definition: process.hh:264
ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
Process::argv
std::vector< std::string > argv
Definition: process.hh:216
Process::pTable
EmulationPageTable * pTable
Definition: process.hh:174
std::vector< ContextID >
Process::initVirtMem
std::unique_ptr< SETranslatingPortProxy > initVirtMem
Definition: process.hh:177
fd_array.hh
Process::exitGroup
bool * exitGroup
Definition: process.hh:278
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:367
Loader::MemoryImage
Definition: memory_image.hh:48
Process::numSyscalls
Stats::Scalar numSyscalls
Definition: process.hh:165
Process::Loader::load
virtual Process * load(ProcessParams *params, ::Loader::ObjectFile *obj_file)=0
Each subclass needs to implement this method.
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
Process::getInterpreter
::Loader::ObjectFile * getInterpreter()
Definition: process.cc:462
Loader
Definition: process.hh:39
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:267
Loader::ObjectFile
Definition: object_file.hh:70
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:40
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:48
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:403
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
Process::allocateMem
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition: process.cc:319
statistics.hh
Process::sigchld
bool * sigchld
Definition: process.hh:288
Process::Loader::Loader
Loader()
Definition: process.cc:87
Process::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: process.cc:280
Process::hostCwd
std::string hostCwd
Definition: process.hh:256
Process::_euid
uint64_t _euid
Definition: process.hh:263
Process::Loader::operator=
void operator=(const Loader &)=delete
Process::tryLoaders
static Process * tryLoaders(ProcessParams *params, ::Loader::ObjectFile *obj_file)
Definition: process.cc:93
Process::image
::Loader::MemoryImage image
Definition: process.hh:214
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Process::objFile
::Loader::ObjectFile * objFile
Definition: process.hh:213
Process::getBias
Addr getBias()
Definition: process.cc:468
Process::_uid
uint64_t _uid
Definition: process.hh:262
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
SimObject::params
const Params * params() const
Definition: sim_object.hh:119
Process::contextIds
std::vector< ContextID > contextIds
Definition: process.hh:160
Process::interpImage
::Loader::MemoryImage interpImage
Definition: process.hh:215
Process::drivers
std::vector< EmulatedDriver * > drivers
Definition: process.hh:274
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:312
Process::mmapGrowsDown
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward,...
Definition: process.hh:136
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:484
types.hh
Process::useArchPT
bool useArchPT
Definition: process.hh:168
Process::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:290
Process::_pid
uint64_t _pid
Definition: process.hh:268
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:383
Process::release
std::string release
Definition: process.hh:259
Process::euid
uint64_t euid()
Definition: process.hh:81
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
Process::getStartPC
Addr getStartPC()
Definition: process.cc:476
Process::replicatePage
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition: process.cc:329
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:348
Process::regStats
void regStats() override
Callback to set stat parameters.
Definition: process.cc:254
Process::system
System * system
Definition: process.hh:163
Process::uid
uint64_t uid()
Definition: process.hh:80
Process::pgid
void pgid(uint64_t pgid)
Definition: process.hh:87
Process::Process
Process(ProcessParams *params, EmulationPageTable *pTable, ::Loader::ObjectFile *obj_file)
Definition: process.cc:112
Process::_pgid
uint64_t _pgid
Definition: process.hh:270
CheckpointIn
Definition: serialize.hh:67
Process::_tgid
uint64_t _tgid
Definition: process.hh:271
Process::_ppid
uint64_t _ppid
Definition: process.hh:269
Process::findDriver
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition: process.cc:392
memory_image.hh
Serializable::path
static std::stack< std::string > path
Definition: serialize.hh:319
Process::childClearTID
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:285
Process::memState
std::shared_ptr< MemState > memState
Definition: process.hh:279
RegVal
uint64_t RegVal
Definition: types.hh:168
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::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: process.cc:354
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17