process.hh revision 11877:5ea85692a53e
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 99 const char *progName() const { return executable.c_str(); } 100 std::string fullPath(const std::string &filename); 101 std::string getcwd() const { return cwd; } 102 103 /** 104 * Find an emulated device driver. 105 * 106 * @param filename Name of the device (under /dev) 107 * @return Pointer to driver object if found, else NULL 108 */ 109 EmulatedDriver *findDriver(std::string filename); 110 111 // This function acts as a callback to update the bias value in 112 // the object file because the parameters needed to calculate the 113 // bias are not available when the object file is created. 114 void updateBias(); 115 Addr getBias(); 116 Addr getStartPC(); 117 ObjectFile *getInterpreter(); 118 119 // override of virtual SimObject method: register statistics 120 void regStats() override; 121 122 void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 123 124 /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 125 /// @return Whether the fault has been fixed. 126 bool fixupStackFault(Addr vaddr); 127 128 // After getting registered with system object, tell process which 129 // system-wide context id it is assigned. 130 void 131 assignThreadContext(ContextID context_id) 132 { 133 contextIds.push_back(context_id); 134 } 135 136 // Find a free context to use 137 ThreadContext *findFreeContext(); 138 139 /** 140 * Does mmap region grow upward or downward from mmap_end? Most 141 * platforms grow downward, but a few (such as Alpha) grow upward 142 * instead, so they can override this method to return false. 143 */ 144 virtual bool mmapGrowsDown() const { return true; } 145 146 /** 147 * Maps a contiguous range of virtual addresses in this process's 148 * address space to a contiguous range of physical addresses. 149 * This function exists primarily to expose the map operation to 150 * python, so that configuration scripts can set up mappings in SE mode. 151 * 152 * @param vaddr The starting virtual address of the range. 153 * @param paddr The starting physical address of the range. 154 * @param size The length of the range in bytes. 155 * @param cacheable Specifies whether accesses are cacheable. 156 * @return True if the map operation was successful. (At this 157 * point in time, the map operation always succeeds.) 158 */ 159 bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 160 161 // list of all blocked contexts 162 std::list<WaitRec> waitList; 163 164 // thread contexts associated with this process 165 std::vector<ContextID> contextIds; 166 167 // system object which owns this process 168 System *system; 169 170 Addr brk_point; // top of the data segment 171 Addr stack_base; // stack segment base 172 unsigned stack_size; // initial stack size 173 Addr stack_min; // furthest address accessed from stack base 174 Addr max_stack_size; // the maximum size allowed for the stack 175 Addr next_thread_stack_base; // addr for next region w/ multithreaded apps 176 Addr mmap_end; // base of automatic mmap region allocs 177 178 Stats::Scalar num_syscalls; // track how many system calls are executed 179 180 bool useArchPT; // flag for using architecture specific page table 181 bool kvmInSE; // running KVM requires special initialization 182 183 PageTableBase* pTable; 184 185 SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 186 187 ObjectFile *objFile; 188 std::vector<std::string> argv; 189 std::vector<std::string> envp; 190 std::string cwd; 191 std::string executable; 192 193 // Id of the owner of the process 194 uint64_t _uid; 195 uint64_t _euid; 196 uint64_t _gid; 197 uint64_t _egid; 198 199 // pid of the process and it's parent 200 uint64_t _pid; 201 uint64_t _ppid; 202 203 // Emulated drivers available to this process 204 std::vector<EmulatedDriver *> drivers; 205 206 std::shared_ptr<FDArray> fds; 207}; 208 209#endif // __PROCESS_HH__ 210