changeset 79af314e9f0d in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=79af314e9f0d description: 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: src/arch/x86/linux/process.cc | 10 +++--- src/sim/Process.py | 3 +- src/sim/process.cc | 9 ++++++- src/sim/process.hh | 5 +++ src/sim/syscall_emul.cc | 45 ++++++++++++++++++++++++++++++--- src/sim/syscall_emul.hh | 6 ++++ src/sim/system.hh | 5 +++ tests/quick/se/01.hello-2T-smt/test.py | 5 ++- 8 files changed, 75 insertions(+), 13 deletions(-) diffs (219 lines): diff -r e8536709cbc0 -r 79af314e9f0d src/arch/x86/linux/process.cc --- a/src/arch/x86/linux/process.cc Mon Feb 27 14:09:30 2017 -0500 +++ b/src/arch/x86/linux/process.cc Mon Feb 27 14:10:02 2017 -0500 @@ -329,7 +329,7 @@ /* 106 */ SyscallDesc("setgid", unimplementedFunc), /* 107 */ SyscallDesc("geteuid", geteuidFunc), /* 108 */ SyscallDesc("getegid", getegidFunc), - /* 109 */ SyscallDesc("setpgid", unimplementedFunc), + /* 109 */ SyscallDesc("setpgid", setpgidFunc), /* 110 */ SyscallDesc("getppid", getppidFunc), /* 111 */ SyscallDesc("getpgrp", unimplementedFunc), /* 112 */ SyscallDesc("setsid", unimplementedFunc), @@ -406,7 +406,7 @@ /* 183 */ SyscallDesc("afs_syscall", unimplementedFunc), /* 184 */ SyscallDesc("tuxcall", unimplementedFunc), /* 185 */ SyscallDesc("security", unimplementedFunc), - /* 186 */ SyscallDesc("gettid", unimplementedFunc), + /* 186 */ SyscallDesc("gettid", gettidFunc), /* 187 */ SyscallDesc("readahead", unimplementedFunc), /* 188 */ SyscallDesc("setxattr", unimplementedFunc), /* 189 */ SyscallDesc("lsetxattr", unimplementedFunc), @@ -563,7 +563,7 @@ /* 17 */ SyscallDesc("break", unimplementedFunc), /* 18 */ SyscallDesc("oldstat", unimplementedFunc), /* 19 */ SyscallDesc("lseek", unimplementedFunc), - /* 20 */ SyscallDesc("getpid", unimplementedFunc), + /* 20 */ SyscallDesc("getpid", getpidFunc), /* 21 */ SyscallDesc("mount", unimplementedFunc), /* 22 */ SyscallDesc("umount", unimplementedFunc), /* 23 */ SyscallDesc("setuid", unimplementedFunc), @@ -600,7 +600,7 @@ /* 54 */ SyscallDesc("ioctl", ioctlFunc<X86Linux32>), /* 55 */ SyscallDesc("fcntl", fcntlFunc), /* 56 */ SyscallDesc("mpx", unimplementedFunc), - /* 57 */ SyscallDesc("setpgid", unimplementedFunc), + /* 57 */ SyscallDesc("setpgid", setpgidFunc), /* 58 */ SyscallDesc("ulimit", unimplementedFunc), /* 59 */ SyscallDesc("oldolduname", unimplementedFunc), /* 60 */ SyscallDesc("umask", unimplementedFunc), @@ -767,7 +767,7 @@ /* 221 */ SyscallDesc("getdents64", unimplementedFunc), /* 222 */ SyscallDesc("fcntl64", unimplementedFunc), /* 223 */ SyscallDesc("unused", unimplementedFunc), - /* 224 */ SyscallDesc("gettid", unimplementedFunc), + /* 224 */ SyscallDesc("gettid", gettidFunc), /* 225 */ SyscallDesc("readahead", unimplementedFunc), /* 226 */ SyscallDesc("setxattr", unimplementedFunc), /* 227 */ SyscallDesc("lsetxattr", unimplementedFunc), diff -r e8536709cbc0 -r 79af314e9f0d src/sim/Process.py --- a/src/sim/Process.py Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/Process.py Mon Feb 27 14:10:02 2017 -0500 @@ -47,7 +47,8 @@ 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 -r e8536709cbc0 -r 79af314e9f0d src/sim/process.cc --- a/src/sim/process.cc Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/process.cc Mon Feb 27 14:10:02 2017 -0500 @@ -112,11 +112,18 @@ _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 -r e8536709cbc0 -r 79af314e9f0d src/sim/process.hh --- a/src/sim/process.hh Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/process.hh Mon Feb 27 14:10:02 2017 -0500 @@ -95,6 +95,9 @@ 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 @@ // 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 -r e8536709cbc0 -r 79af314e9f0d src/sim/syscall_emul.cc --- a/src/sim/syscall_emul.cc Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/syscall_emul.cc Mon Feb 27 14:10:02 2017 -0500 @@ -729,6 +729,41 @@ 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 @@ 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 -r e8536709cbc0 -r 79af314e9f0d src/sim/syscall_emul.hh --- a/src/sim/syscall_emul.hh Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/syscall_emul.hh Mon Feb 27 14:10:02 2017 -0500 @@ -216,11 +216,17 @@ 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 -r e8536709cbc0 -r 79af314e9f0d src/sim/system.hh --- a/src/sim/system.hh Mon Feb 27 14:09:30 2017 -0500 +++ b/src/sim/system.hh Mon Feb 27 14:10:02 2017 -0500 @@ -551,6 +551,11 @@ // 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: /** diff -r e8536709cbc0 -r 79af314e9f0d tests/quick/se/01.hello-2T-smt/test.py --- a/tests/quick/se/01.hello-2T-smt/test.py Mon Feb 27 14:09:30 2017 -0500 +++ b/tests/quick/se/01.hello-2T-smt/test.py Mon Feb 27 14:10:02 2017 -0500 @@ -26,7 +26,8 @@ # # Authors: Korey Sewell -process1 = Process(cmd = 'hello', executable = binpath('hello')) -process2 = Process(cmd = 'hello', executable = binpath('hello')) +process1 = Process(cmd = 'hello', executable = binpath('hello'), pid = 100) +process2 = Process(cmd = 'hello', executable = binpath('hello'), + pid = 101, ppid = 100) root.system.cpu[0].workload = [process1, process2] _______________________________________________ gem5-dev mailing list gem5-dev@gem5.org http://m5sim.org/mailman/listinfo/gem5-dev