diff options
author | Gabe Black <gblack@eecs.umich.edu> | 2006-11-22 15:45:32 -0500 |
---|---|---|
committer | Gabe Black <gblack@eecs.umich.edu> | 2006-11-22 15:45:32 -0500 |
commit | 0a99750ebfe9a9b400ee5f0610ed429851345c4b (patch) | |
tree | b73463f5330730cca540b0fb0bd3757353e88d1a /src | |
parent | 04e6a3a07b6fdaba9f0954971b61556078611a55 (diff) | |
parent | 719416b60ff2ab60403d22b6c7f75139b9535d8c (diff) | |
download | gem5-0a99750ebfe9a9b400ee5f0610ed429851345c4b.tar.xz |
Merge zizzer:/bk/sparcfs
into zower.eecs.umich.edu:/eecshome/m5/newmem
--HG--
extra : convert_revision : 75f3398e38e18eb1f8248e23708d7a8d8cce0fc5
Diffstat (limited to 'src')
33 files changed, 176 insertions, 78 deletions
diff --git a/src/arch/alpha/interrupts.hh b/src/arch/alpha/interrupts.hh index a86fb2d7b..388ccacde 100644 --- a/src/arch/alpha/interrupts.hh +++ b/src/arch/alpha/interrupts.hh @@ -138,9 +138,8 @@ namespace AlphaISA } if (ipl && ipl > tc->readMiscReg(IPR_IPLR)) { -// assert(!newInfoSet); newIpl = ipl; - newSummary = newSummary; + newSummary = summary; newInfoSet = true; DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n", tc->readMiscReg(IPR_IPLR), ipl, summary); diff --git a/src/arch/alpha/linux/process.cc b/src/arch/alpha/linux/process.cc index 56342dbc5..f7d946e2e 100644 --- a/src/arch/alpha/linux/process.cc +++ b/src/arch/alpha/linux/process.cc @@ -576,6 +576,7 @@ AlphaLinuxProcess::AlphaLinuxProcess(const std::string &name, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, @@ -583,7 +584,7 @@ AlphaLinuxProcess::AlphaLinuxProcess(const std::string &name, uint64_t _pid, uint64_t _ppid) : AlphaLiveProcess(name, objFile, system, stdin_fd, stdout_fd, - stderr_fd, argv, envp, _uid, _euid, _gid, _egid, _pid, _ppid), + stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), 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 b23904844..2076f6339 100644 --- a/src/arch/alpha/linux/process.hh +++ b/src/arch/alpha/linux/process.hh @@ -46,6 +46,7 @@ class AlphaLinuxProcess : public AlphaLiveProcess int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 9e360e80f..85619e493 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -43,10 +43,11 @@ using namespace std; AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &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, _uid, _euid, _gid, _egid, _pid, _ppid) + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) { 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 c4aeb1885..8eede502a 100644 --- a/src/arch/alpha/process.hh +++ b/src/arch/alpha/process.hh @@ -47,6 +47,7 @@ class AlphaLiveProcess : public LiveProcess System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/alpha/tru64/process.cc b/src/arch/alpha/tru64/process.cc index 55b8ebf8b..a1f02b16c 100644 --- a/src/arch/alpha/tru64/process.cc +++ b/src/arch/alpha/tru64/process.cc @@ -581,11 +581,12 @@ AlphaTru64Process::AlphaTru64Process(const std::string &name, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &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, _uid, _euid, _gid, _egid, _pid, _ppid), + stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), 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 23429dad3..f5643c0b9 100644 --- a/src/arch/alpha/tru64/process.hh +++ b/src/arch/alpha/tru64/process.hh @@ -45,6 +45,7 @@ class AlphaTru64Process : public AlphaLiveProcess int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/mips/linux/process.cc b/src/arch/mips/linux/process.cc index d182cfa30..a847608d8 100644 --- a/src/arch/mips/linux/process.cc +++ b/src/arch/mips/linux/process.cc @@ -411,6 +411,7 @@ MipsLinuxProcess::MipsLinuxProcess(const std::string &name, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, @@ -418,7 +419,7 @@ MipsLinuxProcess::MipsLinuxProcess(const std::string &name, uint64_t _pid, uint64_t _ppid) : MipsLiveProcess(name, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, _uid, _euid, _gid, _egid, _pid, _ppid), + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { } diff --git a/src/arch/mips/linux/process.hh b/src/arch/mips/linux/process.hh index 06f86379c..398e1cfc2 100644 --- a/src/arch/mips/linux/process.hh +++ b/src/arch/mips/linux/process.hh @@ -43,6 +43,7 @@ class MipsLinuxProcess : public MipsLiveProcess int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index 4bc91ca24..d1e6e27bf 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -44,10 +44,11 @@ using namespace MipsISA; MipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile, System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &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, _uid, _euid, _gid, _egid, _pid, _ppid) + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) { // 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 fb004375d..af85e8ee9 100644 --- a/src/arch/mips/process.hh +++ b/src/arch/mips/process.hh @@ -48,6 +48,7 @@ class MipsLiveProcess : public LiveProcess System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/sparc/linux/process.cc b/src/arch/sparc/linux/process.cc index 44c893f2b..565975fe0 100644 --- a/src/arch/sparc/linux/process.cc +++ b/src/arch/sparc/linux/process.cc @@ -391,11 +391,12 @@ SparcLinuxProcess::SparcLinuxProcess(const std::string &name, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid) : SparcLiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, + stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { diff --git a/src/arch/sparc/linux/process.hh b/src/arch/sparc/linux/process.hh index c758d5433..e212de973 100644 --- a/src/arch/sparc/linux/process.hh +++ b/src/arch/sparc/linux/process.hh @@ -49,6 +49,7 @@ class SparcLinuxProcess : public SparcLiveProcess int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index 11a799ccb..3efe4fc08 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -47,10 +47,11 @@ using namespace SparcISA; SparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile, System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &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, _uid, _euid, _gid, _egid, _pid, _ppid) + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid) { // 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 2320810c7..1cf7ec224 100644 --- a/src/arch/sparc/process.hh +++ b/src/arch/sparc/process.hh @@ -64,6 +64,7 @@ class SparcLiveProcess : public LiveProcess System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/arch/sparc/solaris/process.cc b/src/arch/sparc/solaris/process.cc index ff466c8e6..f9876bf00 100644 --- a/src/arch/sparc/solaris/process.cc +++ b/src/arch/sparc/solaris/process.cc @@ -329,6 +329,7 @@ SparcSolarisProcess::SparcSolarisProcess(const std::string &name, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, @@ -336,7 +337,7 @@ SparcSolarisProcess::SparcSolarisProcess(const std::string &name, uint64_t _pid, uint64_t _ppid) : SparcLiveProcess(name, objFile, system, - stdin_fd, stdout_fd, stderr_fd, argv, envp, + stdin_fd, stdout_fd, stderr_fd, argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid), Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)) { diff --git a/src/arch/sparc/solaris/process.hh b/src/arch/sparc/solaris/process.hh index 2cf329211..f65a60656 100644 --- a/src/arch/sparc/solaris/process.hh +++ b/src/arch/sparc/solaris/process.hh @@ -48,6 +48,7 @@ class SparcSolarisProcess : public SparcLiveProcess int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/base/misc.hh b/src/base/misc.hh index 87faf20e6..1c5720ce1 100644 --- a/src/base/misc.hh +++ b/src/base/misc.hh @@ -76,6 +76,19 @@ void __warn(const std::string&, cp::ArgList &, const char*, const char*, int); #define warn(args...) \ __warn__(args, cp::ArgListNull()) +// Only print the warning message the first time it is seen. This +// doesn't check the warning string itself, it just only lets one +// warning come from the statement. So, even if the arguments change +// and that would have resulted in a different warning message, +// subsequent messages would still be supressed. +#define warn_once(args...) do { \ + static bool once = false; \ + if (!once) { \ + __warn__(args, cp::ArgListNull()); \ + once = true; \ + } \ + } while (0) + // // assert() that prints out the current cycle // diff --git a/src/cpu/o3/alpha/cpu_impl.hh b/src/cpu/o3/alpha/cpu_impl.hh index b2ef78360..98fd0699a 100644 --- a/src/cpu/o3/alpha/cpu_impl.hh +++ b/src/cpu/o3/alpha/cpu_impl.hh @@ -116,24 +116,6 @@ AlphaO3CPU<Impl>::AlphaO3CPU(Params *params) #if FULL_SYSTEM // Setup quiesce event. this->thread[i]->quiesceEvent = new EndQuiesceEvent(tc); - - Port *mem_port; - FunctionalPort *phys_port; - VirtualPort *virt_port; - phys_port = new FunctionalPort(csprintf("%s-%d-funcport", - name(), i)); - mem_port = this->system->physmem->getPort("functional"); - mem_port->setPeer(phys_port); - phys_port->setPeer(mem_port); - - virt_port = new VirtualPort(csprintf("%s-%d-vport", - name(), i)); - mem_port = this->system->physmem->getPort("functional"); - mem_port->setPeer(virt_port); - virt_port->setPeer(mem_port); - - this->thread[i]->setPhysPort(phys_port); - this->thread[i]->setVirtPort(virt_port); #endif // Give the thread the TC. this->thread[i]->tc = tc; diff --git a/src/cpu/o3/cpu.cc b/src/cpu/o3/cpu.cc index 580816372..3dc353a9f 100644 --- a/src/cpu/o3/cpu.cc +++ b/src/cpu/o3/cpu.cc @@ -497,6 +497,8 @@ FullO3CPU<Impl>::init() } #if FULL_SYSTEM + src_tc->init(); + TheISA::initCPU(src_tc, src_tc->readCpuId()); #endif } diff --git a/src/cpu/o3/thread_context.hh b/src/cpu/o3/thread_context.hh index daee2fc7d..031f36480 100755 --- a/src/cpu/o3/thread_context.hh +++ b/src/cpu/o3/thread_context.hh @@ -91,6 +91,8 @@ class O3ThreadContext : public ThreadContext virtual VirtualPort *getVirtPort(ThreadContext *src_tc = NULL); void delVirtPort(VirtualPort *vp); + + virtual void init() { thread->init(); } #else virtual TranslatingPort *getMemPort() { return thread->getMemPort(); } diff --git a/src/cpu/o3/thread_context_impl.hh b/src/cpu/o3/thread_context_impl.hh index 8d623f5b8..0180756e3 100755 --- a/src/cpu/o3/thread_context_impl.hh +++ b/src/cpu/o3/thread_context_impl.hh @@ -41,12 +41,9 @@ O3ThreadContext<Impl>::getVirtPort(ThreadContext *src_tc) return thread->getVirtPort(); VirtualPort *vp; - Port *mem_port; vp = new VirtualPort("tc-vport", src_tc); - mem_port = cpu->system->physmem->getPort("functional"); - mem_port->setPeer(vp); - vp->setPeer(mem_port); + thread->connectToMemFunc(vp); return vp; } diff --git a/src/cpu/simple/atomic.cc b/src/cpu/simple/atomic.cc index 133b5500b..cd335e36d 100644 --- a/src/cpu/simple/atomic.cc +++ b/src/cpu/simple/atomic.cc @@ -77,6 +77,9 @@ AtomicSimpleCPU::init() for (int i = 0; i < threadContexts.size(); ++i) { ThreadContext *tc = threadContexts[i]; + // initialize the mem pointers + tc->init(); + // initialize CPU, including PC TheISA::initCPU(tc, tc->readCpuId()); } diff --git a/src/cpu/simple/timing.cc b/src/cpu/simple/timing.cc index 3648f7613..aa23a00e8 100644 --- a/src/cpu/simple/timing.cc +++ b/src/cpu/simple/timing.cc @@ -59,6 +59,9 @@ TimingSimpleCPU::init() for (int i = 0; i < threadContexts.size(); ++i) { ThreadContext *tc = threadContexts[i]; + // initialize the mem pointers + tc->init(); + // initialize CPU, including PC TheISA::initCPU(tc, tc->readCpuId()); } diff --git a/src/cpu/simple_thread.cc b/src/cpu/simple_thread.cc index 1edcbf352..13d0e2e29 100644 --- a/src/cpu/simple_thread.cc +++ b/src/cpu/simple_thread.cc @@ -91,18 +91,6 @@ SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys, } else { kernelStats = NULL; } - Port *mem_port; - physPort = new FunctionalPort(csprintf("%s-%d-funcport", - cpu->name(), tid)); - mem_port = system->physmem->getPort("functional"); - mem_port->setPeer(physPort); - physPort->setPeer(mem_port); - - virtPort = new VirtualPort(csprintf("%s-%d-vport", - cpu->name(), tid)); - mem_port = system->physmem->getPort("functional"); - mem_port->setPeer(virtPort); - virtPort->setPeer(mem_port); } #else SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, @@ -309,10 +297,7 @@ SimpleThread::getVirtPort(ThreadContext *src_tc) return virtPort; VirtualPort *vp = new VirtualPort("tc-vport", src_tc); - Port *mem_port = getMemFuncPort(); - - mem_port->setPeer(vp); - vp->setPeer(mem_port); + connectToMemFunc(vp); return vp; } diff --git a/src/cpu/thread_context.hh b/src/cpu/thread_context.hh index 1e6a907f8..baeb7a8be 100644 --- a/src/cpu/thread_context.hh +++ b/src/cpu/thread_context.hh @@ -133,6 +133,8 @@ class ThreadContext virtual VirtualPort *getVirtPort(ThreadContext *tc = NULL) = 0; virtual void delVirtPort(VirtualPort *vp) = 0; + + virtual void init() = 0; #else virtual TranslatingPort *getMemPort() = 0; @@ -305,6 +307,8 @@ class ProxyThreadContext : public ThreadContext VirtualPort *getVirtPort(ThreadContext *tc = NULL) { return actualTC->getVirtPort(tc); } void delVirtPort(VirtualPort *vp) { return actualTC->delVirtPort(vp); } + + void init() {actualTC->init(); } #else TranslatingPort *getMemPort() { return actualTC->getMemPort(); } diff --git a/src/cpu/thread_state.cc b/src/cpu/thread_state.cc index 8602f8a50..9cac4fd26 100644 --- a/src/cpu/thread_state.cc +++ b/src/cpu/thread_state.cc @@ -39,6 +39,7 @@ #if FULL_SYSTEM #include "arch/kernel_stats.hh" #include "cpu/quiesce_event.hh" +#include "mem/vport.hh" #endif #if FULL_SYSTEM @@ -111,6 +112,28 @@ ThreadState::unserialize(Checkpoint *cp, const std::string §ion) } #if FULL_SYSTEM +void +ThreadState::init() +{ + initPhysPort(); + initVirtPort(); +} + +void +ThreadState::initPhysPort() +{ + physPort = new FunctionalPort(csprintf("%s-%d-funcport", + baseCpu->name(), tid)); + connectToMemFunc(physPort); +} + +void +ThreadState::initVirtPort() +{ + virtPort = new VirtualPort(csprintf("%s-%d-vport", + baseCpu->name(), tid)); + connectToMemFunc(virtPort); +} void ThreadState::profileClear() @@ -138,17 +161,14 @@ ThreadState::getMemPort() baseCpu->name(), tid), process->pTable, false); - Port *func_port = getMemFuncPort(); - - func_port->setPeer(port); - port->setPeer(func_port); + connectToMemFunc(port); return port; } #endif -Port * -ThreadState::getMemFuncPort() +void +ThreadState::connectToMemFunc(Port *port) { Port *dcache_port, *func_mem_port; @@ -161,5 +181,6 @@ ThreadState::getMemFuncPort() func_mem_port = mem_object->getPort("functional"); assert(func_mem_port != NULL); - return func_mem_port; + func_mem_port->setPeer(port); + port->setPeer(func_mem_port); } diff --git a/src/cpu/thread_state.hh b/src/cpu/thread_state.hh index 0a0af8b71..1844be8b7 100644 --- a/src/cpu/thread_state.hh +++ b/src/cpu/thread_state.hh @@ -91,6 +91,12 @@ struct ThreadState { Tick readLastSuspend() { return lastSuspend; } #if FULL_SYSTEM + void init(); + + void initPhysPort(); + + void initVirtPort(); + void dumpFuncProfile(); EndQuiesceEvent *getQuiesceEvent() { return quiesceEvent; } @@ -141,12 +147,11 @@ struct ThreadState { /** Sets the status of this thread. */ void setStatus(Status new_status) { _status = new_status; } - protected: - /** Gets a functional port from the memory object that's connected - * to the CPU. */ - Port *getMemFuncPort(); - public: + /** Connects port to the functional port of the memory object + * below the CPU. */ + void connectToMemFunc(Port *port); + /** Number of instructions committed. */ Counter numInst; /** Stat for number instructions committed. */ diff --git a/src/python/m5/objects/Process.py b/src/python/m5/objects/Process.py index 771ad4101..79268e6f4 100644 --- a/src/python/m5/objects/Process.py +++ b/src/python/m5/objects/Process.py @@ -12,6 +12,7 @@ class LiveProcess(Process): executable = Param.String('', "executable (overrides cmd[0] if set)") 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') diff --git a/src/sim/process.cc b/src/sim/process.cc index f3e289d41..b43fa7d00 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -314,11 +314,12 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *_objFile, System *_system, int stdin_fd, int stdout_fd, int stderr_fd, vector<string> &_argv, vector<string> &_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) + objFile(_objFile), argv(_argv), envp(_envp), cwd(_cwd) { __uid = _uid; __euid = _euid; @@ -427,6 +428,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, int stdout_fd, int stderr_fd, std::string executable, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid) @@ -445,14 +447,14 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, case ObjectFile::Tru64: process = new AlphaTru64Process(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid); break; case ObjectFile::Linux: process = new AlphaLinuxProcess(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid); break; @@ -466,7 +468,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, case ObjectFile::Linux: process = new SparcLinuxProcess(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid); break; @@ -474,7 +476,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, case ObjectFile::Solaris: process = new SparcSolarisProcess(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid); break; default: @@ -487,7 +489,7 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd, case ObjectFile::Linux: process = new MipsLinuxProcess(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, - argv, envp, + argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid); break; @@ -512,6 +514,7 @@ BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess) Param<string> input; Param<string> output; VectorParam<string> env; + Param<string> cwd; SimObjectParam<System *> system; Param<uint64_t> uid; Param<uint64_t> euid; @@ -530,6 +533,7 @@ BEGIN_INIT_SIM_OBJECT_PARAMS(LiveProcess) INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), INIT_PARAM(env, "environment settings"), + INIT_PARAM(cwd, "current working directory"), INIT_PARAM(system, "system"), INIT_PARAM(uid, "user id"), INIT_PARAM(euid, "effective user id"), @@ -566,7 +570,7 @@ CREATE_SIM_OBJECT(LiveProcess) return LiveProcess::create(getInstanceName(), system, stdin_fd, stdout_fd, stderr_fd, (string)executable == "" ? cmd[0] : executable, - cmd, env, + cmd, env, cwd, uid, euid, gid, egid, pid, ppid); } diff --git a/src/sim/process.hh b/src/sim/process.hh index 5c37f725e..616c02c00 100644 --- a/src/sim/process.hh +++ b/src/sim/process.hh @@ -177,11 +177,13 @@ class LiveProcess : public Process ObjectFile *objFile; std::vector<std::string> argv; std::vector<std::string> envp; + std::string cwd; LiveProcess(const std::string &nm, ObjectFile *objFile, System *_system, int stdin_fd, int stdout_fd, int stderr_fd, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); @@ -207,6 +209,20 @@ class LiveProcess : public Process inline uint64_t pid() {return __pid;} inline uint64_t ppid() {return __ppid;} + std::string + fullPath(const std::string &filename) + { + if (filename[0] == '/' || cwd.empty()) + return filename; + + std::string full = cwd; + + if (cwd[cwd.size() - 1] != '/') + full += '/'; + + return full + filename; + } + virtual void syscall(int64_t callnum, ThreadContext *tc); virtual SyscallDesc* getDesc(int callnum) = 0; @@ -220,6 +236,7 @@ class LiveProcess : public Process std::string executable, std::vector<std::string> &argv, std::vector<std::string> &envp, + const std::string &cwd, uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid, uint64_t _pid, uint64_t _ppid); diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index 9028d590b..ab44c0a35 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -214,6 +214,9 @@ unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) return (TheISA::IntReg)-EFAULT; + // Adjust path for current working directory + path = p->fullPath(path); + int result = unlink(path.c_str()); return (result == -1) ? -errno : result; } @@ -231,6 +234,10 @@ renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) if (!tc->getMemPort()->tryReadString(new_name, tc->getSyscallArg(1))) return -EFAULT; + // Adjust path for current working directory + old_name = p->fullPath(old_name); + new_name = p->fullPath(new_name); + int64_t result = rename(old_name.c_str(), new_name.c_str()); return (result == -1) ? -errno : result; } @@ -245,6 +252,9 @@ truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) off_t length = tc->getSyscallArg(1); + // Adjust path for current working directory + path = p->fullPath(path); + int result = truncate(path.c_str(), length); return (result == -1) ? -errno : result; } @@ -277,6 +287,9 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) uint32_t group = tc->getSyscallArg(2); gid_t hostGroup = group; + // Adjust path for current working directory + path = p->fullPath(path); + int result = chown(path.c_str(), hostOwner, hostGroup); return (result == -1) ? -errno : result; } diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index e79712a19..27356c9f1 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -500,6 +500,9 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process, hostFlags |= O_BINARY; #endif + // Adjust path for current working directory + path = process->fullPath(path); + DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str()); // open the file @@ -526,6 +529,9 @@ chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process, // XXX translate mode flags via OS::something??? hostMode = mode; + // Adjust path for current working directory + path = process->fullPath(path); + // do the chmod int result = chmod(path.c_str(), hostMode); if (result < 0) @@ -573,6 +579,9 @@ statFunc(SyscallDesc *desc, int callnum, LiveProcess *process, if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) return -EFAULT; + // Adjust path for current working directory + path = process->fullPath(path); + struct stat hostBuf; int result = stat(path.c_str(), &hostBuf); @@ -626,6 +635,9 @@ lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) return -EFAULT; + // Adjust path for current working directory + path = process->fullPath(path); + struct stat hostBuf; int result = lstat(path.c_str(), &hostBuf); @@ -648,6 +660,9 @@ lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) return -EFAULT; + // Adjust path for current working directory + path = process->fullPath(path); + #if NO_STAT64 struct stat hostBuf; int result = lstat(path.c_str(), &hostBuf); @@ -701,6 +716,9 @@ statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process, if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0))) return -EFAULT; + // Adjust path for current working directory + path = process->fullPath(path); + struct statfs hostBuf; int result = statfs(path.c_str(), &hostBuf); @@ -896,6 +914,10 @@ utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process, hostTimeval[i].tv_sec = gtoh((*tp)[i].tv_sec); hostTimeval[i].tv_usec = gtoh((*tp)[i].tv_usec); } + + // Adjust path for current working directory + path = process->fullPath(path); + int result = utimes(path.c_str(), hostTimeval); if (result < 0) @@ -912,17 +934,8 @@ getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process, int who = tc->getSyscallArg(0); // THREAD, SELF, or CHILDREN TypedBufferArg<typename OS::rusage> rup(tc->getSyscallArg(1)); - if (who != OS::TGT_RUSAGE_SELF) { - // don't really handle THREAD or CHILDREN, but just warn and - // plow ahead - warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.", - who); - } - - getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec); - rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec); - rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec); - + rup->ru_utime.tv_sec = 0; + rup->ru_utime.tv_usec = 0; rup->ru_stime.tv_sec = 0; rup->ru_stime.tv_usec = 0; rup->ru_maxrss = 0; @@ -940,6 +953,24 @@ getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process, rup->ru_nvcsw = 0; rup->ru_nivcsw = 0; + switch (who) { + case OS::TGT_RUSAGE_SELF: + getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec); + rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec); + rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec); + break; + + case OS::TGT_RUSAGE_CHILDREN: + // do nothing. We have no child processes, so they take no time. + break; + + default: + // don't really handle THREAD or CHILDREN, but just warn and + // plow ahead + warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.", + who); + } + rup.copyOut(tc->getMemPort()); return 0; |