syscall_emul: adding symlink system call
authorMatt Sinclair <mattdsinclair@gmail.com>
Thu, 21 Jun 2018 23:31:09 +0000 (19:31 -0400)
committerMatt Sinclair <mattdsinclair@gmail.com>
Mon, 25 Jun 2018 20:42:30 +0000 (20:42 +0000)
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>

src/arch/x86/linux/process.cc
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index 5717218f9f9abf7b90cc79f06937c1525abc9fb3..51512fdda83b2067fff8523793ddd0144d91493f 100644 (file)
@@ -308,7 +308,7 @@ static SyscallDesc syscallDescs64[] = {
     /*  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),
index c56963acf4dc8085215306ee4b6f0babc4c976f4..dd2323eaaed379096d3ffd683dd2bd84aaf05a96 100644 (file)
@@ -539,6 +539,26 @@ linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
     return (result == -1) ? -errno : result;
 }
 
+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)
 {
index e3d99cea99846b42b0223414bb3b7a7fe9bd3f80..1f4233aa889d9bb9d6ac12b39271f4f6b450fd46 100644 (file)
@@ -207,6 +207,10 @@ SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
 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);