process.hh revision 4434
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302SN/A */ 312SN/A 32360SN/A#ifndef __PROCESS_HH__ 33360SN/A#define __PROCESS_HH__ 342SN/A 352SN/A// 362SN/A// The purpose of this code is to fake the loader & syscall mechanism 372SN/A// when there's no OS: thus there's no reason to use it in FULL_SYSTEM 382SN/A// mode when we do have an OS. 392SN/A// 401858SN/A#include "config/full_system.hh" 411858SN/A 421858SN/A#if !FULL_SYSTEM 432SN/A 444117Sgblack@eecs.umich.edu#include <string> 45180SN/A#include <vector> 462SN/A 472378SN/A#include "base/statistics.hh" 484111Sgblack@eecs.umich.edu#include "sim/host.hh" 4956SN/A#include "sim/sim_object.hh" 502SN/A 512680Sktlim@umich.educlass ThreadContext; 522093SN/Aclass SyscallDesc; 532462SN/Aclass PageTable; 542401SN/Aclass TranslatingPort; 552378SN/Aclass System; 563971Sgblack@eecs.umich.educlass GDBListener; 573971Sgblack@eecs.umich.edunamespace TheISA 583971Sgblack@eecs.umich.edu{ 593971Sgblack@eecs.umich.edu class RemoteGDB; 603971Sgblack@eecs.umich.edu} 612378SN/A 622SN/Aclass Process : public SimObject 632SN/A{ 642SN/A public: 652SN/A 662378SN/A /// Pointer to object representing the system this process is 672378SN/A /// running on. 682378SN/A System *system; 692378SN/A 702680Sktlim@umich.edu // have we initialized a thread context from this process? If 712SN/A // yes, subsequent contexts are assumed to be for dynamically 722SN/A // created threads and are not initialized. 732SN/A bool initialContextLoaded; 742SN/A 752680Sktlim@umich.edu // thread contexts associated with this process 762680Sktlim@umich.edu std::vector<ThreadContext *> threadContexts; 77180SN/A 783971Sgblack@eecs.umich.edu // remote gdb objects 793971Sgblack@eecs.umich.edu std::vector<TheISA::RemoteGDB *> remoteGDB; 803971Sgblack@eecs.umich.edu std::vector<GDBListener *> gdbListen; 813971Sgblack@eecs.umich.edu bool breakpoint(); 823971Sgblack@eecs.umich.edu 83180SN/A // number of CPUs (esxec contexts, really) assigned to this process. 842680Sktlim@umich.edu unsigned int numCpus() { return threadContexts.size(); } 852SN/A 862SN/A // record of blocked context 872SN/A struct WaitRec 882SN/A { 892SN/A Addr waitChan; 902680Sktlim@umich.edu ThreadContext *waitingContext; 912SN/A 922680Sktlim@umich.edu WaitRec(Addr chan, ThreadContext *ctx) 932SN/A : waitChan(chan), waitingContext(ctx) 942378SN/A { } 952SN/A }; 962SN/A 972SN/A // list of all blocked contexts 982SN/A std::list<WaitRec> waitList; 992SN/A 1002SN/A Addr brk_point; // top of the data segment 1012SN/A 1022SN/A Addr stack_base; // stack segment base (highest address) 1032SN/A unsigned stack_size; // initial stack size 1042SN/A Addr stack_min; // lowest address accessed on the stack 1052SN/A 1062SN/A // addr to use for next stack region (for multithreaded apps) 1072SN/A Addr next_thread_stack_base; 1082SN/A 109360SN/A // Base of region for mmaps (when user doesn't specify an address). 1101408SN/A Addr mmap_start; 1111408SN/A Addr mmap_end; 112360SN/A 1131514SN/A // Base of region for nxm data 1141514SN/A Addr nxm_start; 1151514SN/A Addr nxm_end; 1161514SN/A 1172SN/A std::string prog_fname; // file name 1182SN/A 119729SN/A Stats::Scalar<> num_syscalls; // number of syscalls executed 1202SN/A 1212SN/A 1222SN/A protected: 1232SN/A // constructor 1241450SN/A Process(const std::string &nm, 1252378SN/A System *_system, 1262SN/A int stdin_fd, // initial I/O descriptors 1272SN/A int stdout_fd, 1282SN/A int stderr_fd); 1292SN/A 1301395SN/A // post initialization startup 1311395SN/A virtual void startup(); 1322SN/A 1332SN/A protected: 1342378SN/A /// Memory object for initialization (image loading) 1352401SN/A TranslatingPort *initVirtMem; 1362378SN/A 1372378SN/A public: 1382378SN/A PageTable *pTable; 1392SN/A 1402SN/A private: 1412SN/A // file descriptor remapping support 1421970SN/A static const int MAX_FD = 256; // max legal fd value 1432SN/A int fd_map[MAX_FD+1]; 1442SN/A 1452SN/A public: 1462SN/A // static helper functions to generate file descriptors for constructor 1472SN/A static int openInputFile(const std::string &filename); 1482SN/A static int openOutputFile(const std::string &filename); 1492SN/A 1502SN/A // override of virtual SimObject method: register statistics 1512SN/A virtual void regStats(); 1522SN/A 1532680Sktlim@umich.edu // register a thread context for this process. 1542680Sktlim@umich.edu // returns tc's cpu number (index into threadContexts[]) 1552680Sktlim@umich.edu int registerThreadContext(ThreadContext *tc); 156180SN/A 157180SN/A 1582680Sktlim@umich.edu void replaceThreadContext(ThreadContext *tc, int tcIndex); 1592SN/A 1602SN/A // map simulator fd sim_fd to target fd tgt_fd 1612SN/A void dup_fd(int sim_fd, int tgt_fd); 1622SN/A 1632SN/A // generate new target fd for sim_fd 1641970SN/A int alloc_fd(int sim_fd); 1651970SN/A 1661970SN/A // free target fd (e.g., after close) 1671970SN/A void free_fd(int tgt_fd); 1682SN/A 1692SN/A // look up simulator fd for given target fd 1702SN/A int sim_fd(int tgt_fd); 1712SN/A 1722680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc) = 0; 1733311Ssaidi@eecs.umich.edu 1744434Ssaidi@eecs.umich.edu // check if the this addr is on the next available page and allocate it 1754434Ssaidi@eecs.umich.edu // if it's not we'll panic 1764434Ssaidi@eecs.umich.edu bool checkAndAllocNextPage(Addr vaddr); 1774434Ssaidi@eecs.umich.edu 1783311Ssaidi@eecs.umich.edu void serialize(std::ostream &os); 1793311Ssaidi@eecs.umich.edu void unserialize(Checkpoint *cp, const std::string §ion); 1802SN/A}; 1812SN/A 1822SN/A// 1832SN/A// "Live" process with system calls redirected to host system 1842SN/A// 185360SN/Aclass ObjectFile; 1862SN/Aclass LiveProcess : public Process 1872SN/A{ 188360SN/A protected: 1892378SN/A ObjectFile *objFile; 1902378SN/A std::vector<std::string> argv; 1912378SN/A std::vector<std::string> envp; 1923669Sbinkertn@umich.edu std::string cwd; 1932378SN/A 1941450SN/A LiveProcess(const std::string &nm, ObjectFile *objFile, 1952378SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 1962SN/A std::vector<std::string> &argv, 1973114Sgblack@eecs.umich.edu std::vector<std::string> &envp, 1983669Sbinkertn@umich.edu const std::string &cwd, 1993114Sgblack@eecs.umich.edu uint64_t _uid, uint64_t _euid, 2003114Sgblack@eecs.umich.edu uint64_t _gid, uint64_t _egid, 2013114Sgblack@eecs.umich.edu uint64_t _pid, uint64_t _ppid); 2022SN/A 2032561SN/A virtual void argsInit(int intSize, int pageSize); 2042378SN/A 2053114Sgblack@eecs.umich.edu // Id of the owner of the process 2063114Sgblack@eecs.umich.edu uint64_t __uid; 2073114Sgblack@eecs.umich.edu uint64_t __euid; 2083114Sgblack@eecs.umich.edu uint64_t __gid; 2093114Sgblack@eecs.umich.edu uint64_t __egid; 2103114Sgblack@eecs.umich.edu 2113114Sgblack@eecs.umich.edu // pid of the process and it's parent 2123114Sgblack@eecs.umich.edu uint64_t __pid; 2133114Sgblack@eecs.umich.edu uint64_t __ppid; 2143114Sgblack@eecs.umich.edu 215360SN/A public: 2163114Sgblack@eecs.umich.edu 2173114Sgblack@eecs.umich.edu inline uint64_t uid() {return __uid;} 2183114Sgblack@eecs.umich.edu inline uint64_t euid() {return __euid;} 2193114Sgblack@eecs.umich.edu inline uint64_t gid() {return __gid;} 2203114Sgblack@eecs.umich.edu inline uint64_t egid() {return __egid;} 2213114Sgblack@eecs.umich.edu inline uint64_t pid() {return __pid;} 2223114Sgblack@eecs.umich.edu inline uint64_t ppid() {return __ppid;} 2233114Sgblack@eecs.umich.edu 2243669Sbinkertn@umich.edu std::string 2253669Sbinkertn@umich.edu fullPath(const std::string &filename) 2263669Sbinkertn@umich.edu { 2273669Sbinkertn@umich.edu if (filename[0] == '/' || cwd.empty()) 2283669Sbinkertn@umich.edu return filename; 2293669Sbinkertn@umich.edu 2303669Sbinkertn@umich.edu std::string full = cwd; 2313669Sbinkertn@umich.edu 2323669Sbinkertn@umich.edu if (cwd[cwd.size() - 1] != '/') 2333669Sbinkertn@umich.edu full += '/'; 2343669Sbinkertn@umich.edu 2353669Sbinkertn@umich.edu return full + filename; 2363669Sbinkertn@umich.edu } 2373669Sbinkertn@umich.edu 2382680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc); 2392093SN/A 2402462SN/A virtual SyscallDesc* getDesc(int callnum) = 0; 2412715Sstever@eecs.umich.edu 2422715Sstever@eecs.umich.edu // this function is used to create the LiveProcess object, since 2432715Sstever@eecs.umich.edu // we can't tell which subclass of LiveProcess to use until we 2442715Sstever@eecs.umich.edu // open and look at the object file. 2452715Sstever@eecs.umich.edu static LiveProcess *create(const std::string &nm, 2462715Sstever@eecs.umich.edu System *_system, 2472715Sstever@eecs.umich.edu int stdin_fd, int stdout_fd, int stderr_fd, 2482715Sstever@eecs.umich.edu std::string executable, 2492715Sstever@eecs.umich.edu std::vector<std::string> &argv, 2503114Sgblack@eecs.umich.edu std::vector<std::string> &envp, 2513669Sbinkertn@umich.edu const std::string &cwd, 2523114Sgblack@eecs.umich.edu uint64_t _uid, uint64_t _euid, 2533114Sgblack@eecs.umich.edu uint64_t _gid, uint64_t _egid, 2543114Sgblack@eecs.umich.edu uint64_t _pid, uint64_t _ppid); 2552SN/A}; 2562SN/A 257360SN/A 2582SN/A#endif // !FULL_SYSTEM 2592SN/A 260360SN/A#endif // __PROCESS_HH__ 261