From 54466a31c3c295f11d5936d34a1b2ac0d3e0045f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 16 Oct 2007 18:04:01 -0700 Subject: [PATCH] Make the process objects use the Params structs in their constructors, and use a limit to check if access are on the stack. --HG-- extra : convert_revision : af40a7acf424c4c4f62d0d76db1001a714ae0474 --- src/arch/alpha/linux/process.cc | 20 +--- src/arch/alpha/linux/process.hh | 11 +-- src/arch/alpha/process.cc | 11 +-- src/arch/alpha/process.hh | 9 +- src/arch/alpha/tru64/process.cc | 17 +--- src/arch/alpha/tru64/process.hh | 12 +-- src/arch/mips/linux/process.cc | 20 +--- src/arch/mips/linux/process.hh | 11 +-- src/arch/mips/process.cc | 11 +-- src/arch/mips/process.hh | 9 +- src/arch/sparc/linux/process.cc | 36 ++----- src/arch/sparc/linux/process.hh | 22 +---- src/arch/sparc/process.cc | 11 +-- src/arch/sparc/process.hh | 37 +------- src/arch/sparc/solaris/process.cc | 21 +--- src/arch/sparc/solaris/process.hh | 11 +-- src/arch/x86/linux/process.cc | 18 +--- src/arch/x86/linux/process.hh | 11 +-- src/arch/x86/process.cc | 11 +-- src/arch/x86/process.hh | 10 +- src/sim/Process.py | 3 +- src/sim/process.cc | 153 ++++++++++++------------------ src/sim/process.hh | 39 +++----- 23 files changed, 122 insertions(+), 392 deletions(-) diff --git a/src/arch/alpha/linux/process.cc b/src/arch/alpha/linux/process.cc index b638aa927..ec47992bd 100644 --- a/src/arch/alpha/linux/process.cc +++ b/src/arch/alpha/linux/process.cc @@ -568,23 +568,9 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = { /* 441 */ SyscallDesc("keyctl", unimplementedFunc) }; -AlphaLinuxProcess::AlphaLinuxProcess(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, - uint64_t _euid, - uint64_t _gid, - uint64_t _egid, - uint64_t _pid, - uint64_t _ppid) - : AlphaLiveProcess(name, objFile, system, stdin_fd, stdout_fd, - stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), +AlphaLinuxProcess::AlphaLinuxProcess(LiveProcessParams * params, + ObjectFile *objFile) + : AlphaLiveProcess(params, objFile), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { //init_regs->intRegFile[0] = 0; diff --git a/src/arch/alpha/linux/process.hh b/src/arch/alpha/linux/process.hh index cb22f521b..8d7c24e37 100644 --- a/src/arch/alpha/linux/process.hh +++ b/src/arch/alpha/linux/process.hh @@ -40,16 +40,7 @@ class AlphaLinuxProcess : public AlphaLiveProcess { public: /// Constructor. - AlphaLinuxProcess(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + AlphaLinuxProcess(LiveProcessParams * params, ObjectFile *objFile); virtual SyscallDesc* getDesc(int callnum); diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index a9848ebb5..ef53021c5 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -40,14 +40,9 @@ using namespace AlphaISA; using namespace std; -AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) +AlphaLiveProcess::AlphaLiveProcess(LiveProcessParams * params, + ObjectFile *objFile) + : LiveProcess(params, objFile) { brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); brk_point = roundUp(brk_point, VMPageSize); diff --git a/src/arch/alpha/process.hh b/src/arch/alpha/process.hh index 8eede502a..c66b97d23 100644 --- a/src/arch/alpha/process.hh +++ b/src/arch/alpha/process.hh @@ -43,14 +43,7 @@ class System; class AlphaLiveProcess : public LiveProcess { protected: - AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + AlphaLiveProcess(LiveProcessParams * params, ObjectFile *objFile); void startup(); }; diff --git a/src/arch/alpha/tru64/process.cc b/src/arch/alpha/tru64/process.cc index a1f02b16c..6823d820a 100644 --- a/src/arch/alpha/tru64/process.cc +++ b/src/arch/alpha/tru64/process.cc @@ -573,20 +573,9 @@ AlphaTru64Process::getDesc(int callnum) } -AlphaTru64Process::AlphaTru64Process(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : AlphaLiveProcess(name, objFile, system, stdin_fd, stdout_fd, - stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), +AlphaTru64Process::AlphaTru64Process(LiveProcessParams * params, + ObjectFile *objFile) + : AlphaLiveProcess(params, objFile), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)), Num_Mach_Syscall_Descs(sizeof(machSyscallDescs) / sizeof(SyscallDesc)) { diff --git a/src/arch/alpha/tru64/process.hh b/src/arch/alpha/tru64/process.hh index f5643c0b9..16bc499c6 100644 --- a/src/arch/alpha/tru64/process.hh +++ b/src/arch/alpha/tru64/process.hh @@ -39,16 +39,8 @@ class AlphaTru64Process : public AlphaLiveProcess { public: /// Constructor. - AlphaTru64Process(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + AlphaTru64Process(LiveProcessParams * params, + ObjectFile *objFile); /// Array of syscall descriptors, indexed by call number. static SyscallDesc syscallDescs[]; diff --git a/src/arch/mips/linux/process.cc b/src/arch/mips/linux/process.cc index 283088cb2..425ef9ac3 100644 --- a/src/arch/mips/linux/process.cc +++ b/src/arch/mips/linux/process.cc @@ -405,23 +405,9 @@ SyscallDesc MipsLinuxProcess::syscallDescs[] = { }; -MipsLinuxProcess::MipsLinuxProcess(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, - uint64_t _euid, - uint64_t _gid, - uint64_t _egid, - uint64_t _pid, - uint64_t _ppid) - : MipsLiveProcess(name, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), +MipsLinuxProcess::MipsLinuxProcess(LiveProcessParams * params, + ObjectFile *objFile) + : MipsLiveProcess(params, objFile), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { } diff --git a/src/arch/mips/linux/process.hh b/src/arch/mips/linux/process.hh index d18c96188..a1e738d61 100644 --- a/src/arch/mips/linux/process.hh +++ b/src/arch/mips/linux/process.hh @@ -38,16 +38,7 @@ class MipsLinuxProcess : public MipsLiveProcess { public: /// Constructor. - MipsLinuxProcess(const std::string &name, - ObjectFile *objFile, - System *system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + MipsLinuxProcess(LiveProcessParams * params, ObjectFile *objFile); void startup(); diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index d1e6e27bf..3ce6b19fa 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -41,14 +41,9 @@ using namespace std; using namespace MipsISA; -MipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) +MipsLiveProcess::MipsLiveProcess(LiveProcessParams * params, + ObjectFile *objFile) + : LiveProcess(params, objFile) { // Set up stack. On MIPS, stack starts at the top of kuseg // user address space. MIPS stack grows down from here diff --git a/src/arch/mips/process.hh b/src/arch/mips/process.hh index b6249f76d..350a5bed9 100644 --- a/src/arch/mips/process.hh +++ b/src/arch/mips/process.hh @@ -44,14 +44,7 @@ class System; class MipsLiveProcess : public LiveProcess { protected: - MipsLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + MipsLiveProcess(LiveProcessParams * params, ObjectFile *objFile); virtual void startup(); diff --git a/src/arch/sparc/linux/process.cc b/src/arch/sparc/linux/process.cc index 9e3f74075..f4ec28c00 100644 --- a/src/arch/sparc/linux/process.cc +++ b/src/arch/sparc/linux/process.cc @@ -72,21 +72,9 @@ SparcLinuxProcess::SparcLinuxProcess() : assert(Num_Syscall_Descs <= 299); } -Sparc32LinuxProcess::Sparc32LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : Sparc32LiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid) +Sparc32LinuxProcess::Sparc32LinuxProcess(LiveProcessParams * params, + ObjectFile *objFile) + : Sparc32LiveProcess(params, objFile) {} void Sparc32LinuxProcess::handleTrap(int trapNum, ThreadContext *tc) @@ -101,21 +89,9 @@ void Sparc32LinuxProcess::handleTrap(int trapNum, ThreadContext *tc) } } -Sparc64LinuxProcess::Sparc64LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : Sparc64LiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid) +Sparc64LinuxProcess::Sparc64LinuxProcess(LiveProcessParams * params, + ObjectFile *objFile) + : Sparc64LiveProcess(params, objFile) {} void Sparc64LinuxProcess::handleTrap(int trapNum, ThreadContext *tc) diff --git a/src/arch/sparc/linux/process.hh b/src/arch/sparc/linux/process.hh index 6c7f30a43..06eee9235 100644 --- a/src/arch/sparc/linux/process.hh +++ b/src/arch/sparc/linux/process.hh @@ -65,16 +65,7 @@ class Sparc32LinuxProcess : public SparcLinuxProcess, public Sparc32LiveProcess { public: /// Constructor. - Sparc32LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + Sparc32LinuxProcess(LiveProcessParams * params, ObjectFile *objFile); SyscallDesc* getDesc(int callnum) { @@ -89,16 +80,7 @@ class Sparc64LinuxProcess : public SparcLinuxProcess, public Sparc64LiveProcess { public: /// Constructor. - Sparc64LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + Sparc64LinuxProcess(LiveProcessParams * params, ObjectFile *objFile); SyscallDesc* getDesc(int callnum) { diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index 91564e754..e0d204a2d 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -47,14 +47,9 @@ using namespace std; using namespace SparcISA; -SparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) +SparcLiveProcess::SparcLiveProcess(LiveProcessParams * params, + ObjectFile *objFile) + : LiveProcess(params, objFile) { // XXX all the below need to be updated for SPARC - Ali diff --git a/src/arch/sparc/process.hh b/src/arch/sparc/process.hh index f4e823a9a..dd8eae316 100644 --- a/src/arch/sparc/process.hh +++ b/src/arch/sparc/process.hh @@ -46,14 +46,7 @@ class SparcLiveProcess : public LiveProcess //The locations of the fill and spill handlers Addr fillStart, spillStart; - SparcLiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + SparcLiveProcess(LiveProcessParams * params, ObjectFile *objFile); public: @@ -90,18 +83,8 @@ class Sparc32LiveProcess : public SparcLiveProcess std::vector auxv; - Sparc32LiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) : - SparcLiveProcess(nm, objFile, _system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid) + Sparc32LiveProcess(LiveProcessParams * params, ObjectFile *objFile) : + SparcLiveProcess(params, objFile) { // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. @@ -143,18 +126,8 @@ class Sparc64LiveProcess : public SparcLiveProcess std::vector auxv; - Sparc64LiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) : - SparcLiveProcess(nm, objFile, _system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid) + Sparc64LiveProcess(LiveProcessParams * params, ObjectFile *objFile) : + SparcLiveProcess(params, objFile) { // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. diff --git a/src/arch/sparc/solaris/process.cc b/src/arch/sparc/solaris/process.cc index b7a49ab8d..40d172690 100644 --- a/src/arch/sparc/solaris/process.cc +++ b/src/arch/sparc/solaris/process.cc @@ -321,24 +321,9 @@ SyscallDesc SparcSolarisProcess::syscallDescs[] = { /* 255 */ SyscallDesc("umount2", unimplementedFunc) }; -SparcSolarisProcess::SparcSolarisProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, - uint64_t _euid, - uint64_t _gid, - uint64_t _egid, - uint64_t _pid, - uint64_t _ppid) - : Sparc64LiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid), +SparcSolarisProcess::SparcSolarisProcess(LiveProcessParams * params, + ObjectFile *objFile) + : Sparc64LiveProcess(params, objFile), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { // The sparc syscall table must be <= 284 entries because that is all there diff --git a/src/arch/sparc/solaris/process.hh b/src/arch/sparc/solaris/process.hh index 174eaecd7..2cf56f6ba 100644 --- a/src/arch/sparc/solaris/process.hh +++ b/src/arch/sparc/solaris/process.hh @@ -42,16 +42,7 @@ class SparcSolarisProcess : public Sparc64LiveProcess { public: /// Constructor. - SparcSolarisProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + SparcSolarisProcess(LiveProcessParams * params, ObjectFile *objFile); virtual SyscallDesc* getDesc(int callnum); diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 9ef591a1c..8beaf150b 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -77,21 +77,9 @@ X86LinuxProcess::getDesc(int callnum) return &syscallDescs[callnum]; } -X86LinuxProcess::X86LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, - int stdout_fd, - int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : X86LiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid), +X86LinuxProcess::X86LinuxProcess(LiveProcessParams * params, + ObjectFile *objFile) + : X86LiveProcess(params, objFile), Num_Syscall_Descs(273) {} diff --git a/src/arch/x86/linux/process.hh b/src/arch/x86/linux/process.hh index 7e7236f0d..e224374d4 100644 --- a/src/arch/x86/linux/process.hh +++ b/src/arch/x86/linux/process.hh @@ -70,16 +70,7 @@ class X86LinuxProcess : public X86LiveProcess { public: /// Constructor. - X86LinuxProcess(const std::string &name, - ObjectFile *objFile, - System * system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + X86LinuxProcess(LiveProcessParams * params, ObjectFile *objFile); /// Array of syscall descriptors, indexed by call number. static SyscallDesc syscallDescs[]; diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 0193344e8..db32437d5 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -109,14 +109,9 @@ M5_64_auxv_t::M5_64_auxv_t(int64_t type, int64_t val) a_val = TheISA::htog(val); } -X86LiveProcess::X86LiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) +X86LiveProcess::X86LiveProcess(LiveProcessParams * params, + ObjectFile *objFile) + : LiveProcess(params, objFile) { brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); brk_point = roundUp(brk_point, VMPageSize); diff --git a/src/arch/x86/process.hh b/src/arch/x86/process.hh index a2fa258c8..5def9e13d 100644 --- a/src/arch/x86/process.hh +++ b/src/arch/x86/process.hh @@ -84,15 +84,7 @@ namespace X86ISA protected: std::vector auxv; - X86LiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + X86LiveProcess(LiveProcessParams * params, ObjectFile *objFile); void startup(); diff --git a/src/sim/Process.py b/src/sim/Process.py index 34ff6c394..07ed2c692 100644 --- a/src/sim/Process.py +++ b/src/sim/Process.py @@ -33,8 +33,10 @@ from m5.proxy import * class Process(SimObject): type = 'Process' abstract = True + input = Param.String('cin', "filename for stdin") output = Param.String('cout', 'filename for stdout/stderr') system = Param.System(Parent.any, "system process will run on") + max_stack_size = Param.MemorySize('64MB', 'maximum size of the stack') class LiveProcess(Process): type = 'LiveProcess' @@ -42,7 +44,6 @@ class LiveProcess(Process): cmd = VectorParam.String("command line (executable plus arguments)") env = VectorParam.String([], "environment settings") cwd = Param.String('', "current working directory") - input = Param.String('cin', "filename for stdin") uid = Param.Int(100, 'user id') euid = Param.Int(100, 'effective user id') gid = Param.Int(100, 'group id') diff --git a/src/sim/process.cc b/src/sim/process.cc index 6ec7c8609..c5be4087d 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -45,6 +45,7 @@ #include "mem/page_table.hh" #include "mem/physical.hh" #include "mem/translating_port.hh" +#include "params/Process.hh" #include "params/LiveProcess.hh" #include "sim/process.hh" #include "sim/process_impl.hh" @@ -83,13 +84,34 @@ using namespace TheISA; // current number of allocated processes int num_processes = 0; -Process::Process(const string &nm, - System *_system, - int stdin_fd, // initial I/O descriptors - int stdout_fd, - int stderr_fd) - : SimObject(makeParams(nm)), system(_system) +Process::Process(ProcessParams * params) + : SimObject(params), system(params->system), + max_stack_size(params->max_stack_size) { + string in = params->input; + string out = params->output; + + // initialize file descriptors to default: same as simulator + int stdin_fd, stdout_fd, stderr_fd; + + if (in == "stdin" || in == "cin") + stdin_fd = STDIN_FILENO; + else if (in == "None") + stdin_fd = -1; + else + stdin_fd = Process::openInputFile(in); + + if (out == "stdout" || out == "cout") + stdout_fd = STDOUT_FILENO; + else if (out == "stderr" || out == "cerr") + stdout_fd = STDERR_FILENO; + else if (out == "None") + stdout_fd = -1; + else + stdout_fd = Process::openOutputFile(out); + + stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; + M5_pid = system->allocatePID(); // initialize first 3 fds (stdin, stdout, stderr) fd_map[STDIN_FILENO] = stdin_fd; @@ -264,13 +286,16 @@ Process::checkAndAllocNextPage(Addr vaddr) // We've accessed the next page of the stack, so extend the stack // to cover it. - if(vaddr < stack_min && vaddr >= stack_min - TheISA::PageBytes) - { - stack_min -= TheISA::PageBytes; - if(stack_base - stack_min > 8*1024*1024) - fatal("Over max stack size for one thread\n"); - pTable->allocate(stack_min, TheISA::PageBytes); - warn("Increasing stack size by one page."); + if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { + while (vaddr < stack_min) { + stack_min -= TheISA::PageBytes; + if(stack_base - stack_min > max_stack_size) + fatal("Maximum stack size exceeded\n"); + if(stack_base - stack_min > 8*1024*1024) + fatal("Over max stack size for one thread\n"); + pTable->allocate(stack_min, TheISA::PageBytes); + warn("Increasing stack size by one page."); + }; return true; } return false; @@ -320,25 +345,18 @@ Process::unserialize(Checkpoint *cp, const std::string §ion) //////////////////////////////////////////////////////////////////////// -LiveProcess::LiveProcess(const string &nm, ObjectFile *_objFile, - System *_system, - int stdin_fd, int stdout_fd, int stderr_fd, - vector &_argv, vector &_envp, - const string &_cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) - : Process(nm, _system, stdin_fd, stdout_fd, stderr_fd), - objFile(_objFile), argv(_argv), envp(_envp), cwd(_cwd) +LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile) + : Process(params), objFile(_objFile), + argv(params->cmd), envp(params->env), cwd(params->cwd) { - __uid = _uid; - __euid = _euid; - __gid = _gid; - __egid = _egid; - __pid = _pid; - __ppid = _ppid; + __uid = params->uid; + __euid = params->euid; + __gid = params->gid; + __egid = params->egid; + __pid = params->pid; + __ppid = params->ppid; - prog_fname = argv[0]; + prog_fname = params->cmd[0]; // load up symbols, if any... these may be used for debugging or // profiling. @@ -435,17 +453,12 @@ LiveProcess::syscall(int64_t callnum, ThreadContext *tc) } LiveProcess * -LiveProcess::create(const std::string &nm, System *system, int stdin_fd, - int stdout_fd, int stderr_fd, std::string executable, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid) +LiveProcess::create(LiveProcessParams * params) { LiveProcess *process = NULL; + string executable = + params->executable == "" ? params->cmd[0] : params->executable; ObjectFile *objFile = createObjectFile(executable); if (objFile == NULL) { fatal("Can't load object file %s", executable); @@ -466,17 +479,11 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, fatal("Object file architecture does not match compiled ISA (Alpha)."); switch (objFile->getOpSys()) { case ObjectFile::Tru64: - process = new AlphaTru64Process(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid); + process = new AlphaTru64Process(params, objFile); break; case ObjectFile::Linux: - process = new AlphaLinuxProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid); + process = new AlphaLinuxProcess(params, objFile); break; default: @@ -488,26 +495,15 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, switch (objFile->getOpSys()) { case ObjectFile::Linux: if (objFile->getArch() == ObjectFile::SPARC64) { - process = new Sparc64LinuxProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, - _egid, _pid, _ppid); + process = new Sparc64LinuxProcess(params, objFile); } else { - process = new Sparc32LinuxProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, - _egid, _pid, _ppid); + process = new Sparc32LinuxProcess(params, objFile); } break; case ObjectFile::Solaris: - process = new SparcSolarisProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid); + process = new SparcSolarisProcess(params, objFile); break; default: fatal("Unknown/unsupported operating system."); @@ -517,11 +513,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, fatal("Object file architecture does not match compiled ISA (x86)."); switch (objFile->getOpSys()) { case ObjectFile::Linux: - process = new X86LinuxProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, - _egid, _pid, _ppid); + process = new X86LinuxProcess(params, objFile); break; default: fatal("Unknown/unsupported operating system."); @@ -531,10 +523,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, fatal("Object file architecture does not match compiled ISA (MIPS)."); switch (objFile->getOpSys()) { case ObjectFile::Linux: - process = new MipsLinuxProcess(nm, objFile, system, - stdin_fd, stdout_fd, stderr_fd, - argv, envp, cwd, - _uid, _euid, _gid, _egid, _pid, _ppid); + process = new MipsLinuxProcess(params, objFile); break; default: @@ -553,29 +542,5 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, LiveProcess * LiveProcessParams::create() { - string in = input; - string out = output; - - // initialize file descriptors to default: same as simulator - int stdin_fd, stdout_fd, stderr_fd; - - if (in == "stdin" || in == "cin") - stdin_fd = STDIN_FILENO; - else - stdin_fd = Process::openInputFile(input); - - if (out == "stdout" || out == "cout") - stdout_fd = STDOUT_FILENO; - else if (out == "stderr" || out == "cerr") - stdout_fd = STDERR_FILENO; - else - stdout_fd = Process::openOutputFile(out); - - stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; - - return LiveProcess::create(name, system, - stdin_fd, stdout_fd, stderr_fd, - (string)executable == "" ? cmd[0] : executable, - cmd, env, cwd, - uid, euid, gid, egid, pid, ppid); + return LiveProcess::create(this); } diff --git a/src/sim/process.hh b/src/sim/process.hh index 83c00a676..d43208c27 100644 --- a/src/sim/process.hh +++ b/src/sim/process.hh @@ -48,12 +48,14 @@ #include "sim/host.hh" #include "sim/sim_object.hh" -class ThreadContext; -class SyscallDesc; +class GDBListener; class PageTable; -class TranslatingPort; +class ProcessParams; +class LiveProcessParams; +class SyscallDesc; class System; -class GDBListener; +class ThreadContext; +class TranslatingPort; namespace TheISA { class RemoteGDB; @@ -103,6 +105,9 @@ class Process : public SimObject unsigned stack_size; // initial stack size Addr stack_min; // lowest address accessed on the stack + // The maximum size allowed for the stack. + Addr max_stack_size; + // addr to use for next stack region (for multithreaded apps) Addr next_thread_stack_base; @@ -121,11 +126,7 @@ class Process : public SimObject protected: // constructor - Process(const std::string &nm, - System *_system, - int stdin_fd, // initial I/O descriptors - int stdout_fd, - int stderr_fd); + Process(ProcessParams * params); // post initialization startup virtual void startup(); @@ -195,14 +196,7 @@ class LiveProcess : public Process std::vector envp; std::string cwd; - LiveProcess(const std::string &nm, ObjectFile *objFile, - System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + LiveProcess(LiveProcessParams * params, ObjectFile *objFile); virtual void argsInit(int intSize, int pageSize); @@ -272,16 +266,7 @@ class LiveProcess : public Process // this function is used to create the LiveProcess object, since // we can't tell which subclass of LiveProcess to use until we // open and look at the object file. - static LiveProcess *create(const std::string &nm, - System *_system, - int stdin_fd, int stdout_fd, int stderr_fd, - std::string executable, - std::vector &argv, - std::vector &envp, - const std::string &cwd, - uint64_t _uid, uint64_t _euid, - uint64_t _gid, uint64_t _egid, - uint64_t _pid, uint64_t _ppid); + static LiveProcess *create(LiveProcessParams * params); }; -- 2.30.2