summaryrefslogtreecommitdiff
path: root/src/sim/process.cc
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2007-10-16 18:04:01 -0700
committerGabe Black <gblack@eecs.umich.edu>2007-10-16 18:04:01 -0700
commit54466a31c3c295f11d5936d34a1b2ac0d3e0045f (patch)
tree9214dd0f304c8376ff6c81b080589f994916d439 /src/sim/process.cc
parent9660a0a5524a65094a43b557edf6a6cf0d11222d (diff)
downloadgem5-54466a31c3c295f11d5936d34a1b2ac0d3e0045f.tar.xz
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
Diffstat (limited to 'src/sim/process.cc')
-rw-r--r--src/sim/process.cc153
1 files changed, 59 insertions, 94 deletions
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);
}