syscall_emul: adding symlink system call
Change-Id: Iebda05c130b4d2ee8434cad1e703933bfda486c8
Reviewed-on: https://gem5-review.googlesource.com/11490
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc
index 5717218..51512fd 100644
--- a/src/arch/x86/linux/process.cc
+++ b/src/arch/x86/linux/process.cc
@@ -308,7 +308,7 @@
/* 85 */ SyscallDesc("creat", unimplementedFunc),
/* 86 */ SyscallDesc("link", linkFunc),
/* 87 */ SyscallDesc("unlink", unlinkFunc),
- /* 88 */ SyscallDesc("symlink", unimplementedFunc),
+ /* 88 */ SyscallDesc("symlink", symlinkFunc),
/* 89 */ SyscallDesc("readlink", readlinkFunc),
/* 90 */ SyscallDesc("chmod", unimplementedFunc),
/* 91 */ SyscallDesc("fchmod", unimplementedFunc),
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index c56963a..dd2323e 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -540,6 +540,26 @@
}
SyscallReturn
+symlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
+{
+ string path;
+ string new_path;
+
+ int index = 0;
+ auto &virt_mem = tc->getMemProxy();
+ if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
+ if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
+
+ path = p->fullPath(path);
+ new_path = p->fullPath(new_path);
+
+ int result = symlink(path.c_str(), new_path.c_str());
+ return (result == -1) ? -errno : result;
+}
+
+SyscallReturn
mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
{
string path;
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index e3d99ce..1f4233a 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -207,6 +207,10 @@
SyscallReturn linkFunc(SyscallDesc *desc, int num, Process *p,
ThreadContext *tc);
+/// Target symlink() handler.
+SyscallReturn symlinkFunc(SyscallDesc *desc, int num, Process *p,
+ ThreadContext *tc);
+
/// Target mkdir() handler.
SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
Process *p, ThreadContext *tc);