process.hh revision 12431
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/mem_state.hh"
5112391Sjason@lowepower.com#include "sim/sim_object.hh"
5212391Sjason@lowepower.com
5312391Sjason@lowepower.comstruct ProcessParams;
5412391Sjason@lowepower.com
5512391Sjason@lowepower.comclass EmulatedDriver;
5612391Sjason@lowepower.comclass ObjectFile;
5712391Sjason@lowepower.comclass PageTableBase;
5812391Sjason@lowepower.comclass SyscallDesc;
5912391Sjason@lowepower.comclass SyscallReturn;
6012391Sjason@lowepower.comclass System;
6112391Sjason@lowepower.comclass ThreadContext;
6212391Sjason@lowepower.com
6312391Sjason@lowepower.comclass Process : public SimObject
6412391Sjason@lowepower.com{
6512391Sjason@lowepower.com  public:
6612391Sjason@lowepower.com    Process(ProcessParams *params, PageTableBase *pTable,
6712391Sjason@lowepower.com            ObjectFile *obj_file);
6812391Sjason@lowepower.com
6912391Sjason@lowepower.com    void serialize(CheckpointOut &cp) const override;
7012391Sjason@lowepower.com    void unserialize(CheckpointIn &cp) override;
7112391Sjason@lowepower.com
7212391Sjason@lowepower.com    void initState() override;
7312391Sjason@lowepower.com    DrainState drain() override;
7412391Sjason@lowepower.com
7512391Sjason@lowepower.com    virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
7612391Sjason@lowepower.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
7712391Sjason@lowepower.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
7812391Sjason@lowepower.com    virtual void setSyscallArg(ThreadContext *tc, int i,
7912391Sjason@lowepower.com                               TheISA::IntReg val) = 0;
8012391Sjason@lowepower.com    virtual void setSyscallReturn(ThreadContext *tc,
8112391Sjason@lowepower.com                                  SyscallReturn return_value) = 0;
8212391Sjason@lowepower.com    virtual SyscallDesc *getDesc(int callnum) = 0;
8311986Sandreas.sandberg@arm.com
8411986Sandreas.sandberg@arm.com    inline uint64_t uid() { return _uid; }
8512391Sjason@lowepower.com    inline uint64_t euid() { return _euid; }
8612391Sjason@lowepower.com    inline uint64_t gid() { return _gid; }
8712391Sjason@lowepower.com    inline uint64_t egid() { return _egid; }
8812391Sjason@lowepower.com    inline uint64_t pid() { return _pid; }
8912391Sjason@lowepower.com    inline uint64_t ppid() { return _ppid; }
9012391Sjason@lowepower.com    inline uint64_t pgid() { return _pgid; }
9112391Sjason@lowepower.com    inline uint64_t tgid() { return _tgid; }
9212391Sjason@lowepower.com    inline void setpgid(uint64_t pgid) { _pgid = pgid; }
9312391Sjason@lowepower.com
9412391Sjason@lowepower.com    const char *progName() const { return executable.c_str(); }
9512391Sjason@lowepower.com    std::string fullPath(const std::string &filename);
9612391Sjason@lowepower.com    std::string getcwd() const { return cwd; }
9712391Sjason@lowepower.com
9812391Sjason@lowepower.com    /**
9912391Sjason@lowepower.com     * Find an emulated device driver.
10012391Sjason@lowepower.com     *
10112391Sjason@lowepower.com     * @param filename Name of the device (under /dev)
10212391Sjason@lowepower.com     * @return Pointer to driver object if found, else nullptr
10312391Sjason@lowepower.com     */
10412391Sjason@lowepower.com    EmulatedDriver *findDriver(std::string filename);
10512391Sjason@lowepower.com
10612391Sjason@lowepower.com    // This function acts as a callback to update the bias value in
10712391Sjason@lowepower.com    // the object file because the parameters needed to calculate the
10812391Sjason@lowepower.com    // bias are not available when the object file is created.
10912391Sjason@lowepower.com    void updateBias();
11012391Sjason@lowepower.com    Addr getBias();
11112391Sjason@lowepower.com    Addr getStartPC();
11212391Sjason@lowepower.com    ObjectFile *getInterpreter();
11312391Sjason@lowepower.com
11412391Sjason@lowepower.com    // override of virtual SimObject method: register statistics
11512391Sjason@lowepower.com    void regStats() override;
11611986Sandreas.sandberg@arm.com
11712391Sjason@lowepower.com    void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
11811986Sandreas.sandberg@arm.com
11912391Sjason@lowepower.com    /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
12012391Sjason@lowepower.com    /// @return Whether the fault has been fixed.
12112391Sjason@lowepower.com    bool fixupStackFault(Addr vaddr);
12212391Sjason@lowepower.com
12312391Sjason@lowepower.com    // After getting registered with system object, tell process which
12412391Sjason@lowepower.com    // system-wide context id it is assigned.
12512391Sjason@lowepower.com    void
12612391Sjason@lowepower.com    assignThreadContext(ContextID context_id)
12712391Sjason@lowepower.com    {
12812391Sjason@lowepower.com        contextIds.push_back(context_id);
12912391Sjason@lowepower.com    }
13012391Sjason@lowepower.com
13112391Sjason@lowepower.com    // Find a free context to use
13212391Sjason@lowepower.com    ThreadContext *findFreeContext();
13311986Sandreas.sandberg@arm.com
13411986Sandreas.sandberg@arm.com    /**
13511986Sandreas.sandberg@arm.com     * After delegating a thread context to a child process
13612391Sjason@lowepower.com     * no longer should relate to the ThreadContext
13712391Sjason@lowepower.com     */
13812391Sjason@lowepower.com    void revokeThreadContext(int context_id);
13912391Sjason@lowepower.com
14012391Sjason@lowepower.com    /**
14112391Sjason@lowepower.com     * Does mmap region grow upward or downward from mmapEnd?  Most
14212391Sjason@lowepower.com     * platforms grow downward, but a few (such as Alpha) grow upward
14312391Sjason@lowepower.com     * instead, so they can override this method to return false.
14412391Sjason@lowepower.com     */
14512391Sjason@lowepower.com    virtual bool mmapGrowsDown() const { return true; }
14612391Sjason@lowepower.com
14712391Sjason@lowepower.com    /**
14812391Sjason@lowepower.com     * Maps a contiguous range of virtual addresses in this process's
14912391Sjason@lowepower.com     * address space to a contiguous range of physical addresses.
15012391Sjason@lowepower.com     * This function exists primarily to expose the map operation to
15112391Sjason@lowepower.com     * python, so that configuration scripts can set up mappings in SE mode.
15212391Sjason@lowepower.com     *
15311986Sandreas.sandberg@arm.com     * @param vaddr The starting virtual address of the range.
15411986Sandreas.sandberg@arm.com     * @param paddr The starting physical address of the range.
15512391Sjason@lowepower.com     * @param size The length of the range in bytes.
15612391Sjason@lowepower.com     * @param cacheable Specifies whether accesses are cacheable.
15712391Sjason@lowepower.com     * @return True if the map operation was successful.  (At this
15812391Sjason@lowepower.com     *           point in time, the map operation always succeeds.)
15912391Sjason@lowepower.com     */
16012391Sjason@lowepower.com    bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
16112391Sjason@lowepower.com
16212391Sjason@lowepower.com    void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
16312391Sjason@lowepower.com                       ThreadContext *new_tc, bool alloc_page);
16412391Sjason@lowepower.com
16512391Sjason@lowepower.com    virtual void clone(ThreadContext *old_tc, ThreadContext *new_tc,
16612391Sjason@lowepower.com                       Process *new_p, TheISA::IntReg flags);
16712391Sjason@lowepower.com
16812391Sjason@lowepower.com    // thread contexts associated with this process
16912391Sjason@lowepower.com    std::vector<ContextID> contextIds;
17012391Sjason@lowepower.com
17112391Sjason@lowepower.com    // system object which owns this process
17212391Sjason@lowepower.com    System *system;
17312391Sjason@lowepower.com
17412391Sjason@lowepower.com    Stats::Scalar numSyscalls;  // track how many system calls are executed
17512391Sjason@lowepower.com
17612391Sjason@lowepower.com    bool useArchPT; // flag for using architecture specific page table
17712391Sjason@lowepower.com    bool kvmInSE;   // running KVM requires special initialization
17812391Sjason@lowepower.com
17912391Sjason@lowepower.com    PageTableBase* pTable;
18012391Sjason@lowepower.com
18112391Sjason@lowepower.com    SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
18212391Sjason@lowepower.com
18312391Sjason@lowepower.com    ObjectFile *objFile;
18412391Sjason@lowepower.com    std::vector<std::string> argv;
18512391Sjason@lowepower.com    std::vector<std::string> envp;
18612391Sjason@lowepower.com    std::string cwd;
18711986Sandreas.sandberg@arm.com    std::string executable;
18812391Sjason@lowepower.com
18912391Sjason@lowepower.com    // Id of the owner of the process
19012391Sjason@lowepower.com    uint64_t _uid;
19112391Sjason@lowepower.com    uint64_t _euid;
19211986Sandreas.sandberg@arm.com    uint64_t _gid;
19311986Sandreas.sandberg@arm.com    uint64_t _egid;
19411986Sandreas.sandberg@arm.com
19511986Sandreas.sandberg@arm.com    // pid of the process and it's parent
19611986Sandreas.sandberg@arm.com    uint64_t _pid;
19711986Sandreas.sandberg@arm.com    uint64_t _ppid;
19811986Sandreas.sandberg@arm.com    uint64_t _pgid;
19911986Sandreas.sandberg@arm.com    uint64_t _tgid;
20011986Sandreas.sandberg@arm.com
20111986Sandreas.sandberg@arm.com    // Emulated drivers available to this process
20211986Sandreas.sandberg@arm.com    std::vector<EmulatedDriver *> drivers;
20311986Sandreas.sandberg@arm.com
20411986Sandreas.sandberg@arm.com    std::shared_ptr<FDArray> fds;
20511986Sandreas.sandberg@arm.com
20612391Sjason@lowepower.com    bool *exitGroup;
20714299Sbbruce@ucdavis.edu    std::shared_ptr<MemState> memState;
20814299Sbbruce@ucdavis.edu
20914299Sbbruce@ucdavis.edu    /**
21014299Sbbruce@ucdavis.edu     * Calls a futex wakeup at the address specified by this pointer when
21112391Sjason@lowepower.com     * this process exits.
21212391Sjason@lowepower.com     */
21312391Sjason@lowepower.com    uint64_t childClearTID;
21412391Sjason@lowepower.com
21512391Sjason@lowepower.com    // Process was forked with SIGCHLD set.
21612391Sjason@lowepower.com    bool *sigchld;
21712391Sjason@lowepower.com};
21812391Sjason@lowepower.com
21914299Sbbruce@ucdavis.edu#endif // __PROCESS_HH__
22012391Sjason@lowepower.com