#include "cpu/base.hh"
#include "debug/SyscallVerbose.hh"
+#include "sim/mem_state.hh"
#include "sim/process.hh"
#include "sim/system.hh"
+#include "sim/vma.hh"
+
+// The OS methods are called statically. Instantiate the random number
+// generator for access to /dev/urandom here.
+Random Linux::random;
int
Linux::openSpecialFile(std::string path, Process *process,
} else if (path.compare(0, 11, "/etc/passwd") == 0) {
data = Linux::etcPasswd(process, tc);
matched = true;
+ } else if (path.compare(0, 15, "/proc/self/maps") == 0) {
+ data = Linux::procSelfMaps(process, tc);
+ matched = true;
+ } else if (path.compare(0, 30, "/sys/devices/system/cpu/online") == 0) {
+ data = Linux::cpuOnline(process, tc);
+ matched = true;
+ } else if (path.compare(0, 12 ,"/dev/urandom") == 0) {
+ data = Linux::devRandom(process, tc);
+ matched = true;
}
if (matched) {
return csprintf("gem5-user:x:1000:1000:gem5-user,,,:%s:/bin/bash\n",
process->tgtCwd);
}
+
+std::string
+Linux::procSelfMaps(Process *process, ThreadContext *tc)
+{
+ return process->memState->printVmaList();
+}
+
+std::string
+Linux::cpuOnline(Process *process, ThreadContext *tc)
+{
+ return csprintf("0-%d\n",
+ tc->getSystemPtr()->numContexts() - 1);
+}
+
+std::string
+Linux::devRandom(Process *process, ThreadContext *tc)
+{
+ DPRINTFR(SyscallVerbose,
+ "%d: %s: open: generating urandom\n",
+ curTick(), tc->getCpuPtr()->name());
+
+ std::stringstream line;
+ int max = 1E5;
+ for (int i = 0; i < max; i++) {
+ uint8_t rand_uint = random.random<uint8_t>(0, 255);
+
+ line << rand_uint;
+ }
+ return line.str();
+}
#ifndef __LINUX_HH__
#define __LINUX_HH__
-#include "base/types.hh"
-
#include <string>
+#include "base/random.hh"
+#include "base/types.hh"
#include "kern/operatingsystem.hh"
#include "sim/process.hh"
int64_t ru_nivcsw; //!< involuntary "
};
+ // For /dev/urandom accesses
+ static Random random;
+
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);
+ static std::string procSelfMaps(Process *process, ThreadContext *tc);
static std::string cpuOnline(Process *process, ThreadContext *tc);
+ static std::string devRandom(Process *process, ThreadContext *tc);
// For futex system call
static const unsigned TGT_FUTEX_WAIT = 0;
return start;
}
+
+std::string
+MemState::printVmaList()
+{
+ std::stringstream file_content;
+
+ for (auto vma : _vmaList) {
+ std::stringstream line;
+ line << std::hex << vma.start() << "-";
+ line << std::hex << vma.end() << " ";
+ line << "r-xp 00000000 00:00 0 ";
+ line << "[" << vma.getName() << "]" << std::endl;
+ file_content << line.str();
+ }
+
+ return file_content.str();
+}
paramIn(cp, "mmapEnd", _mmapEnd);
}
+ /**
+ * Print the list of VMAs in a format similar to /proc/self/maps
+ */
+ std::string printVmaList();
+
private:
/**
* Owner process of MemState. Used to manipulate page tables.
int sim_fd = -1;
std::string used_path;
std::vector<std::string> special_paths =
- { "/proc/meminfo/", "/system/", "/platform/", "/etc/passwd" };
+ { "/proc/meminfo/", "/system/", "/platform/", "/etc/passwd",
+ "/proc/self/maps", "/dev/urandom",
+ "/sys/devices/system/cpu/online" };
for (auto entry : special_paths) {
if (startswith(path, entry)) {
sim_fd = OS::openSpecialFile(abs_path, p, tc);