summaryrefslogtreecommitdiff
path: root/src/sim/syscall_emul.hh
diff options
context:
space:
mode:
authorBrandon Potter <brandon.potter@amd.com>2016-12-15 13:16:03 -0500
committerBrandon Potter <brandon.potter@amd.com>2016-12-15 13:16:03 -0500
commit68e9c0e73b1466b7e43c77a75cd38913afcfcafe (patch)
tree7be99d46777d396d8706620ee9d4c7791712eac1 /src/sim/syscall_emul.hh
parent4ff1b165d007c50c0c4700eb8ecafa1e700bc7aa (diff)
downloadgem5-68e9c0e73b1466b7e43c77a75cd38913afcfcafe.tar.xz
syscall_emul: add support for x86 statfs system calls
Diffstat (limited to 'src/sim/syscall_emul.hh')
-rw-r--r--src/sim/syscall_emul.hh32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 53da9197b..bf7ec1ae7 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -62,6 +62,7 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <unistd.h>
@@ -451,6 +452,7 @@ getElapsedTimeNano(T1 &sec, T2 &nsec)
//
//////////////////////////////////////////////////////////////////////
+ typedef struct statfs hst_statfs;
#if NO_STAT64
typedef struct stat hst_stat;
typedef struct stat hst_stat64;
@@ -556,6 +558,32 @@ copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
tgt.copyOut(mem);
}
+template <class OS>
+static void
+copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr,
+ hst_statfs *host)
+{
+ TypedBufferArg<typename OS::tgt_statfs> tgt(addr);
+
+#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD__)
+ tgt->f_type = 0;
+#else
+ tgt->f_type = TheISA::htog(host->f_type);
+#endif
+ tgt->f_bsize = TheISA::htog(host->f_bsize);
+ tgt->f_blocks = TheISA::htog(host->f_blocks);
+ tgt->f_bfree = TheISA::htog(host->f_bfree);
+ tgt->f_bavail = TheISA::htog(host->f_bavail);
+ tgt->f_files = TheISA::htog(host->f_files);
+ tgt->f_ffree = TheISA::htog(host->f_ffree);
+ memcpy(&tgt->f_fsid, &host->f_fsid, sizeof(host->f_fsid));
+ tgt->f_namelen = TheISA::htog(host->f_namelen);
+ tgt->f_frsize = TheISA::htog(host->f_frsize);
+ memcpy(&tgt->f_spare, &host->f_spare, sizeof(host->f_spare));
+
+ tgt.copyOut(mem);
+}
+
/// Target ioctl() handler. For the most part, programs call ioctl()
/// only to find out if their stdout is a tty, to determine whether to
/// do line or block buffering. We always claim that output fds are
@@ -1156,7 +1184,7 @@ statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
- OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
+ copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
return 0;
}
@@ -1182,7 +1210,7 @@ fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
- OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
+ copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
return 0;
}