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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45899 Reviewed-by: Gabe Black <gabe.black@gmail.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
// open(2) flags translation table
|
||||
SyscallFlagTransTable ArmFreebsd32::openFlagTable[] = {
|
||||
const 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 @@ SyscallFlagTransTable ArmFreebsd32::openFlagTable[] = {
|
||||
{ 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[] = {
|
||||
const 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 @@ SyscallFlagTransTable ArmFreebsd64::openFlagTable[] = {
|
||||
{ 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]);
|
||||
|
||||
|
||||
@@ -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 @@ class ArmFreebsd32 : public ArmFreebsd
|
||||
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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// Basic ARM FreeBSD types
|
||||
@@ -211,10 +210,7 @@ class ArmFreebsd64 : public ArmFreebsd
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// Basic ARM FreeBSD types
|
||||
|
||||
@@ -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 @@ class ArmLinux32 : public ArmLinux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// Basic ARM Linux types
|
||||
@@ -160,8 +159,6 @@ class ArmLinux32 : public ArmLinux
|
||||
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 @@ class ArmLinux64 : public ArmLinux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// Basic ARM Linux types
|
||||
@@ -375,7 +369,7 @@ class ArmLinux64 : public ArmLinux
|
||||
//@}
|
||||
|
||||
/// For mmap().
|
||||
static SyscallFlagTransTable mmapFlagTable[];
|
||||
static const std::map<int, int> mmapFlagTable;
|
||||
|
||||
static const unsigned TGT_MAP_SHARED = 0x00001;
|
||||
static const unsigned TGT_MAP_PRIVATE = 0x00002;
|
||||
@@ -393,8 +387,6 @@ class ArmLinux64 : public ArmLinux
|
||||
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;
|
||||
|
||||
@@ -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 @@ class MipsLinux : public Linux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// open(2) flag values.
|
||||
@@ -118,8 +117,6 @@ class MipsLinux : public Linux
|
||||
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
|
||||
|
||||
@@ -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 @@ class PowerLinux : public Linux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// open(2) flag values.
|
||||
@@ -182,8 +181,6 @@ class PowerLinux : public Linux
|
||||
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;
|
||||
|
||||
@@ -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 @@ class RiscvLinux64 : public RiscvLinux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// open(2) flag values.
|
||||
@@ -119,8 +118,6 @@ class RiscvLinux64 : public RiscvLinux
|
||||
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 @@ class RiscvLinux32 : public RiscvLinux
|
||||
|
||||
/// 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 const std::map<int, int> openFlagTable;
|
||||
|
||||
//@{
|
||||
/// open(2) flag values.
|
||||
@@ -295,8 +289,6 @@ class RiscvLinux32 : public RiscvLinux
|
||||
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;
|
||||
|
||||
@@ -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 @@ class SparcLinux : public Linux
|
||||
static const int TGT_SIGUSR1 = 0x00001e;
|
||||
static const int TGT_SIGUSR2 = 0x00001f;
|
||||
|
||||
static SyscallFlagTransTable openFlagTable[];
|
||||
static const 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 @@ class SparcLinux : public Linux
|
||||
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 @@ class SparcLinux : public Linux
|
||||
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 */
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
// open(2) flags translation table
|
||||
SyscallFlagTransTable SparcSolaris::openFlagTable[] = {
|
||||
const 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 @@ SyscallFlagTransTable SparcSolaris::openFlagTable[] = {
|
||||
#endif /* _MSC_VER */
|
||||
};
|
||||
|
||||
const int SparcSolaris::NUM_OPEN_FLAGS =
|
||||
(sizeof(SparcSolaris::openFlagTable)/sizeof(SparcSolaris::openFlagTable[0]));
|
||||
|
||||
// mmap(2) flags translation table
|
||||
SyscallFlagTransTable SparcSolaris::mmapFlagTable[] = {
|
||||
const 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 @@ SyscallFlagTransTable SparcSolaris::mmapFlagTable[] = {
|
||||
{ TGT_MAP_ANONYMOUS, MAP_ANONYMOUS },
|
||||
{ TGT_MAP_FIXED, MAP_FIXED },
|
||||
};
|
||||
|
||||
const unsigned SparcSolaris::NUM_MMAP_FLAGS =
|
||||
sizeof(SparcSolaris::mmapFlagTable) /
|
||||
sizeof(SparcSolaris::mmapFlagTable[0]);
|
||||
|
||||
|
||||
@@ -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 @@ class SparcSolaris : public Solaris
|
||||
|
||||
static const ByteOrder byteOrder = ByteOrder::big;
|
||||
|
||||
static SyscallFlagTransTable openFlagTable[];
|
||||
static const 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 @@ class SparcSolaris : public Solaris
|
||||
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 const std::map<int, int> mmapFlagTable;
|
||||
|
||||
static const unsigned TGT_MAP_SHARED = 0x00001;
|
||||
static const unsigned TGT_MAP_PRIVATE = 0x00002;
|
||||
@@ -77,8 +77,6 @@ class SparcSolaris : public Solaris
|
||||
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
|
||||
|
||||
@@ -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"
|
||||
@@ -171,7 +173,7 @@ class X86Linux64 : public X86Linux
|
||||
static const int TGT_SIGSYS = 0x00001f;
|
||||
static const int TGT_SIGUNUSED = 0x00001f;
|
||||
|
||||
static SyscallFlagTransTable openFlagTable[];
|
||||
static const std::map<int, int> openFlagTable;
|
||||
|
||||
static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
|
||||
static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
|
||||
@@ -193,8 +195,6 @@ class X86Linux64 : public X86Linux
|
||||
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;
|
||||
@@ -220,8 +220,6 @@ class X86Linux64 : public X86Linux
|
||||
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 *
|
||||
@@ -307,7 +305,7 @@ class X86Linux32 : public X86Linux
|
||||
static const int TGT_SIGSYS = 0x00001f;
|
||||
static const int TGT_SIGUNUSED = 0x00001f;
|
||||
|
||||
static SyscallFlagTransTable openFlagTable[];
|
||||
static const std::map<int, int> openFlagTable;
|
||||
|
||||
static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
|
||||
static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
|
||||
@@ -329,9 +327,7 @@ class X86Linux32 : public X86Linux
|
||||
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 const std::map<int, int> mmapFlagTable;
|
||||
|
||||
//@{
|
||||
/// Basic X86 Linux types
|
||||
@@ -358,8 +354,6 @@ class X86Linux32 : public X86Linux
|
||||
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 */
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
*/
|
||||
|
||||
// open(2) flags translation table
|
||||
SyscallFlagTransTable TARGET::openFlagTable[] = {
|
||||
const 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 @@ SyscallFlagTransTable TARGET::openFlagTable[] = {
|
||||
#endif
|
||||
#endif /* _MSC_VER */
|
||||
};
|
||||
|
||||
const int TARGET::NUM_OPEN_FLAGS =
|
||||
sizeof(TARGET::openFlagTable) / sizeof(TARGET::openFlagTable[0]);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -771,14 +771,13 @@ openatFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
* 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 (const 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;
|
||||
|
||||
Reference in New Issue
Block a user