Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/45899 )
Change subject: arch,kern,sim: Use a map to map syscall flags.
......................................................................
arch,kern,sim: Use a map to map syscall flags.
Use a std::map to map target syscall flag bits to host flag bits. This
avoids having to track the number of elements in the map separately.
Change-Id: I43bd54f5286f11b9635d46240a55742ddfdb0901
---
M src/arch/arm/freebsd/freebsd.cc
M src/arch/arm/freebsd/freebsd.hh
M src/arch/arm/linux/linux.hh
M src/arch/mips/linux/linux.hh
M src/arch/power/linux/linux.hh
M src/arch/riscv/linux/linux.hh
M src/arch/sparc/linux/linux.hh
M src/arch/sparc/solaris/solaris.cc
M src/arch/sparc/solaris/solaris.hh
M src/arch/x86/linux/linux.hh
M src/kern/linux/flag_tables.hh
M src/kern/operatingsystem.hh
M src/sim/syscall_emul.hh
13 files changed, 41 insertions(+), 105 deletions(-)
diff --git a/src/arch/arm/freebsd/freebsd.cc
b/src/arch/arm/freebsd/freebsd.cc
index 99cd032..34f0e40 100644
--- a/src/arch/arm/freebsd/freebsd.cc
+++ b/src/arch/arm/freebsd/freebsd.cc
@@ -35,7 +35,7 @@
#include <fcntl.h>
// open(2) flags translation table
-SyscallFlagTransTable ArmFreebsd32::openFlagTable[] = {
+std::map<int, int> ArmFreebsd32::openFlagTable = {
{ ArmFreebsd32::TGT_O_RDONLY, O_RDONLY },
{ ArmFreebsd32::TGT_O_WRONLY, O_WRONLY },
{ ArmFreebsd32::TGT_O_RDWR, O_RDWR },
@@ -54,11 +54,8 @@
{ ArmFreebsd32::TGT_O_NOFOLLOW, O_NOFOLLOW },
};
-const int ArmFreebsd32::NUM_OPEN_FLAGS =
sizeof(ArmFreebsd32::openFlagTable) /
-
sizeof(ArmFreebsd32::openFlagTable[0]);
-
// open(2) flags translation table
-SyscallFlagTransTable ArmFreebsd64::openFlagTable[] = {
+std::map<int, int> ArmFreebsd64::openFlagTable = {
{ ArmFreebsd64::TGT_O_RDONLY, O_RDONLY },
{ ArmFreebsd64::TGT_O_WRONLY, O_WRONLY },
{ ArmFreebsd64::TGT_O_RDWR, O_RDWR },
@@ -76,7 +73,3 @@
{ ArmFreebsd64::TGT_O_DIRECTORY, O_DIRECTORY },
{ ArmFreebsd64::TGT_O_NOFOLLOW, O_NOFOLLOW },
};
-
-const int ArmFreebsd64::NUM_OPEN_FLAGS =
sizeof(ArmFreebsd64::openFlagTable) /
-
sizeof(ArmFreebsd64::openFlagTable[0]);
-
diff --git a/src/arch/arm/freebsd/freebsd.hh
b/src/arch/arm/freebsd/freebsd.hh
index c552588..a059c20 100644
--- a/src/arch/arm/freebsd/freebsd.hh
+++ b/src/arch/arm/freebsd/freebsd.hh
@@ -33,6 +33,8 @@
#ifndef __ARCH_ARM_FREEBSD_FREEBSD_HH__
#define __ARCH_ARM_FREEBSD_FREEBSD_HH__
+#include <map>
+
#include "kern/freebsd/freebsd.hh"
#include "sim/byteswap.hh"
@@ -47,10 +49,7 @@
public:
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// Basic ARM FreeBSD types
@@ -211,10 +210,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// Basic ARM FreeBSD types
diff --git a/src/arch/arm/linux/linux.hh b/src/arch/arm/linux/linux.hh
index 6ca877c..9a5440b 100644
--- a/src/arch/arm/linux/linux.hh
+++ b/src/arch/arm/linux/linux.hh
@@ -42,6 +42,8 @@
#ifndef __ARCH_ARM_LINUX_LINUX_HH__
#define __ARCH_ARM_LINUX_LINUX_HH__
+#include <map>
+
#include "arch/arm/utility.hh"
#include "base/compiler.hh"
#include "kern/linux/linux.hh"
@@ -108,10 +110,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// Basic ARM Linux types
@@ -160,8 +159,6 @@
static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
static const unsigned TGT_MAP_FIXED = 0x00010;
- static const unsigned NUM_MMAP_FLAGS;
-
/// For table().
static const int TBL_SYSINFO = 12;
@@ -338,10 +335,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// Basic ARM Linux types
@@ -375,7 +369,7 @@
//@}
/// For mmap().
- static SyscallFlagTransTable mmapFlagTable[];
+ static std::map<int, int> mmapFlagTable;
static const unsigned TGT_MAP_SHARED = 0x00001;
static const unsigned TGT_MAP_PRIVATE = 0x00002;
@@ -393,8 +387,6 @@
static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
static const unsigned TGT_MAP_FIXED = 0x00010;
- static const unsigned NUM_MMAP_FLAGS;
-
//@{
/// For getrusage().
static const int TGT_RUSAGE_SELF = 0;
diff --git a/src/arch/mips/linux/linux.hh b/src/arch/mips/linux/linux.hh
index 5a74e13..d15d14d 100644
--- a/src/arch/mips/linux/linux.hh
+++ b/src/arch/mips/linux/linux.hh
@@ -29,6 +29,8 @@
#ifndef __ARCH_MIPS_LINUX_LINUX_HH__
#define __ARCH_MIPS_LINUX_LINUX_HH__
+#include <map>
+
#include "kern/linux/linux.hh"
class MipsLinux : public Linux
@@ -74,10 +76,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// open(2) flag values.
@@ -118,8 +117,6 @@
static const unsigned TGT_MAP_ANONYMOUS = 0x00800;
static const unsigned TGT_MAP_FIXED = 0x00010;
- static const unsigned NUM_MMAP_FLAGS;
-
//@{
/// For getsysinfo().
static const unsigned GSI_PLATFORM_NAME = 103; //!< platform name as
string
diff --git a/src/arch/power/linux/linux.hh b/src/arch/power/linux/linux.hh
index 471ee24..93838c0 100644
--- a/src/arch/power/linux/linux.hh
+++ b/src/arch/power/linux/linux.hh
@@ -30,6 +30,8 @@
#ifndef __ARCH_POWER_LINUX_LINUX_HH__
#define __ARCH_POWER_LINUX_LINUX_HH__
+#include <map>
+
#include "kern/linux/linux.hh"
/*
@@ -138,10 +140,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// open(2) flag values.
@@ -182,8 +181,6 @@
static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
static const unsigned TGT_MAP_FIXED = 0x00010;
- static const unsigned NUM_MMAP_FLAGS;
-
//@{
/// ioctl() command codes.
static const unsigned TGT_TIOCGETP = 0x40067408;
diff --git a/src/arch/riscv/linux/linux.hh b/src/arch/riscv/linux/linux.hh
index f0bc513..e920399 100644
--- a/src/arch/riscv/linux/linux.hh
+++ b/src/arch/riscv/linux/linux.hh
@@ -29,6 +29,8 @@
#ifndef __ARCH_RISCV_LINUX_LINUX_HH__
#define __ARCH_RISCV_LINUX_LINUX_HH__
+#include <map>
+
#include "arch/riscv/utility.hh"
#include "kern/linux/linux.hh"
@@ -79,10 +81,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// open(2) flag values.
@@ -119,8 +118,6 @@
static const unsigned TGT_MAP_POPULATE = 0x1000;
static const unsigned TGT_MREMAP_FIXED = 0x0020;
- static const unsigned NUM_MMAP_FLAGS;
-
typedef int64_t time_t;
typedef uint64_t dev_t;
typedef uint64_t ino_t;
@@ -253,10 +250,7 @@
/// This table maps the target open() flags to the corresponding
/// host open() flags.
- static SyscallFlagTransTable openFlagTable[];
-
- /// Number of entries in openFlagTable[].
- static const int NUM_OPEN_FLAGS;
+ static std::map<int, int> openFlagTable;
//@{
/// open(2) flag values.
@@ -295,8 +289,6 @@
static const unsigned TGT_MAP_POPULATE = 0x1000;
static const unsigned TGT_MREMAP_FIXED = 0x0020;
- static const unsigned NUM_MMAP_FLAGS;
-
// Newlib 3.0.0 defaults to 64-bits for time_t.
// Currently time_t in glibc for riscv32 is 32-bits, but will be
changed.
typedef int64_t time_t;
diff --git a/src/arch/sparc/linux/linux.hh b/src/arch/sparc/linux/linux.hh
index 5d5f67c..dd4072c 100644
--- a/src/arch/sparc/linux/linux.hh
+++ b/src/arch/sparc/linux/linux.hh
@@ -29,6 +29,8 @@
#ifndef __ARCH_SPARC_LINUX_LINUX_HH__
#define __ARCH_SPARC_LINUX_LINUX_HH__
+#include <map>
+
#include "arch/sparc/asi.hh"
#include "arch/sparc/regs/int.hh"
#include "arch/sparc/regs/misc.hh"
@@ -124,7 +126,7 @@
static const int TGT_SIGUSR1 = 0x00001e;
static const int TGT_SIGUSR2 = 0x00001f;
- static SyscallFlagTransTable openFlagTable[];
+ static std::map<int, int> openFlagTable;
static const int TGT_O_RDONLY = 0x00000000; //!< O_RDONLY
static const int TGT_O_WRONLY = 0x00000001; //!< O_WRONLY
@@ -147,8 +149,6 @@
static const int TGT_O_DIRECTORY = 000200000; //!< O_DIRECTORY
static const int TGT_O_NOFOLLOW = 000400000; //!< O_NOFOLLOW
- static const int NUM_OPEN_FLAGS;
-
static const unsigned TGT_MAP_SHARED = 0x00001;
static const unsigned TGT_MAP_PRIVATE = 0x00002;
static const unsigned TGT_MAP_ANON = 0x00020;
@@ -166,8 +166,6 @@
static const unsigned TGT_MAP_FIXED = 0x00010;
static const unsigned TGT_MAP_INHERIT = 0x00080;
- static const unsigned NUM_MMAP_FLAGS;
-
typedef struct
{
int64_t uptime; /* Seconds since boot */
diff --git a/src/arch/sparc/solaris/solaris.cc
b/src/arch/sparc/solaris/solaris.cc
index 33b2078..8a28732 100644
--- a/src/arch/sparc/solaris/solaris.cc
+++ b/src/arch/sparc/solaris/solaris.cc
@@ -32,7 +32,7 @@
#include <sys/mman.h>
// open(2) flags translation table
-SyscallFlagTransTable SparcSolaris::openFlagTable[] = {
+std::map<int, int> SparcSolaris::openFlagTable = {
#ifdef _MSC_VER
{ SparcSolaris::TGT_O_RDONLY, _O_RDONLY },
{ SparcSolaris::TGT_O_WRONLY, _O_WRONLY },
@@ -72,11 +72,8 @@
#endif /* _MSC_VER */
};
-const int SparcSolaris::NUM_OPEN_FLAGS =
-
(sizeof(SparcSolaris::openFlagTable)/sizeof(SparcSolaris::openFlagTable[0]));
-
// mmap(2) flags translation table
-SyscallFlagTransTable SparcSolaris::mmapFlagTable[] = {
+std::map<int, int> SparcSolaris::mmapFlagTable = {
{ TGT_MAP_SHARED, MAP_SHARED },
{ TGT_MAP_PRIVATE, MAP_PRIVATE },
{ TGT_MAP_ANON, MAP_ANON },
@@ -93,8 +90,3 @@
{ TGT_MAP_ANONYMOUS, MAP_ANONYMOUS },
{ TGT_MAP_FIXED, MAP_FIXED },
};
-
-const unsigned SparcSolaris::NUM_MMAP_FLAGS =
- sizeof(SparcSolaris::mmapFlagTable) /
- sizeof(SparcSolaris::mmapFlagTable[0]);
-
diff --git a/src/arch/sparc/solaris/solaris.hh
b/src/arch/sparc/solaris/solaris.hh
index 7a5aaaf..14aef37 100644
--- a/src/arch/sparc/solaris/solaris.hh
+++ b/src/arch/sparc/solaris/solaris.hh
@@ -29,6 +29,8 @@
#ifndef __ARCH_SPARC_SOLARIS_SOLARIS_HH__
#define __ARCH_SPARC_SOLARIS_SOLARIS_HH__
+#include <map>
+
#include "kern/solaris/solaris.hh"
#include "sim/byteswap.hh"
@@ -38,7 +40,7 @@
static const ByteOrder byteOrder = ByteOrder::big;
- static SyscallFlagTransTable openFlagTable[];
+ static std::map<int, int> openFlagTable;
static const int TGT_O_RDONLY = 0x00000000; //!< O_RDONLY
static const int TGT_O_WRONLY = 0x00000001; //!< O_WRONLY
@@ -57,10 +59,8 @@
static const int TGT_O_NOCTTY = 0x00000800; //!< O_NOCTTY
static const int TGT_O_XATTR = 0x00004000; //??
- static const int NUM_OPEN_FLAGS;
-
/// For mmap().
- static SyscallFlagTransTable mmapFlagTable[];
+ static std::map<int, int> mmapFlagTable;
static const unsigned TGT_MAP_SHARED = 0x00001;
static const unsigned TGT_MAP_PRIVATE = 0x00002;
@@ -77,8 +77,6 @@
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;
};
#endif
diff --git a/src/arch/x86/linux/linux.hh b/src/arch/x86/linux/linux.hh
index 5051325..42e4e2c 100644
--- a/src/arch/x86/linux/linux.hh
+++ b/src/arch/x86/linux/linux.hh
@@ -38,6 +38,8 @@
#ifndef __ARCH_X86_LINUX_LINUX_HH__
#define __ARCH_X86_LINUX_LINUX_HH__
+#include <map>
+
#include "arch/x86/utility.hh"
#include "base/compiler.hh"
#include "kern/linux/linux.hh"
@@ -170,7 +172,7 @@
static const int TGT_SIGSYS = 0x00001f;
static const int TGT_SIGUNUSED = 0x00001f;
- static SyscallFlagTransTable openFlagTable[];
+ static std::map<int, int> openFlagTable;
static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
@@ -192,8 +194,6 @@
static const int TGT_O_SYNC = 004010000; //!< O_SYNC
static const int TGT_O_PATH = 010000000;
- static const int NUM_OPEN_FLAGS;
-
//@{
/// Basic X86_64 Linux types
typedef uint64_t size_t;
@@ -219,8 +219,6 @@
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 *
@@ -306,7 +304,7 @@
static const int TGT_SIGSYS = 0x00001f;
static const int TGT_SIGUNUSED = 0x00001f;
- static SyscallFlagTransTable openFlagTable[];
+ static std::map<int, int> openFlagTable;
static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
@@ -328,9 +326,7 @@
static const int TGT_O_SYNC = 004010000; //!< O_SYNC
static const int TGT_O_PATH = 010000000;
- static const int NUM_OPEN_FLAGS;
-
- static SyscallFlagTransTable mmapFlagTable[];
+ static std::map<int, int> mmapFlagTable;
//@{
/// Basic X86 Linux types
@@ -357,8 +353,6 @@
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 */
diff --git a/src/kern/linux/flag_tables.hh b/src/kern/linux/flag_tables.hh
index 44d2507..c776006 100644
--- a/src/kern/linux/flag_tables.hh
+++ b/src/kern/linux/flag_tables.hh
@@ -54,7 +54,7 @@
*/
// open(2) flags translation table
-SyscallFlagTransTable TARGET::openFlagTable[] = {
+std::map<int, int> TARGET::openFlagTable = {
#ifdef _MSC_VER
{ TARGET::TGT_O_RDONLY, _O_RDONLY },
{ TARGET::TGT_O_WRONLY, _O_WRONLY },
@@ -105,6 +105,3 @@
#endif
#endif /* _MSC_VER */
};
-
-const int TARGET::NUM_OPEN_FLAGS =
- sizeof(TARGET::openFlagTable) / sizeof(TARGET::openFlagTable[0]);
diff --git a/src/kern/operatingsystem.hh b/src/kern/operatingsystem.hh
index 5a5f6e8f..084eceb 100644
--- a/src/kern/operatingsystem.hh
+++ b/src/kern/operatingsystem.hh
@@ -36,15 +36,6 @@
class Process;
class ThreadContext;
-/// This struct is used to build target-OS-dependent tables that
-/// map the target's flags to the host's flags.
-struct SyscallFlagTransTable
-{
- int tgtFlag; //!< Target system flag value.
- int hostFlag; //!< Corresponding host system flag value.
-};
-
-
///
/// This class encapsulates the types, structures, constants,
/// functions, and syscall-number mappings specific to an operating system
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 63a9ea6..c2e154b 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -771,14 +771,13 @@
* Translate target flags into host flags. Flags exist which are not
* ported between architectures which can cause check failures.
*/
- for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
- if (tgt_flags & OS::openFlagTable[i].tgtFlag) {
- tgt_flags &= ~OS::openFlagTable[i].tgtFlag;
- host_flags |= OS::openFlagTable[i].hostFlag;
+ for (auto &p: OS::openFlagTable) {
+ if (tgt_flags & p.first) {
+ tgt_flags &= ~p.first;
+ host_flags |= p.second;
}
}
- if (tgt_flags)
- warn("%s: cannot decode flags %#x", desc->name(), tgt_flags);
+ warn_if(tgt_flags, "%s: cannot decode flags %#x", desc->name(),
tgt_flags);
#ifdef __CYGWIN32__
host_flags |= O_BINARY;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45899
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I43bd54f5286f11b9635d46240a55742ddfdb0901
Gerrit-Change-Number: 45899
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s