misc: Using OS::off_t in syscall signature

Change-Id: Iefa1e207a3e825959b0fe8df30e6be182d73a0f8
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51490
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Giacomo Travaglini
2021-10-12 18:49:59 +01:00
parent 37495f8823
commit 851e543b2f
8 changed files with 82 additions and 89 deletions

View File

@@ -223,8 +223,8 @@ class SyscallTable32 : public SyscallDescTable<EmuLinux::SyscallABI32>
{ base + 89, "readdir" },
{ base + 90, "mmap", mmapFunc<ArmLinux32> },
{ base + 91, "munmap", munmapFunc<ArmLinux32> },
{ base + 92, "truncate", truncateFunc },
{ base + 93, "ftruncate", ftruncateFunc },
{ base + 92, "truncate", truncateFunc<ArmLinux32> },
{ base + 93, "ftruncate", ftruncateFunc<ArmLinux32> },
{ base + 94, "fchmod" },
{ base + 95, "fchown", fchownFunc },
{ base + 96, "getpriority" },
@@ -545,7 +545,7 @@ class SyscallTable64 : public SyscallDescTable<EmuLinux::SyscallABI64>
{ base + 44, "fstatfs64" },
{ base + 45, "truncate64" },
{ base + 46, "ftruncate64", ftruncate64Func },
{ base + 47, "fallocate", fallocateFunc },
{ base + 47, "fallocate", fallocateFunc<ArmLinux64> },
{ base + 48, "faccessat", faccessatFunc<ArmLinux64> },
{ base + 49, "chdir" },
{ base + 50, "fchdir" },
@@ -781,8 +781,8 @@ class SyscallTable64 : public SyscallDescTable<EmuLinux::SyscallABI64>
{ base + 1044, "eventfd" },
{ base + 1045, "signalfd" },
{ base + 1046, "sendfile" },
{ base + 1047, "ftruncate", ftruncateFunc },
{ base + 1048, "truncate", truncateFunc },
{ base + 1047, "ftruncate", ftruncateFunc<ArmLinux64> },
{ base + 1048, "truncate", truncateFunc<ArmLinux64> },
{ base + 1049, "stat", statFunc<ArmLinux64> },
{ base + 1050, "lstat" },
{ base + 1051, "fstat", fstatFunc<ArmLinux64> },

View File

@@ -250,8 +250,8 @@ SyscallDescTable<MipsISA::SEWorkload::SyscallABI> EmuLinux::syscallDescs = {
{ 4089, "readdir" },
{ 4090, "mmap", mmapFunc<MipsLinux> },
{ 4091, "munmap",munmapFunc<MipsLinux> },
{ 4092, "truncate", truncateFunc },
{ 4093, "ftruncate", ftruncateFunc },
{ 4092, "truncate", truncateFunc<MipsLinux> },
{ 4093, "ftruncate", ftruncateFunc<MipsLinux> },
{ 4094, "fchmod", fchmodFunc<MipsLinux> },
{ 4095, "fchown", fchownFunc },
{ 4096, "getpriority" },

View File

@@ -199,8 +199,8 @@ SyscallDescTable<PowerISA::SEWorkload::SyscallABI> EmuLinux::syscallDescs = {
{ 89, "readdir" },
{ 90, "mmap", mmapFunc<PowerLinux> },
{ 91, "munmap",munmapFunc<PowerLinux> },
{ 92, "truncate", truncateFunc },
{ 93, "ftruncate", ftruncateFunc },
{ 92, "truncate", truncateFunc<PowerLinux> },
{ 93, "ftruncate", ftruncateFunc<PowerLinux> },
{ 94, "fchmod" },
{ 95, "fchown" },
{ 96, "getpriority" },

View File

@@ -169,9 +169,9 @@ SyscallDescTable<SEWorkload::SyscallABI> EmuLinux::syscallDescs64 = {
{ 42, "nfsservctl" },
{ 43, "statfs", statfsFunc<RiscvLinux64> },
{ 44, "fstatfs", fstatfsFunc<RiscvLinux64> },
{ 45, "truncate", truncateFunc },
{ 45, "truncate", truncateFunc<RiscvLinux64> },
{ 46, "ftruncate", ftruncate64Func },
{ 47, "fallocate", fallocateFunc },
{ 47, "fallocate", fallocateFunc<RiscvLinux64> },
{ 48, "faccessat", faccessatFunc<RiscvLinux64> },
{ 49, "chdir" },
{ 50, "fchdir" },
@@ -500,9 +500,9 @@ SyscallDescTable<SEWorkload::SyscallABI> EmuLinux::syscallDescs32 = {
{ 42, "nfsservctl" },
{ 43, "statfs", statfsFunc<RiscvLinux32> },
{ 44, "fstatfs", fstatfsFunc<RiscvLinux32> },
{ 45, "truncate", truncateFunc },
{ 46, "ftruncate", ftruncateFunc },
{ 47, "fallocate", fallocateFunc },
{ 45, "truncate", truncateFunc<RiscvLinux32> },
{ 46, "ftruncate", ftruncateFunc<RiscvLinux32> },
{ 47, "fallocate", fallocateFunc<RiscvLinux32> },
{ 48, "faccessat", faccessatFunc<RiscvLinux32> },
{ 49, "chdir" },
{ 50, "fchdir" },
@@ -749,8 +749,8 @@ SyscallDescTable<SEWorkload::SyscallABI> EmuLinux::syscallDescs32 = {
{ 1044, "eventfd" },
{ 1045, "signalfd" },
{ 1046, "sendfile" },
{ 1047, "ftruncate", ftruncateFunc },
{ 1048, "truncate", truncateFunc },
{ 1047, "ftruncate", ftruncateFunc<RiscvLinux32> },
{ 1048, "truncate", truncateFunc<RiscvLinux32> },
{ 1049, "stat", statFunc<RiscvLinux32> },
{ 1050, "lstat", lstatFunc<RiscvLinux32> },
{ 1051, "fstat", fstatFunc<RiscvLinux32> },

View File

@@ -131,8 +131,8 @@ SyscallDescTable<EmuLinux::SyscallABI32> EmuLinux::syscallDescs32 = {
{ 89, "readdir" },
{ 90, "mmap" },
{ 91, "munmap", munmapFunc<X86Linux32> },
{ 92, "truncate", truncateFunc },
{ 93, "ftruncate", ftruncateFunc },
{ 92, "truncate", truncateFunc<X86Linux32> },
{ 93, "ftruncate", ftruncateFunc<X86Linux32> },
{ 94, "fchmod" },
{ 95, "fchown" },
{ 96, "getpriority" },

View File

@@ -115,8 +115,8 @@ SyscallDescTable<EmuLinux::SyscallABI64> EmuLinux::syscallDescs64 = {
{ 73, "flock" },
{ 74, "fsync" },
{ 75, "fdatasync", ignoreFunc },
{ 76, "truncate", truncateFunc },
{ 77, "ftruncate", ftruncateFunc },
{ 76, "truncate", truncateFunc<X86Linux64> },
{ 77, "ftruncate", ftruncateFunc<X86Linux64> },
#if defined(SYS_getdents)
{ 78, "getdents", getdentsFunc },
#else
@@ -332,7 +332,7 @@ SyscallDescTable<EmuLinux::SyscallABI64> EmuLinux::syscallDescs64 = {
{ 282, "signalfd" },
{ 283, "timerfd_create" },
{ 284, "eventfd", eventfdFunc<X86Linux64> },
{ 285, "fallocate", fallocateFunc },
{ 285, "fallocate", fallocateFunc<X86Linux64> },
{ 286, "timerfd_settime" },
{ 287, "timerfd_gettime" },
{ 288, "accept4" },

View File

@@ -485,37 +485,6 @@ renameImpl(SyscallDesc *desc, ThreadContext *tc,
}
SyscallReturn
truncateFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname,
off_t length)
{
std::string path;
auto p = tc->getProcessPtr();
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
return -EFAULT;
// Adjust path for cwd and redirection
path = p->checkPathRedirect(path);
int result = truncate(path.c_str(), length);
return (result == -1) ? -errno : result;
}
SyscallReturn
ftruncateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, off_t length)
{
auto p = tc->getProcessPtr();
auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
if (!ffdp)
return -EBADF;
int sim_fd = ffdp->getSimFD();
int result = ftruncate(sim_fd, length);
return (result == -1) ? -errno : result;
}
SyscallReturn
truncate64Func(SyscallDesc *desc, ThreadContext *tc,
VPtr<> pathname, int64_t length)
@@ -926,28 +895,6 @@ getegidFunc(SyscallDesc *desc, ThreadContext *tc)
return process->egid();
}
SyscallReturn
fallocateFunc(SyscallDesc *desc, ThreadContext *tc,
int tgt_fd, int mode, off_t offset, off_t len)
{
#if defined(__linux__)
auto p = tc->getProcessPtr();
auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
if (!ffdp)
return -EBADF;
int sim_fd = ffdp->getSimFD();
int result = fallocate(sim_fd, mode, offset, len);
if (result < 0)
return -errno;
return 0;
#else
warnUnsupportedOS("fallocate");
return -1;
#endif
}
SyscallReturn
accessFunc(SyscallDesc *desc, ThreadContext *tc,
VPtr<> pathname, mode_t mode)

View File

@@ -140,10 +140,6 @@ SyscallReturn ignoreFunc(SyscallDesc *desc, ThreadContext *tc);
SyscallReturn
ignoreWarnOnceFunc(SyscallDesc *desc, ThreadContext *tc);
// Target fallocateFunc() handler.
SyscallReturn fallocateFunc(SyscallDesc *desc, ThreadContext *tc,
int tgt_fd, int mode, off_t offset, off_t len);
/// Target exit() handler: terminate current context.
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status);
@@ -218,17 +214,6 @@ SyscallReturn renameFunc(SyscallDesc *desc, ThreadContext *tc,
SyscallReturn renameImpl(SyscallDesc *desc, ThreadContext *tc,
std::string oldpath, std::string newpath);
/// Target truncate() handler.
SyscallReturn truncateFunc(SyscallDesc *desc, ThreadContext *tc,
VPtr<> pathname, off_t length);
/// Target ftruncate() handler.
SyscallReturn ftruncateFunc(SyscallDesc *desc, ThreadContext *tc,
int tgt_fd, off_t length);
/// Target truncate64() handler.
SyscallReturn truncate64Func(SyscallDesc *desc, ThreadContext *tc,
VPtr<> pathname, int64_t length);
@@ -2877,6 +2862,67 @@ munmapFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> start,
return 0;
}
// Target fallocate() handler.
template <typename OS>
SyscallReturn
fallocateFunc(SyscallDesc *desc, ThreadContext *tc,
int tgt_fd, int mode, typename OS::off_t offset,
typename OS::off_t len)
{
#if defined(__linux__)
auto p = tc->getProcessPtr();
auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
if (!ffdp)
return -EBADF;
int sim_fd = ffdp->getSimFD();
int result = fallocate(sim_fd, mode, offset, len);
if (result < 0)
return -errno;
return 0;
#else
warnUnsupportedOS("fallocate");
return -1;
#endif
}
/// Target truncate() handler.
template <typename OS>
SyscallReturn
truncateFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname,
typename OS::off_t length)
{
std::string path;
auto p = tc->getProcessPtr();
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
return -EFAULT;
// Adjust path for cwd and redirection
path = p->checkPathRedirect(path);
int result = truncate(path.c_str(), length);
return (result == -1) ? -errno : result;
}
/// Target ftruncate() handler.
template <typename OS>
SyscallReturn
ftruncateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd,
typename OS::off_t length)
{
auto p = tc->getProcessPtr();
auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
if (!ffdp)
return -EBADF;
int sim_fd = ffdp->getSimFD();
int result = ftruncate(sim_fd, length);
return (result == -1) ? -errno : result;
}
} // namespace gem5
#endif // __SIM_SYSCALL_EMUL_HH__