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" 5011905SBrandon.Potter@amd.com#include "sim/mem_state.hh" 5156SN/A#include "sim/sim_object.hh" 522SN/A 538737Skoansin.tan@gmail.comstruct ProcessParams; 5411800Sbrandon.potter@amd.com 5511800Sbrandon.potter@amd.comclass EmulatedDriver; 5611851Sbrandon.potter@amd.comclass ObjectFile; 5712448Sgabeblack@google.comclass EmulationPageTable; 585154Sgblack@eecs.umich.educlass SyscallDesc; 5911800Sbrandon.potter@amd.comclass SyscallReturn; 605154Sgblack@eecs.umich.educlass System; 612680Sktlim@umich.educlass ThreadContext; 622378SN/A 632SN/Aclass Process : public SimObject 642SN/A{ 652SN/A public: 6612448Sgabeblack@google.com Process(ProcessParams *params, EmulationPageTable *pTable, 6712431Sgabeblack@google.com ObjectFile *obj_file); 682SN/A 6911854Sbrandon.potter@amd.com void serialize(CheckpointOut &cp) const override; 7011854Sbrandon.potter@amd.com void unserialize(CheckpointIn &cp) override; 712SN/A 7211169Sandreas.hansson@arm.com void initState() override; 7311168Sandreas.hansson@arm.com DrainState drain() override; 7410905Sandreas.sandberg@arm.com 7512044Sgabeblack@google.com virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 7613557Sgabeblack@google.com virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0; 7713557Sgabeblack@google.com virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width); 7813557Sgabeblack@google.com virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0; 7911854Sbrandon.potter@amd.com virtual void setSyscallReturn(ThreadContext *tc, 8011854Sbrandon.potter@amd.com SyscallReturn return_value) = 0; 8111854Sbrandon.potter@amd.com virtual SyscallDesc *getDesc(int callnum) = 0; 822SN/A 8311854Sbrandon.potter@amd.com inline uint64_t uid() { return _uid; } 8411854Sbrandon.potter@amd.com inline uint64_t euid() { return _euid; } 8511854Sbrandon.potter@amd.com inline uint64_t gid() { return _gid; } 8611854Sbrandon.potter@amd.com inline uint64_t egid() { return _egid; } 8711854Sbrandon.potter@amd.com inline uint64_t pid() { return _pid; } 8811854Sbrandon.potter@amd.com inline uint64_t ppid() { return _ppid; } 8911885Sbrandon.potter@amd.com inline uint64_t pgid() { return _pgid; } 9014149Sbrandon.potter@amd.com inline void pgid(uint64_t pgid) { _pgid = pgid; } 9111885Sbrandon.potter@amd.com inline uint64_t tgid() { return _tgid; } 9210554Salexandru.dutu@amd.com 9311854Sbrandon.potter@amd.com const char *progName() const { return executable.c_str(); } 948852Sandreas.hansson@arm.com 9511854Sbrandon.potter@amd.com /** 9611854Sbrandon.potter@amd.com * Find an emulated device driver. 9711854Sbrandon.potter@amd.com * 9811854Sbrandon.potter@amd.com * @param filename Name of the device (under /dev) 9911919SBrandon.Potter@amd.com * @return Pointer to driver object if found, else nullptr 10011854Sbrandon.potter@amd.com */ 10111854Sbrandon.potter@amd.com EmulatedDriver *findDriver(std::string filename); 1028852Sandreas.hansson@arm.com 10311854Sbrandon.potter@amd.com // This function acts as a callback to update the bias value in 10411854Sbrandon.potter@amd.com // the object file because the parameters needed to calculate the 10511854Sbrandon.potter@amd.com // bias are not available when the object file is created. 10611854Sbrandon.potter@amd.com void updateBias(); 10711854Sbrandon.potter@amd.com Addr getBias(); 10811854Sbrandon.potter@amd.com Addr getStartPC(); 10911854Sbrandon.potter@amd.com ObjectFile *getInterpreter(); 1105282Srstrong@cs.ucsd.edu 1112SN/A // override of virtual SimObject method: register statistics 11211169Sandreas.hansson@arm.com void regStats() override; 1132SN/A 1148601Ssteve.reinhardt@amd.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1158601Ssteve.reinhardt@amd.com 1168539Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1178539Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 1188539Sgblack@eecs.umich.edu bool fixupStackFault(Addr vaddr); 1194434Ssaidi@eecs.umich.edu 12011854Sbrandon.potter@amd.com // After getting registered with system object, tell process which 12111854Sbrandon.potter@amd.com // system-wide context id it is assigned. 12211854Sbrandon.potter@amd.com void 12311854Sbrandon.potter@amd.com assignThreadContext(ContextID context_id) 12411854Sbrandon.potter@amd.com { 12511854Sbrandon.potter@amd.com contextIds.push_back(context_id); 12611854Sbrandon.potter@amd.com } 12711854Sbrandon.potter@amd.com 12811854Sbrandon.potter@amd.com // Find a free context to use 12911854Sbrandon.potter@amd.com ThreadContext *findFreeContext(); 13011854Sbrandon.potter@amd.com 13111854Sbrandon.potter@amd.com /** 13211886Sbrandon.potter@amd.com * After delegating a thread context to a child process 13311886Sbrandon.potter@amd.com * no longer should relate to the ThreadContext 13411886Sbrandon.potter@amd.com */ 13511886Sbrandon.potter@amd.com void revokeThreadContext(int context_id); 13611886Sbrandon.potter@amd.com 13711886Sbrandon.potter@amd.com /** 13811886Sbrandon.potter@amd.com * Does mmap region grow upward or downward from mmapEnd? Most 13911854Sbrandon.potter@amd.com * platforms grow downward, but a few (such as Alpha) grow upward 14011854Sbrandon.potter@amd.com * instead, so they can override this method to return false. 14111854Sbrandon.potter@amd.com */ 14211854Sbrandon.potter@amd.com virtual bool mmapGrowsDown() const { return true; } 14311854Sbrandon.potter@amd.com 1449110Ssteve.reinhardt@amd.com /** 14510558Salexandru.dutu@amd.com * Maps a contiguous range of virtual addresses in this process's 1469110Ssteve.reinhardt@amd.com * address space to a contiguous range of physical addresses. 14710558Salexandru.dutu@amd.com * This function exists primarily to expose the map operation to 14810558Salexandru.dutu@amd.com * python, so that configuration scripts can set up mappings in SE mode. 1499110Ssteve.reinhardt@amd.com * 1509110Ssteve.reinhardt@amd.com * @param vaddr The starting virtual address of the range. 1519110Ssteve.reinhardt@amd.com * @param paddr The starting physical address of the range. 1529110Ssteve.reinhardt@amd.com * @param size The length of the range in bytes. 15310558Salexandru.dutu@amd.com * @param cacheable Specifies whether accesses are cacheable. 1549110Ssteve.reinhardt@amd.com * @return True if the map operation was successful. (At this 1559110Ssteve.reinhardt@amd.com * point in time, the map operation always succeeds.) 1569110Ssteve.reinhardt@amd.com */ 15710558Salexandru.dutu@amd.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 1589110Ssteve.reinhardt@amd.com 15911886Sbrandon.potter@amd.com void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, 16011886Sbrandon.potter@amd.com ThreadContext *new_tc, bool alloc_page); 16111886Sbrandon.potter@amd.com 16212141Sspwilson2@wisc.edu virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, 16313557Sgabeblack@google.com Process *new_p, RegVal flags); 16411886Sbrandon.potter@amd.com 16511854Sbrandon.potter@amd.com // thread contexts associated with this process 16611854Sbrandon.potter@amd.com std::vector<ContextID> contextIds; 16711854Sbrandon.potter@amd.com 16811854Sbrandon.potter@amd.com // system object which owns this process 16911854Sbrandon.potter@amd.com System *system; 17011854Sbrandon.potter@amd.com 17111886Sbrandon.potter@amd.com Stats::Scalar numSyscalls; // track how many system calls are executed 17211854Sbrandon.potter@amd.com 17313867Salexandru.dutu@amd.com // flag for using architecture specific page table 17413867Salexandru.dutu@amd.com bool useArchPT; 17513867Salexandru.dutu@amd.com // running KVM requires special initialization 17613867Salexandru.dutu@amd.com bool kvmInSE; 17713867Salexandru.dutu@amd.com // flag for using the process as a thread which shares page tables 17813867Salexandru.dutu@amd.com bool useForClone; 17911854Sbrandon.potter@amd.com 18012448Sgabeblack@google.com EmulationPageTable *pTable; 18111854Sbrandon.potter@amd.com 18211854Sbrandon.potter@amd.com SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 18311854Sbrandon.potter@amd.com 18411851Sbrandon.potter@amd.com ObjectFile *objFile; 18511851Sbrandon.potter@amd.com std::vector<std::string> argv; 18611851Sbrandon.potter@amd.com std::vector<std::string> envp; 18711851Sbrandon.potter@amd.com std::string executable; 18811851Sbrandon.potter@amd.com 18913883Sdavid.hashe@amd.com /** 19013883Sdavid.hashe@amd.com * Return an absolute path given a relative path paired with the current 19113883Sdavid.hashe@amd.com * working directory of the process running under simulation. 19213883Sdavid.hashe@amd.com * 19313883Sdavid.hashe@amd.com * @param path The relative path (generally a filename) that needs the 19413883Sdavid.hashe@amd.com * current working directory prepended. 19513883Sdavid.hashe@amd.com * @param host_fs A flag which determines whether to return a 19613883Sdavid.hashe@amd.com * path for the host filesystem or the filesystem of the process running 19713883Sdavid.hashe@amd.com * under simulation. Only matters if filesysem redirection is used to 19813883Sdavid.hashe@amd.com * replace files (or directories) that would normally appear via the 19913883Sdavid.hashe@amd.com * host filesystem. 20013883Sdavid.hashe@amd.com * @return String containing an absolute path. 20113883Sdavid.hashe@amd.com */ 20213883Sdavid.hashe@amd.com std::string absolutePath(const std::string &path, bool host_fs); 20313883Sdavid.hashe@amd.com 20413883Sdavid.hashe@amd.com /** 20513883Sdavid.hashe@amd.com * Redirect file path if it matches any keys initialized by system object. 20613883Sdavid.hashe@amd.com * @param filename An input parameter containing either a relative path 20713883Sdavid.hashe@amd.com * or an absolute path. If given a relative path, the path will be 20813883Sdavid.hashe@amd.com * prepended to the current working directory of the simulation with 20913883Sdavid.hashe@amd.com * respect to the host filesystem. 21013883Sdavid.hashe@amd.com * @return String containing an absolute path. 21113883Sdavid.hashe@amd.com */ 21213883Sdavid.hashe@amd.com std::string checkPathRedirect(const std::string &filename); 21313883Sdavid.hashe@amd.com 21413883Sdavid.hashe@amd.com /** 21513883Sdavid.hashe@amd.com * The cwd members are used to track changes to the current working 21613883Sdavid.hashe@amd.com * directory for the purpose of executing system calls which depend on 21713883Sdavid.hashe@amd.com * relative paths (i.e. open, chdir). 21813883Sdavid.hashe@amd.com * 21913883Sdavid.hashe@amd.com * The tgt member and host member may differ if the path for the current 22013883Sdavid.hashe@amd.com * working directory is redirected to point to a different location 22113883Sdavid.hashe@amd.com * (i.e. `cd /proc` should point to '$(gem5_repo)/m5out/fs/proc' 22213883Sdavid.hashe@amd.com * instead of '/proc'). 22313883Sdavid.hashe@amd.com */ 22413883Sdavid.hashe@amd.com std::string tgtCwd; 22513883Sdavid.hashe@amd.com std::string hostCwd; 22613883Sdavid.hashe@amd.com 22714014Sciro.santilli@arm.com // Syscall emulation uname release. 22814014Sciro.santilli@arm.com std::string release; 22914014Sciro.santilli@arm.com 23011801Sbrandon.potter@amd.com // Id of the owner of the process 23111801Sbrandon.potter@amd.com uint64_t _uid; 23211801Sbrandon.potter@amd.com uint64_t _euid; 23311801Sbrandon.potter@amd.com uint64_t _gid; 23411801Sbrandon.potter@amd.com uint64_t _egid; 23511801Sbrandon.potter@amd.com 23611801Sbrandon.potter@amd.com // pid of the process and it's parent 23711801Sbrandon.potter@amd.com uint64_t _pid; 23811801Sbrandon.potter@amd.com uint64_t _ppid; 23911885Sbrandon.potter@amd.com uint64_t _pgid; 24011885Sbrandon.potter@amd.com uint64_t _tgid; 24111801Sbrandon.potter@amd.com 24210496Ssteve.reinhardt@amd.com // Emulated drivers available to this process 24310496Ssteve.reinhardt@amd.com std::vector<EmulatedDriver *> drivers; 24411856Sbrandon.potter@amd.com 24511856Sbrandon.potter@amd.com std::shared_ptr<FDArray> fds; 24611886Sbrandon.potter@amd.com 24711886Sbrandon.potter@amd.com bool *exitGroup; 24811905SBrandon.Potter@amd.com std::shared_ptr<MemState> memState; 24911886Sbrandon.potter@amd.com 25011886Sbrandon.potter@amd.com /** 25111886Sbrandon.potter@amd.com * Calls a futex wakeup at the address specified by this pointer when 25211886Sbrandon.potter@amd.com * this process exits. 25311886Sbrandon.potter@amd.com */ 25411886Sbrandon.potter@amd.com uint64_t childClearTID; 25511886Sbrandon.potter@amd.com 25611886Sbrandon.potter@amd.com // Process was forked with SIGCHLD set. 25711886Sbrandon.potter@amd.com bool *sigchld; 2582SN/A}; 2592SN/A 260360SN/A#endif // __PROCESS_HH__ 261