process.hh revision 11886
12SN/A/* 211856Sbrandon.potter@amd.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 31762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 42SN/A * All rights reserved. 52SN/A * 62SN/A * Redistribution and use in source and binary forms, with or without 72SN/A * modification, are permitted provided that the following conditions are 82SN/A * met: redistributions of source code must retain the above copyright 92SN/A * notice, this list of conditions and the following disclaimer; 102SN/A * redistributions in binary form must reproduce the above copyright 112SN/A * notice, this list of conditions and the following disclaimer in the 122SN/A * documentation and/or other materials provided with the distribution; 132SN/A * neither the name of the copyright holders nor the names of its 142SN/A * contributors may be used to endorse or promote products derived from 152SN/A * this software without specific prior written permission. 162SN/A * 172SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 302665Ssaidi@eecs.umich.edu * Steve Reinhardt 3111856Sbrandon.potter@amd.com * Brandon Potter 322SN/A */ 332SN/A 34360SN/A#ifndef __PROCESS_HH__ 35360SN/A#define __PROCESS_HH__ 362SN/A 3711854Sbrandon.potter@amd.com#include <inttypes.h> 3811854Sbrandon.potter@amd.com 3911800Sbrandon.potter@amd.com#include <map> 404117Sgblack@eecs.umich.edu#include <string> 41180SN/A#include <vector> 422SN/A 436329Sgblack@eecs.umich.edu#include "arch/registers.hh" 442378SN/A#include "base/statistics.hh" 456214Snate@binkert.org#include "base/types.hh" 466658Snate@binkert.org#include "config/the_isa.hh" 478852Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh" 4811856Sbrandon.potter@amd.com#include "sim/fd_array.hh" 4910930Sbrandon.potter@amd.com#include "sim/fd_entry.hh" 5056SN/A#include "sim/sim_object.hh" 512SN/A 528737Skoansin.tan@gmail.comstruct ProcessParams; 5311800Sbrandon.potter@amd.com 5411800Sbrandon.potter@amd.comclass EmulatedDriver; 5511851Sbrandon.potter@amd.comclass ObjectFile; 5611800Sbrandon.potter@amd.comclass PageTableBase; 575154Sgblack@eecs.umich.educlass SyscallDesc; 5811800Sbrandon.potter@amd.comclass SyscallReturn; 595154Sgblack@eecs.umich.educlass System; 602680Sktlim@umich.educlass ThreadContext; 612378SN/A 622SN/Aclass Process : public SimObject 632SN/A{ 642SN/A public: 652SN/A struct WaitRec 662SN/A { 672SN/A Addr waitChan; 682680Sktlim@umich.edu ThreadContext *waitingContext; 692SN/A 702680Sktlim@umich.edu WaitRec(Addr chan, ThreadContext *ctx) 712SN/A : waitChan(chan), waitingContext(ctx) 7211854Sbrandon.potter@amd.com { } 732SN/A }; 742SN/A 7511886Sbrandon.potter@amd.com struct MemState 7611886Sbrandon.potter@amd.com { 7711886Sbrandon.potter@amd.com Addr brkPoint; 7811886Sbrandon.potter@amd.com Addr stackBase; 7911886Sbrandon.potter@amd.com unsigned stackSize; 8011886Sbrandon.potter@amd.com Addr stackMin; 8111886Sbrandon.potter@amd.com Addr nextThreadStackBase; 8211886Sbrandon.potter@amd.com Addr mmapEnd; 8311886Sbrandon.potter@amd.com 8411886Sbrandon.potter@amd.com MemState() 8511886Sbrandon.potter@amd.com : brkPoint(0), stackBase(0), stackSize(0), stackMin(0), 8611886Sbrandon.potter@amd.com nextThreadStackBase(0), mmapEnd(0) 8711886Sbrandon.potter@amd.com { } 8811886Sbrandon.potter@amd.com 8911886Sbrandon.potter@amd.com MemState& 9011886Sbrandon.potter@amd.com operator=(const MemState &in) 9111886Sbrandon.potter@amd.com { 9211886Sbrandon.potter@amd.com if (this == &in) 9311886Sbrandon.potter@amd.com return *this; 9411886Sbrandon.potter@amd.com 9511886Sbrandon.potter@amd.com brkPoint = in.brkPoint; 9611886Sbrandon.potter@amd.com stackBase = in.stackBase; 9711886Sbrandon.potter@amd.com stackSize = in.stackSize; 9811886Sbrandon.potter@amd.com stackMin = in.stackMin; 9911886Sbrandon.potter@amd.com nextThreadStackBase = in.nextThreadStackBase; 10011886Sbrandon.potter@amd.com mmapEnd = in.mmapEnd; 10111886Sbrandon.potter@amd.com return *this; 10211886Sbrandon.potter@amd.com } 10311886Sbrandon.potter@amd.com 10411886Sbrandon.potter@amd.com void serialize(CheckpointOut &cp) const; 10511886Sbrandon.potter@amd.com void unserialize(CheckpointIn &cp); 10611886Sbrandon.potter@amd.com }; 10711886Sbrandon.potter@amd.com 10811854Sbrandon.potter@amd.com Process(ProcessParams *params, ObjectFile *obj_file); 1092SN/A 11011854Sbrandon.potter@amd.com void serialize(CheckpointOut &cp) const override; 11111854Sbrandon.potter@amd.com void unserialize(CheckpointIn &cp) override; 1122SN/A 11311169Sandreas.hansson@arm.com void initState() override; 11411168Sandreas.hansson@arm.com DrainState drain() override; 11510905Sandreas.sandberg@arm.com 11611877Sbrandon.potter@amd.com void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 11711854Sbrandon.potter@amd.com virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0; 11811854Sbrandon.potter@amd.com virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); 11911854Sbrandon.potter@amd.com virtual void setSyscallArg(ThreadContext *tc, int i, 12011854Sbrandon.potter@amd.com TheISA::IntReg val) = 0; 12111854Sbrandon.potter@amd.com virtual void setSyscallReturn(ThreadContext *tc, 12211854Sbrandon.potter@amd.com SyscallReturn return_value) = 0; 12311854Sbrandon.potter@amd.com virtual SyscallDesc *getDesc(int callnum) = 0; 1242SN/A 12511854Sbrandon.potter@amd.com inline uint64_t uid() { return _uid; } 12611854Sbrandon.potter@amd.com inline uint64_t euid() { return _euid; } 12711854Sbrandon.potter@amd.com inline uint64_t gid() { return _gid; } 12811854Sbrandon.potter@amd.com inline uint64_t egid() { return _egid; } 12911854Sbrandon.potter@amd.com inline uint64_t pid() { return _pid; } 13011854Sbrandon.potter@amd.com inline uint64_t ppid() { return _ppid; } 13111885Sbrandon.potter@amd.com inline uint64_t pgid() { return _pgid; } 13211885Sbrandon.potter@amd.com inline uint64_t tgid() { return _tgid; } 13311885Sbrandon.potter@amd.com inline void setpgid(uint64_t pgid) { _pgid = pgid; } 13410554Salexandru.dutu@amd.com 13511854Sbrandon.potter@amd.com const char *progName() const { return executable.c_str(); } 13611854Sbrandon.potter@amd.com std::string fullPath(const std::string &filename); 13711854Sbrandon.potter@amd.com std::string getcwd() const { return cwd; } 1388852Sandreas.hansson@arm.com 13911854Sbrandon.potter@amd.com /** 14011854Sbrandon.potter@amd.com * Find an emulated device driver. 14111854Sbrandon.potter@amd.com * 14211854Sbrandon.potter@amd.com * @param filename Name of the device (under /dev) 14311854Sbrandon.potter@amd.com * @return Pointer to driver object if found, else NULL 14411854Sbrandon.potter@amd.com */ 14511854Sbrandon.potter@amd.com EmulatedDriver *findDriver(std::string filename); 1468852Sandreas.hansson@arm.com 14711854Sbrandon.potter@amd.com // This function acts as a callback to update the bias value in 14811854Sbrandon.potter@amd.com // the object file because the parameters needed to calculate the 14911854Sbrandon.potter@amd.com // bias are not available when the object file is created. 15011854Sbrandon.potter@amd.com void updateBias(); 15111854Sbrandon.potter@amd.com Addr getBias(); 15211854Sbrandon.potter@amd.com Addr getStartPC(); 15311854Sbrandon.potter@amd.com ObjectFile *getInterpreter(); 1545282Srstrong@cs.ucsd.edu 1552SN/A // override of virtual SimObject method: register statistics 15611169Sandreas.hansson@arm.com void regStats() override; 1572SN/A 1588601Ssteve.reinhardt@amd.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1598601Ssteve.reinhardt@amd.com 1608539Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1618539Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 1628539Sgblack@eecs.umich.edu bool fixupStackFault(Addr vaddr); 1634434Ssaidi@eecs.umich.edu 16411854Sbrandon.potter@amd.com // After getting registered with system object, tell process which 16511854Sbrandon.potter@amd.com // system-wide context id it is assigned. 16611854Sbrandon.potter@amd.com void 16711854Sbrandon.potter@amd.com assignThreadContext(ContextID context_id) 16811854Sbrandon.potter@amd.com { 16911854Sbrandon.potter@amd.com contextIds.push_back(context_id); 17011854Sbrandon.potter@amd.com } 17111854Sbrandon.potter@amd.com 17211854Sbrandon.potter@amd.com // Find a free context to use 17311854Sbrandon.potter@amd.com ThreadContext *findFreeContext(); 17411854Sbrandon.potter@amd.com 17511854Sbrandon.potter@amd.com /** 17611886Sbrandon.potter@amd.com * After delegating a thread context to a child process 17711886Sbrandon.potter@amd.com * no longer should relate to the ThreadContext 17811886Sbrandon.potter@amd.com */ 17911886Sbrandon.potter@amd.com void revokeThreadContext(int context_id); 18011886Sbrandon.potter@amd.com 18111886Sbrandon.potter@amd.com /** 18211886Sbrandon.potter@amd.com * Does mmap region grow upward or downward from mmapEnd? Most 18311854Sbrandon.potter@amd.com * platforms grow downward, but a few (such as Alpha) grow upward 18411854Sbrandon.potter@amd.com * instead, so they can override this method to return false. 18511854Sbrandon.potter@amd.com */ 18611854Sbrandon.potter@amd.com virtual bool mmapGrowsDown() const { return true; } 18711854Sbrandon.potter@amd.com 1889110Ssteve.reinhardt@amd.com /** 18910558Salexandru.dutu@amd.com * Maps a contiguous range of virtual addresses in this process's 1909110Ssteve.reinhardt@amd.com * address space to a contiguous range of physical addresses. 19110558Salexandru.dutu@amd.com * This function exists primarily to expose the map operation to 19210558Salexandru.dutu@amd.com * python, so that configuration scripts can set up mappings in SE mode. 1939110Ssteve.reinhardt@amd.com * 1949110Ssteve.reinhardt@amd.com * @param vaddr The starting virtual address of the range. 1959110Ssteve.reinhardt@amd.com * @param paddr The starting physical address of the range. 1969110Ssteve.reinhardt@amd.com * @param size The length of the range in bytes. 19710558Salexandru.dutu@amd.com * @param cacheable Specifies whether accesses are cacheable. 1989110Ssteve.reinhardt@amd.com * @return True if the map operation was successful. (At this 1999110Ssteve.reinhardt@amd.com * point in time, the map operation always succeeds.) 2009110Ssteve.reinhardt@amd.com */ 20110558Salexandru.dutu@amd.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 2029110Ssteve.reinhardt@amd.com 20311886Sbrandon.potter@amd.com void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, 20411886Sbrandon.potter@amd.com ThreadContext *new_tc, bool alloc_page); 20511886Sbrandon.potter@amd.com 20611886Sbrandon.potter@amd.com void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, 20711886Sbrandon.potter@amd.com TheISA::IntReg flags); 20811886Sbrandon.potter@amd.com 20911854Sbrandon.potter@amd.com // list of all blocked contexts 21011854Sbrandon.potter@amd.com std::list<WaitRec> waitList; 21111801Sbrandon.potter@amd.com 21211854Sbrandon.potter@amd.com // thread contexts associated with this process 21311854Sbrandon.potter@amd.com std::vector<ContextID> contextIds; 21411854Sbrandon.potter@amd.com 21511854Sbrandon.potter@amd.com // system object which owns this process 21611854Sbrandon.potter@amd.com System *system; 21711854Sbrandon.potter@amd.com 21811886Sbrandon.potter@amd.com Stats::Scalar numSyscalls; // track how many system calls are executed 21911854Sbrandon.potter@amd.com 22011854Sbrandon.potter@amd.com bool useArchPT; // flag for using architecture specific page table 22111854Sbrandon.potter@amd.com bool kvmInSE; // running KVM requires special initialization 22211854Sbrandon.potter@amd.com 22311854Sbrandon.potter@amd.com PageTableBase* pTable; 22411854Sbrandon.potter@amd.com 22511854Sbrandon.potter@amd.com SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 22611854Sbrandon.potter@amd.com 22711851Sbrandon.potter@amd.com ObjectFile *objFile; 22811851Sbrandon.potter@amd.com std::vector<std::string> argv; 22911851Sbrandon.potter@amd.com std::vector<std::string> envp; 23011851Sbrandon.potter@amd.com std::string cwd; 23111851Sbrandon.potter@amd.com std::string executable; 23211851Sbrandon.potter@amd.com 23311801Sbrandon.potter@amd.com // Id of the owner of the process 23411801Sbrandon.potter@amd.com uint64_t _uid; 23511801Sbrandon.potter@amd.com uint64_t _euid; 23611801Sbrandon.potter@amd.com uint64_t _gid; 23711801Sbrandon.potter@amd.com uint64_t _egid; 23811801Sbrandon.potter@amd.com 23911801Sbrandon.potter@amd.com // pid of the process and it's parent 24011801Sbrandon.potter@amd.com uint64_t _pid; 24111801Sbrandon.potter@amd.com uint64_t _ppid; 24211885Sbrandon.potter@amd.com uint64_t _pgid; 24311885Sbrandon.potter@amd.com uint64_t _tgid; 24411801Sbrandon.potter@amd.com 24510496Ssteve.reinhardt@amd.com // Emulated drivers available to this process 24610496Ssteve.reinhardt@amd.com std::vector<EmulatedDriver *> drivers; 24711856Sbrandon.potter@amd.com 24811856Sbrandon.potter@amd.com std::shared_ptr<FDArray> fds; 24911886Sbrandon.potter@amd.com 25011886Sbrandon.potter@amd.com bool *exitGroup; 25111886Sbrandon.potter@amd.com 25211886Sbrandon.potter@amd.com Addr maxStackSize; 25311886Sbrandon.potter@amd.com MemState *memState; 25411886Sbrandon.potter@amd.com 25511886Sbrandon.potter@amd.com /** 25611886Sbrandon.potter@amd.com * Calls a futex wakeup at the address specified by this pointer when 25711886Sbrandon.potter@amd.com * this process exits. 25811886Sbrandon.potter@amd.com */ 25911886Sbrandon.potter@amd.com uint64_t childClearTID; 26011886Sbrandon.potter@amd.com 26111886Sbrandon.potter@amd.com // Process was forked with SIGCHLD set. 26211886Sbrandon.potter@amd.com bool *sigchld; 2632SN/A}; 2642SN/A 265360SN/A#endif // __PROCESS_HH__ 266