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
This commit is contained in:
Gabe Black 2007-10-16 18:04:01 -07:00
parent 9660a0a552
commit 54466a31c3
23 changed files with 123 additions and 393 deletions

View file

@ -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<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, 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;

View file

@ -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<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);
AlphaLinuxProcess(LiveProcessParams * params, ObjectFile *objFile);
virtual SyscallDesc* getDesc(int callnum);

View file

@ -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<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, 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);

View file

@ -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<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(LiveProcessParams * params, ObjectFile *objFile);
void startup();
};

View file

@ -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<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, 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))
{

View file

@ -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<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);
AlphaTru64Process(LiveProcessParams * params,
ObjectFile *objFile);
/// Array of syscall descriptors, indexed by call number.
static SyscallDesc syscallDescs[];

View file

@ -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<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)
: 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))
{ }

View file

@ -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<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);
MipsLinuxProcess(LiveProcessParams * params, ObjectFile *objFile);
void startup();

View file

@ -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<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, 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

View file

@ -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<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);
MipsLiveProcess(LiveProcessParams * params, ObjectFile *objFile);
virtual void startup();

View file

@ -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<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)
: 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<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)
: 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)

View file

@ -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<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);
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<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);
Sparc64LinuxProcess(LiveProcessParams * params, ObjectFile *objFile);
SyscallDesc* getDesc(int callnum)
{

View file

@ -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<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, 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

View file

@ -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<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(LiveProcessParams * params, ObjectFile *objFile);
public:
@ -90,18 +83,8 @@ class Sparc32LiveProcess : public SparcLiveProcess
std::vector<M5_32_auxv_t> auxv;
Sparc32LiveProcess(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) :
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<M5_64_auxv_t> auxv;
Sparc64LiveProcess(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) :
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.

View file

@ -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<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)
: 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

View file

@ -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<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);
SparcSolarisProcess(LiveProcessParams * params, ObjectFile *objFile);
virtual SyscallDesc* getDesc(int callnum);

View file

@ -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<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)
: 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)
{}

View file

@ -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<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);
X86LinuxProcess(LiveProcessParams * params, ObjectFile *objFile);
/// Array of syscall descriptors, indexed by call number.
static SyscallDesc syscallDescs[];

View file

@ -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<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, 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);

View file

@ -84,15 +84,7 @@ namespace X86ISA
protected:
std::vector<M5_64_auxv_t> auxv;
X86LiveProcess(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);
X86LiveProcess(LiveProcessParams * params, ObjectFile *objFile);
void startup();

View file

@ -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')

View file

@ -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 &section)
////////////////////////////////////////////////////////////////////////
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), 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<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::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);
}

View file

@ -48,12 +48,14 @@
#include "sim/host.hh"
#include "sim/sim_object.hh"
class ThreadContext;
class SyscallDesc;
class PageTable;
class TranslatingPort;
class System;
class GDBListener;
class PageTable;
class ProcessParams;
class LiveProcessParams;
class SyscallDesc;
class System;
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<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);
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<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);
static LiveProcess *create(LiveProcessParams * params);
};