process.hh revision 11885:79af314e9f0d
111986Sandreas.sandberg@arm.com/* 211986Sandreas.sandberg@arm.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 311986Sandreas.sandberg@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 411986Sandreas.sandberg@arm.com * All rights reserved. 511986Sandreas.sandberg@arm.com * 611986Sandreas.sandberg@arm.com * Redistribution and use in source and binary forms, with or without 711986Sandreas.sandberg@arm.com * modification, are permitted provided that the following conditions are 811986Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright 911986Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer; 1011986Sandreas.sandberg@arm.com * redistributions in binary form must reproduce the above copyright 1111986Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer in the 1211986Sandreas.sandberg@arm.com * documentation and/or other materials provided with the distribution; 1311986Sandreas.sandberg@arm.com * neither the name of the copyright holders nor the names of its 1412391Sjason@lowepower.com * contributors may be used to endorse or promote products derived from 1512391Sjason@lowepower.com * this software without specific prior written permission. 1612391Sjason@lowepower.com * 1711986Sandreas.sandberg@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1811986Sandreas.sandberg@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912391Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2014299Sbbruce@ucdavis.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2111986Sandreas.sandberg@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212391Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312391Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412391Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512391Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612391Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712391Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812391Sjason@lowepower.com * 2912391Sjason@lowepower.com * Authors: Nathan Binkert 3012391Sjason@lowepower.com * Steve Reinhardt 3112391Sjason@lowepower.com * Brandon Potter 3212391Sjason@lowepower.com */ 3312391Sjason@lowepower.com 3412391Sjason@lowepower.com#ifndef __PROCESS_HH__ 3512391Sjason@lowepower.com#define __PROCESS_HH__ 3611986Sandreas.sandberg@arm.com 3711986Sandreas.sandberg@arm.com#include <inttypes.h> 3812391Sjason@lowepower.com 3912391Sjason@lowepower.com#include <map> 4012391Sjason@lowepower.com#include <string> 4112391Sjason@lowepower.com#include <vector> 4212391Sjason@lowepower.com 4312391Sjason@lowepower.com#include "arch/registers.hh" 4412391Sjason@lowepower.com#include "base/statistics.hh" 4512391Sjason@lowepower.com#include "base/types.hh" 4612391Sjason@lowepower.com#include "config/the_isa.hh" 4712391Sjason@lowepower.com#include "mem/se_translating_port_proxy.hh" 4812391Sjason@lowepower.com#include "sim/fd_array.hh" 4912391Sjason@lowepower.com#include "sim/fd_entry.hh" 5012391Sjason@lowepower.com#include "sim/sim_object.hh" 5112391Sjason@lowepower.com 5212391Sjason@lowepower.comstruct ProcessParams; 5312391Sjason@lowepower.com 5412391Sjason@lowepower.comclass EmulatedDriver; 5512391Sjason@lowepower.comclass ObjectFile; 5612391Sjason@lowepower.comclass PageTableBase; 5712391Sjason@lowepower.comclass SyscallDesc; 5812391Sjason@lowepower.comclass SyscallReturn; 5912391Sjason@lowepower.comclass System; 6012391Sjason@lowepower.comclass ThreadContext; 6112391Sjason@lowepower.com 6212391Sjason@lowepower.comclass Process : public SimObject 6312391Sjason@lowepower.com{ 6412391Sjason@lowepower.com public: 6512391Sjason@lowepower.com struct WaitRec 6612391Sjason@lowepower.com { 6712391Sjason@lowepower.com Addr waitChan; 6812391Sjason@lowepower.com ThreadContext *waitingContext; 6912391Sjason@lowepower.com 7012391Sjason@lowepower.com WaitRec(Addr chan, ThreadContext *ctx) 7112391Sjason@lowepower.com : waitChan(chan), waitingContext(ctx) 7212391Sjason@lowepower.com { } 7312391Sjason@lowepower.com }; 7412391Sjason@lowepower.com 7512391Sjason@lowepower.com Process(ProcessParams *params, ObjectFile *obj_file); 7612391Sjason@lowepower.com 7712391Sjason@lowepower.com void serialize(CheckpointOut &cp) const override; 7812391Sjason@lowepower.com void unserialize(CheckpointIn &cp) override; 7912391Sjason@lowepower.com 8012391Sjason@lowepower.com void initState() override; 8112391Sjason@lowepower.com DrainState drain() override; 8212391Sjason@lowepower.com 8311986Sandreas.sandberg@arm.com void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 8411986Sandreas.sandberg@arm.com virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0; 8512391Sjason@lowepower.com virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); 8612391Sjason@lowepower.com virtual void setSyscallArg(ThreadContext *tc, int i, 8712391Sjason@lowepower.com TheISA::IntReg val) = 0; 8812391Sjason@lowepower.com virtual void setSyscallReturn(ThreadContext *tc, 8912391Sjason@lowepower.com SyscallReturn return_value) = 0; 9012391Sjason@lowepower.com virtual SyscallDesc *getDesc(int callnum) = 0; 9112391Sjason@lowepower.com 9212391Sjason@lowepower.com inline uint64_t uid() { return _uid; } 9312391Sjason@lowepower.com inline uint64_t euid() { return _euid; } 9412391Sjason@lowepower.com inline uint64_t gid() { return _gid; } 9512391Sjason@lowepower.com inline uint64_t egid() { return _egid; } 9612391Sjason@lowepower.com inline uint64_t pid() { return _pid; } 9712391Sjason@lowepower.com inline uint64_t ppid() { return _ppid; } 9812391Sjason@lowepower.com inline uint64_t pgid() { return _pgid; } 9912391Sjason@lowepower.com inline uint64_t tgid() { return _tgid; } 10012391Sjason@lowepower.com inline void setpgid(uint64_t pgid) { _pgid = pgid; } 10112391Sjason@lowepower.com 10212391Sjason@lowepower.com const char *progName() const { return executable.c_str(); } 10312391Sjason@lowepower.com std::string fullPath(const std::string &filename); 10412391Sjason@lowepower.com std::string getcwd() const { return cwd; } 10512391Sjason@lowepower.com 10612391Sjason@lowepower.com /** 10712391Sjason@lowepower.com * Find an emulated device driver. 10812391Sjason@lowepower.com * 10912391Sjason@lowepower.com * @param filename Name of the device (under /dev) 11012391Sjason@lowepower.com * @return Pointer to driver object if found, else NULL 11112391Sjason@lowepower.com */ 11212391Sjason@lowepower.com EmulatedDriver *findDriver(std::string filename); 11312391Sjason@lowepower.com 11412391Sjason@lowepower.com // This function acts as a callback to update the bias value in 11512391Sjason@lowepower.com // the object file because the parameters needed to calculate the 11611986Sandreas.sandberg@arm.com // bias are not available when the object file is created. 11712391Sjason@lowepower.com void updateBias(); 11811986Sandreas.sandberg@arm.com Addr getBias(); 11912391Sjason@lowepower.com Addr getStartPC(); 12012391Sjason@lowepower.com ObjectFile *getInterpreter(); 12112391Sjason@lowepower.com 12212391Sjason@lowepower.com // override of virtual SimObject method: register statistics 12312391Sjason@lowepower.com void regStats() override; 12412391Sjason@lowepower.com 12512391Sjason@lowepower.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 12612391Sjason@lowepower.com 12712391Sjason@lowepower.com /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 12812391Sjason@lowepower.com /// @return Whether the fault has been fixed. 12912391Sjason@lowepower.com bool fixupStackFault(Addr vaddr); 13012391Sjason@lowepower.com 13112391Sjason@lowepower.com // After getting registered with system object, tell process which 13212391Sjason@lowepower.com // system-wide context id it is assigned. 13311986Sandreas.sandberg@arm.com void 13411986Sandreas.sandberg@arm.com assignThreadContext(ContextID context_id) 13511986Sandreas.sandberg@arm.com { 13612391Sjason@lowepower.com contextIds.push_back(context_id); 13712391Sjason@lowepower.com } 13812391Sjason@lowepower.com 13912391Sjason@lowepower.com // Find a free context to use 14012391Sjason@lowepower.com ThreadContext *findFreeContext(); 14112391Sjason@lowepower.com 14212391Sjason@lowepower.com /** 14312391Sjason@lowepower.com * Does mmap region grow upward or downward from mmap_end? Most 14412391Sjason@lowepower.com * platforms grow downward, but a few (such as Alpha) grow upward 14512391Sjason@lowepower.com * instead, so they can override this method to return false. 14612391Sjason@lowepower.com */ 14712391Sjason@lowepower.com virtual bool mmapGrowsDown() const { return true; } 14812391Sjason@lowepower.com 14912391Sjason@lowepower.com /** 15012391Sjason@lowepower.com * Maps a contiguous range of virtual addresses in this process's 15112391Sjason@lowepower.com * address space to a contiguous range of physical addresses. 15212391Sjason@lowepower.com * This function exists primarily to expose the map operation to 15311986Sandreas.sandberg@arm.com * python, so that configuration scripts can set up mappings in SE mode. 15411986Sandreas.sandberg@arm.com * 15512391Sjason@lowepower.com * @param vaddr The starting virtual address of the range. 15612391Sjason@lowepower.com * @param paddr The starting physical address of the range. 15712391Sjason@lowepower.com * @param size The length of the range in bytes. 15812391Sjason@lowepower.com * @param cacheable Specifies whether accesses are cacheable. 15912391Sjason@lowepower.com * @return True if the map operation was successful. (At this 16012391Sjason@lowepower.com * point in time, the map operation always succeeds.) 16112391Sjason@lowepower.com */ 16212391Sjason@lowepower.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 16312391Sjason@lowepower.com 16412391Sjason@lowepower.com // list of all blocked contexts 16512391Sjason@lowepower.com std::list<WaitRec> waitList; 16612391Sjason@lowepower.com 16712391Sjason@lowepower.com // thread contexts associated with this process 16812391Sjason@lowepower.com std::vector<ContextID> contextIds; 16912391Sjason@lowepower.com 17012391Sjason@lowepower.com // system object which owns this process 17112391Sjason@lowepower.com System *system; 17212391Sjason@lowepower.com 17312391Sjason@lowepower.com Addr brk_point; // top of the data segment 17412391Sjason@lowepower.com Addr stack_base; // stack segment base 17512391Sjason@lowepower.com unsigned stack_size; // initial stack size 17612391Sjason@lowepower.com Addr stack_min; // furthest address accessed from stack base 17712391Sjason@lowepower.com Addr max_stack_size; // the maximum size allowed for the stack 17812391Sjason@lowepower.com Addr next_thread_stack_base; // addr for next region w/ multithreaded apps 17912391Sjason@lowepower.com Addr mmap_end; // base of automatic mmap region allocs 18012391Sjason@lowepower.com 18112391Sjason@lowepower.com Stats::Scalar num_syscalls; // track how many system calls are executed 18212391Sjason@lowepower.com 18312391Sjason@lowepower.com bool useArchPT; // flag for using architecture specific page table 18412391Sjason@lowepower.com bool kvmInSE; // running KVM requires special initialization 18512391Sjason@lowepower.com 18612391Sjason@lowepower.com PageTableBase* pTable; 18711986Sandreas.sandberg@arm.com 18812391Sjason@lowepower.com SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 18912391Sjason@lowepower.com 19012391Sjason@lowepower.com ObjectFile *objFile; 19112391Sjason@lowepower.com std::vector<std::string> argv; 19211986Sandreas.sandberg@arm.com std::vector<std::string> envp; 19311986Sandreas.sandberg@arm.com std::string cwd; 19411986Sandreas.sandberg@arm.com std::string executable; 19511986Sandreas.sandberg@arm.com 19611986Sandreas.sandberg@arm.com // Id of the owner of the process 19711986Sandreas.sandberg@arm.com uint64_t _uid; 19811986Sandreas.sandberg@arm.com uint64_t _euid; 19911986Sandreas.sandberg@arm.com uint64_t _gid; 20011986Sandreas.sandberg@arm.com uint64_t _egid; 20111986Sandreas.sandberg@arm.com 20211986Sandreas.sandberg@arm.com // pid of the process and it's parent 20311986Sandreas.sandberg@arm.com uint64_t _pid; 20411986Sandreas.sandberg@arm.com uint64_t _ppid; 20511986Sandreas.sandberg@arm.com uint64_t _pgid; 20612391Sjason@lowepower.com uint64_t _tgid; 20714299Sbbruce@ucdavis.edu 20814299Sbbruce@ucdavis.edu // Emulated drivers available to this process 20914299Sbbruce@ucdavis.edu std::vector<EmulatedDriver *> drivers; 21014299Sbbruce@ucdavis.edu 21112391Sjason@lowepower.com std::shared_ptr<FDArray> fds; 21212391Sjason@lowepower.com}; 21312391Sjason@lowepower.com 21412391Sjason@lowepower.com#endif // __PROCESS_HH__ 21512391Sjason@lowepower.com