process.hh revision 12431
12SN/A/*
211856Sbrandon.potter@amd.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
31762SN/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
272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
302665Ssaidi@eecs.umich.edu *          Steve Reinhardt
3111856Sbrandon.potter@amd.com *          Brandon Potter
322SN/A */
332SN/A
34360SN/A#ifndef __PROCESS_HH__
35360SN/A#define __PROCESS_HH__
362SN/A
3711854Sbrandon.potter@amd.com#include <inttypes.h>
3811854Sbrandon.potter@amd.com
3911800Sbrandon.potter@amd.com#include <map>
404117Sgblack@eecs.umich.edu#include <string>
41180SN/A#include <vector>
422SN/A
436329Sgblack@eecs.umich.edu#include "arch/registers.hh"
442378SN/A#include "base/statistics.hh"
456214Snate@binkert.org#include "base/types.hh"
466658Snate@binkert.org#include "config/the_isa.hh"
478852Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh"
4811856Sbrandon.potter@amd.com#include "sim/fd_array.hh"
4910930Sbrandon.potter@amd.com#include "sim/fd_entry.hh"
5011905SBrandon.Potter@amd.com#include "sim/mem_state.hh"
5156SN/A#include "sim/sim_object.hh"
522SN/A
538737Skoansin.tan@gmail.comstruct ProcessParams;
5411800Sbrandon.potter@amd.com
5511800Sbrandon.potter@amd.comclass EmulatedDriver;
5611851Sbrandon.potter@amd.comclass ObjectFile;
5711800Sbrandon.potter@amd.comclass PageTableBase;
585154Sgblack@eecs.umich.educlass SyscallDesc;
5911800Sbrandon.potter@amd.comclass SyscallReturn;
605154Sgblack@eecs.umich.educlass System;
612680Sktlim@umich.educlass ThreadContext;
622378SN/A
632SN/Aclass Process : public SimObject
642SN/A{
652SN/A  public:
6612431Sgabeblack@google.com    Process(ProcessParams *params, PageTableBase *pTable,
6712431Sgabeblack@google.com            ObjectFile *obj_file);
682SN/A
6911854Sbrandon.potter@amd.com    void serialize(CheckpointOut &cp) const override;
7011854Sbrandon.potter@amd.com    void unserialize(CheckpointIn &cp) override;
712SN/A
7211169Sandreas.hansson@arm.com    void initState() override;
7311168Sandreas.hansson@arm.com    DrainState drain() override;
7410905Sandreas.sandberg@arm.com
7512044Sgabeblack@google.com    virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
7611854Sbrandon.potter@amd.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
7711854Sbrandon.potter@amd.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
7811854Sbrandon.potter@amd.com    virtual void setSyscallArg(ThreadContext *tc, int i,
7911854Sbrandon.potter@amd.com                               TheISA::IntReg val) = 0;
8011854Sbrandon.potter@amd.com    virtual void setSyscallReturn(ThreadContext *tc,
8111854Sbrandon.potter@amd.com                                  SyscallReturn return_value) = 0;
8211854Sbrandon.potter@amd.com    virtual SyscallDesc *getDesc(int callnum) = 0;
832SN/A
8411854Sbrandon.potter@amd.com    inline uint64_t uid() { return _uid; }
8511854Sbrandon.potter@amd.com    inline uint64_t euid() { return _euid; }
8611854Sbrandon.potter@amd.com    inline uint64_t gid() { return _gid; }
8711854Sbrandon.potter@amd.com    inline uint64_t egid() { return _egid; }
8811854Sbrandon.potter@amd.com    inline uint64_t pid() { return _pid; }
8911854Sbrandon.potter@amd.com    inline uint64_t ppid() { return _ppid; }
9011885Sbrandon.potter@amd.com    inline uint64_t pgid() { return _pgid; }
9111885Sbrandon.potter@amd.com    inline uint64_t tgid() { return _tgid; }
9211885Sbrandon.potter@amd.com    inline void setpgid(uint64_t pgid) { _pgid = pgid; }
9310554Salexandru.dutu@amd.com
9411854Sbrandon.potter@amd.com    const char *progName() const { return executable.c_str(); }
9511854Sbrandon.potter@amd.com    std::string fullPath(const std::string &filename);
9611854Sbrandon.potter@amd.com    std::string getcwd() const { return cwd; }
978852Sandreas.hansson@arm.com
9811854Sbrandon.potter@amd.com    /**
9911854Sbrandon.potter@amd.com     * Find an emulated device driver.
10011854Sbrandon.potter@amd.com     *
10111854Sbrandon.potter@amd.com     * @param filename Name of the device (under /dev)
10211919SBrandon.Potter@amd.com     * @return Pointer to driver object if found, else nullptr
10311854Sbrandon.potter@amd.com     */
10411854Sbrandon.potter@amd.com    EmulatedDriver *findDriver(std::string filename);
1058852Sandreas.hansson@arm.com
10611854Sbrandon.potter@amd.com    // This function acts as a callback to update the bias value in
10711854Sbrandon.potter@amd.com    // the object file because the parameters needed to calculate the
10811854Sbrandon.potter@amd.com    // bias are not available when the object file is created.
10911854Sbrandon.potter@amd.com    void updateBias();
11011854Sbrandon.potter@amd.com    Addr getBias();
11111854Sbrandon.potter@amd.com    Addr getStartPC();
11211854Sbrandon.potter@amd.com    ObjectFile *getInterpreter();
1135282Srstrong@cs.ucsd.edu
1142SN/A    // override of virtual SimObject method: register statistics
11511169Sandreas.hansson@arm.com    void regStats() override;
1162SN/A
1178601Ssteve.reinhardt@amd.com    void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
1188601Ssteve.reinhardt@amd.com
1198539Sgblack@eecs.umich.edu    /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
1208539Sgblack@eecs.umich.edu    /// @return Whether the fault has been fixed.
1218539Sgblack@eecs.umich.edu    bool fixupStackFault(Addr vaddr);
1224434Ssaidi@eecs.umich.edu
12311854Sbrandon.potter@amd.com    // After getting registered with system object, tell process which
12411854Sbrandon.potter@amd.com    // system-wide context id it is assigned.
12511854Sbrandon.potter@amd.com    void
12611854Sbrandon.potter@amd.com    assignThreadContext(ContextID context_id)
12711854Sbrandon.potter@amd.com    {
12811854Sbrandon.potter@amd.com        contextIds.push_back(context_id);
12911854Sbrandon.potter@amd.com    }
13011854Sbrandon.potter@amd.com
13111854Sbrandon.potter@amd.com    // Find a free context to use
13211854Sbrandon.potter@amd.com    ThreadContext *findFreeContext();
13311854Sbrandon.potter@amd.com
13411854Sbrandon.potter@amd.com    /**
13511886Sbrandon.potter@amd.com     * After delegating a thread context to a child process
13611886Sbrandon.potter@amd.com     * no longer should relate to the ThreadContext
13711886Sbrandon.potter@amd.com     */
13811886Sbrandon.potter@amd.com    void revokeThreadContext(int context_id);
13911886Sbrandon.potter@amd.com
14011886Sbrandon.potter@amd.com    /**
14111886Sbrandon.potter@amd.com     * Does mmap region grow upward or downward from mmapEnd?  Most
14211854Sbrandon.potter@amd.com     * platforms grow downward, but a few (such as Alpha) grow upward
14311854Sbrandon.potter@amd.com     * instead, so they can override this method to return false.
14411854Sbrandon.potter@amd.com     */
14511854Sbrandon.potter@amd.com    virtual bool mmapGrowsDown() const { return true; }
14611854Sbrandon.potter@amd.com
1479110Ssteve.reinhardt@amd.com    /**
14810558Salexandru.dutu@amd.com     * Maps a contiguous range of virtual addresses in this process's
1499110Ssteve.reinhardt@amd.com     * address space to a contiguous range of physical addresses.
15010558Salexandru.dutu@amd.com     * This function exists primarily to expose the map operation to
15110558Salexandru.dutu@amd.com     * python, so that configuration scripts can set up mappings in SE mode.
1529110Ssteve.reinhardt@amd.com     *
1539110Ssteve.reinhardt@amd.com     * @param vaddr The starting virtual address of the range.
1549110Ssteve.reinhardt@amd.com     * @param paddr The starting physical address of the range.
1559110Ssteve.reinhardt@amd.com     * @param size The length of the range in bytes.
15610558Salexandru.dutu@amd.com     * @param cacheable Specifies whether accesses are cacheable.
1579110Ssteve.reinhardt@amd.com     * @return True if the map operation was successful.  (At this
1589110Ssteve.reinhardt@amd.com     *           point in time, the map operation always succeeds.)
1599110Ssteve.reinhardt@amd.com     */
16010558Salexandru.dutu@amd.com    bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
1619110Ssteve.reinhardt@amd.com
16211886Sbrandon.potter@amd.com    void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
16311886Sbrandon.potter@amd.com                       ThreadContext *new_tc, bool alloc_page);
16411886Sbrandon.potter@amd.com
16512141Sspwilson2@wisc.edu    virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
16612141Sspwilson2@wisc.edu                       Process *new_p, TheISA::IntReg flags);
16711886Sbrandon.potter@amd.com
16811854Sbrandon.potter@amd.com    // thread contexts associated with this process
16911854Sbrandon.potter@amd.com    std::vector<ContextID> contextIds;
17011854Sbrandon.potter@amd.com
17111854Sbrandon.potter@amd.com    // system object which owns this process
17211854Sbrandon.potter@amd.com    System *system;
17311854Sbrandon.potter@amd.com
17411886Sbrandon.potter@amd.com    Stats::Scalar numSyscalls;  // track how many system calls are executed
17511854Sbrandon.potter@amd.com
17611854Sbrandon.potter@amd.com    bool useArchPT; // flag for using architecture specific page table
17711854Sbrandon.potter@amd.com    bool kvmInSE;   // running KVM requires special initialization
17811854Sbrandon.potter@amd.com
17911854Sbrandon.potter@amd.com    PageTableBase* pTable;
18011854Sbrandon.potter@amd.com
18111854Sbrandon.potter@amd.com    SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
18211854Sbrandon.potter@amd.com
18311851Sbrandon.potter@amd.com    ObjectFile *objFile;
18411851Sbrandon.potter@amd.com    std::vector<std::string> argv;
18511851Sbrandon.potter@amd.com    std::vector<std::string> envp;
18611851Sbrandon.potter@amd.com    std::string cwd;
18711851Sbrandon.potter@amd.com    std::string executable;
18811851Sbrandon.potter@amd.com
18911801Sbrandon.potter@amd.com    // Id of the owner of the process
19011801Sbrandon.potter@amd.com    uint64_t _uid;
19111801Sbrandon.potter@amd.com    uint64_t _euid;
19211801Sbrandon.potter@amd.com    uint64_t _gid;
19311801Sbrandon.potter@amd.com    uint64_t _egid;
19411801Sbrandon.potter@amd.com
19511801Sbrandon.potter@amd.com    // pid of the process and it's parent
19611801Sbrandon.potter@amd.com    uint64_t _pid;
19711801Sbrandon.potter@amd.com    uint64_t _ppid;
19811885Sbrandon.potter@amd.com    uint64_t _pgid;
19911885Sbrandon.potter@amd.com    uint64_t _tgid;
20011801Sbrandon.potter@amd.com
20110496Ssteve.reinhardt@amd.com    // Emulated drivers available to this process
20210496Ssteve.reinhardt@amd.com    std::vector<EmulatedDriver *> drivers;
20311856Sbrandon.potter@amd.com
20411856Sbrandon.potter@amd.com    std::shared_ptr<FDArray> fds;
20511886Sbrandon.potter@amd.com
20611886Sbrandon.potter@amd.com    bool *exitGroup;
20711905SBrandon.Potter@amd.com    std::shared_ptr<MemState> memState;
20811886Sbrandon.potter@amd.com
20911886Sbrandon.potter@amd.com    /**
21011886Sbrandon.potter@amd.com     * Calls a futex wakeup at the address specified by this pointer when
21111886Sbrandon.potter@amd.com     * this process exits.
21211886Sbrandon.potter@amd.com     */
21311886Sbrandon.potter@amd.com    uint64_t childClearTID;
21411886Sbrandon.potter@amd.com
21511886Sbrandon.potter@amd.com    // Process was forked with SIGCHLD set.
21611886Sbrandon.potter@amd.com    bool *sigchld;
2172SN/A};
2182SN/A
219360SN/A#endif // __PROCESS_HH__
220