process.hh revision 11919:54c2e390fc22
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
3211793Sbrandon.potter@amd.com */
3311793Sbrandon.potter@amd.com
344997Sgblack@eecs.umich.edu#ifndef __PROCESS_HH__
354997Sgblack@eecs.umich.edu#define __PROCESS_HH__
368229Snate@binkert.org
378229Snate@binkert.org#include <inttypes.h>
382680Sktlim@umich.edu
398229Snate@binkert.org#include <map>
4011793Sbrandon.potter@amd.com#include <string>
412800Ssaidi@eecs.umich.edu#include <vector>
422SN/A
435569Snate@binkert.org#include "arch/registers.hh"
442167SN/A#include "base/statistics.hh"
452203SN/A#include "base/types.hh"
462203SN/A#include "config/the_isa.hh"
472222SN/A#include "mem/se_translating_port_proxy.hh"
482166SN/A#include "sim/fd_array.hh"
492203SN/A#include "sim/fd_entry.hh"
502203SN/A#include "sim/mem_state.hh"
512222SN/A#include "sim/sim_object.hh"
522166SN/A
532147SN/Astruct ProcessParams;
542147SN/A
552222SN/Aclass EmulatedDriver;
562147SN/Aclass ObjectFile;
572147SN/Aclass PageTableBase;
582147SN/Aclass SyscallDesc;
592222SN/Aclass SyscallReturn;
602147SN/Aclass System;
612147SN/Aclass ThreadContext;
622147SN/A
632222SN/Aclass Process : public SimObject
642147SN/A{
652147SN/A  public:
662147SN/A    Process(ProcessParams *params, ObjectFile *obj_file);
672222SN/A
682147SN/A    void serialize(CheckpointOut &cp) const override;
692147SN/A    void unserialize(CheckpointIn &cp) override;
702147SN/A
712222SN/A    void initState() override;
722147SN/A    DrainState drain() override;
738405Sksewell@umich.edu
742147SN/A    void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
752222SN/A    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
762147SN/A    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
778405Sksewell@umich.edu    virtual void setSyscallArg(ThreadContext *tc, int i,
782147SN/A                               TheISA::IntReg val) = 0;
792222SN/A    virtual void setSyscallReturn(ThreadContext *tc,
802147SN/A                                  SyscallReturn return_value) = 0;
812289SN/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; }
852147SN/A    inline uint64_t gid() { return _gid; }
862147SN/A    inline uint64_t egid() { return _egid; }
872222SN/A    inline uint64_t pid() { return _pid; }
882147SN/A    inline uint64_t ppid() { return _ppid; }
892147SN/A    inline uint64_t pgid() { return _pgid; }
902147SN/A    inline uint64_t tgid() { return _tgid; }
912222SN/A    inline void setpgid(uint64_t pgid) { _pgid = pgid; }
922147SN/A
932147SN/A    const char *progName() const { return executable.c_str(); }
942147SN/A    std::string fullPath(const std::string &filename);
952222SN/A    std::string getcwd() const { return cwd; }
962147SN/A
972147SN/A    /**
982147SN/A     * Find an emulated device driver.
992222SN/A     *
1002147SN/A     * @param filename Name of the device (under /dev)
10112110SRekai.GonzalezAlberquilla@arm.com     * @return Pointer to driver object if found, else nullptr
10212110SRekai.GonzalezAlberquilla@arm.com     */
10312110SRekai.GonzalezAlberquilla@arm.com    EmulatedDriver *findDriver(std::string filename);
10412110SRekai.GonzalezAlberquilla@arm.com
10512110SRekai.GonzalezAlberquilla@arm.com    // This function acts as a callback to update the bias value in
10612110SRekai.GonzalezAlberquilla@arm.com    // the object file because the parameters needed to calculate the
10712110SRekai.GonzalezAlberquilla@arm.com    // bias are not available when the object file is created.
1082147SN/A    void updateBias();
1092147SN/A    Addr getBias();
1102222SN/A    Addr getStartPC();
1112147SN/A    ObjectFile *getInterpreter();
1122147SN/A
1132147SN/A    // override of virtual SimObject method: register statistics
1142222SN/A    void regStats() override;
1152147SN/A
1165569Snate@binkert.org    void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
11710417Sandreas.hansson@arm.com
1182174SN/A    /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
1192680Sktlim@umich.edu    /// @return Whether the fault has been fixed.
1208780Sgblack@eecs.umich.edu    bool fixupStackFault(Addr vaddr);
1218780Sgblack@eecs.umich.edu
1222222SN/A    // After getting registered with system object, tell process which
1232174SN/A    // system-wide context id it is assigned.
1247720Sgblack@eecs.umich.edu    void
1257720Sgblack@eecs.umich.edu    assignThreadContext(ContextID context_id)
1262196SN/A    {
1277720Sgblack@eecs.umich.edu        contextIds.push_back(context_id);
1287720Sgblack@eecs.umich.edu    }
1292196SN/A
1302201SN/A    // Find a free context to use
1312196SN/A    ThreadContext *findFreeContext();
1325568Snate@binkert.org
1335568Snate@binkert.org    /**
1342196SN/A     * After delegating a thread context to a child process
1352196SN/A     * no longer should relate to the ThreadContext
1367720Sgblack@eecs.umich.edu     */
1377720Sgblack@eecs.umich.edu    void revokeThreadContext(int context_id);
1382174SN/A
1392174SN/A    /**
1405569Snate@binkert.org     * Does mmap region grow upward or downward from mmapEnd?  Most
14110417Sandreas.hansson@arm.com     * platforms grow downward, but a few (such as Alpha) grow upward
1422201SN/A     * instead, so they can override this method to return false.
1432680Sktlim@umich.edu     */
1448780Sgblack@eecs.umich.edu    virtual bool mmapGrowsDown() const { return true; }
1458780Sgblack@eecs.umich.edu
1462201SN/A    /**
1472201SN/A     * Maps a contiguous range of virtual addresses in this process's
1482201SN/A     * address space to a contiguous range of physical addresses.
1495569Snate@binkert.org     * This function exists primarily to expose the map operation to
15010417Sandreas.hansson@arm.com     * python, so that configuration scripts can set up mappings in SE mode.
1512289SN/A     *
1528780Sgblack@eecs.umich.edu     * @param vaddr The starting virtual address of the range.
1538780Sgblack@eecs.umich.edu     * @param paddr The starting physical address of the range.
1548780Sgblack@eecs.umich.edu     * @param size The length of the range in bytes.
1558780Sgblack@eecs.umich.edu     * @param cacheable Specifies whether accesses are cacheable.
1568780Sgblack@eecs.umich.edu     * @return True if the map operation was successful.  (At this
1578780Sgblack@eecs.umich.edu     *           point in time, the map operation always succeeds.)
15810823SAndreas.Sandberg@ARM.com     */
1598780Sgblack@eecs.umich.edu    bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
1608780Sgblack@eecs.umich.edu
1612289SN/A    void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
1628780Sgblack@eecs.umich.edu                       ThreadContext *new_tc, bool alloc_page);
1638780Sgblack@eecs.umich.edu
1648780Sgblack@eecs.umich.edu    void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p,
1658780Sgblack@eecs.umich.edu               TheISA::IntReg flags);
1668780Sgblack@eecs.umich.edu
1678780Sgblack@eecs.umich.edu    // thread contexts associated with this process
1682289SN/A    std::vector<ContextID> contextIds;
1698780Sgblack@eecs.umich.edu
1708780Sgblack@eecs.umich.edu    // system object which owns this process
1718780Sgblack@eecs.umich.edu    System *system;
1728780Sgblack@eecs.umich.edu
1732289SN/A    Stats::Scalar numSyscalls;  // track how many system calls are executed
1742289SN/A
1752680Sktlim@umich.edu    bool useArchPT; // flag for using architecture specific page table
1762289SN/A    bool kvmInSE;   // running KVM requires special initialization
1772289SN/A
1785569Snate@binkert.org    PageTableBase* pTable;
17910417Sandreas.hansson@arm.com
1802289SN/A    SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
1818780Sgblack@eecs.umich.edu
18210664SAli.Saidi@ARM.com    ObjectFile *objFile;
18310664SAli.Saidi@ARM.com    std::vector<std::string> argv;
18410664SAli.Saidi@ARM.com    std::vector<std::string> envp;
1852289SN/A    std::string cwd;
1862289SN/A    std::string executable;
1872680Sktlim@umich.edu
1882289SN/A    // Id of the owner of the process
1892289SN/A    uint64_t _uid;
1905569Snate@binkert.org    uint64_t _euid;
19110417Sandreas.hansson@arm.com    uint64_t _gid;
1924997Sgblack@eecs.umich.edu    uint64_t _egid;
1938780Sgblack@eecs.umich.edu
1948780Sgblack@eecs.umich.edu    // pid of the process and it's parent
1958806Sgblack@eecs.umich.edu    uint64_t _pid;
1968806Sgblack@eecs.umich.edu    uint64_t _ppid;
1978806Sgblack@eecs.umich.edu    uint64_t _pgid;
1988806Sgblack@eecs.umich.edu    uint64_t _tgid;
1998806Sgblack@eecs.umich.edu
2008806Sgblack@eecs.umich.edu    // Emulated drivers available to this process
2018806Sgblack@eecs.umich.edu    std::vector<EmulatedDriver *> drivers;
2028806Sgblack@eecs.umich.edu
2034997Sgblack@eecs.umich.edu    std::shared_ptr<FDArray> fds;
2048806Sgblack@eecs.umich.edu
2058806Sgblack@eecs.umich.edu    bool *exitGroup;
2064997Sgblack@eecs.umich.edu    std::shared_ptr<MemState> memState;
2074997Sgblack@eecs.umich.edu
2084997Sgblack@eecs.umich.edu    /**
2095569Snate@binkert.org     * Calls a futex wakeup at the address specified by this pointer when
21010417Sandreas.hansson@arm.com     * this process exits.
2114997Sgblack@eecs.umich.edu     */
2128780Sgblack@eecs.umich.edu    uint64_t childClearTID;
2138780Sgblack@eecs.umich.edu
2148806Sgblack@eecs.umich.edu    // Process was forked with SIGCHLD set.
2158806Sgblack@eecs.umich.edu    bool *sigchld;
2168806Sgblack@eecs.umich.edu};
2178806Sgblack@eecs.umich.edu
2188806Sgblack@eecs.umich.edu#endif // __PROCESS_HH__
2198806Sgblack@eecs.umich.edu