fix problems on darwin/*BSD for syscall emulation mode

arch/alpha/alpha_linux_process.cc:
arch/alpha/alpha_tru64_process.cc:
    fixup for bsd hosts. Some headers are included by default which means that
    more variables need TGT_ prefixes and there isn't a stat call (everything
    is a stat64 call) so we have to work around that a bit
base/intmath.hh:
base/socket.cc:
    this is no longer needed with mac os 10.4
cpu/inst_seq.hh:
    just use a uint64_t instead of long long
cpu/o3/inst_queue_impl.hh:
    I much cleaner way to get max int
sim/syscall_emul.hh:
    fix stat64 problems on *BSD

--HG--
extra : convert_revision : 9eef5f896e083ae1774e818a9765dd83e0305942
This commit is contained in:
Ali Saidi 2006-02-10 14:21:32 -05:00
parent 2c528d5865
commit fb7899aa68
7 changed files with 97 additions and 68 deletions

View file

@ -71,6 +71,15 @@ class Linux {
typedef uint32_t gid_t; typedef uint32_t gid_t;
//@} //@}
#if BSD_HOST
typedef struct stat hst_stat;
typedef struct stat hst_stat64;
#else
typedef struct stat hst_stat ;
typedef struct stat64 hst_stat64;
#endif
//@{ //@{
/// open(2) flag values. /// open(2) flag values.
static const int TGT_O_RDONLY = 00000000; //!< O_RDONLY static const int TGT_O_RDONLY = 00000000; //!< O_RDONLY
@ -139,7 +148,7 @@ class Linux {
uint64_t st_mtime_nsec; uint64_t st_mtime_nsec;
uint64_t tgt_st_ctime; uint64_t tgt_st_ctime;
uint64_t st_ctime_nsec; uint64_t st_ctime_nsec;
int64_t __unused[3]; int64_t ___unused[3];
}; };
/// Length of strings in struct utsname (plus 1 for null char). /// Length of strings in struct utsname (plus 1 for null char).
@ -170,18 +179,18 @@ class Linux {
/// Resource enumeration for getrlimit(). /// Resource enumeration for getrlimit().
enum rlimit_resources { enum rlimit_resources {
RLIMIT_CPU = 0, TGT_RLIMIT_CPU = 0,
RLIMIT_FSIZE = 1, TGT_RLIMIT_FSIZE = 1,
RLIMIT_DATA = 2, TGT_RLIMIT_DATA = 2,
RLIMIT_STACK = 3, TGT_RLIMIT_STACK = 3,
RLIMIT_CORE = 4, TGT_RLIMIT_CORE = 4,
RLIMIT_RSS = 5, TGT_RLIMIT_RSS = 5,
RLIMIT_NOFILE = 6, TGT_RLIMIT_NOFILE = 6,
RLIMIT_AS = 7, TGT_RLIMIT_AS = 7,
RLIMIT_VMEM = 7, TGT_RLIMIT_VMEM = 7,
RLIMIT_NPROC = 8, TGT_RLIMIT_NPROC = 8,
RLIMIT_MEMLOCK = 9, TGT_RLIMIT_MEMLOCK = 9,
RLIMIT_LOCKS = 10 TGT_RLIMIT_LOCKS = 10
}; };
/// Limit struct for getrlimit/setrlimit. /// Limit struct for getrlimit/setrlimit.
@ -208,9 +217,9 @@ class Linux {
//@{ //@{
/// For getrusage(). /// For getrusage().
static const int RUSAGE_SELF = 0; static const int TGT_RUSAGE_SELF = 0;
static const int RUSAGE_CHILDREN = -1; static const int TGT_RUSAGE_CHILDREN = -1;
static const int RUSAGE_BOTH = -2; static const int TGT_RUSAGE_BOTH = -2;
//@} //@}
/// For getrusage(). /// For getrusage().
@ -236,8 +245,9 @@ class Linux {
/// Helper function to convert a host stat buffer to a target stat /// Helper function to convert a host stat buffer to a target stat
/// buffer. Also copies the target buffer out to the simulated /// buffer. Also copies the target buffer out to the simulated
/// memory space. Used by stat(), fstat(), and lstat(). /// memory space. Used by stat(), fstat(), and lstat().
#if !BSD_HOST
static void static void
copyOutStatBuf(FunctionalMemory *mem, Addr addr, struct stat *host) copyOutStatBuf(FunctionalMemory *mem, Addr addr, hst_stat *host)
{ {
TypedBufferArg<Linux::tgt_stat> tgt(addr); TypedBufferArg<Linux::tgt_stat> tgt(addr);
@ -257,10 +267,36 @@ class Linux {
tgt.copyOut(mem); tgt.copyOut(mem);
} }
#else
// Third version for bsd systems which no longer have any support for
// the old stat() call and stat() is actually a stat64()
static void
copyOutStatBuf(FunctionalMemory *mem, Addr addr, hst_stat64 *host)
{
TypedBufferArg<Linux::tgt_stat> tgt(addr);
tgt->st_dev = host->st_dev;
tgt->st_ino = host->st_ino;
tgt->st_mode = host->st_mode;
tgt->st_nlink = host->st_nlink;
tgt->st_uid = host->st_uid;
tgt->st_gid = host->st_gid;
tgt->st_rdev = host->st_rdev;
tgt->st_size = host->st_size;
tgt->st_atimeX = host->st_atime;
tgt->st_mtimeX = host->st_mtime;
tgt->st_ctimeX = host->st_ctime;
tgt->st_blksize = host->st_blksize;
tgt->st_blocks = host->st_blocks;
tgt.copyOut(mem);
}
#endif
// Same for stat64 // Same for stat64
static void static void
copyOutStat64Buf(FunctionalMemory *mem, Addr addr, struct stat64 *host) copyOutStat64Buf(FunctionalMemory *mem, Addr addr, hst_stat64 *host)
{ {
TypedBufferArg<Linux::tgt_stat64> tgt(addr); TypedBufferArg<Linux::tgt_stat64> tgt(addr);

View file

@ -28,7 +28,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#if defined(__OpenBSD__) #if defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/param.h> #include <sys/param.h>
#include <sys/mount.h> #include <sys/mount.h>
#else #else
@ -260,15 +260,15 @@ class Tru64 {
/// Resource enumeration for getrlimit(). /// Resource enumeration for getrlimit().
enum rlimit_resources { enum rlimit_resources {
RLIMIT_CPU = 0, TGT_RLIMIT_CPU = 0,
RLIMIT_FSIZE = 1, TGT_RLIMIT_FSIZE = 1,
RLIMIT_DATA = 2, TGT_RLIMIT_DATA = 2,
RLIMIT_STACK = 3, TGT_RLIMIT_STACK = 3,
RLIMIT_CORE = 4, TGT_RLIMIT_CORE = 4,
RLIMIT_RSS = 5, TGT_RLIMIT_RSS = 5,
RLIMIT_NOFILE = 6, TGT_RLIMIT_NOFILE = 6,
RLIMIT_AS = 7, TGT_RLIMIT_AS = 7,
RLIMIT_VMEM = 7 TGT_RLIMIT_VMEM = 7
}; };
/// Limit struct for getrlimit/setrlimit. /// Limit struct for getrlimit/setrlimit.
@ -320,9 +320,9 @@ class Tru64 {
//@{ //@{
/// For getrusage(). /// For getrusage().
static const int RUSAGE_THREAD = 1; static const int TGT_RUSAGE_THREAD = 1;
static const int RUSAGE_SELF = 0; static const int TGT_RUSAGE_SELF = 0;
static const int RUSAGE_CHILDREN = -1; static const int TGT_RUSAGE_CHILDREN = -1;
//@} //@}
/// For getrusage(). /// For getrusage().
@ -568,7 +568,7 @@ class Tru64 {
{ {
TypedBufferArg<T> tgt(addr); TypedBufferArg<T> tgt(addr);
#if defined(__OpenBSD__) #if defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD__)
tgt->f_type = 0; tgt->f_type = 0;
#else #else
tgt->f_type = host->f_type; tgt->f_type = host->f_type;

View file

@ -145,22 +145,6 @@ floorLog2(long long x)
return floorLog2((unsigned long long)x); return floorLog2((unsigned long long)x);
} }
#if defined(__APPLE__)
inline int
floorLog2(size_t x)
{
assert(x > 0);
assert(sizeof(size_t) == 4 || sizeof(size_t) == 8);
// It's my hope that this is optimized away?
if (sizeof(size_t) == 4)
return floorLog2((uint32_t)x);
else if (sizeof(size_t) == 8)
return floorLog2((uint64_t)x);
}
#endif
template <class T> template <class T>
inline int inline int
ceilLog2(T n) ceilLog2(T n)

View file

@ -93,9 +93,6 @@ ListenSocket::listen(int port, bool reuse)
return true; return true;
} }
#if defined(__APPLE__)
typedef int socklen_t;
#endif
// Open a connection. Accept will block, so if you don't want it to, // Open a connection. Accept will block, so if you don't want it to,
// make sure a connection is ready before you call accept. // make sure a connection is ready before you call accept.

View file

@ -32,7 +32,7 @@
// inst sequence type, used to order instructions in the ready list, // inst sequence type, used to order instructions in the ready list,
// if this rolls over the ready list order temporarily will get messed // if this rolls over the ready list order temporarily will get messed
// up, but execution will continue and complete correctly // up, but execution will continue and complete correctly
typedef unsigned long long InstSeqNum; typedef uint64_t InstSeqNum;
// inst tag type, used to tag an operation instance in the IQ // inst tag type, used to tag an operation instance in the IQ
typedef unsigned int InstTag; typedef unsigned int InstTag;

View file

@ -34,6 +34,7 @@
// but probably is more flexible to actually add in a delay parameter than // but probably is more flexible to actually add in a delay parameter than
// just running it backwards. // just running it backwards.
#include <limits>
#include <vector> #include <vector>
#include "sim/root.hh" #include "sim/root.hh"
@ -42,7 +43,7 @@
// Either compile error or max int due to sign extension. // Either compile error or max int due to sign extension.
// Hack to avoid compile warnings. // Hack to avoid compile warnings.
const InstSeqNum MaxInstSeqNum = 0 - 1; const InstSeqNum MaxInstSeqNum = std::numeric_limits<InstSeqNum>::max();
template <class Impl> template <class Impl>
InstructionQueue<Impl>::InstructionQueue(Params &params) InstructionQueue<Impl>::InstructionQueue(Params &params)

View file

@ -29,6 +29,9 @@
#ifndef __SIM_SYSCALL_EMUL_HH__ #ifndef __SIM_SYSCALL_EMUL_HH__
#define __SIM_SYSCALL_EMUL_HH__ #define __SIM_SYSCALL_EMUL_HH__
#define BSD_HOST (defined(__APPLE__) || defined(__OpenBSD__) || \
defined(__FreeBSD__))
/// ///
/// @file syscall_emul.hh /// @file syscall_emul.hh
/// ///
@ -441,8 +444,13 @@ fstat64Func(SyscallDesc *desc, int callnum, Process *process,
return -EBADF; return -EBADF;
} }
struct stat64 hostBuf; #ifdef BSD_HOST
struct stat hostBuf;
int result = fstat(process->sim_fd(fd), &hostBuf);
#else
struct stat64 hostBuf;
int result = fstat64(process->sim_fd(fd), &hostBuf); int result = fstat64(process->sim_fd(fd), &hostBuf);
#endif
if (result < 0) if (result < 0)
return errno; return errno;
@ -486,8 +494,13 @@ lstat64Func(SyscallDesc *desc, int callnum, Process *process,
if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault) if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault)
return -EFAULT; return -EFAULT;
#ifdef BSD_HOST
struct stat hostBuf;
int result = lstat(path.c_str(), &hostBuf);
#else
struct stat64 hostBuf; struct stat64 hostBuf;
int result = lstat64(path.c_str(), &hostBuf); int result = lstat64(path.c_str(), &hostBuf);
#endif
if (result < 0) if (result < 0)
return -errno; return -errno;
@ -517,7 +530,6 @@ fstatFunc(SyscallDesc *desc, int callnum, Process *process,
return -errno; return -errno;
OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf); OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
return 0; return 0;
} }
@ -653,22 +665,22 @@ mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
template <class OS> template <class OS>
SyscallReturn SyscallReturn
getrlimitFunc(SyscallDesc *desc, int callnum, Process *process, getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc) ExecContext *xc)
{ {
unsigned resource = xc->getSyscallArg(0); unsigned resource = xc->getSyscallArg(0);
TypedBufferArg<typename OS::rlimit> rlp(xc->getSyscallArg(1)); TypedBufferArg<typename OS::rlimit> rlp(xc->getSyscallArg(1));
switch (resource) { switch (resource) {
case OS::RLIMIT_STACK: case OS::TGT_RLIMIT_STACK:
// max stack size in bytes: make up a number (2MB for now) // max stack size in bytes: make up a number (2MB for now)
rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024; rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
break; break;
default: default:
std::cerr << "getrlimitFunc: unimplemented resource " << resource std::cerr << "getrlimitFunc: unimplemented resource " << resource
<< std::endl; << std::endl;
abort(); abort();
break; break;
} }
rlp.copyOut(xc->mem); rlp.copyOut(xc->mem);
@ -679,7 +691,7 @@ getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
template <class OS> template <class OS>
SyscallReturn SyscallReturn
gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process, gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc) ExecContext *xc)
{ {
TypedBufferArg<typename OS::timeval> tp(xc->getSyscallArg(0)); TypedBufferArg<typename OS::timeval> tp(xc->getSyscallArg(0));
@ -719,7 +731,6 @@ utimesFunc(SyscallDesc *desc, int callnum, Process *process,
return 0; return 0;
} }
/// Target getrusage() function. /// Target getrusage() function.
template <class OS> template <class OS>
SyscallReturn SyscallReturn
@ -729,7 +740,7 @@ getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
int who = xc->getSyscallArg(0); // THREAD, SELF, or CHILDREN int who = xc->getSyscallArg(0); // THREAD, SELF, or CHILDREN
TypedBufferArg<typename OS::rusage> rup(xc->getSyscallArg(1)); TypedBufferArg<typename OS::rusage> rup(xc->getSyscallArg(1));
if (who != OS::RUSAGE_SELF) { if (who != OS::TGT_RUSAGE_SELF) {
// don't really handle THREAD or CHILDREN, but just warn and // don't really handle THREAD or CHILDREN, but just warn and
// plow ahead // plow ahead
warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.", warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",