gem5  v20.0.0.3
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, Fault *fault) { 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();
106  ::Loader::ObjectFile *getInterpreter();
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__
virtual ~Loader()
Definition: process.hh:194
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:285
std::string release
Definition: process.hh:259
uint64_t _egid
Definition: process.hh:265
std::unique_ptr< SETranslatingPortProxy > initVirtMem
Definition: process.hh:177
std::vector< ContextID > contextIds
Definition: process.hh:160
bool * sigchld
Definition: process.hh:288
uint64_t uid()
Definition: process.hh:80
Stats::Scalar numSyscalls
Definition: process.hh:165
void pgid(uint64_t pgid)
Definition: process.hh:87
uint64_t _tgid
Definition: process.hh:271
uint64_t RegVal
Definition: types.hh:166
Definition: system.hh:72
std::string executable
Definition: process.hh:218
Definition: cprintf.cc:40
std::shared_ptr< MemState > memState
Definition: process.hh:279
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:2505
DrainState
Object drain/handover states.
Definition: drain.hh:71
uint64_t _ppid
Definition: process.hh:269
bool useArchPT
Definition: process.hh:168
void assignThreadContext(ContextID context_id)
Definition: process.hh:120
uint64_t _euid
Definition: process.hh:263
uint64_t ppid()
Definition: process.hh:85
uint64_t _pid
Definition: process.hh:268
uint64_t pid()
Definition: process.hh:84
uint64_t euid()
Definition: process.hh:81
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
System * system
Definition: process.hh:163
bool kvmInSE
Definition: process.hh:170
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
uint64_t _pgid
Definition: process.hh:270
std::vector< std::string > envp
Definition: process.hh:217
uint64_t pgid()
Definition: process.hh:86
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:140
uint64_t _gid
Definition: process.hh:264
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66
EmulationPageTable * pTable
Definition: process.hh:174
::Loader::MemoryImage image
Definition: process.hh:214
std::ostream CheckpointOut
Definition: serialize.hh:63
const char * progName() const
Definition: process.hh:90
::Loader::MemoryImage interpImage
Definition: process.hh:215
bool useForClone
Definition: process.hh:172
virtual void syscall(ThreadContext *tc, Fault *fault)
Definition: process.hh:78
uint64_t gid()
Definition: process.hh:82
void unserialize(ThreadContext &tc, CheckpointIn &cp)
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:136
std::string hostCwd
Definition: process.hh:256
std::vector< std::string > argv
Definition: process.hh:216
This class represents the return value from an emulated system call, including any errno setting...
uint64_t tgid()
Definition: process.hh:88
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
Abstract superclass for simulation objects.
Definition: sim_object.hh:93
::Loader::ObjectFile * objFile
Definition: process.hh:213
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
uint64_t _uid
Definition: process.hh:262
const FlagsType init
This Stat is Initialized.
Definition: info.hh:45
bool * exitGroup
Definition: process.hh:278
uint64_t egid()
Definition: process.hh:83
std::shared_ptr< FDArray > fds
Definition: process.hh:276
std::vector< EmulatedDriver * > drivers
Definition: process.hh:274

Generated on Fri Jul 3 2020 15:42:39 for gem5 by doxygen 1.8.13