process.hh revision 13867:9b10bbcf0543
12SN/A/* 21762SN/A * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 32SN/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 272665Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 302SN/A * Steve Reinhardt 312SN/A * Brandon Potter 324997Sgblack@eecs.umich.edu */ 331110SN/A 344997Sgblack@eecs.umich.edu#ifndef __PROCESS_HH__ 352680Sktlim@umich.edu#define __PROCESS_HH__ 362196SN/A 372196SN/A#include <inttypes.h> 387676Snate@binkert.org 394997Sgblack@eecs.umich.edu#include <map> 402800Ssaidi@eecs.umich.edu#include <string> 412800Ssaidi@eecs.umich.edu#include <vector> 422289SN/A 432SN/A#include "arch/registers.hh" 445569Snate@binkert.org#include "base/statistics.hh" 452167SN/A#include "base/types.hh" 462203SN/A#include "config/the_isa.hh" 472203SN/A#include "mem/se_translating_port_proxy.hh" 482222SN/A#include "sim/fd_array.hh" 492166SN/A#include "sim/fd_entry.hh" 502203SN/A#include "sim/mem_state.hh" 512203SN/A#include "sim/sim_object.hh" 522222SN/A 532166SN/Astruct ProcessParams; 542147SN/A 552147SN/Aclass EmulatedDriver; 562222SN/Aclass ObjectFile; 572147SN/Aclass EmulationPageTable; 582147SN/Aclass SyscallDesc; 592147SN/Aclass SyscallReturn; 602222SN/Aclass System; 612147SN/Aclass ThreadContext; 622147SN/A 632147SN/Aclass Process : public SimObject 642222SN/A{ 652147SN/A public: 662147SN/A Process(ProcessParams *params, EmulationPageTable *pTable, 672147SN/A ObjectFile *obj_file); 682222SN/A 692147SN/A void serialize(CheckpointOut &cp) const override; 702147SN/A void unserialize(CheckpointIn &cp) override; 712147SN/A 722222SN/A void initState() override; 732147SN/A DrainState drain() override; 742147SN/A 752147SN/A virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 762222SN/A virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0; 772147SN/A virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width); 782147SN/A virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0; 792147SN/A virtual void setSyscallReturn(ThreadContext *tc, 802222SN/A SyscallReturn return_value) = 0; 812147SN/A virtual SyscallDesc *getDesc(int callnum) = 0; 822289SN/A 832289SN/A inline uint64_t uid() { return _uid; } 842289SN/A inline uint64_t euid() { return _euid; } 852289SN/A inline uint64_t gid() { return _gid; } 862147SN/A inline uint64_t egid() { return _egid; } 872147SN/A inline uint64_t pid() { return _pid; } 882222SN/A inline uint64_t ppid() { return _ppid; } 892147SN/A inline uint64_t pgid() { return _pgid; } 902147SN/A inline uint64_t tgid() { return _tgid; } 912147SN/A inline void setpgid(uint64_t pgid) { _pgid = pgid; } 922222SN/A 932147SN/A const char *progName() const { return executable.c_str(); } 942147SN/A std::string fullPath(const std::string &filename); 952147SN/A std::string getcwd() const { return cwd; } 962222SN/A 972147SN/A /** 982147SN/A * Find an emulated device driver. 992147SN/A * 1002222SN/A * @param filename Name of the device (under /dev) 1012147SN/A * @return Pointer to driver object if found, else nullptr 1022147SN/A */ 1032147SN/A EmulatedDriver *findDriver(std::string filename); 1042222SN/A 1052147SN/A // This function acts as a callback to update the bias value in 1062147SN/A // the object file because the parameters needed to calculate the 1072147SN/A // bias are not available when the object file is created. 1082222SN/A void updateBias(); 1092147SN/A Addr getBias(); 1102174SN/A Addr getStartPC(); 1112174SN/A ObjectFile *getInterpreter(); 1125569Snate@binkert.org 1137678Sgblack@eecs.umich.edu // override of virtual SimObject method: register statistics 1142174SN/A void regStats() override; 1152680Sktlim@umich.edu 1162222SN/A void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1172174SN/A 1187720Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1197720Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 1202196SN/A bool fixupStackFault(Addr vaddr); 1217720Sgblack@eecs.umich.edu 1227720Sgblack@eecs.umich.edu // After getting registered with system object, tell process which 1232196SN/A // system-wide context id it is assigned. 1242201SN/A void 1252196SN/A assignThreadContext(ContextID context_id) 1265568Snate@binkert.org { 1275568Snate@binkert.org contextIds.push_back(context_id); 1282196SN/A } 1292196SN/A 1307720Sgblack@eecs.umich.edu // Find a free context to use 1317720Sgblack@eecs.umich.edu ThreadContext *findFreeContext(); 1322174SN/A 1332174SN/A /** 1345569Snate@binkert.org * After delegating a thread context to a child process 1357678Sgblack@eecs.umich.edu * no longer should relate to the ThreadContext 1362201SN/A */ 1372680Sktlim@umich.edu void revokeThreadContext(int context_id); 1382201SN/A 1392201SN/A /** 1402201SN/A * Does mmap region grow upward or downward from mmapEnd? Most 1415569Snate@binkert.org * platforms grow downward, but a few (such as Alpha) grow upward 1427678Sgblack@eecs.umich.edu * instead, so they can override this method to return false. 1432289SN/A */ 1442289SN/A virtual bool mmapGrowsDown() const { return true; } 1452289SN/A 1462289SN/A /** 1472289SN/A * Maps a contiguous range of virtual addresses in this process's 1482289SN/A * address space to a contiguous range of physical addresses. 1495569Snate@binkert.org * This function exists primarily to expose the map operation to 1506739Sgblack@eecs.umich.edu * python, so that configuration scripts can set up mappings in SE mode. 1512289SN/A * 1525568Snate@binkert.org * @param vaddr The starting virtual address of the range. 1532289SN/A * @param paddr The starting physical address of the range. 1542289SN/A * @param size The length of the range in bytes. 1557678Sgblack@eecs.umich.edu * @param cacheable Specifies whether accesses are cacheable. 1565568Snate@binkert.org * @return True if the map operation was successful. (At this 1577678Sgblack@eecs.umich.edu * point in time, the map operation always succeeds.) 1587678Sgblack@eecs.umich.edu */ 1595569Snate@binkert.org bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 1602289SN/A 1612289SN/A void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, 1625568Snate@binkert.org ThreadContext *new_tc, bool alloc_page); 1635568Snate@binkert.org 1642289SN/A virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc, 1652289SN/A Process *new_p, RegVal flags); 1662680Sktlim@umich.edu 1672289SN/A // thread contexts associated with this process 1682289SN/A std::vector<ContextID> contextIds; 1695569Snate@binkert.org 1707678Sgblack@eecs.umich.edu // system object which owns this process 1712289SN/A System *system; 1722680Sktlim@umich.edu 1735568Snate@binkert.org Stats::Scalar numSyscalls; // track how many system calls are executed 1745568Snate@binkert.org 1755569Snate@binkert.org // flag for using architecture specific page table 1762289SN/A bool useArchPT; 1772289SN/A // running KVM requires special initialization 1782680Sktlim@umich.edu bool kvmInSE; 1792289SN/A // flag for using the process as a thread which shares page tables 1802289SN/A bool useForClone; 1814997Sgblack@eecs.umich.edu 1824997Sgblack@eecs.umich.edu EmulationPageTable *pTable; 1835569Snate@binkert.org 1847678Sgblack@eecs.umich.edu SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 1854997Sgblack@eecs.umich.edu 1864997Sgblack@eecs.umich.edu ObjectFile *objFile; 1875184Sgblack@eecs.umich.edu std::vector<std::string> argv; 1885184Sgblack@eecs.umich.edu std::vector<std::string> envp; 1895569Snate@binkert.org std::string cwd; 1904997Sgblack@eecs.umich.edu std::string executable; 1914997Sgblack@eecs.umich.edu 1924997Sgblack@eecs.umich.edu // Id of the owner of the process 1935004Sgblack@eecs.umich.edu uint64_t _uid; 1944997Sgblack@eecs.umich.edu uint64_t _euid; 1954997Sgblack@eecs.umich.edu uint64_t _gid; 1964997Sgblack@eecs.umich.edu uint64_t _egid; 1975569Snate@binkert.org 1987678Sgblack@eecs.umich.edu // pid of the process and it's parent 1994997Sgblack@eecs.umich.edu uint64_t _pid; 2004997Sgblack@eecs.umich.edu uint64_t _ppid; 2015184Sgblack@eecs.umich.edu uint64_t _pgid; 2025184Sgblack@eecs.umich.edu uint64_t _tgid; 2035569Snate@binkert.org 2044997Sgblack@eecs.umich.edu // Emulated drivers available to this process 2055184Sgblack@eecs.umich.edu std::vector<EmulatedDriver *> drivers; 2064997Sgblack@eecs.umich.edu 2075569Snate@binkert.org std::shared_ptr<FDArray> fds; 2084997Sgblack@eecs.umich.edu 2094997Sgblack@eecs.umich.edu bool *exitGroup; 2105004Sgblack@eecs.umich.edu std::shared_ptr<MemState> memState; 2114997Sgblack@eecs.umich.edu 2124997Sgblack@eecs.umich.edu /** 2134997Sgblack@eecs.umich.edu * Calls a futex wakeup at the address specified by this pointer when 2142174SN/A * this process exits. 2152174SN/A */ 2162167SN/A uint64_t childClearTID; 2172167SN/A 218 // Process was forked with SIGCHLD set. 219 bool *sigchld; 220}; 221 222#endif // __PROCESS_HH__ 223