process.hh revision 11885:79af314e9f0d
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" 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" 51 52struct ProcessParams; 53 54class EmulatedDriver; 55class ObjectFile; 56class PageTableBase; 57class SyscallDesc; 58class SyscallReturn; 59class System; 60class ThreadContext; 61 62class Process : public SimObject 63{ 64 public: 65 struct WaitRec 66 { 67 Addr waitChan; 68 ThreadContext *waitingContext; 69 70 WaitRec(Addr chan, ThreadContext *ctx) 71 : waitChan(chan), waitingContext(ctx) 72 { } 73 }; 74 75 Process(ProcessParams *params, ObjectFile *obj_file); 76 77 void serialize(CheckpointOut &cp) const override; 78 void unserialize(CheckpointIn &cp) override; 79 80 void initState() override; 81 DrainState drain() override; 82 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; 91 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; } 101 102 const char *progName() const { return executable.c_str(); } 103 std::string fullPath(const std::string &filename); 104 std::string getcwd() const { return cwd; } 105 106 /** 107 * Find an emulated device driver. 108 * 109 * @param filename Name of the device (under /dev) 110 * @return Pointer to driver object if found, else NULL 111 */ 112 EmulatedDriver *findDriver(std::string filename); 113 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. 117 void updateBias(); 118 Addr getBias(); 119 Addr getStartPC(); 120 ObjectFile *getInterpreter(); 121 122 // override of virtual SimObject method: register statistics 123 void regStats() override; 124 125 void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 126 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); 130 131 // After getting registered with system object, tell process which 132 // system-wide context id it is assigned. 133 void 134 assignThreadContext(ContextID context_id) 135 { 136 contextIds.push_back(context_id); 137 } 138 139 // Find a free context to use 140 ThreadContext *findFreeContext(); 141 142 /** 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. 146 */ 147 virtual bool mmapGrowsDown() const { return true; } 148 149 /** 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. 154 * 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.) 161 */ 162 bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 163 164 // list of all blocked contexts 165 std::list<WaitRec> waitList; 166 167 // thread contexts associated with this process 168 std::vector<ContextID> contextIds; 169 170 // system object which owns this process 171 System *system; 172 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 180 181 Stats::Scalar num_syscalls; // track how many system calls are executed 182 183 bool useArchPT; // flag for using architecture specific page table 184 bool kvmInSE; // running KVM requires special initialization 185 186 PageTableBase* pTable; 187 188 SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 189 190 ObjectFile *objFile; 191 std::vector<std::string> argv; 192 std::vector<std::string> envp; 193 std::string cwd; 194 std::string executable; 195 196 // Id of the owner of the process 197 uint64_t _uid; 198 uint64_t _euid; 199 uint64_t _gid; 200 uint64_t _egid; 201 202 // pid of the process and it's parent 203 uint64_t _pid; 204 uint64_t _ppid; 205 uint64_t _pgid; 206 uint64_t _tgid; 207 208 // Emulated drivers available to this process 209 std::vector<EmulatedDriver *> drivers; 210 211 std::shared_ptr<FDArray> fds; 212}; 213 214#endif // __PROCESS_HH__ 215