From acce7b0dc0edf85b99c75d1800df99bd9e288b01 Mon Sep 17 00:00:00 2001 From: Brandon Potter Date: Wed, 1 Mar 2017 13:24:16 -0600 Subject: 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 Reviewed-by: Tony Gutierrez Reviewed-by: Michael LeBeane --- src/kern/linux/linux.cc | 35 ++++++++++++++++++++++++++++------- src/kern/linux/linux.hh | 1 + src/kern/solaris/solaris.hh | 3 +++ 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src/kern') 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 #include +#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__ -- cgit v1.2.3