2 * Copyright (c) 2012-2013, 2015 ARM Limited
3 * Copyright (c) 2015 Advanced Micro Devices, Inc.
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Copyright (c) 2003-2005 The Regents of The University of Michigan
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * Authors: Steve Reinhardt
45 #ifndef __SIM_SYSCALL_EMUL_HH__
46 #define __SIM_SYSCALL_EMUL_HH__
48 #define NO_STAT64 (defined(__APPLE__) || defined(__OpenBSD__) || \
49 defined(__FreeBSD__) || defined(__CYGWIN__) || \
52 #define NO_STATFS (defined(__APPLE__) || defined(__OpenBSD__) || \
53 defined(__FreeBSD__) || defined(__NetBSD__))
55 #define NO_FALLOCATE (defined(__APPLE__) || defined(__OpenBSD__) || \
56 defined(__FreeBSD__) || defined(__NetBSD__))
59 /// @file syscall_emul.hh
61 /// This file defines objects used to emulate syscalls from the target
62 /// application on the host machine.
65 #include <sys/fcntl.h>
72 #include <sys/statfs.h>
81 #include "base/intmath.hh"
82 #include "base/loader/object_file.hh"
83 #include "base/misc.hh"
84 #include "base/trace.hh"
85 #include "base/types.hh"
86 #include "config/the_isa.hh"
87 #include "cpu/base.hh"
88 #include "cpu/thread_context.hh"
89 #include "mem/page_table.hh"
90 #include "sim/emul_driver.hh"
91 #include "sim/process.hh"
92 #include "sim/syscall_debug_macros.hh"
93 #include "sim/syscall_emul_buf.hh"
94 #include "sim/syscall_return.hh"
98 //////////////////////////////////////////////////////////////////////
100 // The following emulation functions are generic enough that they
101 // don't need to be recompiled for different emulated OS's. They are
102 // defined in sim/syscall_emul.cc.
104 //////////////////////////////////////////////////////////////////////
107 /// Handler for unimplemented syscalls that we haven't thought about.
108 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
109 LiveProcess *p, ThreadContext *tc);
111 /// Handler for unimplemented syscalls that we never intend to
112 /// implement (signal handling, etc.) and should not affect the correct
113 /// behavior of the program. Print a warning only if the appropriate
114 /// trace flag is enabled. Return success to the target program.
115 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
116 LiveProcess *p, ThreadContext *tc);
118 // Target fallocateFunc() handler.
119 SyscallReturn fallocateFunc(SyscallDesc *desc, int num,
120 LiveProcess *p, ThreadContext *tc);
122 /// Target exit() handler: terminate current context.
123 SyscallReturn exitFunc(SyscallDesc *desc, int num,
124 LiveProcess *p, ThreadContext *tc);
126 /// Target exit_group() handler: terminate simulation. (exit all threads)
127 SyscallReturn exitGroupFunc(SyscallDesc *desc, int num,
128 LiveProcess *p, ThreadContext *tc);
130 /// Target getpagesize() handler.
131 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
132 LiveProcess *p, ThreadContext *tc);
134 /// Target brk() handler: set brk address.
135 SyscallReturn brkFunc(SyscallDesc *desc, int num,
136 LiveProcess *p, ThreadContext *tc);
138 /// Target close() handler.
139 SyscallReturn closeFunc(SyscallDesc *desc, int num,
140 LiveProcess *p, ThreadContext *tc);
142 /// Target read() handler.
143 SyscallReturn readFunc(SyscallDesc *desc, int num,
144 LiveProcess *p, ThreadContext *tc);
146 /// Target write() handler.
147 SyscallReturn writeFunc(SyscallDesc *desc, int num,
148 LiveProcess *p, ThreadContext *tc);
150 /// Target lseek() handler.
151 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
152 LiveProcess *p, ThreadContext *tc);
154 /// Target _llseek() handler.
155 SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
156 LiveProcess *p, ThreadContext *tc);
158 /// Target munmap() handler.
159 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
160 LiveProcess *p, ThreadContext *tc);
162 /// Target gethostname() handler.
163 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
164 LiveProcess *p, ThreadContext *tc);
166 /// Target getcwd() handler.
167 SyscallReturn getcwdFunc(SyscallDesc *desc, int num,
168 LiveProcess *p, ThreadContext *tc);
170 /// Target readlink() handler.
171 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
172 LiveProcess *p, ThreadContext *tc,
174 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
175 LiveProcess *p, ThreadContext *tc);
177 /// Target unlink() handler.
178 SyscallReturn unlinkHelper(SyscallDesc *desc, int num,
179 LiveProcess *p, ThreadContext *tc,
181 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
182 LiveProcess *p, ThreadContext *tc);
184 /// Target mkdir() handler.
185 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
186 LiveProcess *p, ThreadContext *tc);
188 /// Target rename() handler.
189 SyscallReturn renameFunc(SyscallDesc *desc, int num,
190 LiveProcess *p, ThreadContext *tc);
193 /// Target truncate() handler.
194 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
195 LiveProcess *p, ThreadContext *tc);
198 /// Target ftruncate() handler.
199 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
200 LiveProcess *p, ThreadContext *tc);
203 /// Target truncate64() handler.
204 SyscallReturn truncate64Func(SyscallDesc *desc, int num,
205 LiveProcess *p, ThreadContext *tc);
207 /// Target ftruncate64() handler.
208 SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
209 LiveProcess *p, ThreadContext *tc);
212 /// Target umask() handler.
213 SyscallReturn umaskFunc(SyscallDesc *desc, int num,
214 LiveProcess *p, ThreadContext *tc);
217 /// Target chown() handler.
218 SyscallReturn chownFunc(SyscallDesc *desc, int num,
219 LiveProcess *p, ThreadContext *tc);
222 /// Target fchown() handler.
223 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
224 LiveProcess *p, ThreadContext *tc);
226 /// Target dup() handler.
227 SyscallReturn dupFunc(SyscallDesc *desc, int num,
228 LiveProcess *process, ThreadContext *tc);
230 /// Target fnctl() handler.
231 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
232 LiveProcess *process, ThreadContext *tc);
234 /// Target fcntl64() handler.
235 SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
236 LiveProcess *process, ThreadContext *tc);
238 /// Target setuid() handler.
239 SyscallReturn setuidFunc(SyscallDesc *desc, int num,
240 LiveProcess *p, ThreadContext *tc);
242 /// Target getpid() handler.
243 SyscallReturn getpidFunc(SyscallDesc *desc, int num,
244 LiveProcess *p, ThreadContext *tc);
246 /// Target getuid() handler.
247 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
248 LiveProcess *p, ThreadContext *tc);
250 /// Target getgid() handler.
251 SyscallReturn getgidFunc(SyscallDesc *desc, int num,
252 LiveProcess *p, ThreadContext *tc);
254 /// Target getppid() handler.
255 SyscallReturn getppidFunc(SyscallDesc *desc, int num,
256 LiveProcess *p, ThreadContext *tc);
258 /// Target geteuid() handler.
259 SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
260 LiveProcess *p, ThreadContext *tc);
262 /// Target getegid() handler.
263 SyscallReturn getegidFunc(SyscallDesc *desc, int num,
264 LiveProcess *p, ThreadContext *tc);
266 /// Target clone() handler.
267 SyscallReturn cloneFunc(SyscallDesc *desc, int num,
268 LiveProcess *p, ThreadContext *tc);
270 /// Target access() handler
271 SyscallReturn accessFunc(SyscallDesc *desc, int num,
272 LiveProcess *p, ThreadContext *tc);
273 SyscallReturn accessFunc(SyscallDesc *desc, int num,
274 LiveProcess *p, ThreadContext *tc,
277 /// Futex system call
278 /// Implemented by Daniel Sanchez
279 /// Used by printf's in multi-threaded apps
282 futexFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
288 int index_timeout = 3;
290 uint64_t uaddr = process->getSyscallArg(tc, index_uaddr);
291 int op = process->getSyscallArg(tc, index_op);
292 int val = process->getSyscallArg(tc, index_val);
293 uint64_t timeout = process->getSyscallArg(tc, index_timeout);
295 std::map<uint64_t, std::list<ThreadContext *> * >
296 &futex_map = tc->getSystemPtr()->futexMap;
298 DPRINTF(SyscallVerbose, "In sys_futex: Address=%llx, op=%d, val=%d\n",
301 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
303 if (op == OS::TGT_FUTEX_WAIT) {
305 warn("sys_futex: FUTEX_WAIT with non-null timeout unimplemented;"
306 "we'll wait indefinitely");
309 uint8_t *buf = new uint8_t[sizeof(int)];
310 tc->getMemProxy().readBlob((Addr)uaddr, buf, (int)sizeof(int));
311 int mem_val = *((int *)buf);
314 if (val != mem_val) {
315 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, read: %d, "
316 "expected: %d\n", mem_val, val);
317 return -OS::TGT_EWOULDBLOCK;
320 // Queue the thread context
321 std::list<ThreadContext *> * tcWaitList;
322 if (futex_map.count(uaddr)) {
323 tcWaitList = futex_map.find(uaddr)->second;
325 tcWaitList = new std::list<ThreadContext *>();
326 futex_map.insert(std::pair< uint64_t,
327 std::list<ThreadContext *> * >(uaddr, tcWaitList));
329 tcWaitList->push_back(tc);
330 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAIT, suspending calling "
334 } else if (op == OS::TGT_FUTEX_WAKE){
336 std::list<ThreadContext *> * tcWaitList;
337 if (futex_map.count(uaddr)) {
338 tcWaitList = futex_map.find(uaddr)->second;
339 while (tcWaitList->size() > 0 && wokenUp < val) {
340 tcWaitList->front()->activate();
341 tcWaitList->pop_front();
344 if (tcWaitList->empty()) {
345 futex_map.erase(uaddr);
349 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, activated %d waiting "
350 "thread contexts\n", wokenUp);
353 warn("sys_futex: op %d is not implemented, just returning...", op);
360 /// Pseudo Funcs - These functions use a different return convension,
361 /// returning a second value in a register other than the normal return register
362 SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
363 LiveProcess *process, ThreadContext *tc);
365 /// Target getpidPseudo() handler.
366 SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
367 LiveProcess *p, ThreadContext *tc);
369 /// Target getuidPseudo() handler.
370 SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
371 LiveProcess *p, ThreadContext *tc);
373 /// Target getgidPseudo() handler.
374 SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
375 LiveProcess *p, ThreadContext *tc);
378 /// A readable name for 1,000,000, for converting microseconds to seconds.
379 const int one_million = 1000000;
380 /// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
381 const int one_billion = 1000000000;
383 /// Approximate seconds since the epoch (1/1/1970). About a billion,
384 /// by my reckoning. We want to keep this a constant (not use the
385 /// real-world time) to keep simulations repeatable.
386 const unsigned seconds_since_epoch = 1000000000;
388 /// Helper function to convert current elapsed time to seconds and
390 template <class T1, class T2>
392 getElapsedTimeMicro(T1 &sec, T2 &usec)
394 uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
395 sec = elapsed_usecs / one_million;
396 usec = elapsed_usecs % one_million;
399 /// Helper function to convert current elapsed time to seconds and
401 template <class T1, class T2>
403 getElapsedTimeNano(T1 &sec, T2 &nsec)
405 uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
406 sec = elapsed_nsecs / one_billion;
407 nsec = elapsed_nsecs % one_billion;
410 //////////////////////////////////////////////////////////////////////
412 // The following emulation functions are generic, but need to be
413 // templated to account for differences in types, constants, etc.
415 //////////////////////////////////////////////////////////////////////
417 typedef struct statfs hst_statfs;
419 typedef struct stat hst_stat;
420 typedef struct stat hst_stat64;
422 typedef struct stat hst_stat;
423 typedef struct stat64 hst_stat64;
426 //// Helper function to convert a host stat buffer to a target stat
427 //// buffer. Also copies the target buffer out to the simulated
428 //// memory space. Used by stat(), fstat(), and lstat().
430 template <typename target_stat, typename host_stat>
432 convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
434 using namespace TheISA;
439 tgt->st_dev = host->st_dev;
440 tgt->st_dev = TheISA::htog(tgt->st_dev);
441 tgt->st_ino = host->st_ino;
442 tgt->st_ino = TheISA::htog(tgt->st_ino);
443 tgt->st_mode = host->st_mode;
445 // Claim to be a character device
446 tgt->st_mode &= ~S_IFMT; // Clear S_IFMT
447 tgt->st_mode |= S_IFCHR; // Set S_IFCHR
449 tgt->st_mode = TheISA::htog(tgt->st_mode);
450 tgt->st_nlink = host->st_nlink;
451 tgt->st_nlink = TheISA::htog(tgt->st_nlink);
452 tgt->st_uid = host->st_uid;
453 tgt->st_uid = TheISA::htog(tgt->st_uid);
454 tgt->st_gid = host->st_gid;
455 tgt->st_gid = TheISA::htog(tgt->st_gid);
457 tgt->st_rdev = 0x880d;
459 tgt->st_rdev = host->st_rdev;
460 tgt->st_rdev = TheISA::htog(tgt->st_rdev);
461 tgt->st_size = host->st_size;
462 tgt->st_size = TheISA::htog(tgt->st_size);
463 tgt->st_atimeX = host->st_atime;
464 tgt->st_atimeX = TheISA::htog(tgt->st_atimeX);
465 tgt->st_mtimeX = host->st_mtime;
466 tgt->st_mtimeX = TheISA::htog(tgt->st_mtimeX);
467 tgt->st_ctimeX = host->st_ctime;
468 tgt->st_ctimeX = TheISA::htog(tgt->st_ctimeX);
469 // Force the block size to be 8k. This helps to ensure buffered io works
470 // consistently across different hosts.
471 tgt->st_blksize = 0x2000;
472 tgt->st_blksize = TheISA::htog(tgt->st_blksize);
473 tgt->st_blocks = host->st_blocks;
474 tgt->st_blocks = TheISA::htog(tgt->st_blocks);
479 template <typename target_stat, typename host_stat64>
481 convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
483 using namespace TheISA;
485 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
486 #if defined(STAT_HAVE_NSEC)
487 tgt->st_atime_nsec = host->st_atime_nsec;
488 tgt->st_atime_nsec = TheISA::htog(tgt->st_atime_nsec);
489 tgt->st_mtime_nsec = host->st_mtime_nsec;
490 tgt->st_mtime_nsec = TheISA::htog(tgt->st_mtime_nsec);
491 tgt->st_ctime_nsec = host->st_ctime_nsec;
492 tgt->st_ctime_nsec = TheISA::htog(tgt->st_ctime_nsec);
494 tgt->st_atime_nsec = 0;
495 tgt->st_mtime_nsec = 0;
496 tgt->st_ctime_nsec = 0;
500 //Here are a couple convenience functions
503 copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
504 hst_stat *host, bool fakeTTY = false)
506 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
507 tgt_stat_buf tgt(addr);
508 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
514 copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
515 hst_stat64 *host, bool fakeTTY = false)
517 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
518 tgt_stat_buf tgt(addr);
519 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
525 copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr,
528 TypedBufferArg<typename OS::tgt_statfs> tgt(addr);
530 #if defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD__)
533 tgt->f_type = TheISA::htog(host->f_type);
535 tgt->f_bsize = TheISA::htog(host->f_bsize);
536 tgt->f_blocks = TheISA::htog(host->f_blocks);
537 tgt->f_bfree = TheISA::htog(host->f_bfree);
538 tgt->f_bavail = TheISA::htog(host->f_bavail);
539 tgt->f_files = TheISA::htog(host->f_files);
540 tgt->f_ffree = TheISA::htog(host->f_ffree);
541 memcpy(&tgt->f_fsid, &host->f_fsid, sizeof(host->f_fsid));
542 tgt->f_namelen = TheISA::htog(host->f_namelen);
543 tgt->f_frsize = TheISA::htog(host->f_frsize);
544 memcpy(&tgt->f_spare, &host->f_spare, sizeof(host->f_spare));
549 /// Target ioctl() handler. For the most part, programs call ioctl()
550 /// only to find out if their stdout is a tty, to determine whether to
551 /// do line or block buffering. We always claim that output fds are
552 /// not TTYs to provide repeatable results.
555 ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
559 int tgt_fd = process->getSyscallArg(tc, index);
560 unsigned req = process->getSyscallArg(tc, index);
562 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
564 FDEntry *fde = process->getFDEntry(tgt_fd);
567 // doesn't map to any simulator fd: not a valid target fd
571 if (fde->driver != NULL) {
572 return fde->driver->ioctl(process, tc, req);
575 if (OS::isTtyReq(req)) {
579 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n",
580 tgt_fd, req, tc->pcState());
586 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
587 ThreadContext *tc, int index)
591 if (!tc->getMemProxy().tryReadString(path,
592 process->getSyscallArg(tc, index)))
595 int tgtFlags = process->getSyscallArg(tc, index);
596 int mode = process->getSyscallArg(tc, index);
599 // translate open flags
600 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
601 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
602 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
603 hostFlags |= OS::openFlagTable[i].hostFlag;
607 // any target flags left?
609 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
612 hostFlags |= O_BINARY;
615 // Adjust path for current working directory
616 path = process->fullPath(path);
618 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
620 if (startswith(path, "/dev/")) {
621 std::string filename = path.substr(strlen("/dev/"));
622 if (filename == "sysdev0") {
623 // This is a memory-mapped high-resolution timer device on Alpha.
624 // We don't support it, so just punt.
625 warn("Ignoring open(%s, ...)\n", path);
629 EmulatedDriver *drv = process->findDriver(filename);
631 // the driver's open method will allocate a fd from the
632 // process if necessary.
633 return drv->open(process, tc, mode, hostFlags);
636 // fall through here for pass through to host devices, such as
642 if (startswith(path, "/proc/") || startswith(path, "/system/") ||
643 startswith(path, "/platform/") || startswith(path, "/sys/")) {
644 // It's a proc/sys entry and requires special handling
645 fd = OS::openSpecialFile(path, process, tc);
646 local_errno = ENOENT;
649 fd = open(path.c_str(), hostFlags, mode);
656 return process->allocFD(fd, path.c_str(), hostFlags, mode, false);
659 /// Target open() handler.
662 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
665 return openFunc<OS>(desc, callnum, process, tc, 0);
668 /// Target openat() handler.
671 openatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
675 int dirfd = process->getSyscallArg(tc, index);
676 if (dirfd != OS::TGT_AT_FDCWD)
677 warn("openat: first argument not AT_FDCWD; unlikely to work");
678 return openFunc<OS>(desc, callnum, process, tc, 1);
681 /// Target unlinkat() handler.
684 unlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
688 int dirfd = process->getSyscallArg(tc, index);
689 if (dirfd != OS::TGT_AT_FDCWD)
690 warn("unlinkat: first argument not AT_FDCWD; unlikely to work");
692 return unlinkHelper(desc, callnum, process, tc, 1);
695 /// Target facessat() handler
698 faccessatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
702 int dirfd = process->getSyscallArg(tc, index);
703 if (dirfd != OS::TGT_AT_FDCWD)
704 warn("faccessat: first argument not AT_FDCWD; unlikely to work");
705 return accessFunc(desc, callnum, process, tc, 1);
708 /// Target readlinkat() handler
711 readlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
715 int dirfd = process->getSyscallArg(tc, index);
716 if (dirfd != OS::TGT_AT_FDCWD)
717 warn("openat: first argument not AT_FDCWD; unlikely to work");
718 return readlinkFunc(desc, callnum, process, tc, 1);
721 /// Target renameat() handler.
724 renameatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
729 int olddirfd = process->getSyscallArg(tc, index);
730 if (olddirfd != OS::TGT_AT_FDCWD)
731 warn("renameat: first argument not AT_FDCWD; unlikely to work");
733 std::string old_name;
735 if (!tc->getMemProxy().tryReadString(old_name,
736 process->getSyscallArg(tc, index)))
739 int newdirfd = process->getSyscallArg(tc, index);
740 if (newdirfd != OS::TGT_AT_FDCWD)
741 warn("renameat: third argument not AT_FDCWD; unlikely to work");
743 std::string new_name;
745 if (!tc->getMemProxy().tryReadString(new_name,
746 process->getSyscallArg(tc, index)))
749 // Adjust path for current working directory
750 old_name = process->fullPath(old_name);
751 new_name = process->fullPath(new_name);
753 int result = rename(old_name.c_str(), new_name.c_str());
754 return (result == -1) ? -errno : result;
757 /// Target sysinfo() handler.
760 sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
765 TypedBufferArg<typename OS::tgt_sysinfo>
766 sysinfo(process->getSyscallArg(tc, index));
768 sysinfo->uptime = seconds_since_epoch;
769 sysinfo->totalram = process->system->memSize();
770 sysinfo->mem_unit = 1;
772 sysinfo.copyOut(tc->getMemProxy());
777 /// Target chmod() handler.
780 chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
786 if (!tc->getMemProxy().tryReadString(path,
787 process->getSyscallArg(tc, index))) {
791 uint32_t mode = process->getSyscallArg(tc, index);
794 // XXX translate mode flags via OS::something???
797 // Adjust path for current working directory
798 path = process->fullPath(path);
801 int result = chmod(path.c_str(), hostMode);
809 /// Target fchmod() handler.
812 fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
816 int tgt_fd = process->getSyscallArg(tc, index);
817 uint32_t mode = process->getSyscallArg(tc, index);
819 int sim_fd = process->getSimFD(tgt_fd);
825 // XXX translate mode flags via OS::someting???
829 int result = fchmod(sim_fd, hostMode);
836 /// Target mremap() handler.
839 mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc)
842 Addr start = process->getSyscallArg(tc, index);
843 uint64_t old_length = process->getSyscallArg(tc, index);
844 uint64_t new_length = process->getSyscallArg(tc, index);
845 uint64_t flags = process->getSyscallArg(tc, index);
846 uint64_t provided_address = 0;
847 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
849 if (use_provided_address)
850 provided_address = process->getSyscallArg(tc, index);
852 if ((start % TheISA::PageBytes != 0) ||
853 (provided_address % TheISA::PageBytes != 0)) {
854 warn("mremap failing: arguments not page aligned");
858 new_length = roundUp(new_length, TheISA::PageBytes);
860 if (new_length > old_length) {
861 if ((start + old_length) == process->mmap_end &&
862 (!use_provided_address || provided_address == start)) {
863 uint64_t diff = new_length - old_length;
864 process->allocateMem(process->mmap_end, diff);
865 process->mmap_end += diff;
868 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
869 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
872 uint64_t new_start = use_provided_address ?
873 provided_address : process->mmap_end;
874 process->pTable->remap(start, old_length, new_start);
875 warn("mremapping to new vaddr %08p-%08p, adding %d\n",
876 new_start, new_start + new_length,
877 new_length - old_length);
878 // add on the remaining unallocated pages
879 process->allocateMem(new_start + old_length,
880 new_length - old_length,
881 use_provided_address /* clobber */);
882 if (!use_provided_address)
883 process->mmap_end += new_length;
884 if (use_provided_address &&
885 new_start + new_length > process->mmap_end) {
886 // something fishy going on here, at least notify the user
887 // @todo: increase mmap_end?
888 warn("mmap region limit exceeded with MREMAP_FIXED\n");
890 warn("returning %08p as start\n", new_start);
895 if (use_provided_address && provided_address != start)
896 process->pTable->remap(start, new_length, provided_address);
897 process->pTable->unmap(start + new_length, old_length - new_length);
898 return use_provided_address ? provided_address : start;
902 /// Target stat() handler.
905 statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
911 if (!tc->getMemProxy().tryReadString(path,
912 process->getSyscallArg(tc, index))) {
915 Addr bufPtr = process->getSyscallArg(tc, index);
917 // Adjust path for current working directory
918 path = process->fullPath(path);
921 int result = stat(path.c_str(), &hostBuf);
926 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
932 /// Target stat64() handler.
935 stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
941 if (!tc->getMemProxy().tryReadString(path,
942 process->getSyscallArg(tc, index)))
944 Addr bufPtr = process->getSyscallArg(tc, index);
946 // Adjust path for current working directory
947 path = process->fullPath(path);
951 int result = stat(path.c_str(), &hostBuf);
953 struct stat64 hostBuf;
954 int result = stat64(path.c_str(), &hostBuf);
960 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
966 /// Target fstatat64() handler.
969 fstatat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
973 int dirfd = process->getSyscallArg(tc, index);
974 if (dirfd != OS::TGT_AT_FDCWD)
975 warn("fstatat64: first argument not AT_FDCWD; unlikely to work");
978 if (!tc->getMemProxy().tryReadString(path,
979 process->getSyscallArg(tc, index)))
981 Addr bufPtr = process->getSyscallArg(tc, index);
983 // Adjust path for current working directory
984 path = process->fullPath(path);
988 int result = stat(path.c_str(), &hostBuf);
990 struct stat64 hostBuf;
991 int result = stat64(path.c_str(), &hostBuf);
997 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1003 /// Target fstat64() handler.
1006 fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1010 int tgt_fd = process->getSyscallArg(tc, index);
1011 Addr bufPtr = process->getSyscallArg(tc, index);
1013 int sim_fd = process->getSimFD(tgt_fd);
1018 struct stat hostBuf;
1019 int result = fstat(sim_fd, &hostBuf);
1021 struct stat64 hostBuf;
1022 int result = fstat64(sim_fd, &hostBuf);
1028 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1034 /// Target lstat() handler.
1037 lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1043 if (!tc->getMemProxy().tryReadString(path,
1044 process->getSyscallArg(tc, index))) {
1047 Addr bufPtr = process->getSyscallArg(tc, index);
1049 // Adjust path for current working directory
1050 path = process->fullPath(path);
1052 struct stat hostBuf;
1053 int result = lstat(path.c_str(), &hostBuf);
1058 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1063 /// Target lstat64() handler.
1066 lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1072 if (!tc->getMemProxy().tryReadString(path,
1073 process->getSyscallArg(tc, index))) {
1076 Addr bufPtr = process->getSyscallArg(tc, index);
1078 // Adjust path for current working directory
1079 path = process->fullPath(path);
1082 struct stat hostBuf;
1083 int result = lstat(path.c_str(), &hostBuf);
1085 struct stat64 hostBuf;
1086 int result = lstat64(path.c_str(), &hostBuf);
1092 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1097 /// Target fstat() handler.
1100 fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1104 int tgt_fd = process->getSyscallArg(tc, index);
1105 Addr bufPtr = process->getSyscallArg(tc, index);
1107 DPRINTF_SYSCALL(Verbose, "fstat(%d, ...)\n", tgt_fd);
1109 int sim_fd = process->getSimFD(tgt_fd);
1113 struct stat hostBuf;
1114 int result = fstat(sim_fd, &hostBuf);
1119 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1125 /// Target statfs() handler.
1128 statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1132 warn("Host OS cannot support calls to statfs. Ignoring syscall");
1137 if (!tc->getMemProxy().tryReadString(path,
1138 process->getSyscallArg(tc, index))) {
1141 Addr bufPtr = process->getSyscallArg(tc, index);
1143 // Adjust path for current working directory
1144 path = process->fullPath(path);
1146 struct statfs hostBuf;
1147 int result = statfs(path.c_str(), &hostBuf);
1152 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1158 /// Target fstatfs() handler.
1161 fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1165 int tgt_fd = process->getSyscallArg(tc, index);
1166 Addr bufPtr = process->getSyscallArg(tc, index);
1168 int sim_fd = process->getSimFD(tgt_fd);
1172 struct statfs hostBuf;
1173 int result = fstatfs(sim_fd, &hostBuf);
1178 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1184 /// Target writev() handler.
1187 writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1191 int tgt_fd = process->getSyscallArg(tc, index);
1193 int sim_fd = process->getSimFD(tgt_fd);
1197 SETranslatingPortProxy &p = tc->getMemProxy();
1198 uint64_t tiov_base = process->getSyscallArg(tc, index);
1199 size_t count = process->getSyscallArg(tc, index);
1200 struct iovec hiov[count];
1201 for (size_t i = 0; i < count; ++i) {
1202 typename OS::tgt_iovec tiov;
1204 p.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1205 (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
1206 hiov[i].iov_len = TheISA::gtoh(tiov.iov_len);
1207 hiov[i].iov_base = new char [hiov[i].iov_len];
1208 p.readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
1212 int result = writev(sim_fd, hiov, count);
1214 for (size_t i = 0; i < count; ++i)
1215 delete [] (char *)hiov[i].iov_base;
1223 /// Real mmap handler.
1226 mmapImpl(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
1230 Addr start = p->getSyscallArg(tc, index);
1231 uint64_t length = p->getSyscallArg(tc, index);
1232 int prot = p->getSyscallArg(tc, index);
1233 int tgt_flags = p->getSyscallArg(tc, index);
1234 int tgt_fd = p->getSyscallArg(tc, index);
1235 int offset = p->getSyscallArg(tc, index);
1238 offset *= TheISA::PageBytes;
1240 if (start & (TheISA::PageBytes - 1) ||
1241 offset & (TheISA::PageBytes - 1) ||
1242 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1243 tgt_flags & OS::TGT_MAP_SHARED) ||
1244 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1245 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1250 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1251 // With shared mmaps, there are two cases to consider:
1252 // 1) anonymous: writes should modify the mapping and this should be
1253 // visible to observers who share the mapping. Currently, it's
1254 // difficult to update the shared mapping because there's no
1255 // structure which maintains information about the which virtual
1256 // memory areas are shared. If that structure existed, it would be
1257 // possible to make the translations point to the same frames.
1258 // 2) file-backed: writes should modify the mapping and the file
1259 // which is backed by the mapping. The shared mapping problem is the
1260 // same as what was mentioned about the anonymous mappings. For
1261 // file-backed mappings, the writes to the file are difficult
1262 // because it requires syncing what the mapping holds with the file
1263 // that resides on the host system. So, any write on a real system
1264 // would cause the change to be propagated to the file mapping at
1265 // some point in the future (the inode is tracked along with the
1266 // mapping). This isn't guaranteed to always happen, but it usually
1267 // works well enough. The guarantee is provided by the msync system
1268 // call. We could force the change through with shared mappings with
1269 // a call to msync, but that again would require more information
1270 // than we currently maintain.
1271 warn("mmap: writing to shared mmap region is currently "
1272 "unsupported. The write succeeds on the target, but it "
1273 "will not be propagated to the host or shared mappings");
1276 length = roundUp(length, TheISA::PageBytes);
1279 uint8_t *pmap = nullptr;
1280 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1281 // Check for EmulatedDriver mmap
1282 FDEntry *fde = p->getFDEntry(tgt_fd);
1286 if (fde->driver != NULL) {
1287 return fde->driver->mmap(p, tc, start, length, prot,
1288 tgt_flags, tgt_fd, offset);
1295 pmap = (decltype(pmap))mmap(NULL, length, PROT_READ, MAP_PRIVATE,
1298 if (pmap == (decltype(pmap))-1) {
1299 warn("mmap: failed to map file into host address space");
1304 // Extend global mmap region if necessary. Note that we ignore the
1305 // start address unless MAP_FIXED is specified.
1306 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1307 start = p->mmapGrowsDown() ? p->mmap_end - length : p->mmap_end;
1308 p->mmap_end = p->mmapGrowsDown() ? start : p->mmap_end + length;
1311 DPRINTF_SYSCALL(Verbose, " mmap range is 0x%x - 0x%x\n",
1312 start, start + length - 1);
1314 // We only allow mappings to overwrite existing mappings if
1315 // TGT_MAP_FIXED is set. Otherwise it shouldn't be a problem
1316 // because we ignore the start hint if TGT_MAP_FIXED is not set.
1317 int clobber = tgt_flags & OS::TGT_MAP_FIXED;
1319 for (auto tc : p->system->threadContexts) {
1320 // If we might be overwriting old mappings, we need to
1321 // invalidate potentially stale mappings out of the TLBs.
1322 tc->getDTBPtr()->flushAll();
1323 tc->getITBPtr()->flushAll();
1327 // Allocate physical memory and map it in. If the page table is already
1328 // mapped and clobber is not set, the simulator will issue throw a
1329 // fatal and bail out of the simulation.
1330 p->allocateMem(start, length, clobber);
1332 // Transfer content into target address space.
1333 SETranslatingPortProxy &tp = tc->getMemProxy();
1334 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1335 // In general, we should zero the mapped area for anonymous mappings,
1336 // with something like:
1337 // tp.memsetBlob(start, 0, length);
1338 // However, given that we don't support sparse mappings, and
1339 // some applications can map a couple of gigabytes of space
1340 // (intending sparse usage), that can get painfully expensive.
1341 // Fortunately, since we don't properly implement munmap either,
1342 // there's no danger of remapping used memory, so for now all
1343 // newly mapped memory should already be zeroed so we can skip it.
1345 // It is possible to mmap an area larger than a file, however
1346 // accessing unmapped portions the system triggers a "Bus error"
1347 // on the host. We must know when to stop copying the file from
1348 // the host into the target address space.
1349 struct stat file_stat;
1350 if (fstat(sim_fd, &file_stat) > 0)
1351 fatal("mmap: cannot stat file");
1353 // Copy the portion of the file that is resident. This requires
1354 // checking both the mmap size and the filesize that we are
1355 // trying to mmap into this space; the mmap size also depends
1356 // on the specified offset into the file.
1357 uint64_t size = std::min((uint64_t)file_stat.st_size - offset,
1359 tp.writeBlob(start, pmap, size);
1361 // Cleanup the mmap region before exiting this function.
1362 munmap(pmap, length);
1364 // Maintain the symbol table for dynamic executables.
1365 // The loader will call mmap to map the images into its address
1366 // space and we intercept that here. We can verify that we are
1367 // executing inside the loader by checking the program counter value.
1368 // XXX: with multiprogrammed workloads or multi-node configurations,
1369 // this will not work since there is a single global symbol table.
1370 ObjectFile *interpreter = p->getInterpreter();
1372 Addr text_start = interpreter->textBase();
1373 Addr text_end = text_start + interpreter->textSize();
1375 Addr pc = tc->pcState().pc();
1377 if (pc >= text_start && pc < text_end) {
1378 FDEntry *fde = p->getFDEntry(tgt_fd);
1380 ObjectFile *lib = createObjectFile(fde->filename);
1383 lib->loadAllSymbols(debugSymbolTable,
1384 lib->textBase(), start);
1389 // Note that we do not zero out the remainder of the mapping. This
1390 // is done by a real system, but it probably will not affect
1391 // execution (hopefully).
1399 pwrite64Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1402 int tgt_fd = p->getSyscallArg(tc, index);
1403 Addr bufPtr = p->getSyscallArg(tc, index);
1404 int nbytes = p->getSyscallArg(tc, index);
1405 int offset = p->getSyscallArg(tc, index);
1407 int sim_fd = p->getSimFD(tgt_fd);
1411 BufferArg bufArg(bufPtr, nbytes);
1412 bufArg.copyIn(tc->getMemProxy());
1414 int bytes_written = pwrite(sim_fd, bufArg.bufferPtr(), nbytes, offset);
1416 return (bytes_written == -1) ? -errno : bytes_written;
1419 /// Target mmap() handler.
1422 mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1424 return mmapImpl<OS>(desc, num, p, tc, false);
1427 /// Target mmap2() handler.
1430 mmap2Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1432 return mmapImpl<OS>(desc, num, p, tc, true);
1435 /// Target getrlimit() handler.
1438 getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1442 unsigned resource = process->getSyscallArg(tc, index);
1443 TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
1446 case OS::TGT_RLIMIT_STACK:
1447 // max stack size in bytes: make up a number (8MB for now)
1448 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1449 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1450 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1453 case OS::TGT_RLIMIT_DATA:
1454 // max data segment size in bytes: make up a number
1455 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1456 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1457 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1461 warn("getrlimit: unimplemented resource %d", resource);
1466 rlp.copyOut(tc->getMemProxy());
1470 /// Target clock_gettime() function.
1473 clock_gettimeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1476 //int clk_id = p->getSyscallArg(tc, index);
1477 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1479 getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
1480 tp->tv_sec += seconds_since_epoch;
1481 tp->tv_sec = TheISA::htog(tp->tv_sec);
1482 tp->tv_nsec = TheISA::htog(tp->tv_nsec);
1484 tp.copyOut(tc->getMemProxy());
1489 /// Target clock_getres() function.
1492 clock_getresFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1495 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1497 // Set resolution at ns, which is what clock_gettime() returns
1501 tp.copyOut(tc->getMemProxy());
1506 /// Target gettimeofday() handler.
1509 gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1513 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1515 getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
1516 tp->tv_sec += seconds_since_epoch;
1517 tp->tv_sec = TheISA::htog(tp->tv_sec);
1518 tp->tv_usec = TheISA::htog(tp->tv_usec);
1520 tp.copyOut(tc->getMemProxy());
1526 /// Target utimes() handler.
1529 utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1535 if (!tc->getMemProxy().tryReadString(path,
1536 process->getSyscallArg(tc, index))) {
1540 TypedBufferArg<typename OS::timeval [2]>
1541 tp(process->getSyscallArg(tc, index));
1542 tp.copyIn(tc->getMemProxy());
1544 struct timeval hostTimeval[2];
1545 for (int i = 0; i < 2; ++i)
1547 hostTimeval[i].tv_sec = TheISA::gtoh((*tp)[i].tv_sec);
1548 hostTimeval[i].tv_usec = TheISA::gtoh((*tp)[i].tv_usec);
1551 // Adjust path for current working directory
1552 path = process->fullPath(path);
1554 int result = utimes(path.c_str(), hostTimeval);
1561 /// Target getrusage() function.
1564 getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1568 int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
1569 TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
1571 rup->ru_utime.tv_sec = 0;
1572 rup->ru_utime.tv_usec = 0;
1573 rup->ru_stime.tv_sec = 0;
1574 rup->ru_stime.tv_usec = 0;
1582 rup->ru_inblock = 0;
1583 rup->ru_oublock = 0;
1586 rup->ru_nsignals = 0;
1591 case OS::TGT_RUSAGE_SELF:
1592 getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1593 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1594 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1597 case OS::TGT_RUSAGE_CHILDREN:
1598 // do nothing. We have no child processes, so they take no time.
1602 // don't really handle THREAD or CHILDREN, but just warn and
1604 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
1608 rup.copyOut(tc->getMemProxy());
1613 /// Target times() function.
1616 timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1620 TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
1622 // Fill in the time structure (in clocks)
1623 int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s;
1624 bufp->tms_utime = clocks;
1625 bufp->tms_stime = 0;
1626 bufp->tms_cutime = 0;
1627 bufp->tms_cstime = 0;
1629 // Convert to host endianness
1630 bufp->tms_utime = TheISA::htog(bufp->tms_utime);
1633 bufp.copyOut(tc->getMemProxy());
1635 // Return clock ticks since system boot
1639 /// Target time() function.
1642 timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1645 typename OS::time_t sec, usec;
1646 getElapsedTimeMicro(sec, usec);
1647 sec += seconds_since_epoch;
1650 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1652 typename OS::time_t t = sec;
1653 t = TheISA::htog(t);
1654 SETranslatingPortProxy &p = tc->getMemProxy();
1655 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1661 #endif // __SIM_SYSCALL_EMUL_HH__