Matt Sinclair has uploaded this change for review. ( https://gem5-review.googlesource.com/11489

Change subject: syscall_emul: adding link system call
......................................................................

syscall_emul: adding link system call

Change-Id: If8922c2233bbe1f6fce35f64d1a44b91d2cfeed2
---
M src/arch/x86/linux/process.cc
M src/sim/syscall_emul.cc
M src/sim/syscall_emul.hh
3 files changed, 25 insertions(+), 1 deletion(-)



diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc
index 7993b80..ca42350 100644
--- a/src/arch/x86/linux/process.cc
+++ b/src/arch/x86/linux/process.cc
@@ -558,7 +558,7 @@
     /*   6 */ SyscallDesc("close", closeFunc),
     /*   7 */ SyscallDesc("waitpid", unimplementedFunc),
     /*   8 */ SyscallDesc("creat", unimplementedFunc),
-    /*   9 */ SyscallDesc("link", unimplementedFunc),
+    /*   9 */ SyscallDesc("link", linkFunc),
     /*  10 */ SyscallDesc("unlink", unimplementedFunc),
     /*  11 */ SyscallDesc("execve", execveFunc<X86Linux32>),
     /*  12 */ SyscallDesc("chdir", unimplementedFunc),
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index 7f4d766..e8c1f18 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -519,6 +519,27 @@
     return (result == -1) ? -errno : result;
 }

+SyscallReturn
+linkFunc(SyscallDesc *desc, int num, ThreadContext *tc)
+{
+    string path;
+    string new_path;
+
+    int index = 0;
+    auto p = tc->getProcessPtr();
+    auto mem_state = p->getMemState();
+    auto &virt_mem = mem_state->getVirtMem();
+    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->checkPathRedirect(path);
+    new_path = p->checkPathRedirect(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)
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index e5b0f45..8a7591d 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -203,6 +203,9 @@
 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
                          Process *p, ThreadContext *tc);

+/// Target link() handler
+SyscallReturn linkFunc(SyscallDesc *desc, int num, ThreadContext *tc);
+
 /// Target mkdir() handler.
 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
                         Process *p, ThreadContext *tc);

--
To view, visit https://gem5-review.googlesource.com/11489
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: If8922c2233bbe1f6fce35f64d1a44b91d2cfeed2
Gerrit-Change-Number: 11489
Gerrit-PatchSet: 1
Gerrit-Owner: Matt Sinclair <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to