sim-se: Add prlimit system call
[gem5.git] / src / sim / system.cc
index 3aba5afcb8c23d9200dae71d9cc5d4124f1b5db0..42cd5e720e0d5c2a92d0059b2e3b82b287e10632 100644 (file)
 #include "base/loader/symtab.hh"
 #include "base/str.hh"
 #include "base/trace.hh"
+#include "config/use_kvm.hh"
+#if USE_KVM
+#include "cpu/kvm/base.hh"
+#include "cpu/kvm/vm.hh"
+#endif
+#include "cpu/base.hh"
 #include "cpu/thread_context.hh"
 #include "debug/Loader.hh"
 #include "debug/WorkItems.hh"
@@ -90,6 +96,11 @@ System::System(Params *p)
       kernel(nullptr),
       loadAddrMask(p->load_addr_mask),
       loadAddrOffset(p->load_offset),
+#if USE_KVM
+      kvmVM(p->kvm_vm),
+#else
+      kvmVM(nullptr),
+#endif
       physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
       memoryMode(p->mem_mode),
       _cacheLineSize(p->cache_line_size),
@@ -104,6 +115,12 @@ System::System(Params *p)
     // add self to global system list
     systemList.push_back(this);
 
+#if USE_KVM
+    if (kvmVM) {
+        kvmVM->setSystem(this);
+    }
+#endif
+
     if (FullSystem) {
         kernelSymtab = new SymbolTable;
         if (!debugSymbolTable)
@@ -159,7 +176,7 @@ System::System(Params *p)
         }
     }
 
-    // increment the number of running systms
+    // increment the number of running systems
     numSystemsRunning++;
 
     // Set back pointers to the system in all memories
@@ -205,13 +222,6 @@ bool System::breakpoint()
     return false;
 }
 
-/**
- * Setting rgdb_wait to a positive integer waits for a remote debugger to
- * connect to that context ID before continuing.  This should really
-   be a parameter on the CPU object or something...
- */
-int rgdb_wait = -1;
-
 ContextID
 System::registerThreadContext(ThreadContext *tc, ContextID assigned)
 {
@@ -243,9 +253,13 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned)
         GDBListener *gdbl = new GDBListener(rgdb, port + id);
         gdbl->listen();
 
-        if (rgdb_wait != -1 && rgdb_wait == id)
-            gdbl->accept();
+        BaseCPU *cpu = tc->getCpuPtr();
+        if (cpu->waitForRemoteGDB()) {
+            inform("%s: Waiting for a remote GDB connection on port %d.\n",
+                   cpu->name(), gdbl->getPort());
 
+            gdbl->accept();
+        }
         if (remoteGDB.size() <= id) {
             remoteGDB.resize(id + 1);
         }
@@ -320,6 +334,24 @@ System::replaceThreadContext(ThreadContext *tc, ContextID context_id)
         remoteGDB[context_id]->replaceThreadContext(tc);
 }
 
+bool
+System::validKvmEnvironment() const
+{
+#if USE_KVM
+    if (threadContexts.empty())
+        return false;
+
+    for (auto tc : threadContexts) {
+        if (dynamic_cast<BaseKvmCPU*>(tc->getCpuPtr()) == nullptr) {
+            return false;
+        }
+    }
+    return true;
+#else
+    return false;
+#endif
+}
+
 Addr
 System::allocPhysPages(int npages)
 {