syscall_emul: adding link system call
authorMatt Sinclair <mattdsinclair@gmail.com>
Thu, 21 Jun 2018 18:17:17 +0000 (14:17 -0400)
committerMatt Sinclair <mattdsinclair@gmail.com>
Mon, 25 Jun 2018 18:36:29 +0000 (18:36 +0000)
Change-Id: If8922c2233bbe1f6fce35f64d1a44b91d2cfeed2
Reviewed-on: https://gem5-review.googlesource.com/11489
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Brandon Potter <Brandon.Potter@amd.com>

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

index 7993b80f5c333f1f6867feadfe7aa740e2a754ec..5717218f9f9abf7b90cc79f06937c1525abc9fb3 100644 (file)
@@ -306,7 +306,7 @@ static SyscallDesc syscallDescs64[] = {
     /*  83 */ SyscallDesc("mkdir", unimplementedFunc),
     /*  84 */ SyscallDesc("rmdir", unimplementedFunc),
     /*  85 */ SyscallDesc("creat", unimplementedFunc),
-    /*  86 */ SyscallDesc("link", unimplementedFunc),
+    /*  86 */ SyscallDesc("link", linkFunc),
     /*  87 */ SyscallDesc("unlink", unlinkFunc),
     /*  88 */ SyscallDesc("symlink", unimplementedFunc),
     /*  89 */ SyscallDesc("readlink", readlinkFunc),
index 7f4d766306fe7ca936e3b7cfe644f12d53036563..c56963acf4dc8085215306ee4b6f0babc4c976f4 100644 (file)
@@ -519,6 +519,25 @@ unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc,
     return (result == -1) ? -errno : result;
 }
 
+SyscallReturn
+linkFunc(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 = link(path.c_str(), new_path.c_str());
+    return (result == -1) ? -errno : result;
+}
 
 SyscallReturn
 mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
index e5b0f455a43609b960c9912464c3ce4a6e7afe9c..e3d99cea99846b42b0223414bb3b7a7fe9bd3f80 100644 (file)
@@ -203,6 +203,10 @@ SyscallReturn unlinkHelper(SyscallDesc *desc, int num,
 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
                          Process *p, ThreadContext *tc);
 
+/// Target link() handler
+SyscallReturn linkFunc(SyscallDesc *desc, int num, Process *p,
+                       ThreadContext *tc);
+
 /// Target mkdir() handler.
 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
                         Process *p, ThreadContext *tc);