diff options
author | Brandon Potter <Brandon.Potter@amd.com> | 2017-03-01 13:24:16 -0600 |
---|---|---|
committer | Brandon Potter <Brandon.Potter@amd.com> | 2017-03-09 22:42:45 +0000 |
commit | acce7b0dc0edf85b99c75d1800df99bd9e288b01 (patch) | |
tree | 1737ac1d3885f083f3c568c41870ff97caa9fe66 /src/kern | |
parent | e5fe2b82b7cf8842a5a202da69c003d2a2c6af3f (diff) | |
download | gem5-acce7b0dc0edf85b99c75d1800df99bd9e288b01.tar.xz |
syscall-emul: Add functionality to open syscalls
This changeset adds refactors the existing open system call,
adds the openat variant (enabled for x86 builds), and adds
additional "special file" test cases for /proc/meminfo and
/etc/passwd.
Change-Id: I6f429db65bbf2a28ffa3fd12df518c2d0de49663
Reviewed-on: https://gem5-review.googlesource.com/2265
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Tony Gutierrez <anthony.gutierrez@amd.com>
Reviewed-by: Michael LeBeane <Michael.Lebeane@amd.com>
Diffstat (limited to 'src/kern')
-rw-r--r-- | src/kern/linux/linux.cc | 35 | ||||
-rw-r--r-- | src/kern/linux/linux.hh | 1 | ||||
-rw-r--r-- | src/kern/solaris/solaris.hh | 3 |
3 files changed, 32 insertions, 7 deletions
diff --git a/src/kern/linux/linux.cc b/src/kern/linux/linux.cc index 493be9611..bd0b4d09a 100644 --- a/src/kern/linux/linux.cc +++ b/src/kern/linux/linux.cc @@ -33,6 +33,7 @@ #include <cstdio> #include <string> +#include "cpu/base.hh" #include "debug/SyscallVerbose.hh" #include "sim/process.hh" #include "sim/system.hh" @@ -41,21 +42,35 @@ int Linux::openSpecialFile(std::string path, Process *process, ThreadContext *tc) { - DPRINTF(SyscallVerbose, "Opening special file: %s\n", path.c_str()); + DPRINTFR(SyscallVerbose, + "%d: %s: generic-open: opening special file: %s\n", + curTick(), tc->getCpuPtr()->name(), path.c_str()); + + bool matched = false; + std::string data; + if (path.compare(0, 13, "/proc/meminfo") == 0) { - std::string data = Linux::procMeminfo(process, tc); + data = Linux::procMeminfo(process, tc); + matched = true; + } else if (path.compare(0, 11, "/etc/passwd") == 0) { + data = Linux::etcPasswd(process, tc); + matched = true; + } + + if (matched) { FILE *f = tmpfile(); int fd = fileno(f); size_t ret M5_VAR_USED = fwrite(data.c_str(), 1, data.size(), f); assert(ret == data.size()); rewind(f); return fd; + } else { + warn("Attempting to open special file: %s. Ignoring. Simulation may " + "take un-expected code path or be non-deterministic until proper " + "handling is implemented.\n", path.c_str()); + errno = EACCES; + return -1; } - - warn("Attempting to open special file: %s. Ignoring. Simulation may" - " take un-expected code path or be non-deterministic until proper" - " handling is implemented.\n", path.c_str()); - return -1; } std::string @@ -66,3 +81,9 @@ Linux::procMeminfo(Process *process, ThreadContext *tc) process->system->freeMemSize() >> 10); } +std::string +Linux::etcPasswd(Process *process, ThreadContext *tc) +{ + return csprintf("gem5-user:x:1000:1000:gem5-user,,,:%s:/bin/bash\n", + process->getcwd()); +} diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index e6899a9ca..b24ee3895 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -226,6 +226,7 @@ class Linux : public OperatingSystem static int openSpecialFile(std::string path, Process *process, ThreadContext *tc); static std::string procMeminfo(Process *process, ThreadContext *tc); + static std::string etcPasswd(Process *process, ThreadContext *tc); // For futex system call static const unsigned TGT_FUTEX_WAIT = 0; diff --git a/src/kern/solaris/solaris.hh b/src/kern/solaris/solaris.hh index 9cd5af16f..d875f4402 100644 --- a/src/kern/solaris/solaris.hh +++ b/src/kern/solaris/solaris.hh @@ -114,6 +114,9 @@ class Solaris : public OperatingSystem char machine[_SYS_NMLN]; //!< Machine type. } utsname; + // for *at syscalls + static const int TGT_AT_FDCWD = -100; + }; // class Solaris #endif // __SOLARIS_HH__ |