summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorBrandon Potter <brandon.potter@amd.com>2017-02-27 14:10:02 -0500
committerBrandon Potter <brandon.potter@amd.com>2017-02-27 14:10:02 -0500
commit073cb266079edddec64ea8cd5169dd2cbef8f812 (patch)
tree63de367b090c3aae3e4c3ea5b43949c899c8e811 /src/sim
parentf5656738dc3ded25ba8a269efff70e8f12fc22ee (diff)
downloadgem5-073cb266079edddec64ea8cd5169dd2cbef8f812.tar.xz
syscall_emul: [patch 14/22] adds identifier system calls
This changeset add fields to the process object and adds the following three system calls: setpgid, gettid, getpid.
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/Process.py3
-rw-r--r--src/sim/process.cc9
-rw-r--r--src/sim/process.hh5
-rw-r--r--src/sim/syscall_emul.cc45
-rw-r--r--src/sim/syscall_emul.hh6
-rw-r--r--src/sim/system.hh5
6 files changed, 67 insertions, 6 deletions
diff --git a/src/sim/Process.py b/src/sim/Process.py
index 2d7c7d22c..9c4ee4760 100644
--- a/src/sim/Process.py
+++ b/src/sim/Process.py
@@ -47,7 +47,8 @@ class Process(SimObject):
gid = Param.Int(100, 'group id')
egid = Param.Int(100, 'effective group id')
pid = Param.Int(100, 'process id')
- ppid = Param.Int(99, 'parent process id')
+ ppid = Param.Int(0, 'parent process id')
+ pgid = Param.Int(100, 'process group id')
executable = Param.String('', "executable (overrides cmd[0] if set)")
cmd = VectorParam.String("command line (executable plus arguments)")
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 5acfa88b3..caf986123 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -112,11 +112,18 @@ Process::Process(ProcessParams * params, ObjectFile * obj_file)
_uid(params->uid), _euid(params->euid),
_gid(params->gid), _egid(params->egid),
_pid(params->pid), _ppid(params->ppid),
- drivers(params->drivers),
+ _pgid(params->pgid), drivers(params->drivers),
fds(make_shared<FDArray>(params->input, params->output, params->errout))
{
mmap_end = 0;
+ if (_pid >= System::maxPID)
+ fatal("_pid is too large: %d", _pid);
+
+ auto ret_pair = system->PIDs.emplace(_pid);
+ if (!ret_pair.second)
+ fatal("_pid %d is already used", _pid);
+
// load up symbols, if any... these may be used for debugging or
// profiling.
if (!debugSymbolTable) {
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 101e4a31c..fa2eff6fa 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -95,6 +95,9 @@ class Process : public SimObject
inline uint64_t egid() { return _egid; }
inline uint64_t pid() { return _pid; }
inline uint64_t ppid() { return _ppid; }
+ inline uint64_t pgid() { return _pgid; }
+ inline uint64_t tgid() { return _tgid; }
+ inline void setpgid(uint64_t pgid) { _pgid = pgid; }
const char *progName() const { return executable.c_str(); }
std::string fullPath(const std::string &filename);
@@ -199,6 +202,8 @@ class Process : public SimObject
// pid of the process and it's parent
uint64_t _pid;
uint64_t _ppid;
+ uint64_t _pgid;
+ uint64_t _tgid;
// Emulated drivers available to this process
std::vector<EmulatedDriver *> drivers;
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index 281e4c021..c6b89b0c7 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -729,6 +729,41 @@ pipePseudoFunc(SyscallDesc *desc, int callnum, Process *process,
return sim_fds[0];
}
+SyscallReturn
+setpgidFunc(SyscallDesc *desc, int callnum, Process *process,
+ ThreadContext *tc)
+{
+ int index = 0;
+ int pid = process->getSyscallArg(tc, index);
+ int pgid = process->getSyscallArg(tc, index);
+
+ if (pgid < 0)
+ return -EINVAL;
+
+ if (pid == 0) {
+ process->setpgid(process->pid());
+ return 0;
+ }
+
+ Process *matched_ph = NULL;
+ System *sysh = tc->getSystemPtr();
+
+ // Retrieves process pointer from active/suspended thread contexts.
+ for (int i = 0; i < sysh->numContexts(); i++) {
+ if (sysh->threadContexts[i]->status() != ThreadContext::Halted) {
+ Process *temp_h = sysh->threadContexts[i]->getProcessPtr();
+ Process *walk_ph = (Process*)temp_h;
+
+ if (walk_ph && walk_ph->pid() == process->pid())
+ matched_ph = walk_ph;
+ }
+ }
+
+ assert(matched_ph != NULL);
+ matched_ph->setpgid((pgid == 0) ? matched_ph->pid() : pgid);
+
+ return 0;
+}
SyscallReturn
getpidPseudoFunc(SyscallDesc *desc, int callnum, Process *process,
@@ -780,11 +815,13 @@ SyscallReturn
getpidFunc(SyscallDesc *desc, int callnum, Process *process,
ThreadContext *tc)
{
- // Make up a PID. There's no interprocess communication in
- // fake_syscall mode, so there's no way for a process to know it's
- // not getting a unique value.
+ return process->tgid();
+}
- tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID
+SyscallReturn
+gettidFunc(SyscallDesc *desc, int callnum, Process *process,
+ ThreadContext *tc)
+{
return process->pid();
}
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 1ad2f087f..e0cbbe786 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -216,11 +216,17 @@ SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
SyscallReturn umaskFunc(SyscallDesc *desc, int num,
Process *p, ThreadContext *tc);
+/// Target gettid() handler.
+SyscallReturn gettidFunc(SyscallDesc *desc, int num,
+ Process *p, ThreadContext *tc);
/// Target chown() handler.
SyscallReturn chownFunc(SyscallDesc *desc, int num,
Process *p, ThreadContext *tc);
+/// Target setpgid() handler.
+SyscallReturn setpgidFunc(SyscallDesc *desc, int num,
+ Process *p, ThreadContext *tc);
/// Target fchown() handler.
SyscallReturn fchownFunc(SyscallDesc *desc, int num,
diff --git a/src/sim/system.hh b/src/sim/system.hh
index c3667fe09..3954b35c2 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -551,6 +551,11 @@ class System : public MemObject
// For futex system call
std::map<uint64_t, std::list<ThreadContext *> * > futexMap;
+ static const int maxPID = 32768;
+
+ /** Process set to track which PIDs have already been allocated */
+ std::set<int> PIDs;
+
protected:
/**