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/sim_object.hh"
62 class Process : public SimObject
68 ThreadContext *waitingContext;
70 WaitRec(Addr chan, ThreadContext *ctx)
71 : waitChan(chan), waitingContext(ctx)
75 Process(ProcessParams *params, ObjectFile *obj_file);
77 void serialize(CheckpointOut &cp) const override;
78 void unserialize(CheckpointIn &cp) override;
80 void initState() override;
81 DrainState drain() override;
83 void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
84 virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
85 virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
86 virtual void setSyscallArg(ThreadContext *tc, int i,
87 TheISA::IntReg val) = 0;
88 virtual void setSyscallReturn(ThreadContext *tc,
89 SyscallReturn return_value) = 0;
90 virtual SyscallDesc *getDesc(int callnum) = 0;
92 inline uint64_t uid() { return _uid; }
93 inline uint64_t euid() { return _euid; }
94 inline uint64_t gid() { return _gid; }
95 inline uint64_t egid() { return _egid; }
96 inline uint64_t pid() { return _pid; }
97 inline uint64_t ppid() { return _ppid; }
98 inline uint64_t pgid() { return _pgid; }
99 inline uint64_t tgid() { return _tgid; }
100 inline void setpgid(uint64_t pgid) { _pgid = pgid; }
102 const char *progName() const { return executable.c_str(); }
103 std::string fullPath(const std::string &filename);
104 std::string getcwd() const { return cwd; }
107 * Find an emulated device driver.
109 * @param filename Name of the device (under /dev)
110 * @return Pointer to driver object if found, else NULL
112 EmulatedDriver *findDriver(std::string filename);
114 // This function acts as a callback to update the bias value in
115 // the object file because the parameters needed to calculate the
116 // bias are not available when the object file is created.
120 ObjectFile *getInterpreter();
122 // override of virtual SimObject method: register statistics
123 void regStats() override;
125 void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
127 /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
128 /// @return Whether the fault has been fixed.
129 bool fixupStackFault(Addr vaddr);
131 // After getting registered with system object, tell process which
132 // system-wide context id it is assigned.
134 assignThreadContext(ContextID context_id)
136 contextIds.push_back(context_id);
139 // Find a free context to use
140 ThreadContext *findFreeContext();
143 * Does mmap region grow upward or downward from mmap_end? Most
144 * platforms grow downward, but a few (such as Alpha) grow upward
145 * instead, so they can override this method to return false.
147 virtual bool mmapGrowsDown() const { return true; }
150 * Maps a contiguous range of virtual addresses in this process's
151 * address space to a contiguous range of physical addresses.
152 * This function exists primarily to expose the map operation to
153 * python, so that configuration scripts can set up mappings in SE mode.
155 * @param vaddr The starting virtual address of the range.
156 * @param paddr The starting physical address of the range.
157 * @param size The length of the range in bytes.
158 * @param cacheable Specifies whether accesses are cacheable.
159 * @return True if the map operation was successful. (At this
160 * point in time, the map operation always succeeds.)
162 bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
164 // list of all blocked contexts
165 std::list<WaitRec> waitList;
167 // thread contexts associated with this process
168 std::vector<ContextID> contextIds;
170 // system object which owns this process
173 Addr brk_point; // top of the data segment
174 Addr stack_base; // stack segment base
175 unsigned stack_size; // initial stack size
176 Addr stack_min; // furthest address accessed from stack base
177 Addr max_stack_size; // the maximum size allowed for the stack
178 Addr next_thread_stack_base; // addr for next region w/ multithreaded apps
179 Addr mmap_end; // base of automatic mmap region allocs
181 Stats::Scalar num_syscalls; // track how many system calls are executed
183 bool useArchPT; // flag for using architecture specific page table
184 bool kvmInSE; // running KVM requires special initialization
186 PageTableBase* pTable;
188 SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
191 std::vector<std::string> argv;
192 std::vector<std::string> envp;
194 std::string executable;
196 // Id of the owner of the process
202 // pid of the process and it's parent
208 // Emulated drivers available to this process
209 std::vector<EmulatedDriver *> drivers;
211 std::shared_ptr<FDArray> fds;
214 #endif // __PROCESS_HH__