gem5  v21.1.0.2
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 
41 #include "base/statistics.hh"
42 #include "base/types.hh"
44 #include "sim/fd_array.hh"
45 #include "sim/fd_entry.hh"
46 #include "sim/mem_state.hh"
47 #include "sim/sim_object.hh"
48 
49 namespace gem5
50 {
51 
52 GEM5_DEPRECATED_NAMESPACE(Loader, loader);
53 namespace loader
54 {
55 class ObjectFile;
56 } // namespace loader
57 
58 struct ProcessParams;
59 
60 class EmulatedDriver;
61 class EmulationPageTable;
62 class SyscallDesc;
63 class SyscallReturn;
64 class System;
65 class ThreadContext;
66 
67 class Process : public SimObject
68 {
69  public:
70  Process(const ProcessParams &params, EmulationPageTable *pTable,
71  loader::ObjectFile *obj_file);
72 
73  void serialize(CheckpointOut &cp) const override;
74  void unserialize(CheckpointIn &cp) override;
75 
76  void init() override;
77  void initState() override;
78  DrainState drain() override;
79 
80  virtual void syscall(ThreadContext *tc) { numSyscalls++; }
81 
82  inline uint64_t uid() { return _uid; }
83  inline uint64_t euid() { return _euid; }
84  inline uint64_t gid() { return _gid; }
85  inline uint64_t egid() { return _egid; }
86  inline uint64_t pid() { return _pid; }
87  inline uint64_t ppid() { return _ppid; }
88  inline uint64_t pgid() { return _pgid; }
89  inline void pgid(uint64_t pgid) { _pgid = pgid; }
90  inline uint64_t tgid() { return _tgid; }
91 
92  const char *progName() const { return executable.c_str(); }
93 
100  EmulatedDriver *findDriver(std::string filename);
101 
102  // This function acts as a callback to update the bias value in
103  // the object file because the parameters needed to calculate the
104  // bias are not available when the object file is created.
105  void updateBias();
106  Addr getBias();
107  Addr getStartPC();
109 
110  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
111 
114  bool fixupFault(Addr vaddr);
115 
116  // After getting registered with system object, tell process which
117  // system-wide context id it is assigned.
118  void
120  {
121  contextIds.push_back(context_id);
122  }
123 
128  void revokeThreadContext(int context_id);
129 
135  virtual bool mmapGrowsDown() const { return true; }
136 
150  bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
151 
152  void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
153  ThreadContext *new_tc, bool alloc_page);
154 
155  virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
156  Process *new_p, RegVal flags);
157 
158  // thread contexts associated with this process
160 
161  // system object which owns this process
163 
164  // flag for using architecture specific page table
165  bool useArchPT;
166  // running KVM requires special initialization
167  bool kvmInSE;
168  // flag for using the process as a thread which shares page tables
170 
172 
173  // Memory proxy for initial image load.
174  std::unique_ptr<SETranslatingPortProxy> initVirtMem;
175 
182  class Loader
183  {
184  public:
185  Loader();
186 
187  /* Loader instances are singletons. */
188  Loader(const Loader &) = delete;
189  void operator=(const Loader &) = delete;
190 
191  virtual ~Loader() {}
192 
201  virtual Process *load(const ProcessParams &params,
202  loader::ObjectFile *obj_file) = 0;
203  };
204 
205  // Try all the Loader instance's "load" methods one by one until one is
206  // successful. If none are, complain and fail.
207  static Process *tryLoaders(const ProcessParams &params,
208  loader::ObjectFile *obj_file);
209 
215  std::string executable;
216 
230  std::string absolutePath(const std::string &path, bool host_fs);
231 
240  std::string checkPathRedirect(const std::string &filename);
241 
252  std::string tgtCwd;
253  std::string hostCwd;
254 
255  // Syscall emulation uname release.
256  std::string release;
257 
258  // Id of the owner of the process
259  uint64_t _uid;
260  uint64_t _euid;
261  uint64_t _gid;
262  uint64_t _egid;
263 
264  // pid of the process and it's parent
265  uint64_t _pid;
266  uint64_t _ppid;
267  uint64_t _pgid;
268  uint64_t _tgid;
269 
270  // Emulated drivers available to this process
272 
273  std::shared_ptr<FDArray> fds;
274 
275  bool *exitGroup;
276  std::shared_ptr<MemState> memState;
277 
282  uint64_t childClearTID;
283 
284  // Process was forked with SIGCHLD set.
285  bool *sigchld;
286 
287  // Contexts to wake up when this thread exits or calls execve
289 
290  // Track how many system calls are executed
292 };
293 
294 } // namespace gem5
295 
296 #endif // __PROCESS_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1927
gem5::Process::assignThreadContext
void assignThreadContext(ContextID context_id)
Definition: process.hh:119
gem5::Process::euid
uint64_t euid()
Definition: process.hh:83
gem5::Process::drivers
std::vector< EmulatedDriver * > drivers
Definition: process.hh:271
gem5::Process::tgid
uint64_t tgid()
Definition: process.hh:90
gem5::EmulationPageTable
Definition: page_table.hh:52
gem5::loader::ObjectFile
Definition: object_file.hh:85
gem5::RegVal
uint64_t RegVal
Definition: types.hh:173
gem5::Process::interpImage
loader::MemoryImage interpImage
Definition: process.hh:212
gem5::Process::progName
const char * progName() const
Definition: process.hh:92
gem5::Process::clone
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
Definition: process.cc:166
gem5::Process::useArchPT
bool useArchPT
Definition: process.hh:165
fd_entry.hh
gem5::Process::findDriver
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition: process.cc:406
gem5::Process::getStartPC
Addr getStartPC()
Definition: process.cc:490
gem5::Process::initVirtMem
std::unique_ptr< SETranslatingPortProxy > initVirtMem
Definition: process.hh:174
gem5::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:252
gem5::Process::Loader::~Loader
virtual ~Loader()
Definition: process.hh:191
gem5::Process::numSyscalls
statistics::Scalar numSyscalls
Definition: process.hh:291
gem5::Process::getBias
Addr getBias()
Definition: process.cc:482
gem5::Serializable::path
static std::stack< std::string > path
Definition: serialize.hh:315
gem5::Process::_pgid
uint64_t _pgid
Definition: process.hh:267
gem5::Process::release
std::string release
Definition: process.hh:256
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::Process::updateBias
void updateBias()
Definition: process.cc:450
gem5::Process::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:287
gem5::Process::_pid
uint64_t _pid
Definition: process.hh:265
gem5::Process::egid
uint64_t egid()
Definition: process.hh:85
std::vector< ContextID >
gem5::Process::pid
uint64_t pid()
Definition: process.hh:86
gem5::Process::_euid
uint64_t _euid
Definition: process.hh:260
fd_array.hh
gem5::Process::fds
std::shared_ptr< FDArray > fds
Definition: process.hh:273
gem5::Process::pgid
void pgid(uint64_t pgid)
Definition: process.hh:89
gem5::Process::gid
uint64_t gid()
Definition: process.hh:84
mem_state.hh
gem5::Process::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: process.cc:365
gem5::Process::useForClone
bool useForClone
Definition: process.hh:169
gem5::Process::memState
std::shared_ptr< MemState > memState
Definition: process.hh:276
gem5::Process::syscall
virtual void syscall(ThreadContext *tc)
Definition: process.hh:80
gem5::Process::allocateMem
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition: process.cc:316
gem5::Process::fixupFault
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Definition: process.cc:359
gem5::Process::childClearTID
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:282
gem5::Process::Loader::Loader
Loader()
Definition: process.cc:86
gem5::Process::uid
uint64_t uid()
Definition: process.hh:82
gem5::Process::_tgid
uint64_t _tgid
Definition: process.hh:268
gem5::DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:74
gem5::Process::ppid
uint64_t ppid()
Definition: process.hh:87
gem5::Process::tryLoaders
static Process * tryLoaders(const ProcessParams &params, loader::ObjectFile *obj_file)
Definition: process.cc:92
gem5::System
Definition: system.hh:77
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::Process::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: process.cc:380
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
sim_object.hh
gem5::Process::pTable
EmulationPageTable * pTable
Definition: process.hh:171
statistics.hh
gem5::Process::Loader::load
virtual Process * load(const ProcessParams &params, loader::ObjectFile *obj_file)=0
Each subclass needs to implement this method.
gem5::Process::exitGroup
bool * exitGroup
Definition: process.hh:275
gem5::loader::MemoryImage
Definition: memory_image.hh:53
gem5::Process::argv
std::vector< std::string > argv
Definition: process.hh:213
gem5::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:498
gem5::Process::executable
std::string executable
Definition: process.hh:215
gem5::Process::Process
Process(const ProcessParams &params, EmulationPageTable *pTable, loader::ObjectFile *obj_file)
Definition: process.cc:112
gem5::Process::checkPathRedirect
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
Definition: process.cc:417
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Process::replicatePage
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition: process.cc:341
gem5::Process::_egid
uint64_t _egid
Definition: process.hh:262
gem5::Process::getInterpreter
loader::ObjectFile * getInterpreter()
Definition: process.cc:476
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::Process::envp
std::vector< std::string > envp
Definition: process.hh:214
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::Process
Definition: process.hh:67
gem5::EmulatedDriver
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:55
gem5::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:397
types.hh
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:246
gem5::Process::sigchld
bool * sigchld
Definition: process.hh:285
gem5::Process::_gid
uint64_t _gid
Definition: process.hh:261
gem5::Process::_ppid
uint64_t _ppid
Definition: process.hh:266
gem5::Process::system
System * system
Definition: process.hh:162
gem5::Process::mmapGrowsDown
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward,...
Definition: process.hh:135
gem5::Process::pgid
uint64_t pgid()
Definition: process.hh:88
gem5::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:264
gem5::Process::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: process.cc:277
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::Process::_uid
uint64_t _uid
Definition: process.hh:259
gem5::Process::contextIds
std::vector< ContextID > contextIds
Definition: process.hh:159
se_translating_port_proxy.hh
gem5::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:309
gem5::MipsISA::vaddr
vaddr
Definition: pra_constants.hh:278
gem5::Process::hostCwd
std::string hostCwd
Definition: process.hh:253
gem5::Process::Loader::operator=
void operator=(const Loader &)=delete
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::Process::vforkContexts
std::vector< ContextID > vforkContexts
Definition: process.hh:288
gem5::Process::kvmInSE
bool kvmInSE
Definition: process.hh:167
memory_image.hh
gem5::Process::image
loader::MemoryImage image
Definition: process.hh:211
gem5::Process::objFile
loader::ObjectFile * objFile
Definition: process.hh:210
gem5::Process::Loader
Each instance of a Loader subclass will have a chance to try to load an object file when tryLoaders i...
Definition: process.hh:182

Generated on Tue Sep 21 2021 12:24:36 for gem5 by doxygen 1.8.17