process.hh revision 13617
12391SN/A/* 28931Sandreas.hansson@arm.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 37733SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 47733SN/A * All rights reserved. 57733SN/A * 67733SN/A * Redistribution and use in source and binary forms, with or without 77733SN/A * modification, are permitted provided that the following conditions are 87733SN/A * met: redistributions of source code must retain the above copyright 97733SN/A * notice, this list of conditions and the following disclaimer; 107733SN/A * redistributions in binary form must reproduce the above copyright 117733SN/A * notice, this list of conditions and the following disclaimer in the 127733SN/A * documentation and/or other materials provided with the distribution; 137733SN/A * neither the name of the copyright holders nor the names of its 142391SN/A * contributors may be used to endorse or promote products derived from 152391SN/A * this software without specific prior written permission. 162391SN/A * 172391SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182391SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192391SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202391SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212391SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222391SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232391SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242391SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252391SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262391SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272391SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282391SN/A * 292391SN/A * Authors: Nathan Binkert 302391SN/A * Steve Reinhardt 312391SN/A * Brandon Potter 322391SN/A */ 332391SN/A 342391SN/A#ifndef __PROCESS_HH__ 352391SN/A#define __PROCESS_HH__ 362391SN/A 372391SN/A#include <inttypes.h> 382391SN/A 392665SN/A#include <map> 402665SN/A#include <string> 412914SN/A#include <vector> 428931Sandreas.hansson@arm.com 432391SN/A#include "arch/registers.hh" 442391SN/A#include "base/statistics.hh" 458229SN/A#include "base/types.hh" 462391SN/A#include "config/the_isa.hh" 477730SN/A#include "mem/se_translating_port_proxy.hh" 482391SN/A#include "sim/fd_array.hh" 492391SN/A#include "sim/fd_entry.hh" 502391SN/A#include "sim/mem_state.hh" 512391SN/A#include "sim/sim_object.hh" 528229SN/A 536712SN/Astruct ProcessParams; 549203Smarco.elver@ed.ac.uk 552391SN/Aclass EmulatedDriver; 562391SN/Aclass ObjectFile; 572391SN/Aclass EmulationPageTable; 586329SN/Aclass SyscallDesc; 596658SN/Aclass SyscallReturn; 608232SN/Aclass System; 618232SN/Aclass ThreadContext; 628931Sandreas.hansson@arm.com 633879SN/Aclass Process : public SimObject 649053Sdam.sunwoo@arm.com{ 652394SN/A public: 662391SN/A Process(ProcessParams *params, EmulationPageTable *pTable, 672391SN/A ObjectFile *obj_file); 688931Sandreas.hansson@arm.com 698931Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 709053Sdam.sunwoo@arm.com void unserialize(CheckpointIn &cp) override; 719053Sdam.sunwoo@arm.com 722391SN/A void initState() override; 737730SN/A DrainState drain() override; 742391SN/A 752391SN/A virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 765477SN/A virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0; 775477SN/A virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width); 785477SN/A virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0; 797730SN/A virtual void setSyscallReturn(ThreadContext *tc, 807730SN/A SyscallReturn return_value) = 0; 817730SN/A virtual SyscallDesc *getDesc(int callnum) = 0; 827730SN/A 837730SN/A inline uint64_t uid() { return _uid; } 847730SN/A inline uint64_t euid() { return _euid; } 857730SN/A inline uint64_t gid() { return _gid; } 868931Sandreas.hansson@arm.com inline uint64_t egid() { return _egid; } 878931Sandreas.hansson@arm.com inline uint64_t pid() { return _pid; } 888931Sandreas.hansson@arm.com inline uint64_t ppid() { return _ppid; } 898931Sandreas.hansson@arm.com inline uint64_t pgid() { return _pgid; } 908931Sandreas.hansson@arm.com inline uint64_t tgid() { return _tgid; } 918931Sandreas.hansson@arm.com inline void setpgid(uint64_t pgid) { _pgid = pgid; } 927730SN/A 938931Sandreas.hansson@arm.com const char *progName() const { return executable.c_str(); } 947730SN/A std::string fullPath(const std::string &filename); 957730SN/A std::string getcwd() const { return cwd; } 962391SN/A 973012SN/A /** 982391SN/A * Find an emulated device driver. 997730SN/A * 1007730SN/A * @param filename Name of the device (under /dev) 1017730SN/A * @return Pointer to driver object if found, else nullptr 1027730SN/A */ 1032391SN/A EmulatedDriver *findDriver(std::string filename); 1042391SN/A 1053751SN/A // This function acts as a callback to update the bias value in 1064762SN/A // the object file because the parameters needed to calculate the 1077730SN/A // bias are not available when the object file is created. 1082391SN/A void updateBias(); 1092391SN/A Addr getBias(); 1102541SN/A Addr getStartPC(); 1118931Sandreas.hansson@arm.com ObjectFile *getInterpreter(); 1122391SN/A 1133012SN/A // override of virtual SimObject method: register statistics 1147730SN/A void regStats() override; 1152391SN/A 1162391SN/A void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1178719SN/A 1188931Sandreas.hansson@arm.com /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1198719SN/A /// @return Whether the fault has been fixed. 1208719SN/A bool fixupStackFault(Addr vaddr); 1218719SN/A 1229053Sdam.sunwoo@arm.com // After getting registered with system object, tell process which 1239053Sdam.sunwoo@arm.com // system-wide context id it is assigned. 1248719SN/A void 1259053Sdam.sunwoo@arm.com assignThreadContext(ContextID context_id) 1268719SN/A { 1278719SN/A contextIds.push_back(context_id); 1289053Sdam.sunwoo@arm.com } 1298719SN/A 1309053Sdam.sunwoo@arm.com // Find a free context to use 1319053Sdam.sunwoo@arm.com ThreadContext *findFreeContext(); 1329053Sdam.sunwoo@arm.com 1338719SN/A /** 1349053Sdam.sunwoo@arm.com * After delegating a thread context to a child process 1358719SN/A * no longer should relate to the ThreadContext 1368719SN/A */ 1379053Sdam.sunwoo@arm.com void revokeThreadContext(int context_id); 1388719SN/A 1399053Sdam.sunwoo@arm.com /** 1409053Sdam.sunwoo@arm.com * Does mmap region grow upward or downward from mmapEnd? Most 1419053Sdam.sunwoo@arm.com * platforms grow downward, but a few (such as Alpha) grow upward 1428719SN/A * instead, so they can override this method to return false. 1439053Sdam.sunwoo@arm.com */ 1448719SN/A virtual bool mmapGrowsDown() const { return true; } 1458719SN/A 1469053Sdam.sunwoo@arm.com /** 1478719SN/A * Maps a contiguous range of virtual addresses in this process's 1489053Sdam.sunwoo@arm.com * address space to a contiguous range of physical addresses. 1499053Sdam.sunwoo@arm.com * This function exists primarily to expose the map operation to 1509053Sdam.sunwoo@arm.com * python, so that configuration scripts can set up mappings in SE mode. 1518719SN/A * 1529053Sdam.sunwoo@arm.com * @param vaddr The starting virtual address of the range. 1538719SN/A * @param paddr The starting physical address of the range. 1548719SN/A * @param size The length of the range in bytes. 1559053Sdam.sunwoo@arm.com * @param cacheable Specifies whether accesses are cacheable. 1568719SN/A * @return True if the map operation was successful. (At this 1579053Sdam.sunwoo@arm.com * point in time, the map operation always succeeds.) 1589053Sdam.sunwoo@arm.com */ 1599053Sdam.sunwoo@arm.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 1608719SN/A 1619053Sdam.sunwoo@arm.com void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, 1628719SN/A ThreadContext *new_tc, bool alloc_page); 1638719SN/A 1649053Sdam.sunwoo@arm.com virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, 1658719SN/A Process *new_p, RegVal flags); 1669053Sdam.sunwoo@arm.com 1679053Sdam.sunwoo@arm.com // thread contexts associated with this process 1689053Sdam.sunwoo@arm.com std::vector<ContextID> contextIds; 1698719SN/A 1709053Sdam.sunwoo@arm.com // system object which owns this process 1718719SN/A System *system; 1728719SN/A 1739053Sdam.sunwoo@arm.com Stats::Scalar numSyscalls; // track how many system calls are executed 1748719SN/A 1759053Sdam.sunwoo@arm.com bool useArchPT; // flag for using architecture specific page table 1769053Sdam.sunwoo@arm.com bool kvmInSE; // running KVM requires special initialization 1779053Sdam.sunwoo@arm.com 1788719SN/A EmulationPageTable *pTable; 1798719SN/A 1808719SN/A SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 1818719SN/A 1828719SN/A ObjectFile *objFile; 1839053Sdam.sunwoo@arm.com std::vector<std::string> argv; 1848719SN/A std::vector<std::string> envp; 1859053Sdam.sunwoo@arm.com std::string cwd; 1869053Sdam.sunwoo@arm.com std::string executable; 1879053Sdam.sunwoo@arm.com 1889053Sdam.sunwoo@arm.com // Id of the owner of the process 1898719SN/A uint64_t _uid; 1908719SN/A uint64_t _euid; 1918719SN/A uint64_t _gid; 1928719SN/A uint64_t _egid; 1938719SN/A 1949053Sdam.sunwoo@arm.com // pid of the process and it's parent 1958719SN/A uint64_t _pid; 1969053Sdam.sunwoo@arm.com uint64_t _ppid; 1979053Sdam.sunwoo@arm.com uint64_t _pgid; 1989053Sdam.sunwoo@arm.com uint64_t _tgid; 1998719SN/A 2008719SN/A // Emulated drivers available to this process 2018719SN/A std::vector<EmulatedDriver *> drivers; 2028719SN/A 2038719SN/A std::shared_ptr<FDArray> fds; 2049053Sdam.sunwoo@arm.com 2058719SN/A bool *exitGroup; 2069053Sdam.sunwoo@arm.com std::shared_ptr<MemState> memState; 2079053Sdam.sunwoo@arm.com 2089053Sdam.sunwoo@arm.com /** 2098719SN/A * Calls a futex wakeup at the address specified by this pointer when 2108719SN/A * this process exits. 2118719SN/A */ 2128719SN/A uint64_t childClearTID; 2138719SN/A 2149053Sdam.sunwoo@arm.com // Process was forked with SIGCHLD set. 2158719SN/A bool *sigchld; 2169053Sdam.sunwoo@arm.com}; 2179053Sdam.sunwoo@arm.com 2189053Sdam.sunwoo@arm.com#endif // __PROCESS_HH__ 2198719SN/A