sim-se: Rewrite some syscalls to use a syscallImpl function
The following at suffixed syscalls are implemented on top of their CWD version * readlinkat -> readlink * unlinkat -> unlink * renameat -> rename * faccessat -> access With this patch we are decoupling interface from implementation, moving the latter into a separate syscallImpl function which will by called by both syscall flavours This is a required step towards properly implementing AT based syscalls JIRA: https://gem5.atlassian.net/browse/GEM5-1098 Change-Id: I022e9876a2a0b9ddf2d70d10cd4e6851ba7ff094 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51047 Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Gabe Black <gabe.black@gmail.com> Reviewed-by: Richard Cooper <richard.cooper@arm.com>
This commit is contained in:
@@ -403,11 +403,18 @@ readlinkFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> pathname, VPtr<> buf_ptr, size_t bufsiz)
|
||||
{
|
||||
std::string path;
|
||||
auto p = tc->getProcessPtr();
|
||||
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
return readlinkImpl(desc, tc, path, buf_ptr, bufsiz);
|
||||
}
|
||||
|
||||
SyscallReturn
|
||||
readlinkImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string path, VPtr<> buf_ptr, size_t bufsiz)
|
||||
{
|
||||
auto p = tc->getProcessPtr();
|
||||
|
||||
// Adjust path for cwd and redirection
|
||||
path = p->checkPathRedirect(path);
|
||||
|
||||
@@ -460,11 +467,16 @@ SyscallReturn
|
||||
unlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname)
|
||||
{
|
||||
std::string path;
|
||||
auto p = tc->getProcessPtr();
|
||||
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
return unlinkImpl(desc, tc, path);
|
||||
}
|
||||
|
||||
SyscallReturn
|
||||
unlinkImpl(SyscallDesc *desc, ThreadContext *tc, std::string path)
|
||||
{
|
||||
auto p = tc->getProcessPtr();
|
||||
path = p->checkPathRedirect(path);
|
||||
|
||||
int result = unlink(path.c_str());
|
||||
@@ -531,8 +543,6 @@ SyscallReturn
|
||||
renameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> oldpath,
|
||||
VPtr<> newpath)
|
||||
{
|
||||
auto p = tc->getProcessPtr();
|
||||
|
||||
SETranslatingPortProxy proxy(tc);
|
||||
std::string old_name;
|
||||
if (!proxy.tryReadString(old_name, oldpath))
|
||||
@@ -542,6 +552,15 @@ renameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> oldpath,
|
||||
if (!proxy.tryReadString(new_name, newpath))
|
||||
return -EFAULT;
|
||||
|
||||
return renameImpl(desc, tc, old_name, new_name);
|
||||
}
|
||||
|
||||
SyscallReturn
|
||||
renameImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string old_name, std::string new_name)
|
||||
{
|
||||
auto p = tc->getProcessPtr();
|
||||
|
||||
// Adjust path for cwd and redirection
|
||||
old_name = p->checkPathRedirect(old_name);
|
||||
new_name = p->checkPathRedirect(new_name);
|
||||
@@ -550,6 +569,7 @@ renameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> oldpath,
|
||||
return (result == -1) ? -errno : result;
|
||||
}
|
||||
|
||||
|
||||
SyscallReturn
|
||||
truncateFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname,
|
||||
off_t length)
|
||||
@@ -1011,10 +1031,17 @@ accessFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> pathname, mode_t mode)
|
||||
{
|
||||
std::string path;
|
||||
auto p = tc->getProcessPtr();
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
return accessImpl(desc, tc, path, mode);
|
||||
}
|
||||
|
||||
SyscallReturn
|
||||
accessImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string path, mode_t mode)
|
||||
{
|
||||
auto p = tc->getProcessPtr();
|
||||
// Adjust path for cwd and redirection
|
||||
path = p->checkPathRedirect(path);
|
||||
|
||||
|
||||
@@ -191,10 +191,14 @@ SyscallReturn getcwdFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
/// Target readlink() handler.
|
||||
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> pathname, VPtr<> buf, size_t bufsiz);
|
||||
SyscallReturn readlinkImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string path, VPtr<> buf, size_t bufsiz);
|
||||
|
||||
/// Target unlink() handler.
|
||||
SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> pathname);
|
||||
SyscallReturn unlinkImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string path);
|
||||
|
||||
/// Target link() handler
|
||||
SyscallReturn linkFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
@@ -221,6 +225,8 @@ SyscallReturn rmdirFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname);
|
||||
/// Target rename() handler.
|
||||
SyscallReturn renameFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> oldpath, VPtr<> newpath);
|
||||
SyscallReturn renameImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string oldpath, std::string newpath);
|
||||
|
||||
|
||||
/// Target truncate() handler.
|
||||
@@ -353,6 +359,8 @@ SyscallReturn getegidFunc(SyscallDesc *desc, ThreadContext *tc);
|
||||
/// Target access() handler
|
||||
SyscallReturn accessFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
VPtr<> pathname, mode_t mode);
|
||||
SyscallReturn accessImpl(SyscallDesc *desc, ThreadContext *tc,
|
||||
std::string path, mode_t mode);
|
||||
|
||||
// Target getsockopt() handler.
|
||||
SyscallReturn getsockoptFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
@@ -916,10 +924,14 @@ template <class OS>
|
||||
SyscallReturn
|
||||
unlinkatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, VPtr<> pathname)
|
||||
{
|
||||
std::string path;
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
if (dirfd != OS::TGT_AT_FDCWD)
|
||||
warn("unlinkat: first argument not AT_FDCWD; unlikely to work");
|
||||
|
||||
return unlinkFunc(desc, tc, pathname);
|
||||
return unlinkImpl(desc, tc, path);
|
||||
}
|
||||
|
||||
/// Target facessat() handler
|
||||
@@ -928,9 +940,14 @@ SyscallReturn
|
||||
faccessatFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
int dirfd, VPtr<> pathname, int mode)
|
||||
{
|
||||
std::string path;
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
if (dirfd != OS::TGT_AT_FDCWD)
|
||||
warn("faccessat: first argument not AT_FDCWD; unlikely to work");
|
||||
return accessFunc(desc, tc, pathname, mode);
|
||||
|
||||
return accessImpl(desc, tc, path, mode);
|
||||
}
|
||||
|
||||
/// Target readlinkat() handler
|
||||
@@ -939,9 +956,14 @@ SyscallReturn
|
||||
readlinkatFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
int dirfd, VPtr<> pathname, VPtr<> buf, size_t bufsiz)
|
||||
{
|
||||
std::string path;
|
||||
if (!SETranslatingPortProxy(tc).tryReadString(path, pathname))
|
||||
return -EFAULT;
|
||||
|
||||
if (dirfd != OS::TGT_AT_FDCWD)
|
||||
warn("openat: first argument not AT_FDCWD; unlikely to work");
|
||||
return readlinkFunc(desc, tc, pathname, buf, bufsiz);
|
||||
|
||||
return readlinkImpl(desc, tc, path, buf, bufsiz);
|
||||
}
|
||||
|
||||
/// Target renameat() handler.
|
||||
@@ -950,13 +972,22 @@ SyscallReturn
|
||||
renameatFunc(SyscallDesc *desc, ThreadContext *tc,
|
||||
int olddirfd, VPtr<> oldpath, int newdirfd, VPtr<> newpath)
|
||||
{
|
||||
SETranslatingPortProxy proxy(tc);
|
||||
std::string old_name;
|
||||
if (!proxy.tryReadString(old_name, oldpath))
|
||||
return -EFAULT;
|
||||
|
||||
std::string new_name;
|
||||
if (!proxy.tryReadString(new_name, newpath))
|
||||
return -EFAULT;
|
||||
|
||||
if (olddirfd != OS::TGT_AT_FDCWD)
|
||||
warn("renameat: first argument not AT_FDCWD; unlikely to work");
|
||||
|
||||
if (newdirfd != OS::TGT_AT_FDCWD)
|
||||
warn("renameat: third argument not AT_FDCWD; unlikely to work");
|
||||
|
||||
return renameFunc(desc, tc, oldpath, newpath);
|
||||
return renameImpl(desc, tc, old_name, new_name);
|
||||
}
|
||||
|
||||
/// Target sysinfo() handler.
|
||||
|
||||
Reference in New Issue
Block a user