diff --git a/configs/example/arm/starter_se.py b/configs/example/arm/starter_se.py index 6d5b06b9ae..fbbb5ea94e 100644 --- a/configs/example/arm/starter_se.py +++ b/configs/example/arm/starter_se.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017, 2022-2023 Arm Limited +# Copyright (c) 2016-2017, 2022-2024 Arm Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -203,6 +203,19 @@ def main(): default="stdoutput", help="Destination for the Tarmac trace output. [Default: stdoutput]", ) + parser.add_argument( + "-P", + "--param", + action="append", + default=[], + help="Set a SimObject parameter relative to the root node. " + "An extended Python multi range slicing syntax can be used " + "for arrays. For example: " + "'system.cpu[0,1,3:8:2].max_insts_all_threads = 42' " + "sets max_insts_all_threads for cpus 0, 1, 3, 5 and 7 " + "Direct parameters of the root object are not accessible, " + "only parameters of its children.", + ) args = parser.parse_args() @@ -215,6 +228,7 @@ def main(): # Populate the root node with a system. A system corresponds to a # single node with shared memory. root.system = create(args) + root.apply_config(args.param) # Instantiate the C++ object hierarchy. After this point, # SimObjects can't be instantiated anymore. diff --git a/src/arch/arm/linux/se_workload.cc b/src/arch/arm/linux/se_workload.cc index c919d85edf..04d2382661 100644 --- a/src/arch/arm/linux/se_workload.cc +++ b/src/arch/arm/linux/se_workload.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013, 2015, 2020 ARM Limited + * Copyright (c) 2010-2013, 2015, 2020, 2024 ARM Limited * * The license below extends only to copyright in the software and shall * not be construed as granting a license to any other intellectual @@ -163,7 +163,7 @@ class SyscallTable32 : public SyscallDescTable { base + 14, "mknod", mknodFunc }, { base + 15, "chmod", chmodFunc }, { base + 16, "lchown", chownFunc }, - { base + 19, "lseek", lseekFunc }, + { base + 19, "lseek", lseekFunc }, { base + 20, "getpid", getpidFunc }, { base + 21, "mount" }, { base + 22, "umount" }, @@ -185,7 +185,7 @@ class SyscallTable32 : public SyscallDescTable { base + 42, "pipe", pipePseudoFunc }, { base + 43, "times", timesFunc }, { base + 45, "brk", brkFunc }, - { base + 46, "setgid" }, + { base + 46, "setgid", ignoreFunc }, { base + 47, "getgid", getgidFunc }, { base + 49, "geteuid", geteuidFunc }, { base + 50, "getegid", getegidFunc }, @@ -272,7 +272,7 @@ class SyscallTable32 : public SyscallDescTable { base + 142, "newselect" }, { base + 143, "flock" }, { base + 144, "msync" }, - { base + 145, "readv" }, + { base + 145, "readv", readvFunc }, { base + 146, "writev", writevFunc }, { base + 147, "getsid" }, { base + 148, "fdatasync" }, @@ -293,7 +293,7 @@ class SyscallTable32 : public SyscallDescTable { base + 163, "mremap", mremapFunc }, // ARM-specific { base + 164, "setresuid" }, { base + 165, "getresuid" }, - { base + 168, "poll" }, + { base + 168, "poll", pollFunc }, { base + 169, "nfsservctl" }, { base + 170, "setresgid" }, { base + 171, "getresgid" }, @@ -305,10 +305,10 @@ class SyscallTable32 : public SyscallDescTable { base + 177, "rt_sigtimedwait" }, { base + 178, "rt_sigqueueinfo", ignoreFunc }, { base + 179, "rt_sigsuspend" }, - { base + 180, "pread64" }, - { base + 181, "pwrite64" }, + { base + 180, "pread64", pread64Func }, + { base + 181, "pwrite64", pwrite64Func }, { base + 182, "chown" }, - { base + 183, "getcwd", getcwdFunc }, + { base + 183, "getcwd", getcwdFunc }, { base + 184, "capget" }, { base + 185, "capset" }, { base + 186, "sigaltstack" }, @@ -316,7 +316,7 @@ class SyscallTable32 : public SyscallDescTable { base + 190, "vfork" }, { base + 191, "getrlimit", getrlimitFunc }, { base + 192, "mmap2", mmapFunc }, - { base + 193, "truncate64" }, + { base + 193, "truncate64", truncate64Func }, { base + 194, "ftruncate64", ftruncate64Func }, { base + 195, "stat64", stat64Func }, { base + 196, "lstat64", lstat64Func }, @@ -336,8 +336,8 @@ class SyscallTable32 : public SyscallDescTable { base + 210, "setresgid" }, { base + 211, "getresgid" }, { base + 212, "chown" }, - { base + 213, "setuid" }, - { base + 214, "setgid" }, + { base + 213, "setuid", ignoreFunc }, + { base + 214, "setgid", ignoreFunc }, { base + 215, "setfsuid" }, { base + 216, "setfsgid" }, #if defined(SYS_getdents64) @@ -488,7 +488,9 @@ class SyscallTable32 : public SyscallDescTable { base + 363, "sys_rt_tgsigqueueinfo" }, { base + 364, "sys_perf_event_open" }, { base + 365, "sys_recvmmsg" }, - { base + 384, "getrandom", getrandomFunc } + { base + 384, "getrandom", getrandomFunc }, + { base + 397, "sys_statx", ignoreFunc }, + { base + 398, "sys_rseq", ignoreFunc } }) {} }; @@ -516,7 +518,7 @@ class SyscallTable64 : public SyscallDescTable { base + 14, "removexattr" }, { base + 15, "lremovexattr" }, { base + 16, "fremovexattr" }, - { base + 17, "getcwd", getcwdFunc }, + { base + 17, "getcwd", getcwdFunc }, { base + 18, "lookup_dcookie" }, { base + 19, "eventfd2" }, { base + 20, "epoll_create1" }, @@ -544,7 +546,7 @@ class SyscallTable64 : public SyscallDescTable { base + 42, "nfsservctl" }, { base + 43, "statfs64" }, { base + 44, "fstatfs64" }, - { base + 45, "truncate64" }, + { base + 45, "truncate64", truncate64Func }, { base + 46, "ftruncate64", ftruncate64Func }, { base + 47, "fallocate", fallocateFunc }, { base + 48, "faccessat", faccessatFunc }, @@ -565,13 +567,13 @@ class SyscallTable64 : public SyscallDescTable #else { base + 61, "getdents64" }, #endif - { base + 62, "llseek", lseekFunc }, + { base + 62, "lseek", lseekFunc }, { base + 63, "read", readFunc }, { base + 64, "write", writeFunc }, - { base + 65, "readv" }, + { base + 65, "readv", readvFunc }, { base + 66, "writev", writevFunc }, - { base + 67, "pread64" }, - { base + 68, "pwrite64" }, + { base + 67, "pread64", pread64Func }, + { base + 68, "pwrite64", pwrite64Func }, { base + 69, "preadv" }, { base + 70, "pwritev" }, { base + 71, "sendfile64" }, @@ -815,7 +817,7 @@ class SyscallTable64 : public SyscallDescTable { base + 1054, "newfstatat" }, { base + 1055, "fstatfs" }, { base + 1056, "statfs" }, - { base + 1057, "lseek", lseekFunc }, + { base + 1057, "lseek", lseekFunc }, { base + 1058, "mmap", mmapFunc }, { base + 1059, "alarm" }, { base + 1060, "getpgrp" }, @@ -830,7 +832,7 @@ class SyscallTable64 : public SyscallDescTable #endif { base + 1066, "futimesat", futimesatFunc }, { base + 1067, "select" }, - { base + 1068, "poll" }, + { base + 1068, "poll", pollFunc }, { base + 1069, "epoll_wait" }, { base + 1070, "ustat" }, { base + 1071, "vfork" }, diff --git a/src/arch/mips/linux/linux.hh b/src/arch/mips/linux/linux.hh index 2dab558750..543cdb05b0 100644 --- a/src/arch/mips/linux/linux.hh +++ b/src/arch/mips/linux/linux.hh @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright (c) 2006 The Regents of The University of Michigan * All rights reserved. * @@ -192,6 +203,8 @@ class MipsLinux : public Linux, public OpenFlagTable uint32_t mem_unit; /* Memory unit size in bytes */ }; + typedef uint32_t size_t; + typedef int32_t off_t; }; } // namespace gem5 diff --git a/src/arch/mips/linux/se_workload.cc b/src/arch/mips/linux/se_workload.cc index 0f5cd788e2..a7aedbc0e6 100644 --- a/src/arch/mips/linux/se_workload.cc +++ b/src/arch/mips/linux/se_workload.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright 2005 The Regents of The University of Michigan * Copyright 2007 MIPS Technologies, Inc. * Copyright 2020 Google Inc. @@ -177,7 +188,7 @@ SyscallDescTable EmuLinux::syscallDescs = { { 4016, "lchown", chownFunc }, { 4017, "break", brkFunc }, { 4018, "unused#18" }, - { 4019, "lseek", lseekFunc }, + { 4019, "lseek", lseekFunc }, { 4020, "getpid", getpidFunc }, { 4021, "mount" }, { 4022, "umount" }, @@ -361,7 +372,7 @@ SyscallDescTable EmuLinux::syscallDescs = { { 4200, "pread64" }, { 4201, "pwrite64" }, { 4202, "chown" }, - { 4203, "getcwd", getcwdFunc }, + { 4203, "getcwd", getcwdFunc }, { 4204, "capget" }, { 4205, "capset" }, { 4206, "sigalstack" }, diff --git a/src/arch/power/linux/se_workload.cc b/src/arch/power/linux/se_workload.cc index c376b5f723..5304de8a15 100644 --- a/src/arch/power/linux/se_workload.cc +++ b/src/arch/power/linux/se_workload.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright 2003-2005 The Regents of The University of Michigan * Copyright 2007-2008 The Florida State University * Copyright 2009 The University of Edinburgh @@ -126,7 +137,7 @@ SyscallDescTable EmuLinux::syscallDescs = { { 16, "lchown", chownFunc }, { 17, "break", brkFunc }, //??? { 18, "unused#18" }, //??? - { 19, "lseek", lseekFunc }, + { 19, "lseek", lseekFunc }, { 20, "getpid", getpidFunc }, { 21, "mount" }, { 22, "umount" }, diff --git a/src/arch/riscv/linux/se_workload.cc b/src/arch/riscv/linux/se_workload.cc index 952fe7140f..c1af16fb3b 100644 --- a/src/arch/riscv/linux/se_workload.cc +++ b/src/arch/riscv/linux/se_workload.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright 2005 The Regents of The University of Michigan * Copyright 2007 MIPS Technologies, Inc. * Copyright 2016 The University of Virginia @@ -141,7 +152,7 @@ SyscallDescTable EmuLinux::syscallDescs64 = { { 14, "removexattr" }, { 15, "lremovexattr" }, { 16, "fremovexattr" }, - { 17, "getcwd", getcwdFunc }, + { 17, "getcwd", getcwdFunc }, { 18, "lookup_dcookie" }, { 19, "eventfd2" }, { 20, "epoll_create1" }, @@ -190,7 +201,7 @@ SyscallDescTable EmuLinux::syscallDescs64 = { #else { 61, "getdents64" }, #endif - { 62, "lseek", lseekFunc }, + { 62, "lseek", lseekFunc }, { 63, "read", readFunc }, { 64, "write", writeFunc }, { 66, "writev", writevFunc }, @@ -432,7 +443,7 @@ SyscallDescTable EmuLinux::syscallDescs64 = { { 1054, "newfstatat", newfstatatFunc }, { 1055, "fstatfs", fstatfsFunc }, { 1056, "statfs", statfsFunc }, - { 1057, "lseek", lseekFunc }, + { 1057, "lseek", lseekFunc }, { 1058, "mmap", mmapFunc }, { 1059, "alarm" }, { 1060, "getpgrp", getpgrpFunc }, @@ -480,7 +491,7 @@ SyscallDescTable EmuLinux::syscallDescs32 = { { 14, "removexattr" }, { 15, "lremovexattr" }, { 16, "fremovexattr" }, - { 17, "getcwd", getcwdFunc }, + { 17, "getcwd", getcwdFunc }, { 18, "lookup_dcookie" }, { 19, "eventfd2" }, { 20, "epoll_create1" }, @@ -529,7 +540,7 @@ SyscallDescTable EmuLinux::syscallDescs32 = { #else { 61, "getdents64" }, #endif - { 62, "lseek", lseekFunc }, + { 62, "lseek", lseekFunc }, { 63, "read", readFunc }, { 64, "write", writeFunc }, { 66, "writev", writevFunc }, @@ -771,7 +782,7 @@ SyscallDescTable EmuLinux::syscallDescs32 = { { 1054, "newfstatat", newfstatatFunc }, { 1055, "fstatfs", fstatfsFunc }, { 1056, "statfs", statfsFunc }, - { 1057, "lseek", lseekFunc }, + { 1057, "lseek", lseekFunc }, { 1058, "mmap", mmapFunc }, { 1059, "alarm" }, { 1060, "getpgrp", getpgrpFunc }, diff --git a/src/arch/sparc/linux/linux.hh b/src/arch/sparc/linux/linux.hh index 5913ddb737..e609031e8b 100644 --- a/src/arch/sparc/linux/linux.hh +++ b/src/arch/sparc/linux/linux.hh @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright (c) 2003-2005 The Regents of The University of Michigan * All rights reserved. * @@ -242,6 +253,9 @@ class SparcLinux : public Linux, public OpenFlagTable ptc->setReg(SparcISA::SyscallPseudoReturnReg, (RegVal)0); ctc->setReg(SparcISA::SyscallPseudoReturnReg, 1); } + + typedef uint64_t size_t; + typedef int64_t off_t; }; class Sparc32Linux : public SparcLinux @@ -288,6 +302,9 @@ class Sparc32Linux : public SparcLinux uint32_t mem_unit; /* Memory unit size in bytes */ }; + typedef uint32_t size_t; + typedef int32_t off_t; + /// Resource constants for getrlimit() (overide some generics). static const unsigned TGT_RLIMIT_NPROC = 7; static const unsigned TGT_RLIMIT_NOFILE = 6; diff --git a/src/arch/sparc/linux/syscalls.cc b/src/arch/sparc/linux/syscalls.cc index 093fc9ccd3..2ff0fa1a1e 100644 --- a/src/arch/sparc/linux/syscalls.cc +++ b/src/arch/sparc/linux/syscalls.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright (c) 2003-2005 The Regents of The University of Michigan * All rights reserved. * @@ -104,7 +115,7 @@ SyscallDescTable EmuLinux::syscall32Descs = { { 16, "lchown" }, // 32 bit { 17, "brk", brkFunc }, { 18, "perfctr" }, // 32 bit - { 19, "lseek", lseekFunc }, // 32 bit + { 19, "lseek", lseekFunc }, // 32 bit { 20, "getpid", getpidFunc }, { 21, "capget" }, { 22, "capset" }, @@ -204,7 +215,7 @@ SyscallDescTable EmuLinux::syscall32Descs = { { 116, "gettimeofday", gettimeofdayFunc }, // 32 bit { 117, "getrusage" }, // 32 bit { 118, "getsockopt" }, - { 119, "getcwd", getcwdFunc }, + { 119, "getcwd", getcwdFunc }, { 120, "readv" }, { 121, "writev" }, { 122, "settimeofday" }, // 32 bit @@ -407,7 +418,7 @@ SyscallDescTable EmuLinux::syscallDescs = { { 16, "lchown" }, { 17, "brk", brkFunc }, { 18, "perfctr" }, - { 19, "lseek", lseekFunc }, + { 19, "lseek", lseekFunc }, { 20, "getpid", getpidFunc }, { 21, "capget" }, { 22, "capset" }, diff --git a/src/arch/x86/linux/linux.hh b/src/arch/x86/linux/linux.hh index 2b2031cc3c..caebbe8247 100644 --- a/src/arch/x86/linux/linux.hh +++ b/src/arch/x86/linux/linux.hh @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Arm Limited * Copyright (c) 2007 The Hewlett-Packard Development Company * All rights reserved. * @@ -240,7 +241,7 @@ class X86Linux64 : public X86Linux, public OpenFlagTable //@{ /// Basic X86_64 Linux types typedef uint64_t size_t; - typedef uint64_t off_t; + typedef int64_t off_t; typedef int64_t time_t; typedef int64_t clock_t; //@} @@ -387,7 +388,7 @@ class X86Linux32 : public X86Linux, public OpenFlagTable //@{ /// Basic X86 Linux types typedef uint32_t size_t; - typedef uint32_t off_t; + typedef int32_t off_t; typedef int32_t time_t; typedef int32_t clock_t; //@} diff --git a/src/arch/x86/linux/syscall_tbl32.cc b/src/arch/x86/linux/syscall_tbl32.cc index 2de334cee3..bf5d03e7b5 100644 --- a/src/arch/x86/linux/syscall_tbl32.cc +++ b/src/arch/x86/linux/syscall_tbl32.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright 2020 Google Inc. * * Redistribution and use in source and binary forms, with or without @@ -58,7 +69,7 @@ SyscallDescTable EmuLinux::syscallDescs32 = { { 16, "lchown" }, { 17, "break" }, { 18, "oldstat" }, - { 19, "lseek" }, + { 19, "lseek", lseekFunc }, { 20, "getpid", getpidFunc }, { 21, "mount" }, { 22, "umount" }, @@ -226,7 +237,7 @@ SyscallDescTable EmuLinux::syscallDescs32 = { { 180, "pread64", pread64Func }, { 181, "pwrite64", pwrite64Func }, { 182, "chown" }, - { 183, "getcwd", getcwdFunc }, + { 183, "getcwd", getcwdFunc }, { 184, "capget" }, { 185, "capset" }, { 186, "sigaltstack" }, diff --git a/src/arch/x86/linux/syscall_tbl64.cc b/src/arch/x86/linux/syscall_tbl64.cc index 1b3dfaf020..1c3eebd63d 100644 --- a/src/arch/x86/linux/syscall_tbl64.cc +++ b/src/arch/x86/linux/syscall_tbl64.cc @@ -1,4 +1,15 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and shall + * not be construed as granting a license to any other intellectual + * property including but not limited to intellectual property relating + * to a hardware implementation of the functionality of the software + * licensed hereunder. You may use the software subject to the license + * terms below provided that you ensure that this notice is replicated + * unmodified and in its entirety in all distributions of the software, + * modified or unmodified, in source code or in binary form. + * * Copyright 2020 Google Inc. * * Redistribution and use in source and binary forms, with or without @@ -47,7 +58,7 @@ SyscallDescTable EmuLinux::syscallDescs64 = { { 5, "fstat", fstat64Func }, { 6, "lstat", lstat64Func }, { 7, "poll", pollFunc }, - { 8, "lseek", lseekFunc }, + { 8, "lseek", lseekFunc }, { 9, "mmap", mmapFunc }, { 10, "mprotect", ignoreFunc }, { 11, "munmap", munmapFunc }, @@ -122,7 +133,7 @@ SyscallDescTable EmuLinux::syscallDescs64 = { #else { 78, "getdents" }, #endif - { 79, "getcwd", getcwdFunc }, + { 79, "getcwd", getcwdFunc }, { 80, "chdir", chdirFunc }, { 81, "fchdir" }, { 82, "rename", renameFunc }, diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index 5b7a20ff4a..9d1d5392de 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited + * Copyright (c) 2021, 2024 Arm Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -66,7 +66,7 @@ class Linux : public OperatingSystem //@{ /// Basic Linux types. typedef uint64_t size_t; - typedef uint64_t off_t; + typedef int64_t off_t; typedef int64_t time_t; typedef int64_t clock_t; typedef uint32_t uid_t; diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index 9794a4835e..909b566b96 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -1,4 +1,16 @@ /* + * Copyright (c) 2024 Arm Limited + * + * The license below extends only to copyright in the software and + * shall not be construed as granting a license to any other + * intellectual property including but not limited to intellectual + * property relating to a hardware implementation of the + * functionality of the software licensed hereunder. You may use the + * software subject to the license terms below provided that you + * ensure that this notice is replicated unmodified and in its + * entirety in all distributions of the software, modified or + * unmodified, in source code or in binary form. + * * Copyright (c) 2003-2005 The Regents of The University of Michigan * All rights reserved. * @@ -277,7 +289,7 @@ brkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> new_brk) } SyscallReturn -setTidAddressFunc(SyscallDesc *desc, ThreadContext *tc, uint64_t tidPtr) +setTidAddressFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> tidPtr) { auto process = tc->getProcessPtr(); @@ -292,26 +304,10 @@ closeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd) return p->fds->closeFDEntry(tgt_fd); } -SyscallReturn -lseekFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t offs, int whence) -{ - auto p = tc->getProcessPtr(); - - auto ffdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); - if (!ffdp) - return -EBADF; - int sim_fd = ffdp->getSimFD(); - - off_t result = lseek(sim_fd, offs, whence); - - return (result == (off_t)-1) ? -errno : result; -} - SyscallReturn _llseekFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t offset_high, uint32_t offset_low, + int tgt_fd, uint32_t offset_high, uint32_t offset_low, VPtr<> result_ptr, int whence) { auto p = tc->getProcessPtr(); @@ -321,7 +317,7 @@ _llseekFunc(SyscallDesc *desc, ThreadContext *tc, return -EBADF; int sim_fd = ffdp->getSimFD(); - uint64_t offset = (offset_high << 32) | offset_low; + uint64_t offset = ((uint64_t) offset_high << 32) | offset_low; uint64_t result = lseek(sim_fd, offset, whence); result = htog(result, tc->getSystemPtr()->getGuestByteOrder()); @@ -348,36 +344,6 @@ gethostnameFunc(SyscallDesc *desc, ThreadContext *tc, return 0; } -SyscallReturn -getcwdFunc(SyscallDesc *desc, ThreadContext *tc, - VPtr<> buf_ptr, unsigned long size) -{ - int result = 0; - auto p = tc->getProcessPtr(); - BufferArg buf(buf_ptr, size); - - // Is current working directory defined? - std::string cwd = p->tgtCwd; - if (!cwd.empty()) { - if (cwd.length() >= size) { - // Buffer too small - return -ERANGE; - } - strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); - result = cwd.length(); - } else { - if (getcwd((char *)buf.bufferPtr(), size)) { - result = strlen((char *)buf.bufferPtr()); - } else { - result = -1; - } - } - - buf.copyOut(SETranslatingPortProxy(tc)); - - return (result == -1) ? -errno : result; -} - SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname) { diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 4c822d14a1..b72d12025b 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2013, 2015, 2019-2021, 2023 Arm Limited + * Copyright (c) 2012-2013, 2015, 2019-2021, 2023-2024 Arm Limited * Copyright (c) 2015 Advanced Micro Devices, Inc. * All rights reserved * @@ -149,7 +149,7 @@ SyscallReturn exitGroupFunc(SyscallDesc *desc, ThreadContext *tc, int status); /// Target set_tid_address() handler. SyscallReturn setTidAddressFunc(SyscallDesc *desc, ThreadContext *tc, - uint64_t tidPtr); + VPtr<> tidPtr); /// Target getpagesize() handler. SyscallReturn getpagesizeFunc(SyscallDesc *desc, ThreadContext *tc); @@ -160,13 +160,9 @@ SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> new_brk); /// Target close() handler. SyscallReturn closeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd); -/// Target lseek() handler. -SyscallReturn lseekFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t offs, int whence); - /// Target _llseek() handler. SyscallReturn _llseekFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t offset_high, + int tgt_fd, uint32_t offset_high, uint32_t offset_low, VPtr<> result_ptr, int whence); /// Target shutdown() handler. @@ -177,10 +173,6 @@ SyscallReturn shutdownFunc(SyscallDesc *desc, ThreadContext *tc, SyscallReturn gethostnameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> buf_ptr, int name_len); -/// Target getcwd() handler. -SyscallReturn getcwdFunc(SyscallDesc *desc, ThreadContext *tc, - VPtr<> buf_ptr, unsigned long size); - /// Target unlink() handler. SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname); @@ -976,6 +968,56 @@ openFunc(SyscallDesc *desc, ThreadContext *tc, desc, tc, OS::TGT_AT_FDCWD, pathname, tgt_flags, mode); } +/// Target getcwd() handler +template +SyscallReturn +getcwdFunc(SyscallDesc *desc, ThreadContext *tc, + VPtr<> buf_ptr, typename OS::size_t size) +{ + int result = 0; + auto p = tc->getProcessPtr(); + BufferArg buf(buf_ptr, size); + + // Is current working directory defined? + std::string cwd = p->tgtCwd; + if (!cwd.empty()) { + if (cwd.length() >= size) { + // Buffer too small + return -ERANGE; + } + strncpy((char *)buf.bufferPtr(), cwd.c_str(), size); + result = cwd.length(); + } else { + if (getcwd((char *)buf.bufferPtr(), size)) { + result = strlen((char *)buf.bufferPtr()); + } else { + result = -1; + } + } + + buf.copyOut(SETranslatingPortProxy(tc)); + + return (result == -1) ? -errno : result; +} + +/// Target lseek() handler +template +SyscallReturn +lseekFunc(SyscallDesc *desc, ThreadContext *tc, + int tgt_fd, typename OS::off_t offs, int whence) +{ + auto p = tc->getProcessPtr(); + + auto ffdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); + if (!ffdp) + return -EBADF; + int sim_fd = ffdp->getSimFD(); + + off_t result = lseek(sim_fd, offs, whence); + + return (result == (off_t)-1) ? -errno : result; +} + /// Target unlinkat() handler. template SyscallReturn @@ -1327,7 +1369,8 @@ fchmodFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t mode) template SyscallReturn mremapFunc(SyscallDesc *desc, ThreadContext *tc, - VPtr<> start, uint64_t old_length, uint64_t new_length, uint64_t flags, + VPtr<> start, typename OS::size_t old_length, + typename OS::size_t new_length, int flags, guest_abi::VarArgs varargs) { auto p = tc->getProcessPtr(); @@ -1877,7 +1920,7 @@ fstatfsFunc(SyscallDesc *desc, ThreadContext *tc, template SyscallReturn readvFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t tiov_base, + int tgt_fd, VPtr<> tiov_base, typename OS::size_t count) { auto p = tc->getProcessPtr(); @@ -1915,7 +1958,7 @@ readvFunc(SyscallDesc *desc, ThreadContext *tc, template SyscallReturn writevFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, uint64_t tiov_base, + int tgt_fd, VPtr<> tiov_base, typename OS::size_t count) { auto p = tc->getProcessPtr(); @@ -2092,7 +2135,8 @@ mmapFunc(SyscallDesc *desc, ThreadContext *tc, template SyscallReturn pread64Func(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, VPtr<> bufPtr, int nbytes, int offset) + int tgt_fd, VPtr<> bufPtr, typename OS::size_t nbytes, + typename OS::off_t offset) { auto p = tc->getProcessPtr(); @@ -2113,7 +2157,8 @@ pread64Func(SyscallDesc *desc, ThreadContext *tc, template SyscallReturn pwrite64Func(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, VPtr<> bufPtr, int nbytes, int offset) + int tgt_fd, VPtr<> bufPtr, typename OS::size_t nbytes, + typename OS::off_t offset) { auto p = tc->getProcessPtr(); @@ -2746,7 +2791,7 @@ selectFunc(SyscallDesc *desc, ThreadContext *tc, int nfds, template SyscallReturn readFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, VPtr<> buf_ptr, int nbytes) + int tgt_fd, VPtr<> buf_ptr, typename OS::size_t nbytes) { auto p = tc->getProcessPtr(); @@ -2774,7 +2819,7 @@ readFunc(SyscallDesc *desc, ThreadContext *tc, template SyscallReturn writeFunc(SyscallDesc *desc, ThreadContext *tc, - int tgt_fd, VPtr<> buf_ptr, int nbytes) + int tgt_fd, VPtr<> buf_ptr, typename OS::size_t nbytes) { auto p = tc->getProcessPtr();