gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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"
43#include "sim/fd_array.hh"
44#include "sim/fd_entry.hh"
45#include "sim/mem_state.hh"
46#include "sim/sim_object.hh"
47
48namespace gem5
49{
50
51namespace loader
52{
53class ObjectFile;
54} // namespace loader
55
56struct ProcessParams;
57
58class EmulatedDriver;
60class SEWorkload;
61class SyscallDesc;
62class SyscallReturn;
63class System;
64class ThreadContext;
65
66class Process : public SimObject
67{
68 public:
69 Process(const ProcessParams &params, EmulationPageTable *pTable,
70 loader::ObjectFile *obj_file);
71
72 void serialize(CheckpointOut &cp) const override;
73 void unserialize(CheckpointIn &cp) override;
74
75 void init() override;
76 void initState() override;
77 DrainState drain() override;
78
79 virtual void syscall(ThreadContext *tc) { numSyscalls++; }
80
81 inline uint64_t uid() { return _uid; }
82 inline uint64_t euid() { return _euid; }
83 inline uint64_t gid() { return _gid; }
84 inline uint64_t egid() { return _egid; }
85 inline uint64_t pid() { return _pid; }
86 inline uint64_t ppid() { return _ppid; }
87 inline uint64_t pgid() { return _pgid; }
88 inline void pgid(uint64_t pgid) { _pgid = pgid; }
89 inline uint64_t tgid() { return _tgid; }
90
91 const char *progName() const { return executable.c_str(); }
92
99 EmulatedDriver *findDriver(std::string filename);
100
101 // This function acts as a callback to update the bias value in
102 // the object file because the parameters needed to calculate the
103 // bias are not available when the object file is created.
104 void updateBias();
105 Addr getBias();
108
109 // This function allocates physical memory as backing store, and then maps
110 // it into the virtual address space of the process. The range of virtual
111 // addresses being configured starts at the address "vaddr" and is of size
112 // "size" bytes. If some part of this range of virtual addresses is already
113 // configured, this function will error out unless "clobber" is set. If
114 // clobber is set, then those existing mappings will be replaced.
115 //
116 // If the beginning or end of the virtual address range does not perfectly
117 // align to page boundaries, it will be expanded in either direction until
118 // it does. This function will therefore set up *at least* the range
119 // requested, and may configure more if necessary.
120 void allocateMem(Addr vaddr, int64_t size, bool clobber=false);
121
126 void deallocateMem(Addr vaddr, int64_t size);
127
130 bool fixupFault(Addr vaddr);
131
132 // After getting registered with system object, tell process which
133 // system-wide context id it is assigned.
134 void
136 {
137 contextIds.push_back(context_id);
138 }
139
144 void revokeThreadContext(int context_id);
145
151 virtual bool mmapGrowsDown() const { return true; }
152
166 bool map(Addr vaddr, Addr paddr, int64_t size, bool cacheable = true);
167
168 void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
169 ThreadContext *new_tc, bool alloc_page);
170
171 virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
172 Process *new_p, RegVal flags);
173
174 // thread contexts associated with this process
176
177 // system object which owns this process
179
181
182 // flag for using architecture specific page table
184 // running KVM requires special initialization
186 // flag for using the process as a thread which shares page tables
188
194
196
197 // Memory proxy for initial image load.
198 std::unique_ptr<SETranslatingPortProxy> initVirtMem;
199
206 class Loader
207 {
208 public:
209 Loader();
210
211 /* Loader instances are singletons. */
212 Loader(const Loader &) = delete;
213 void operator=(const Loader &) = delete;
214
215 virtual ~Loader() {}
216
225 virtual Process *load(const ProcessParams &params,
226 loader::ObjectFile *obj_file) = 0;
227 };
228
229 // Try all the Loader instance's "load" methods one by one until one is
230 // successful. If none are, complain and fail.
231 static Process *tryLoaders(const ProcessParams &params,
232 loader::ObjectFile *obj_file);
233
239 std::string executable;
240
254 std::string absolutePath(const std::string &path, bool host_fs);
255
264 std::string checkPathRedirect(const std::string &filename);
265
276 std::string tgtCwd;
277 std::string hostCwd;
278
279 // Syscall emulation uname release.
280 std::string release;
281
282 // Id of the owner of the process
283 uint64_t _uid;
284 uint64_t _euid;
285 uint64_t _gid;
286 uint64_t _egid;
287
288 // pid of the process and it's parent
289 uint64_t _pid;
290 uint64_t _ppid;
291 uint64_t _pgid;
292 uint64_t _tgid;
293
294 // Emulated drivers available to this process
296
297 std::shared_ptr<FDArray> fds;
298
300 std::shared_ptr<MemState> memState;
301
307
308 // Process was forked with SIGCHLD set.
309 bool *sigchld;
310
311 // Contexts to wake up when this thread exits or calls execve
313
314 // Track how many system calls are executed
316};
317
318} // namespace gem5
319
320#endif // __PROCESS_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
virtual Process * load(const ProcessParams &params, loader::ObjectFile *obj_file)=0
Each subclass needs to implement this method.
Loader(const Loader &)=delete
void operator=(const Loader &)=delete
loader::MemoryImage image
Definition process.hh:235
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd?
Definition process.hh:151
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
Definition process.cc:318
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
Definition process.cc:386
uint64_t egid()
Definition process.hh:84
SEWorkload * seWorkload
Definition process.hh:180
void updateBias()
Definition process.cc:497
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:545
uint64_t _euid
Definition process.hh:284
std::unique_ptr< SETranslatingPortProxy > initVirtMem
Definition process.hh:198
virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, RegVal flags)
Definition process.cc:168
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition process.cc:279
std::shared_ptr< MemState > memState
Definition process.hh:300
bool fixupFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
Definition process.cc:405
void deallocateMem(Addr vaddr, int64_t size)
Unmap the given virtual address range and deallocate any physical pages that it mapped to.
Definition process.cc:348
uint64_t pid()
Definition process.hh:85
uint64_t _tgid
Definition process.hh:292
uint64_t uid()
Definition process.hh:81
std::vector< std::string > argv
Definition process.hh:237
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition process.cc:311
uint64_t pgid()
Definition process.hh:87
uint64_t _egid
Definition process.hh:286
std::shared_ptr< FDArray > fds
Definition process.hh:297
const char * progName() const
Definition process.hh:91
void assignThreadContext(ContextID context_id)
Definition process.hh:135
bool map(Addr vaddr, Addr paddr, int64_t 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:444
uint64_t _pid
Definition process.hh:289
uint64_t _gid
Definition process.hh:285
bool useForClone
Definition process.hh:187
uint64_t _ppid
Definition process.hh:290
loader::ObjectFile * getInterpreter()
Definition process.cc:523
loader::MemoryImage interpImage
Definition process.hh:236
bool * sigchld
Definition process.hh:309
virtual void syscall(ThreadContext *tc)
Definition process.hh:79
bool zeroPages
Whether to ensure that all newly allocated pages are zero-filled.
Definition process.hh:193
uint64_t ppid()
Definition process.hh:86
std::string executable
Definition process.hh:239
std::vector< ContextID > vforkContexts
Definition process.hh:312
std::string hostCwd
Definition process.hh:277
std::vector< ContextID > contextIds
Definition process.hh:175
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
Definition process.cc:464
System * system
Definition process.hh:178
uint64_t _pgid
Definition process.hh:291
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition process.cc:289
bool * exitGroup
Definition process.hh:299
void pgid(uint64_t pgid)
Definition process.hh:88
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition process.cc:411
std::vector< std::string > envp
Definition process.hh:238
std::string tgtCwd
The cwd members are used to track changes to the current working directory for the purpose of executi...
Definition process.hh:276
std::string release
Definition process.hh:280
uint64_t gid()
Definition process.hh:83
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
Definition process.cc:453
uint64_t tgid()
Definition process.hh:89
Addr getStartPC()
Definition process.cc:537
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition process.cc:426
Process(const ProcessParams &params, EmulationPageTable *pTable, loader::ObjectFile *obj_file)
Definition process.cc:113
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext.
Definition process.cc:266
uint64_t _uid
Definition process.hh:283
loader::ObjectFile * objFile
Definition process.hh:234
Addr getBias()
Definition process.cc:529
statistics::Scalar numSyscalls
Definition process.hh:315
static Process * tryLoaders(const ProcessParams &params, loader::ObjectFile *obj_file)
Definition process.cc:93
uint64_t euid()
Definition process.hh:82
std::vector< EmulatedDriver * > drivers
Definition process.hh:295
EmulationPageTable * pTable
Definition process.hh:195
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
Definition process.hh:306
static std::stack< std::string > path
Definition serialize.hh:315
This class provides the wrapper interface for the system call implementations which are defined in th...
This class represents the return value from an emulated system call, including any errno setting.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
This is a simple scalar statistic, like a counter.
STL vector class.
Definition stl.hh:37
DrainState
Object drain/handover states.
Definition drain.hh:76
const Params & params() const
SimObject(const Params &p)
Definition sim_object.cc:58
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int ContextID
Globally unique thread context ID.
Definition types.hh:239
Declaration of Statistics objects.

Generated on Mon Oct 27 2025 04:13:04 for gem5 by doxygen 1.14.0