summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/Process.py3
-rw-r--r--src/sim/process.cc153
-rw-r--r--src/sim/process.hh39
3 files changed, 73 insertions, 122 deletions
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 &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);
}
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<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);
};