process.hh revision 12448:b299e560f1d8
11689SN/A/* 22329SN/A * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 31689SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 41689SN/A * All rights reserved. 51689SN/A * 61689SN/A * Redistribution and use in source and binary forms, with or without 71689SN/A * modification, are permitted provided that the following conditions are 81689SN/A * met: redistributions of source code must retain the above copyright 91689SN/A * notice, this list of conditions and the following disclaimer; 101689SN/A * redistributions in binary form must reproduce the above copyright 111689SN/A * notice, this list of conditions and the following disclaimer in the 121689SN/A * documentation and/or other materials provided with the distribution; 131689SN/A * neither the name of the copyright holders nor the names of its 141689SN/A * contributors may be used to endorse or promote products derived from 151689SN/A * this software without specific prior written permission. 161689SN/A * 171689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272665Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 291689SN/A * Authors: Nathan Binkert 301689SN/A * Steve Reinhardt 311717SN/A * Brandon Potter 321060SN/A */ 331060SN/A 342292SN/A#ifndef __PROCESS_HH__ 352292SN/A#define __PROCESS_HH__ 362292SN/A 372292SN/A#include <inttypes.h> 382292SN/A 392292SN/A#include <map> 402292SN/A#include <string> 411060SN/A#include <vector> 422292SN/A 432292SN/A#include "arch/registers.hh" 442348SN/A#include "base/statistics.hh" 452292SN/A#include "base/types.hh" 462292SN/A#include "config/the_isa.hh" 472292SN/A#include "mem/se_translating_port_proxy.hh" 482292SN/A#include "sim/fd_array.hh" 492292SN/A#include "sim/fd_entry.hh" 502292SN/A#include "sim/mem_state.hh" 512935Sksewell@umich.edu#include "sim/sim_object.hh" 522935Sksewell@umich.edu 532292SN/Astruct ProcessParams; 542292SN/A 552292SN/Aclass EmulatedDriver; 562292SN/Aclass ObjectFile; 572292SN/Aclass EmulationPageTable; 582292SN/Aclass SyscallDesc; 592292SN/Aclass SyscallReturn; 602292SN/Aclass System; 612292SN/Aclass ThreadContext; 622292SN/A 632292SN/Aclass Process : public SimObject 641060SN/A{ 651060SN/A public: 661062SN/A Process(ProcessParams *params, EmulationPageTable *pTable, 671062SN/A ObjectFile *obj_file); 682292SN/A 691062SN/A void serialize(CheckpointOut &cp) const override; 701062SN/A void unserialize(CheckpointIn &cp) override; 712307SN/A 721062SN/A void initState() override; 731062SN/A DrainState drain() override; 741062SN/A 752307SN/A virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 761062SN/A virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0; 771062SN/A virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); 782292SN/A virtual void setSyscallArg(ThreadContext *tc, int i, 792307SN/A TheISA::IntReg val) = 0; 802292SN/A virtual void setSyscallReturn(ThreadContext *tc, 812292SN/A SyscallReturn return_value) = 0; 821062SN/A virtual SyscallDesc *getDesc(int callnum) = 0; 832307SN/A 841062SN/A inline uint64_t uid() { return _uid; } 851062SN/A inline uint64_t euid() { return _euid; } 861062SN/A inline uint64_t gid() { return _gid; } 872307SN/A inline uint64_t egid() { return _egid; } 881062SN/A inline uint64_t pid() { return _pid; } 891062SN/A inline uint64_t ppid() { return _ppid; } 902307SN/A inline uint64_t pgid() { return _pgid; } 912307SN/A inline uint64_t tgid() { return _tgid; } 922307SN/A inline void setpgid(uint64_t pgid) { _pgid = pgid; } 932307SN/A 941062SN/A const char *progName() const { return executable.c_str(); } 952307SN/A std::string fullPath(const std::string &filename); 961062SN/A std::string getcwd() const { return cwd; } 971062SN/A 981062SN/A /** 992307SN/A * Find an emulated device driver. 1001062SN/A * 1011062SN/A * @param filename Name of the device (under /dev) 1021062SN/A * @return Pointer to driver object if found, else nullptr 1031062SN/A */ 1042307SN/A EmulatedDriver *findDriver(std::string filename); 1051062SN/A 1061062SN/A // This function acts as a callback to update the bias value in 1071062SN/A // the object file because the parameters needed to calculate the 1082307SN/A // bias are not available when the object file is created. 1091062SN/A void updateBias(); 1101062SN/A Addr getBias(); 1111062SN/A Addr getStartPC(); 1121062SN/A ObjectFile *getInterpreter(); 1131060SN/A 1141060SN/A // override of virtual SimObject method: register statistics 1152733Sktlim@umich.edu void regStats() override; 1161060SN/A 1172292SN/A void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1181060SN/A 1191060SN/A /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1201060SN/A /// @return Whether the fault has been fixed. 1211060SN/A bool fixupStackFault(Addr vaddr); 1221060SN/A 1232292SN/A // After getting registered with system object, tell process which 1241060SN/A // system-wide context id it is assigned. 1252292SN/A void 1261060SN/A assignThreadContext(ContextID context_id) 1271060SN/A { 1281060SN/A contextIds.push_back(context_id); 1291060SN/A } 1301060SN/A 1311060SN/A // Find a free context to use 1321060SN/A ThreadContext *findFreeContext(); 1331060SN/A 1341060SN/A /** 1351060SN/A * After delegating a thread context to a child process 1361060SN/A * no longer should relate to the ThreadContext 1371060SN/A */ 1381060SN/A void revokeThreadContext(int context_id); 1392292SN/A 1401060SN/A /** 1412292SN/A * Does mmap region grow upward or downward from mmapEnd? Most 1421060SN/A * platforms grow downward, but a few (such as Alpha) grow upward 1431060SN/A * instead, so they can override this method to return false. 1441060SN/A */ 1451060SN/A virtual bool mmapGrowsDown() const { return true; } 1461060SN/A 1471060SN/A /** 1481060SN/A * Maps a contiguous range of virtual addresses in this process's 1491060SN/A * address space to a contiguous range of physical addresses. 1502292SN/A * This function exists primarily to expose the map operation to 1511060SN/A * python, so that configuration scripts can set up mappings in SE mode. 1522292SN/A * 1531060SN/A * @param vaddr The starting virtual address of the range. 1541060SN/A * @param paddr The starting physical address of the range. 1551060SN/A * @param size The length of the range in bytes. 1561060SN/A * @param cacheable Specifies whether accesses are cacheable. 1571060SN/A * @return True if the map operation was successful. (At this 1581060SN/A * point in time, the map operation always succeeds.) 1591060SN/A */ 1602292SN/A bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 1612980Sgblack@eecs.umich.edu 1622292SN/A void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, 1632292SN/A ThreadContext *new_tc, bool alloc_page); 1642292SN/A 1652292SN/A virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, 1662292SN/A Process *new_p, TheISA::IntReg flags); 1672307SN/A 1682863Sktlim@umich.edu // thread contexts associated with this process 1692843Sktlim@umich.edu std::vector<ContextID> contextIds; 1702307SN/A 1712843Sktlim@umich.edu // system object which owns this process 1722843Sktlim@umich.edu System *system; 1732863Sktlim@umich.edu 1742307SN/A Stats::Scalar numSyscalls; // track how many system calls are executed 1752307SN/A 1762307SN/A bool useArchPT; // flag for using architecture specific page table 1772307SN/A bool kvmInSE; // running KVM requires special initialization 1782307SN/A 1792307SN/A EmulationPageTable *pTable; 1802307SN/A 1812307SN/A SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 1822348SN/A 1832307SN/A ObjectFile *objFile; 1842307SN/A std::vector<std::string> argv; 1852307SN/A std::vector<std::string> envp; 1862307SN/A std::string cwd; 1872307SN/A std::string executable; 1882307SN/A 1892307SN/A // Id of the owner of the process 1902307SN/A uint64_t _uid; 1912307SN/A uint64_t _euid; 1922307SN/A uint64_t _gid; 1932307SN/A uint64_t _egid; 1942307SN/A 1952307SN/A // pid of the process and it's parent 1962307SN/A uint64_t _pid; 1972307SN/A uint64_t _ppid; 1982292SN/A uint64_t _pgid; 1992292SN/A uint64_t _tgid; 2002292SN/A 2012292SN/A // Emulated drivers available to this process 2022292SN/A std::vector<EmulatedDriver *> drivers; 2032292SN/A 2042292SN/A std::shared_ptr<FDArray> fds; 2052292SN/A 2062292SN/A bool *exitGroup; 2072292SN/A std::shared_ptr<MemState> memState; 2082292SN/A 2092292SN/A /** 2102292SN/A * Calls a futex wakeup at the address specified by this pointer when 2112292SN/A * this process exits. 2122292SN/A */ 2132292SN/A uint64_t childClearTID; 2142292SN/A 2152292SN/A // Process was forked with SIGCHLD set. 2162292SN/A bool *sigchld; 2172292SN/A}; 2182292SN/A 2191681SN/A#endif // __PROCESS_HH__ 2202292SN/A