gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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"
44 #include "base/statistics.hh"
45 #include "base/types.hh"
46 #include "config/the_isa.hh"
48 #include "sim/fd_array.hh"
49 #include "sim/fd_entry.hh"
50 #include "sim/mem_state.hh"
51 #include "sim/sim_object.hh"
52 
53 struct ProcessParams;
54 
55 class EmulatedDriver;
56 class ObjectFile;
57 class PageTableBase;
58 class SyscallDesc;
59 class SyscallReturn;
60 class System;
61 class ThreadContext;
62 
63 class Process : public SimObject
64 {
65  public:
66  Process(ProcessParams *params, ObjectFile *obj_file);
67 
68  void serialize(CheckpointOut &cp) const override;
69  void unserialize(CheckpointIn &cp) override;
70 
71  void initState() override;
72  DrainState drain() override;
73 
74  virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
75  virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
76  virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
77  virtual void setSyscallArg(ThreadContext *tc, int i,
78  TheISA::IntReg val) = 0;
79  virtual void setSyscallReturn(ThreadContext *tc,
80  SyscallReturn return_value) = 0;
81  virtual SyscallDesc *getDesc(int callnum) = 0;
82 
83  inline uint64_t uid() { return _uid; }
84  inline uint64_t euid() { return _euid; }
85  inline uint64_t gid() { return _gid; }
86  inline uint64_t egid() { return _egid; }
87  inline uint64_t pid() { return _pid; }
88  inline uint64_t ppid() { return _ppid; }
89  inline uint64_t pgid() { return _pgid; }
90  inline uint64_t tgid() { return _tgid; }
91  inline void setpgid(uint64_t pgid) { _pgid = pgid; }
92 
93  const char *progName() const { return executable.c_str(); }
94  std::string fullPath(const std::string &filename);
95  std::string getcwd() const { return cwd; }
96 
103  EmulatedDriver *findDriver(std::string filename);
104 
105  // This function acts as a callback to update the bias value in
106  // the object file because the parameters needed to calculate the
107  // bias are not available when the object file is created.
108  void updateBias();
109  Addr getBias();
110  Addr getStartPC();
112 
113  // override of virtual SimObject method: register statistics
114  void regStats() override;
115 
116  void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
117 
120  bool fixupStackFault(Addr vaddr);
121 
122  // After getting registered with system object, tell process which
123  // system-wide context id it is assigned.
124  void
126  {
127  contextIds.push_back(context_id);
128  }
129 
130  // Find a free context to use
132 
137  void revokeThreadContext(int context_id);
138 
144  virtual bool mmapGrowsDown() const { return true; }
145 
159  bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
160 
161  void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
162  ThreadContext *new_tc, bool alloc_page);
163 
164  void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p,
165  TheISA::IntReg flags);
166 
167  // thread contexts associated with this process
169 
170  // system object which owns this process
172 
173  Stats::Scalar numSyscalls; // track how many system calls are executed
174 
175  bool useArchPT; // flag for using architecture specific page table
176  bool kvmInSE; // running KVM requires special initialization
177 
179 
180  SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
181 
185  std::string cwd;
186  std::string executable;
187 
188  // Id of the owner of the process
189  uint64_t _uid;
190  uint64_t _euid;
191  uint64_t _gid;
192  uint64_t _egid;
193 
194  // pid of the process and it's parent
195  uint64_t _pid;
196  uint64_t _ppid;
197  uint64_t _pgid;
198  uint64_t _tgid;
199 
200  // Emulated drivers available to this process
202 
203  std::shared_ptr<FDArray> fds;
204 
205  bool *exitGroup;
206  std::shared_ptr<MemState> memState;
207 
212  uint64_t childClearTID;
213 
214  // Process was forked with SIGCHLD set.
215  bool *sigchld;
216 };
217 
218 #endif // __PROCESS_HH__
virtual SyscallDesc * getDesc(int callnum)=0
ObjectFile * objFile
Definition: process.hh:182
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
Definition: process.cc:275
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition: process.hh:212
Bitfield< 7 > i
Definition: miscregs.hh:1378
DrainState
Object drain/handover states.
Definition: drain.hh:71
std::string cwd
Definition: process.hh:185
uint64_t _egid
Definition: process.hh:192
std::vector< ContextID > contextIds
Definition: process.hh:168
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition: process.cc:310
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:144
bool * sigchld
Definition: process.hh:215
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: process.cc:385
SETranslatingPortProxy initVirtMem
Definition: process.hh:180
uint64_t uid()
Definition: process.hh:83
void regStats() override
Register statistics for this object.
Definition: process.cc:252
Stats::Scalar numSyscalls
Definition: process.hh:173
const Params * params() const
Definition: sim_object.hh:111
uint64_t _tgid
Definition: process.hh:198
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i)=0
Definition: system.hh:83
ObjectFile * getInterpreter()
Definition: process.cc:468
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:288
std::string executable
Definition: process.hh:186
std::shared_ptr< MemState > memState
Definition: process.hh:206
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:2475
Bitfield< 63 > val
Definition: misc.hh:770
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: process.cc:303
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition: process.cc:319
uint64_t _ppid
Definition: process.hh:196
bool useArchPT
Definition: process.hh:175
void assignThreadContext(ContextID context_id)
Definition: process.hh:125
uint64_t _euid
Definition: process.hh:190
uint64_t ppid()
Definition: process.hh:88
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:405
uint64_t _pid
Definition: process.hh:195
uint64_t pid()
Definition: process.hh:87
uint64_t euid()
Definition: process.hh:84
const char * progName() const
Definition: process.hh:93
ThreadContext * findFreeContext()
Definition: process.cc:265
Addr getStartPC()
Definition: process.cc:482
System * system
Definition: process.hh:171
bool kvmInSE
Definition: process.hh:176
uint64_t _pgid
Definition: process.hh:197
std::vector< std::string > envp
Definition: process.hh:184
uint64_t pgid()
Definition: process.hh:89
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
std::string getcwd() const
Definition: process.hh:95
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition: process.cc:431
virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
Definition: process.cc:413
PageTableBase * pTable
Definition: process.hh:178
Declaration of base class for page table.
Definition: page_table.hh:57
std::string fullPath(const std::string &filename)
Definition: process.cc:646
uint64_t _gid
Definition: process.hh:191
uint64_t IntReg
Definition: registers.hh:47
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:63
bool fixupStackFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Definition: process.cc:338
int size()
Definition: pagetable.hh:146
std::ostream CheckpointOut
Definition: serialize.hh:67
Process(ProcessParams *params, ObjectFile *obj_file)
Definition: process.cc:104
void updateBias()
Definition: process.cc:442
void setpgid(uint64_t pgid)
Definition: process.hh:91
TranslatingPortProxy Object Declaration for SE.
Bitfield< 4 > width
Definition: miscregs.hh:1383
uint64_t gid()
Definition: process.hh:85
virtual void setSyscallArg(ThreadContext *tc, int i, TheISA::IntReg val)=0
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Definition: emul_driver.hh:52
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: process.cc:368
virtual void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)=0
std::vector< std::string > argv
Definition: process.hh:183
This class represents the return value from an emulated system call, including any errno setting...
uint64_t tgid()
Definition: process.hh:90
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, TheISA::IntReg flags)
Definition: process.cc:160
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
Addr getBias()
Definition: process.cc:474
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
uint64_t _uid
Definition: process.hh:189
bool * exitGroup
Definition: process.hh:205
uint64_t egid()
Definition: process.hh:86
std::shared_ptr< FDArray > fds
Definition: process.hh:203
std::vector< EmulatedDriver * > drivers
Definition: process.hh:201

Generated on Fri Jun 9 2017 13:03:35 for gem5 by doxygen 1.8.6