From: Ciro Santilli Date: Wed, 22 Apr 2020 15:01:45 +0000 (+0100) Subject: sim-se: implement the getcpu syscall X-Git-Tag: v20.1.0.0~637 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=66e598fa08b82ba6671abc3e924bc5df4424d313;p=gem5.git sim-se: implement the getcpu syscall Change-Id: I63a1384646829b8cf68453c42aed6a7d12172787 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28590 Reviewed-by: Giacomo Travaglini Maintainer: Giacomo Travaglini Tested-by: kokoro --- diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc index b5b6553d9..55141ba11 100644 --- a/src/arch/arm/linux/process.cc +++ b/src/arch/arm/linux/process.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013, 2015 ARM Limited + * Copyright (c) 2010-2013, 2015, 2020 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -476,7 +476,7 @@ class SyscallTable32 : { base + 342, "tee" }, { base + 343, "vmsplice" }, { base + 344, "move_pages" }, - { base + 345, "getcpu" }, + { base + 345, "getcpu", getcpuFunc }, { base + 346, "epoll_pwait" }, { base + 347, "sys_kexec_load" }, { base + 348, "sys_utimensat" }, @@ -681,7 +681,7 @@ class SyscallTable64 : { base + 165, "getrusage", getrusageFunc }, { base + 166, "umask" }, { base + 167, "prctl" }, - { base + 168, "getcpu" }, + { base + 168, "getcpu", getcpuFunc }, { base + 169, "gettimeofday", gettimeofdayFunc }, { base + 170, "settimeofday" }, { base + 171, "adjtimex" }, diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 6b50dbf5b..2c594e756 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -566,7 +566,7 @@ static SyscallDescTable syscallDescs64 = { { 306, "syncfs" }, { 307, "sendmmsg" }, { 308, "setns" }, - { 309, "getcpu" }, + { 309, "getcpu", getcpuFunc }, { 310, "proess_vm_readv" }, { 311, "proess_vm_writev" }, { 312, "kcmp" }, @@ -914,7 +914,7 @@ static SyscallDescTable syscallDescs32 = { { 315, "tee" }, { 316, "vmsplice" }, { 317, "move_pages" }, - { 318, "getcpu" }, + { 318, "getcpu", getcpuFunc }, { 319, "epoll_pwait" }, { 320, "utimensat" }, { 321, "signalfd" }, diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index bffedfdd9..6d39823b4 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -1633,3 +1633,26 @@ setsockoptFunc(SyscallDesc *desc, ThreadContext *tc, return (status == -1) ? -errno : status; } +SyscallReturn +getcpuFunc(SyscallDesc *desc, ThreadContext *tc, + Addr cpu_ptr, Addr node_ptr, Addr tcache_ptr) +{ + bool error = false; + + // unsigned is the same size (4) on all Linux supported ISAs. + if (cpu_ptr != 0) { + TypedBufferArg result(cpu_ptr); + *result = htog(tc->contextId(), + tc->getSystemPtr()->getGuestByteOrder()); + error |= !result.copyOut(tc->getVirtProxy()); + } + + // Set a fixed NUMA node 0. + if (node_ptr != 0) { + TypedBufferArg result(node_ptr); + *result = 0; + error |= !result.copyOut(tc->getVirtProxy()); + } + + return error ? -EFAULT : 0; +} diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 4a37e99a0..55d30f300 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2013, 2015, 2019 ARM Limited + * Copyright (c) 2012-2013, 2015, 2019-2020 ARM Limited * Copyright (c) 2015 Advanced Micro Devices, Inc. * All rights reserved * @@ -354,6 +354,9 @@ SyscallReturn setsockoptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, socklen_t len); +SyscallReturn getcpuFunc(SyscallDesc *desc, ThreadContext *tc, + Addr cpu_ptr, Addr node_ptr, Addr tcache_ptr); + // Target getsockname() handler. SyscallReturn getsocknameFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr);