From ca867678a6d63f454fcf5d4c751b44a0224b3c76 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 27 Nov 2019 23:03:14 -0800 Subject: [PATCH] arch,sim: Convert clone to GuestABI and define a cloneBackwardsFunc. cloneBackwardsFunc takes its arguments in the order specified for ARM and RISCV. Because of the new GuestABI mechanism, it can be a simple wrapper around the normal clone implementation without the need for #ifdefs. Jira Issue: https://gem5.atlassian.net/browse/GEM5-187 Change-Id: Iff1ffd6774b9162185a124585e9507a5bdbc46f4 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23198 Reviewed-by: Bobby R. Bruce Maintainer: Gabe Black Tested-by: kokoro --- src/arch/arm/linux/process.cc | 4 ++-- src/arch/riscv/linux/process.cc | 4 ++-- src/sim/syscall_emul.hh | 32 +++++++++++++------------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc index e3f548160..1f9feaeeb 100644 --- a/src/arch/arm/linux/process.cc +++ b/src/arch/arm/linux/process.cc @@ -280,7 +280,7 @@ static SyscallDescABI syscallDescs32[] = { /* 117 */ { "ipc" }, /* 118 */ { "fsync" }, /* 119 */ { "sigreturn" }, - /* 120 */ { "clone", cloneFunc }, + /* 120 */ { "clone", cloneBackwardsFunc }, /* 121 */ { "setdomainname" }, /* 122 */ { "uname", unameFunc32 }, /* 123 */ { "unused#123" }, @@ -761,7 +761,7 @@ static SyscallDescABI syscallDescs64[] = { /* 217 */ { "add_key" }, /* 218 */ { "request_key" }, /* 219 */ { "keyctl" }, - /* 220 */ { "clone", cloneFunc }, + /* 220 */ { "clone", cloneBackwardsFunc }, /* 221 */ { "execve", execveFunc }, /* 222 */ { "mmap2", mmapFunc }, /* 223 */ { "fadvise64_64" }, diff --git a/src/arch/riscv/linux/process.cc b/src/arch/riscv/linux/process.cc index 3afbd131b..acf698912 100644 --- a/src/arch/riscv/linux/process.cc +++ b/src/arch/riscv/linux/process.cc @@ -339,7 +339,7 @@ std::map> {217, { "add_key" }}, {218, { "request_key" }}, {219, { "keyctl" }}, - {220, { "clone", cloneFunc }}, + {220, { "clone", cloneBackwardsFunc }}, {221, { "execve", execveFunc }}, {222, { "mmap", mmapFunc }}, {223, { "fadvise64" }}, @@ -671,7 +671,7 @@ std::map> {217, { "add_key" }}, {218, { "request_key" }}, {219, { "keyctl" }}, - {220, { "clone", cloneFunc }}, + {220, { "clone", cloneBackwardsFunc }}, {221, { "execve", execveFunc }}, {222, { "mmap", mmapFunc }}, {223, { "fadvise64" }}, diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 5a4811fb2..44bb14751 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1446,27 +1446,11 @@ statfsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, template SyscallReturn -cloneFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) +cloneFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, + RegVal flags, RegVal newStack, Addr ptidPtr, + Addr ctidPtr, Addr tlsPtr) { - int index = 0; - auto p = tc->getProcessPtr(); - RegVal flags = p->getSyscallArg(tc, index); - RegVal newStack = p->getSyscallArg(tc, index); - Addr ptidPtr = p->getSyscallArg(tc, index); - -#if THE_ISA == RISCV_ISA or THE_ISA == ARM_ISA - /** - * Linux sets CLONE_BACKWARDS flag for RISC-V and Arm. - * The flag defines the list of clone() arguments in the following - * order: flags -> newStack -> ptidPtr -> tlsPtr -> ctidPtr - */ - Addr tlsPtr = p->getSyscallArg(tc, index); - Addr ctidPtr = p->getSyscallArg(tc, index); -#else - Addr ctidPtr = p->getSyscallArg(tc, index); - Addr tlsPtr = p->getSyscallArg(tc, index); -#endif if (((flags & OS::TGT_CLONE_SIGHAND)&& !(flags & OS::TGT_CLONE_VM)) || ((flags & OS::TGT_CLONE_THREAD) && !(flags & OS::TGT_CLONE_SIGHAND)) || @@ -1583,6 +1567,16 @@ cloneFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) return cp->pid(); } +template +SyscallReturn +cloneBackwardsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, + RegVal flags, RegVal newStack, Addr ptidPtr, + Addr tlsPtr, Addr ctidPtr) +{ + return cloneFunc(desc, callnum, tc, flags, newStack, ptidPtr, + ctidPtr, tlsPtr); +} + /// Target fstatfs() handler. template SyscallReturn -- 2.30.2