process.hh revision 13617
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;
5712448Sgabeblack@google.comclass EmulationPageTable;
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:
6612448Sgabeblack@google.com    Process(ProcessParams *params, EmulationPageTable *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);
7613557Sgabeblack@google.com    virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0;
7713557Sgabeblack@google.com    virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width);
7813557Sgabeblack@google.com    virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0;
7911854Sbrandon.potter@amd.com    virtual void setSyscallReturn(ThreadContext *tc,
8011854Sbrandon.potter@amd.com                                  SyscallReturn return_value) = 0;
8111854Sbrandon.potter@amd.com    virtual SyscallDesc *getDesc(int callnum) = 0;
822SN/A
8311854Sbrandon.potter@amd.com    inline uint64_t uid() { return _uid; }
8411854Sbrandon.potter@amd.com    inline uint64_t euid() { return _euid; }
8511854Sbrandon.potter@amd.com    inline uint64_t gid() { return _gid; }
8611854Sbrandon.potter@amd.com    inline uint64_t egid() { return _egid; }
8711854Sbrandon.potter@amd.com    inline uint64_t pid() { return _pid; }
8811854Sbrandon.potter@amd.com    inline uint64_t ppid() { return _ppid; }
8911885Sbrandon.potter@amd.com    inline uint64_t pgid() { return _pgid; }
9011885Sbrandon.potter@amd.com    inline uint64_t tgid() { return _tgid; }
9111885Sbrandon.potter@amd.com    inline void setpgid(uint64_t pgid) { _pgid = pgid; }
9210554Salexandru.dutu@amd.com
9311854Sbrandon.potter@amd.com    const char *progName() const { return executable.c_str(); }
9411854Sbrandon.potter@amd.com    std::string fullPath(const std::string &filename);
9511854Sbrandon.potter@amd.com    std::string getcwd() const { return cwd; }
968852Sandreas.hansson@arm.com
9711854Sbrandon.potter@amd.com    /**
9811854Sbrandon.potter@amd.com     * Find an emulated device driver.
9911854Sbrandon.potter@amd.com     *
10011854Sbrandon.potter@amd.com     * @param filename Name of the device (under /dev)
10111919SBrandon.Potter@amd.com     * @return Pointer to driver object if found, else nullptr
10211854Sbrandon.potter@amd.com     */
10311854Sbrandon.potter@amd.com    EmulatedDriver *findDriver(std::string filename);
1048852Sandreas.hansson@arm.com
10511854Sbrandon.potter@amd.com    // This function acts as a callback to update the bias value in
10611854Sbrandon.potter@amd.com    // the object file because the parameters needed to calculate the
10711854Sbrandon.potter@amd.com    // bias are not available when the object file is created.
10811854Sbrandon.potter@amd.com    void updateBias();
10911854Sbrandon.potter@amd.com    Addr getBias();
11011854Sbrandon.potter@amd.com    Addr getStartPC();
11111854Sbrandon.potter@amd.com    ObjectFile *getInterpreter();
1125282Srstrong@cs.ucsd.edu
1132SN/A    // override of virtual SimObject method: register statistics
11411169Sandreas.hansson@arm.com    void regStats() override;
1152SN/A
1168601Ssteve.reinhardt@amd.com    void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
1178601Ssteve.reinhardt@amd.com
1188539Sgblack@eecs.umich.edu    /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
1198539Sgblack@eecs.umich.edu    /// @return Whether the fault has been fixed.
1208539Sgblack@eecs.umich.edu    bool fixupStackFault(Addr vaddr);
1214434Ssaidi@eecs.umich.edu
12211854Sbrandon.potter@amd.com    // After getting registered with system object, tell process which
12311854Sbrandon.potter@amd.com    // system-wide context id it is assigned.
12411854Sbrandon.potter@amd.com    void
12511854Sbrandon.potter@amd.com    assignThreadContext(ContextID context_id)
12611854Sbrandon.potter@amd.com    {
12711854Sbrandon.potter@amd.com        contextIds.push_back(context_id);
12811854Sbrandon.potter@amd.com    }
12911854Sbrandon.potter@amd.com
13011854Sbrandon.potter@amd.com    // Find a free context to use
13111854Sbrandon.potter@amd.com    ThreadContext *findFreeContext();
13211854Sbrandon.potter@amd.com
13311854Sbrandon.potter@amd.com    /**
13411886Sbrandon.potter@amd.com     * After delegating a thread context to a child process
13511886Sbrandon.potter@amd.com     * no longer should relate to the ThreadContext
13611886Sbrandon.potter@amd.com     */
13711886Sbrandon.potter@amd.com    void revokeThreadContext(int context_id);
13811886Sbrandon.potter@amd.com
13911886Sbrandon.potter@amd.com    /**
14011886Sbrandon.potter@amd.com     * Does mmap region grow upward or downward from mmapEnd?  Most
14111854Sbrandon.potter@amd.com     * platforms grow downward, but a few (such as Alpha) grow upward
14211854Sbrandon.potter@amd.com     * instead, so they can override this method to return false.
14311854Sbrandon.potter@amd.com     */
14411854Sbrandon.potter@amd.com    virtual bool mmapGrowsDown() const { return true; }
14511854Sbrandon.potter@amd.com
1469110Ssteve.reinhardt@amd.com    /**
14710558Salexandru.dutu@amd.com     * Maps a contiguous range of virtual addresses in this process's
1489110Ssteve.reinhardt@amd.com     * address space to a contiguous range of physical addresses.
14910558Salexandru.dutu@amd.com     * This function exists primarily to expose the map operation to
15010558Salexandru.dutu@amd.com     * python, so that configuration scripts can set up mappings in SE mode.
1519110Ssteve.reinhardt@amd.com     *
1529110Ssteve.reinhardt@amd.com     * @param vaddr The starting virtual address of the range.
1539110Ssteve.reinhardt@amd.com     * @param paddr The starting physical address of the range.
1549110Ssteve.reinhardt@amd.com     * @param size The length of the range in bytes.
15510558Salexandru.dutu@amd.com     * @param cacheable Specifies whether accesses are cacheable.
1569110Ssteve.reinhardt@amd.com     * @return True if the map operation was successful.  (At this
1579110Ssteve.reinhardt@amd.com     *           point in time, the map operation always succeeds.)
1589110Ssteve.reinhardt@amd.com     */
15910558Salexandru.dutu@amd.com    bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
1609110Ssteve.reinhardt@amd.com
16111886Sbrandon.potter@amd.com    void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
16211886Sbrandon.potter@amd.com                       ThreadContext *new_tc, bool alloc_page);
16311886Sbrandon.potter@amd.com
16412141Sspwilson2@wisc.edu    virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
16513557Sgabeblack@google.com                       Process *new_p, RegVal flags);
16611886Sbrandon.potter@amd.com
16711854Sbrandon.potter@amd.com    // thread contexts associated with this process
16811854Sbrandon.potter@amd.com    std::vector<ContextID> contextIds;
16911854Sbrandon.potter@amd.com
17011854Sbrandon.potter@amd.com    // system object which owns this process
17111854Sbrandon.potter@amd.com    System *system;
17211854Sbrandon.potter@amd.com
17311886Sbrandon.potter@amd.com    Stats::Scalar numSyscalls;  // track how many system calls are executed
17411854Sbrandon.potter@amd.com
17511854Sbrandon.potter@amd.com    bool useArchPT; // flag for using architecture specific page table
17611854Sbrandon.potter@amd.com    bool kvmInSE;   // running KVM requires special initialization
17711854Sbrandon.potter@amd.com
17812448Sgabeblack@google.com    EmulationPageTable *pTable;
17911854Sbrandon.potter@amd.com
18011854Sbrandon.potter@amd.com    SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
18111854Sbrandon.potter@amd.com
18211851Sbrandon.potter@amd.com    ObjectFile *objFile;
18311851Sbrandon.potter@amd.com    std::vector<std::string> argv;
18411851Sbrandon.potter@amd.com    std::vector<std::string> envp;
18511851Sbrandon.potter@amd.com    std::string cwd;
18611851Sbrandon.potter@amd.com    std::string executable;
18711851Sbrandon.potter@amd.com
18811801Sbrandon.potter@amd.com    // Id of the owner of the process
18911801Sbrandon.potter@amd.com    uint64_t _uid;
19011801Sbrandon.potter@amd.com    uint64_t _euid;
19111801Sbrandon.potter@amd.com    uint64_t _gid;
19211801Sbrandon.potter@amd.com    uint64_t _egid;
19311801Sbrandon.potter@amd.com
19411801Sbrandon.potter@amd.com    // pid of the process and it's parent
19511801Sbrandon.potter@amd.com    uint64_t _pid;
19611801Sbrandon.potter@amd.com    uint64_t _ppid;
19711885Sbrandon.potter@amd.com    uint64_t _pgid;
19811885Sbrandon.potter@amd.com    uint64_t _tgid;
19911801Sbrandon.potter@amd.com
20010496Ssteve.reinhardt@amd.com    // Emulated drivers available to this process
20110496Ssteve.reinhardt@amd.com    std::vector<EmulatedDriver *> drivers;
20211856Sbrandon.potter@amd.com
20311856Sbrandon.potter@amd.com    std::shared_ptr<FDArray> fds;
20411886Sbrandon.potter@amd.com
20511886Sbrandon.potter@amd.com    bool *exitGroup;
20611905SBrandon.Potter@amd.com    std::shared_ptr<MemState> memState;
20711886Sbrandon.potter@amd.com
20811886Sbrandon.potter@amd.com    /**
20911886Sbrandon.potter@amd.com     * Calls a futex wakeup at the address specified by this pointer when
21011886Sbrandon.potter@amd.com     * this process exits.
21111886Sbrandon.potter@amd.com     */
21211886Sbrandon.potter@amd.com    uint64_t childClearTID;
21311886Sbrandon.potter@amd.com
21411886Sbrandon.potter@amd.com    // Process was forked with SIGCHLD set.
21511886Sbrandon.potter@amd.com    bool *sigchld;
2162SN/A};
2172SN/A
218360SN/A#endif // __PROCESS_HH__
219