Luming Wang has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/57809 )

Change subject: sim-se: add getrandom() syscall support
......................................................................

sim-se: add getrandom() syscall support

getrandom() was introduced in version 3.17 of the Linux kernel.
This commit implements getrandom() for Gem5 SE mode.

Change-Id: I86bfeee52048184dbf72330284933b70daab5850
---
M src/arch/arm/linux/se_workload.cc
M src/arch/riscv/linux/se_workload.cc
M src/arch/x86/linux/syscall_tbl32.cc
M src/arch/x86/linux/syscall_tbl64.cc
M src/sim/syscall_emul.hh
5 files changed, 37 insertions(+), 3 deletions(-)



diff --git a/src/arch/arm/linux/se_workload.cc b/src/arch/arm/linux/se_workload.cc
index b511e02..f0c85ae 100644
--- a/src/arch/arm/linux/se_workload.cc
+++ b/src/arch/arm/linux/se_workload.cc
@@ -488,6 +488,7 @@
         { base + 363, "sys_rt_tgsigqueueinfo" },
         { base + 364, "sys_perf_event_open" },
         { base + 365, "sys_recvmmsg" },
+        { base + 384, "getrandom", getrandomFunc<ArmLinux32> }
     })
     {}
 };
@@ -758,6 +759,7 @@
         {  base + 269, "sendmmsg" },
         {  base + 270, "process_vm_readv" },
         {  base + 271, "process_vm_writev" },
+        {  base + 278, "getrandom", getrandomFunc<ArmLinux64> },
         { base + 1024, "open", openFunc<ArmLinux64> },
         { base + 1025, "link" },
         { base + 1026, "unlink", unlinkFunc },
diff --git a/src/arch/riscv/linux/se_workload.cc b/src/arch/riscv/linux/se_workload.cc
index b321ffc..f8053d4 100644
--- a/src/arch/riscv/linux/se_workload.cc
+++ b/src/arch/riscv/linux/se_workload.cc
@@ -385,7 +385,7 @@
     { 275,  "sched_getattr" },
     { 276,  "renameat2" },
     { 277,  "seccomp" },
-    { 278,  "getrandom" },
+    { 278,  "getrandom", getrandomFunc<RiscvLinux64> },
     { 279,  "memfd_create" },
     { 280,  "bpf" },
     { 281,  "execveat" },
@@ -716,7 +716,7 @@
     { 275,  "sched_getattr" },
     { 276,  "renameat2" },
     { 277,  "seccomp" },
-    { 278,  "getrandom" },
+    { 278,  "getrandom", getrandomFunc<RiscvLinux32> },
     { 279,  "memfd_create" },
     { 280,  "bpf" },
     { 281,  "execveat" },
diff --git a/src/arch/x86/linux/syscall_tbl32.cc b/src/arch/x86/linux/syscall_tbl32.cc
index 7f8e905..2de334c 100644
--- a/src/arch/x86/linux/syscall_tbl32.cc
+++ b/src/arch/x86/linux/syscall_tbl32.cc
@@ -370,7 +370,8 @@
     { 320, "utimensat" },
     { 321, "signalfd" },
     { 322, "timerfd" },
-    { 323, "eventfd", eventfdFunc<X86Linux32> }
+    { 323, "eventfd", eventfdFunc<X86Linux32> },
+    { 355, "getrandom", getrandomFunc<X86Linux32>}
 };

 } // namespace X86ISA
diff --git a/src/arch/x86/linux/syscall_tbl64.cc b/src/arch/x86/linux/syscall_tbl64.cc
index 27ee8ec..6b6fa2a 100644
--- a/src/arch/x86/linux/syscall_tbl64.cc
+++ b/src/arch/x86/linux/syscall_tbl64.cc
@@ -361,6 +361,7 @@
     { 311, "proess_vm_writev" },
     { 312, "kcmp" },
     { 313, "finit_module" },
+    { 318, "getrandom", getrandomFunc<X86Linux64> }
 };

 } // namespace X86ISA
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 3fe1cf0..59a97d9 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -90,6 +90,7 @@
 #include "base/intmath.hh"
 #include "base/loader/object_file.hh"
 #include "base/logging.hh"
+#include "base/random.hh"
 #include "base/trace.hh"
 #include "base/types.hh"
 #include "config/the_isa.hh"
@@ -3040,6 +3041,23 @@
     return (result == -1) ? -errno : result;
 }

+template <typename OS>
+SyscallReturn
+getrandomFunc(SyscallDesc *desc, ThreadContext *tc,
+              VPtr<> buf_ptr, typename OS::size_t count,
+              unsigned int flags)
+{
+    SETranslatingPortProxy proxy(tc);
+
+    TypedBufferArg<uint8_t> buf(buf_ptr, count);
+    for (int i = 0; i < count; ++i) {
+        buf[i] = gem5::random_mt.random<uint8_t>();
+    }
+    buf.copyOut(proxy);
+
+    return count;
+}
+
 } // namespace gem5

 #endif // __SIM_SYSCALL_EMUL_HH__

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

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I86bfeee52048184dbf72330284933b70daab5850
Gerrit-Change-Number: 57809
Gerrit-PatchSet: 1
Gerrit-Owner: Luming Wang <wlm199...@126.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to