2 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
3 * Copyright (c) 2001-2005 The Regents of The University of Michigan
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.
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.
29 * Authors: Nathan Binkert
34 #ifndef __PROCESS_HH__
35 #define __PROCESS_HH__
43 #include "arch/registers.hh"
44 #include "base/statistics.hh"
45 #include "base/types.hh"
46 #include "config/the_isa.hh"
47 #include "mem/se_translating_port_proxy.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"
57 class EmulationPageTable;
63 class Process : public SimObject
66 Process(ProcessParams *params, EmulationPageTable *pTable,
67 ObjectFile *obj_file);
69 void serialize(CheckpointOut &cp) const override;
70 void unserialize(CheckpointIn &cp) override;
72 void initState() override;
73 DrainState drain() override;
75 virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
76 virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0;
77 virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width);
78 virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0;
79 virtual void setSyscallReturn(ThreadContext *tc,
80 SyscallReturn return_value) = 0;
81 virtual SyscallDesc *getDesc(int callnum) = 0;
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 void pgid(uint64_t pgid) { _pgid = pgid; }
91 inline uint64_t tgid() { return _tgid; }
93 const char *progName() const { return executable.c_str(); }
96 * Find an emulated device driver.
98 * @param filename Name of the device (under /dev)
99 * @return Pointer to driver object if found, else nullptr
101 EmulatedDriver *findDriver(std::string filename);
103 // This function acts as a callback to update the bias value in
104 // the object file because the parameters needed to calculate the
105 // bias are not available when the object file is created.
109 ObjectFile *getInterpreter();
111 // override of virtual SimObject method: register statistics
112 void regStats() override;
114 void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
116 /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
117 /// @return Whether the fault has been fixed.
118 bool fixupStackFault(Addr vaddr);
120 // After getting registered with system object, tell process which
121 // system-wide context id it is assigned.
123 assignThreadContext(ContextID context_id)
125 contextIds.push_back(context_id);
128 // Find a free context to use
129 ThreadContext *findFreeContext();
132 * After delegating a thread context to a child process
133 * no longer should relate to the ThreadContext
135 void revokeThreadContext(int context_id);
138 * Does mmap region grow upward or downward from mmapEnd? Most
139 * platforms grow downward, but a few (such as Alpha) grow upward
140 * instead, so they can override this method to return false.
142 virtual bool mmapGrowsDown() const { return true; }
145 * Maps a contiguous range of virtual addresses in this process's
146 * address space to a contiguous range of physical addresses.
147 * This function exists primarily to expose the map operation to
148 * python, so that configuration scripts can set up mappings in SE mode.
150 * @param vaddr The starting virtual address of the range.
151 * @param paddr The starting physical address of the range.
152 * @param size The length of the range in bytes.
153 * @param cacheable Specifies whether accesses are cacheable.
154 * @return True if the map operation was successful. (At this
155 * point in time, the map operation always succeeds.)
157 bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
159 void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
160 ThreadContext *new_tc, bool alloc_page);
162 virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
163 Process *new_p, RegVal flags);
165 // thread contexts associated with this process
166 std::vector<ContextID> contextIds;
168 // system object which owns this process
171 Stats::Scalar numSyscalls; // track how many system calls are executed
173 // flag for using architecture specific page table
175 // running KVM requires special initialization
177 // flag for using the process as a thread which shares page tables
180 EmulationPageTable *pTable;
182 SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
185 std::vector<std::string> argv;
186 std::vector<std::string> envp;
187 std::string executable;
190 * Return an absolute path given a relative path paired with the current
191 * working directory of the process running under simulation.
193 * @param path The relative path (generally a filename) that needs the
194 * current working directory prepended.
195 * @param host_fs A flag which determines whether to return a
196 * path for the host filesystem or the filesystem of the process running
197 * under simulation. Only matters if filesysem redirection is used to
198 * replace files (or directories) that would normally appear via the
200 * @return String containing an absolute path.
202 std::string absolutePath(const std::string &path, bool host_fs);
205 * Redirect file path if it matches any keys initialized by system object.
206 * @param filename An input parameter containing either a relative path
207 * or an absolute path. If given a relative path, the path will be
208 * prepended to the current working directory of the simulation with
209 * respect to the host filesystem.
210 * @return String containing an absolute path.
212 std::string checkPathRedirect(const std::string &filename);
215 * The cwd members are used to track changes to the current working
216 * directory for the purpose of executing system calls which depend on
217 * relative paths (i.e. open, chdir).
219 * The tgt member and host member may differ if the path for the current
220 * working directory is redirected to point to a different location
221 * (i.e. `cd /proc` should point to '$(gem5_repo)/m5out/fs/proc'
222 * instead of '/proc').
227 // Syscall emulation uname release.
230 // Id of the owner of the process
236 // pid of the process and it's parent
242 // Emulated drivers available to this process
243 std::vector<EmulatedDriver *> drivers;
245 std::shared_ptr<FDArray> fds;
248 std::shared_ptr<MemState> memState;
251 * Calls a futex wakeup at the address specified by this pointer when
252 * this process exits.
254 uint64_t childClearTID;
256 // Process was forked with SIGCHLD set.
260 #endif // __PROCESS_HH__