gem5  v19.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  * Authors: Nathan Binkert
30  * Steve Reinhardt
31  * Brandon Potter
32  */
33 
34 #ifndef __PROCESS_HH__
35 #define __PROCESS_HH__
36 
37 #include <inttypes.h>
38 
39 #include <map>
40 #include <string>
41 #include <vector>
42 
43 #include "arch/registers.hh"
45 #include "base/statistics.hh"
46 #include "base/types.hh"
47 #include "config/the_isa.hh"
49 #include "sim/fd_array.hh"
50 #include "sim/fd_entry.hh"
51 #include "sim/mem_state.hh"
52 #include "sim/sim_object.hh"
53 
54 struct ProcessParams;
55 
56 class EmulatedDriver;
57 class ObjectFile;
58 class EmulationPageTable;
59 class SyscallDesc;
60 class SyscallReturn;
61 class System;
62 class ThreadContext;
63 
64 class Process : public SimObject
65 {
66  protected:
67  void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault);
68 
69  public:
70  Process(ProcessParams *params, EmulationPageTable *pTable,
71  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, Fault *fault) = 0;
81  virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0;
82  virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width);
83  virtual void setSyscallReturn(ThreadContext *tc,
84  SyscallReturn return_value) = 0;
85  virtual SyscallDesc *getDesc(int callnum) = 0;
86 
87  inline uint64_t uid() { return _uid; }
88  inline uint64_t euid() { return _euid; }
89  inline uint64_t gid() { return _gid; }
90  inline uint64_t egid() { return _egid; }
91  inline uint64_t pid() { return _pid; }
92  inline uint64_t ppid() { return _ppid; }
93  inline uint64_t pgid() { return _pgid; }
94  inline void pgid(uint64_t pgid) { _pgid = pgid; }
95  inline uint64_t tgid() { return _tgid; }
96 
97  const char *progName() const { return executable.c_str(); }
98 
105  EmulatedDriver *findDriver(std::string filename);
106 
107  // This function acts as a callback to update the bias value in
108  // the object file because the parameters needed to calculate the
109  // bias are not available when the object file is created.
110  void updateBias();
111  Addr getBias();
112  Addr getStartPC();
114 
115  // override of virtual SimObject method: register statistics
116  void regStats() override;
117 
118  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
119 
122  bool fixupStackFault(Addr vaddr);
123 
124  // After getting registered with system object, tell process which
125  // system-wide context id it is assigned.
126  void
128  {
129  contextIds.push_back(context_id);
130  }
131 
136  void revokeThreadContext(int context_id);
137 
143  virtual bool mmapGrowsDown() const { return true; }
144 
158  bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
159 
160  void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
161  ThreadContext *new_tc, bool alloc_page);
162 
163  virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
164  Process *new_p, RegVal flags);
165 
166  // thread contexts associated with this process
168 
169  // system object which owns this process
171 
172  Stats::Scalar numSyscalls; // track how many system calls are executed
173 
174  // flag for using architecture specific page table
175  bool useArchPT;
176  // running KVM requires special initialization
177  bool kvmInSE;
178  // flag for using the process as a thread which shares page tables
180 
182 
183  SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
184 
191  class Loader
192  {
193  public:
194  Loader();
195 
196  /* Loader instances are singletons. */
197  Loader(const Loader &) = delete;
198  void operator=(const Loader &) = delete;
199 
200  virtual ~Loader() {}
201 
210  virtual Process *load(ProcessParams *params, ObjectFile *obj_file) = 0;
211  };
212 
213  // Try all the Loader instance's "load" methods one by one until one is
214  // successful. If none are, complain and fail.
215  static Process *tryLoaders(ProcessParams *params, ObjectFile *obj_file);
216 
222  std::string executable;
223 
237  std::string absolutePath(const std::string &path, bool host_fs);
238 
247  std::string checkPathRedirect(const std::string &filename);
248 
259  std::string tgtCwd;
260  std::string hostCwd;
261 
262  // Syscall emulation uname release.
263  std::string release;
264 
265  // Id of the owner of the process
266  uint64_t _uid;
267  uint64_t _euid;
268  uint64_t _gid;
269  uint64_t _egid;
270 
271  // pid of the process and it's parent
272  uint64_t _pid;
273  uint64_t _ppid;
274  uint64_t _pgid;
275  uint64_t _tgid;
276 
277  // Emulated drivers available to this process
279 
280  std::shared_ptr<FDArray> fds;
281 
282  bool *exitGroup;
283  std::shared_ptr<MemState> memState;
284 
289  uint64_t childClearTID;
290 
291  // Process was forked with SIGCHLD set.
292  bool *sigchld;
293 };
294 
295 #endif // __PROCESS_HH__
virtual SyscallDesc * getDesc(int callnum)=0
ObjectFile * objFile
Definition: process.hh:217
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
Definition: process.cc:284
virtual ~Loader()
Definition: process.hh:200
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:289
Bitfield< 7 > i
DrainState
Object drain/handover states.
Definition: drain.hh:71
static std::stack< std::string > path
Definition: serialize.hh:267
std::string release
Definition: process.hh:263
MemoryImage interpImage
Definition: process.hh:219
uint64_t _egid
Definition: process.hh:269
std::vector< ContextID > contextIds
Definition: process.hh:167
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition: process.cc:333
bool * sigchld
Definition: process.hh:292
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: process.cc:405
SETranslatingPortProxy initVirtMem
Definition: process.hh:183
uint64_t uid()
Definition: process.hh:87
void regStats() override
Callback to set stat parameters.
Definition: process.cc:271
Stats::Scalar numSyscalls
Definition: process.hh:172
void pgid(uint64_t pgid)
Definition: process.hh:94
uint64_t _tgid
Definition: process.hh:275
uint64_t RegVal
Definition: types.hh:168
Definition: system.hh:77
void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault)
Definition: process.cc:430
ObjectFile * getInterpreter()
Definition: process.cc:518
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:307
static Process * tryLoaders(ProcessParams *params, ObjectFile *obj_file)
Definition: process.cc:98
std::string executable
Definition: process.hh:222
Definition: cprintf.cc:42
std::shared_ptr< MemState > memState
Definition: process.hh:283
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: process.cc:326
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition: process.cc:343
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:540
uint64_t _ppid
Definition: process.hh:273
bool useArchPT
Definition: process.hh:175
void assignThreadContext(ContextID context_id)
Definition: process.hh:127
uint64_t _euid
Definition: process.hh:267
uint64_t ppid()
Definition: process.hh:92
bool map(Addr vaddr, Addr paddr, int size, bool cacheable=true)
Maps a contiguous range of virtual addresses in this process&#39;s address space to a contiguous range of...
Definition: process.cc:421
uint64_t _pid
Definition: process.hh:272
const Params * params() const
Definition: sim_object.hh:114
uint64_t pid()
Definition: process.hh:91
uint64_t euid()
Definition: process.hh:88
virtual RegVal getSyscallArg(ThreadContext *tc, int &i)=0
Addr getStartPC()
Definition: process.cc:532
System * system
Definition: process.hh:170
bool kvmInSE
Definition: process.hh:177
std::string tgtCwd
The cwd members are used to track changes to the current working directory for the purpose of executi...
Definition: process.hh:259
uint64_t _pgid
Definition: process.hh:274
std::vector< std::string > envp
Definition: process.hh:221
virtual Process * load(ProcessParams *params, ObjectFile *obj_file)=0
Each subclass needs to implement this method.
uint64_t pgid()
Definition: process.hh:93
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition: process.cc:448
uint64_t _gid
Definition: process.hh:268
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:69
bool fixupStackFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Definition: process.cc:362
EmulationPageTable * pTable
Definition: process.hh:181
virtual void syscall(ThreadContext *tc, Fault *fault)=0
void operator=(const Loader &)=delete
std::ostream CheckpointOut
Definition: serialize.hh:68
void updateBias()
Definition: process.cc:492
Process(ProcessParams *params, EmulationPageTable *pTable, ObjectFile *obj_file)
Definition: process.cc:117
const char * progName() const
Definition: process.hh:97
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
Definition: process.cc:177
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
Definition: process.cc:459
bool useForClone
Definition: process.hh:179
TranslatingPortProxy Object Declaration for SE.
Bitfield< 4 > width
uint64_t gid()
Definition: process.hh:89
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward, but a few (such as Alpha) grow upward instead, so they can override this method to return false.
Definition: process.hh:143
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: process.cc:392
virtual void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)=0
std::string hostCwd
Definition: process.hh:260
std::vector< std::string > argv
Definition: process.hh:220
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: process.cc:297
This class represents the return value from an emulated system call, including any errno setting...
uint64_t tgid()
Definition: process.hh:95
Each instance of a Loader subclass will have a chance to try to load an object file when tryLoaders i...
Definition: process.hh:191
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
Addr getBias()
Definition: process.cc:524
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
uint64_t _uid
Definition: process.hh:266
MemoryImage image
Definition: process.hh:218
bool * exitGroup
Definition: process.hh:282
uint64_t egid()
Definition: process.hh:90
std::shared_ptr< FDArray > fds
Definition: process.hh:280
std::vector< EmulatedDriver * > drivers
Definition: process.hh:278

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13