summaryrefslogtreecommitdiff
path: root/src/arch/x86/linux
diff options
context:
space:
mode:
authorBrandon Potter <brandon.potter@amd.com>2016-03-17 10:24:17 -0700
committerBrandon Potter <brandon.potter@amd.com>2016-03-17 10:24:17 -0700
commita04fac976f02377237bb827d46854b669ebc2397 (patch)
tree2f2a5e55e16b2c05e4d94e302081bb977e864a36 /src/arch/x86/linux
parent3fa311e5acd58ce720014dd964728c2fa414ca6a (diff)
downloadgem5-a04fac976f02377237bb827d46854b669ebc2397.tar.xz
syscall_emul: extend mmap system call to support file backed mmaps
For O3, which has a stat that counts reg reads, there is an additional reg read per mmap() call since there's an arg we no longer ignore. Otherwise, stats should not be affected.
Diffstat (limited to 'src/arch/x86/linux')
-rw-r--r--src/arch/x86/linux/linux.cc60
-rw-r--r--src/arch/x86/linux/linux.hh47
2 files changed, 100 insertions, 7 deletions
diff --git a/src/arch/x86/linux/linux.cc b/src/arch/x86/linux/linux.cc
index 2eab555ce..f51bb16e7 100644
--- a/src/arch/x86/linux/linux.cc
+++ b/src/arch/x86/linux/linux.cc
@@ -37,10 +37,11 @@
* Authors: Gabe Black
*/
-#include <fcntl.h>
-
#include "arch/x86/linux/linux.hh"
+#include <fcntl.h>
+#include <sys/mman.h>
+
// open(2) flags translation table
SyscallFlagTransTable X86Linux64::openFlagTable[] = {
#ifdef _MSC_VER
@@ -110,6 +111,34 @@ const int X86Linux64::NUM_OPEN_FLAGS =
sizeof(X86Linux64::openFlagTable) /
sizeof(X86Linux64::openFlagTable[0]);
+// mmap(2) flags translation table
+SyscallFlagTransTable X86Linux64::mmapFlagTable[] = {
+ { X86Linux64::TGT_MAP_SHARED, MAP_SHARED },
+ { X86Linux64::TGT_MAP_PRIVATE, MAP_PRIVATE },
+ { X86Linux64::TGT_MAP_32BIT, MAP_32BIT},
+ { X86Linux64::TGT_MAP_ANON, MAP_ANON },
+ { X86Linux64::TGT_MAP_DENYWRITE, MAP_DENYWRITE },
+ { X86Linux64::TGT_MAP_EXECUTABLE, MAP_EXECUTABLE },
+ { X86Linux64::TGT_MAP_FILE, MAP_FILE },
+ { X86Linux64::TGT_MAP_GROWSDOWN, MAP_GROWSDOWN },
+#ifdef MAP_HUGETLB
+ { X86Linux64::TGT_MAP_HUGETLB, MAP_HUGETLB },
+#endif
+ { X86Linux64::TGT_MAP_LOCKED, MAP_LOCKED },
+ { X86Linux64::TGT_MAP_NONBLOCK, MAP_NONBLOCK },
+ { X86Linux64::TGT_MAP_NORESERVE, MAP_NORESERVE },
+ { X86Linux64::TGT_MAP_POPULATE, MAP_POPULATE },
+#ifdef MAP_STACK
+ { X86Linux64::TGT_MAP_STACK, MAP_STACK },
+#endif
+ { X86Linux64::TGT_MAP_ANONYMOUS, MAP_ANONYMOUS },
+ { X86Linux64::TGT_MAP_FIXED, MAP_FIXED },
+};
+
+const unsigned X86Linux64::NUM_MMAP_FLAGS =
+ sizeof(X86Linux64::mmapFlagTable) /
+ sizeof(X86Linux64::mmapFlagTable[0]);
+
// open(2) flags translation table
SyscallFlagTransTable X86Linux32::openFlagTable[] = {
#ifdef _MSC_VER
@@ -179,3 +208,30 @@ const int X86Linux32::NUM_OPEN_FLAGS =
sizeof(X86Linux32::openFlagTable) /
sizeof(X86Linux32::openFlagTable[0]);
+// mmap(2) flags translation table
+SyscallFlagTransTable X86Linux32::mmapFlagTable[] = {
+ { X86Linux32::TGT_MAP_SHARED, MAP_SHARED },
+ { X86Linux32::TGT_MAP_PRIVATE, MAP_PRIVATE },
+ { X86Linux32::TGT_MAP_32BIT, MAP_32BIT},
+ { X86Linux32::TGT_MAP_ANON, MAP_ANON },
+ { X86Linux32::TGT_MAP_DENYWRITE, MAP_DENYWRITE },
+ { X86Linux32::TGT_MAP_EXECUTABLE, MAP_EXECUTABLE },
+ { X86Linux32::TGT_MAP_FILE, MAP_FILE },
+ { X86Linux32::TGT_MAP_GROWSDOWN, MAP_GROWSDOWN },
+#ifdef MAP_HUGETLB
+ { X86Linux32::TGT_MAP_HUGETLB, MAP_HUGETLB },
+#endif
+ { X86Linux32::TGT_MAP_LOCKED, MAP_LOCKED },
+ { X86Linux32::TGT_MAP_NONBLOCK, MAP_NONBLOCK },
+ { X86Linux32::TGT_MAP_NORESERVE, MAP_NORESERVE },
+ { X86Linux32::TGT_MAP_POPULATE, MAP_POPULATE },
+#ifdef MAP_STACK
+ { X86Linux32::TGT_MAP_STACK, MAP_STACK },
+#endif
+ { X86Linux32::TGT_MAP_ANONYMOUS, MAP_ANONYMOUS },
+ { X86Linux32::TGT_MAP_FIXED, MAP_FIXED },
+};
+
+const unsigned X86Linux32::NUM_MMAP_FLAGS =
+ sizeof(X86Linux32::mmapFlagTable) /
+ sizeof(X86Linux32::mmapFlagTable[0]);
diff --git a/src/arch/x86/linux/linux.hh b/src/arch/x86/linux/linux.hh
index 854ab00a0..ce395f17d 100644
--- a/src/arch/x86/linux/linux.hh
+++ b/src/arch/x86/linux/linux.hh
@@ -126,8 +126,27 @@ class X86Linux64 : public Linux
static const int NUM_OPEN_FLAGS;
- static const unsigned TGT_MAP_ANONYMOUS = 0x20;
- static const unsigned TGT_MAP_FIXED = 0x10;
+ /// For mmap().
+ static SyscallFlagTransTable mmapFlagTable[];
+
+ static const unsigned TGT_MAP_SHARED = 0x00001;
+ static const unsigned TGT_MAP_PRIVATE = 0x00002;
+ static const unsigned TGT_MAP_32BIT = 0x00040;
+ static const unsigned TGT_MAP_ANON = 0x00020;
+ static const unsigned TGT_MAP_DENYWRITE = 0x00800;
+ static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
+ static const unsigned TGT_MAP_FILE = 0x00000;
+ static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
+ static const unsigned TGT_MAP_HUGETLB = 0x40000;
+ static const unsigned TGT_MAP_LOCKED = 0x02000;
+ static const unsigned TGT_MAP_NONBLOCK = 0x10000;
+ static const unsigned TGT_MAP_NORESERVE = 0x04000;
+ static const unsigned TGT_MAP_POPULATE = 0x08000;
+ static const unsigned TGT_MAP_STACK = 0x20000;
+ static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
+ static const unsigned TGT_MAP_FIXED = 0x00010;
+
+ static const unsigned NUM_MMAP_FLAGS;
typedef struct {
uint64_t iov_base; // void *
@@ -147,7 +166,7 @@ class X86Linux64 : public Linux
uint64_t totalhigh; /* Total high memory size */
uint64_t freehigh; /* Available high memory size */
uint64_t mem_unit; /* Memory unit size in bytes */
- } tgt_sysinfo;
+ } tgt_sysinfo;
};
@@ -236,8 +255,26 @@ class X86Linux32 : public Linux
static const int NUM_OPEN_FLAGS;
- static const unsigned TGT_MAP_ANONYMOUS = 0x20;
- static const unsigned TGT_MAP_FIXED = 0x10;
+ static SyscallFlagTransTable mmapFlagTable[];
+
+ static const unsigned TGT_MAP_SHARED = 0x00001;
+ static const unsigned TGT_MAP_PRIVATE = 0x00002;
+ static const unsigned TGT_MAP_32BIT = 0x00040;
+ static const unsigned TGT_MAP_ANON = 0x00020;
+ static const unsigned TGT_MAP_DENYWRITE = 0x00800;
+ static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
+ static const unsigned TGT_MAP_FILE = 0x00000;
+ static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
+ static const unsigned TGT_MAP_HUGETLB = 0x40000;
+ static const unsigned TGT_MAP_LOCKED = 0x02000;
+ static const unsigned TGT_MAP_NONBLOCK = 0x10000;
+ static const unsigned TGT_MAP_NORESERVE = 0x04000;
+ static const unsigned TGT_MAP_POPULATE = 0x08000;
+ static const unsigned TGT_MAP_STACK = 0x20000;
+ static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
+ static const unsigned TGT_MAP_FIXED = 0x00010;
+
+ static const unsigned NUM_MMAP_FLAGS;
typedef struct {
int32_t uptime; /* Seconds since boot */