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>
74 #include <sys/mount.h>
83 #include "base/intmath.hh"
84 #include "base/loader/object_file.hh"
85 #include "base/misc.hh"
86 #include "base/trace.hh"
87 #include "base/types.hh"
88 #include "config/the_isa.hh"
89 #include "cpu/base.hh"
90 #include "cpu/thread_context.hh"
91 #include "mem/page_table.hh"
92 #include "sim/emul_driver.hh"
93 #include "sim/process.hh"
94 #include "sim/syscall_debug_macros.hh"
95 #include "sim/syscall_emul_buf.hh"
96 #include "sim/syscall_return.hh"
100 //////////////////////////////////////////////////////////////////////
102 // The following emulation functions are generic enough that they
103 // don't need to be recompiled for different emulated OS's. They are
104 // defined in sim/syscall_emul.cc.
106 //////////////////////////////////////////////////////////////////////
109 /// Handler for unimplemented syscalls that we haven't thought about.
110 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
111 Process *p, ThreadContext *tc);
113 /// Handler for unimplemented syscalls that we never intend to
114 /// implement (signal handling, etc.) and should not affect the correct
115 /// behavior of the program. Print a warning only if the appropriate
116 /// trace flag is enabled. Return success to the target program.
117 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
118 Process *p, ThreadContext *tc);
120 // Target fallocateFunc() handler.
121 SyscallReturn fallocateFunc(SyscallDesc *desc, int num,
122 Process *p, ThreadContext *tc);
124 /// Target exit() handler: terminate current context.
125 SyscallReturn exitFunc(SyscallDesc *desc, int num,
126 Process *p, ThreadContext *tc);
128 /// Target exit_group() handler: terminate simulation. (exit all threads)
129 SyscallReturn exitGroupFunc(SyscallDesc *desc, int num,
130 Process *p, ThreadContext *tc);
132 /// Target getpagesize() handler.
133 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
134 Process *p, ThreadContext *tc);
136 /// Target brk() handler: set brk address.
137 SyscallReturn brkFunc(SyscallDesc *desc, int num,
138 Process *p, ThreadContext *tc);
140 /// Target close() handler.
141 SyscallReturn closeFunc(SyscallDesc *desc, int num,
142 Process *p, ThreadContext *tc);
144 /// Target read() handler.
145 SyscallReturn readFunc(SyscallDesc *desc, int num,
146 Process *p, ThreadContext *tc);
148 /// Target write() handler.
149 SyscallReturn writeFunc(SyscallDesc *desc, int num,
150 Process *p, ThreadContext *tc);
152 /// Target lseek() handler.
153 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
154 Process *p, ThreadContext *tc);
156 /// Target _llseek() handler.
157 SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
158 Process *p, ThreadContext *tc);
160 /// Target munmap() handler.
161 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
162 Process *p, ThreadContext *tc);
164 /// Target gethostname() handler.
165 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
166 Process *p, ThreadContext *tc);
168 /// Target getcwd() handler.
169 SyscallReturn getcwdFunc(SyscallDesc *desc, int num,
170 Process *p, ThreadContext *tc);
172 /// Target readlink() handler.
173 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
174 Process *p, ThreadContext *tc,
176 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
177 Process *p, ThreadContext *tc);
179 /// Target unlink() handler.
180 SyscallReturn unlinkHelper(SyscallDesc *desc, int num,
181 Process *p, ThreadContext *tc,
183 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
184 Process *p, ThreadContext *tc);
186 /// Target mkdir() handler.
187 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
188 Process *p, ThreadContext *tc);
190 /// Target rename() handler.
191 SyscallReturn renameFunc(SyscallDesc *desc, int num,
192 Process *p, ThreadContext *tc);
195 /// Target truncate() handler.
196 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
197 Process *p, ThreadContext *tc);
200 /// Target ftruncate() handler.
201 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
202 Process *p, ThreadContext *tc);
205 /// Target truncate64() handler.
206 SyscallReturn truncate64Func(SyscallDesc *desc, int num,
207 Process *p, ThreadContext *tc);
209 /// Target ftruncate64() handler.
210 SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
211 Process *p, ThreadContext *tc);
214 /// Target umask() handler.
215 SyscallReturn umaskFunc(SyscallDesc *desc, int num,
216 Process *p, ThreadContext *tc);
219 /// Target chown() handler.
220 SyscallReturn chownFunc(SyscallDesc *desc, int num,
221 Process *p, ThreadContext *tc);
224 /// Target fchown() handler.
225 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
226 Process *p, ThreadContext *tc);
228 /// Target dup() handler.
229 SyscallReturn dupFunc(SyscallDesc *desc, int num,
230 Process *process, ThreadContext *tc);
232 /// Target fnctl() handler.
233 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
234 Process *process, ThreadContext *tc);
236 /// Target fcntl64() handler.
237 SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
238 Process *process, ThreadContext *tc);
240 /// Target setuid() handler.
241 SyscallReturn setuidFunc(SyscallDesc *desc, int num,
242 Process *p, ThreadContext *tc);
244 /// Target getpid() handler.
245 SyscallReturn getpidFunc(SyscallDesc *desc, int num,
246 Process *p, ThreadContext *tc);
248 /// Target getuid() handler.
249 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
250 Process *p, ThreadContext *tc);
252 /// Target getgid() handler.
253 SyscallReturn getgidFunc(SyscallDesc *desc, int num,
254 Process *p, ThreadContext *tc);
256 /// Target getppid() handler.
257 SyscallReturn getppidFunc(SyscallDesc *desc, int num,
258 Process *p, ThreadContext *tc);
260 /// Target geteuid() handler.
261 SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
262 Process *p, ThreadContext *tc);
264 /// Target getegid() handler.
265 SyscallReturn getegidFunc(SyscallDesc *desc, int num,
266 Process *p, ThreadContext *tc);
268 /// Target clone() handler.
269 SyscallReturn cloneFunc(SyscallDesc *desc, int num,
270 Process *p, ThreadContext *tc);
272 /// Target access() handler
273 SyscallReturn accessFunc(SyscallDesc *desc, int num,
274 Process *p, ThreadContext *tc);
275 SyscallReturn accessFunc(SyscallDesc *desc, int num,
276 Process *p, ThreadContext *tc,
279 /// Futex system call
280 /// Implemented by Daniel Sanchez
281 /// Used by printf's in multi-threaded apps
284 futexFunc(SyscallDesc *desc, int callnum, Process *process,
290 int index_timeout = 3;
292 uint64_t uaddr = process->getSyscallArg(tc, index_uaddr);
293 int op = process->getSyscallArg(tc, index_op);
294 int val = process->getSyscallArg(tc, index_val);
295 uint64_t timeout = process->getSyscallArg(tc, index_timeout);
297 std::map<uint64_t, std::list<ThreadContext *> * >
298 &futex_map = tc->getSystemPtr()->futexMap;
300 DPRINTF(SyscallVerbose, "In sys_futex: Address=%llx, op=%d, val=%d\n",
303 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
305 if (op == OS::TGT_FUTEX_WAIT) {
307 warn("sys_futex: FUTEX_WAIT with non-null timeout unimplemented;"
308 "we'll wait indefinitely");
311 uint8_t *buf = new uint8_t[sizeof(int)];
312 tc->getMemProxy().readBlob((Addr)uaddr, buf, (int)sizeof(int));
313 int mem_val = *((int *)buf);
316 if (val != mem_val) {
317 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, read: %d, "
318 "expected: %d\n", mem_val, val);
319 return -OS::TGT_EWOULDBLOCK;
322 // Queue the thread context
323 std::list<ThreadContext *> * tcWaitList;
324 if (futex_map.count(uaddr)) {
325 tcWaitList = futex_map.find(uaddr)->second;
327 tcWaitList = new std::list<ThreadContext *>();
328 futex_map.insert(std::pair< uint64_t,
329 std::list<ThreadContext *> * >(uaddr, tcWaitList));
331 tcWaitList->push_back(tc);
332 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAIT, suspending calling "
336 } else if (op == OS::TGT_FUTEX_WAKE){
338 std::list<ThreadContext *> * tcWaitList;
339 if (futex_map.count(uaddr)) {
340 tcWaitList = futex_map.find(uaddr)->second;
341 while (tcWaitList->size() > 0 && wokenUp < val) {
342 tcWaitList->front()->activate();
343 tcWaitList->pop_front();
346 if (tcWaitList->empty()) {
347 futex_map.erase(uaddr);
351 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, activated %d waiting "
352 "thread contexts\n", wokenUp);
355 warn("sys_futex: op %d is not implemented, just returning...", op);
362 /// Pseudo Funcs - These functions use a different return convension,
363 /// returning a second value in a register other than the normal return register
364 SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
365 Process *process, ThreadContext *tc);
367 /// Target getpidPseudo() handler.
368 SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
369 Process *p, ThreadContext *tc);
371 /// Target getuidPseudo() handler.
372 SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
373 Process *p, ThreadContext *tc);
375 /// Target getgidPseudo() handler.
376 SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
377 Process *p, ThreadContext *tc);
380 /// A readable name for 1,000,000, for converting microseconds to seconds.
381 const int one_million = 1000000;
382 /// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
383 const int one_billion = 1000000000;
385 /// Approximate seconds since the epoch (1/1/1970). About a billion,
386 /// by my reckoning. We want to keep this a constant (not use the
387 /// real-world time) to keep simulations repeatable.
388 const unsigned seconds_since_epoch = 1000000000;
390 /// Helper function to convert current elapsed time to seconds and
392 template <class T1, class T2>
394 getElapsedTimeMicro(T1 &sec, T2 &usec)
396 uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
397 sec = elapsed_usecs / one_million;
398 usec = elapsed_usecs % one_million;
401 /// Helper function to convert current elapsed time to seconds and
403 template <class T1, class T2>
405 getElapsedTimeNano(T1 &sec, T2 &nsec)
407 uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
408 sec = elapsed_nsecs / one_billion;
409 nsec = elapsed_nsecs % one_billion;
412 //////////////////////////////////////////////////////////////////////
414 // The following emulation functions are generic, but need to be
415 // templated to account for differences in types, constants, etc.
417 //////////////////////////////////////////////////////////////////////
419 typedef struct statfs hst_statfs;
421 typedef struct stat hst_stat;
422 typedef struct stat hst_stat64;
424 typedef struct stat hst_stat;
425 typedef struct stat64 hst_stat64;
428 //// Helper function to convert a host stat buffer to a target stat
429 //// buffer. Also copies the target buffer out to the simulated
430 //// memory space. Used by stat(), fstat(), and lstat().
432 template <typename target_stat, typename host_stat>
434 convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
436 using namespace TheISA;
441 tgt->st_dev = host->st_dev;
442 tgt->st_dev = TheISA::htog(tgt->st_dev);
443 tgt->st_ino = host->st_ino;
444 tgt->st_ino = TheISA::htog(tgt->st_ino);
445 tgt->st_mode = host->st_mode;
447 // Claim to be a character device
448 tgt->st_mode &= ~S_IFMT; // Clear S_IFMT
449 tgt->st_mode |= S_IFCHR; // Set S_IFCHR
451 tgt->st_mode = TheISA::htog(tgt->st_mode);
452 tgt->st_nlink = host->st_nlink;
453 tgt->st_nlink = TheISA::htog(tgt->st_nlink);
454 tgt->st_uid = host->st_uid;
455 tgt->st_uid = TheISA::htog(tgt->st_uid);
456 tgt->st_gid = host->st_gid;
457 tgt->st_gid = TheISA::htog(tgt->st_gid);
459 tgt->st_rdev = 0x880d;
461 tgt->st_rdev = host->st_rdev;
462 tgt->st_rdev = TheISA::htog(tgt->st_rdev);
463 tgt->st_size = host->st_size;
464 tgt->st_size = TheISA::htog(tgt->st_size);
465 tgt->st_atimeX = host->st_atime;
466 tgt->st_atimeX = TheISA::htog(tgt->st_atimeX);
467 tgt->st_mtimeX = host->st_mtime;
468 tgt->st_mtimeX = TheISA::htog(tgt->st_mtimeX);
469 tgt->st_ctimeX = host->st_ctime;
470 tgt->st_ctimeX = TheISA::htog(tgt->st_ctimeX);
471 // Force the block size to be 8k. This helps to ensure buffered io works
472 // consistently across different hosts.
473 tgt->st_blksize = 0x2000;
474 tgt->st_blksize = TheISA::htog(tgt->st_blksize);
475 tgt->st_blocks = host->st_blocks;
476 tgt->st_blocks = TheISA::htog(tgt->st_blocks);
481 template <typename target_stat, typename host_stat64>
483 convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
485 using namespace TheISA;
487 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
488 #if defined(STAT_HAVE_NSEC)
489 tgt->st_atime_nsec = host->st_atime_nsec;
490 tgt->st_atime_nsec = TheISA::htog(tgt->st_atime_nsec);
491 tgt->st_mtime_nsec = host->st_mtime_nsec;
492 tgt->st_mtime_nsec = TheISA::htog(tgt->st_mtime_nsec);
493 tgt->st_ctime_nsec = host->st_ctime_nsec;
494 tgt->st_ctime_nsec = TheISA::htog(tgt->st_ctime_nsec);
496 tgt->st_atime_nsec = 0;
497 tgt->st_mtime_nsec = 0;
498 tgt->st_ctime_nsec = 0;
502 //Here are a couple convenience functions
505 copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
506 hst_stat *host, bool fakeTTY = false)
508 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
509 tgt_stat_buf tgt(addr);
510 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
516 copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
517 hst_stat64 *host, bool fakeTTY = false)
519 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
520 tgt_stat_buf tgt(addr);
521 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
527 copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr,
530 TypedBufferArg<typename OS::tgt_statfs> tgt(addr);
532 tgt->f_type = TheISA::htog(host->f_type);
533 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
534 tgt->f_bsize = TheISA::htog(host->f_iosize);
536 tgt->f_bsize = TheISA::htog(host->f_bsize);
538 tgt->f_blocks = TheISA::htog(host->f_blocks);
539 tgt->f_bfree = TheISA::htog(host->f_bfree);
540 tgt->f_bavail = TheISA::htog(host->f_bavail);
541 tgt->f_files = TheISA::htog(host->f_files);
542 tgt->f_ffree = TheISA::htog(host->f_ffree);
543 memcpy(&tgt->f_fsid, &host->f_fsid, sizeof(host->f_fsid));
544 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
545 tgt->f_namelen = TheISA::htog(host->f_namemax);
546 tgt->f_frsize = TheISA::htog(host->f_bsize);
547 #elif defined(__APPLE__)
551 tgt->f_namelen = TheISA::htog(host->f_namelen);
552 tgt->f_frsize = TheISA::htog(host->f_frsize);
554 #if defined(__linux__)
555 memcpy(&tgt->f_spare, &host->f_spare, sizeof(host->f_spare));
558 * The fields are different sizes per OS. Don't bother with
559 * f_spare or f_reserved on non-Linux for now.
561 memset(&tgt->f_spare, 0, sizeof(tgt->f_spare));
567 /// Target ioctl() handler. For the most part, programs call ioctl()
568 /// only to find out if their stdout is a tty, to determine whether to
569 /// do line or block buffering. We always claim that output fds are
570 /// not TTYs to provide repeatable results.
573 ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
577 int tgt_fd = process->getSyscallArg(tc, index);
578 unsigned req = process->getSyscallArg(tc, index);
580 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
582 FDEntry *fde = process->getFDEntry(tgt_fd);
585 // doesn't map to any simulator fd: not a valid target fd
589 if (fde->driver != NULL) {
590 return fde->driver->ioctl(process, tc, req);
593 if (OS::isTtyReq(req)) {
597 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n",
598 tgt_fd, req, tc->pcState());
604 openFunc(SyscallDesc *desc, int callnum, Process *process,
605 ThreadContext *tc, int index)
609 if (!tc->getMemProxy().tryReadString(path,
610 process->getSyscallArg(tc, index)))
613 int tgtFlags = process->getSyscallArg(tc, index);
614 int mode = process->getSyscallArg(tc, index);
617 // translate open flags
618 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
619 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
620 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
621 hostFlags |= OS::openFlagTable[i].hostFlag;
625 // any target flags left?
627 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
630 hostFlags |= O_BINARY;
633 // Adjust path for current working directory
634 path = process->fullPath(path);
636 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
638 if (startswith(path, "/dev/")) {
639 std::string filename = path.substr(strlen("/dev/"));
640 if (filename == "sysdev0") {
641 // This is a memory-mapped high-resolution timer device on Alpha.
642 // We don't support it, so just punt.
643 warn("Ignoring open(%s, ...)\n", path);
647 EmulatedDriver *drv = process->findDriver(filename);
649 // the driver's open method will allocate a fd from the
650 // process if necessary.
651 return drv->open(process, tc, mode, hostFlags);
654 // fall through here for pass through to host devices, such as
660 if (startswith(path, "/proc/") || startswith(path, "/system/") ||
661 startswith(path, "/platform/") || startswith(path, "/sys/")) {
662 // It's a proc/sys entry and requires special handling
663 fd = OS::openSpecialFile(path, process, tc);
664 local_errno = ENOENT;
667 fd = open(path.c_str(), hostFlags, mode);
674 return process->allocFD(fd, path.c_str(), hostFlags, mode, false);
677 /// Target open() handler.
680 openFunc(SyscallDesc *desc, int callnum, Process *process,
683 return openFunc<OS>(desc, callnum, process, tc, 0);
686 /// Target openat() handler.
689 openatFunc(SyscallDesc *desc, int callnum, Process *process,
693 int dirfd = process->getSyscallArg(tc, index);
694 if (dirfd != OS::TGT_AT_FDCWD)
695 warn("openat: first argument not AT_FDCWD; unlikely to work");
696 return openFunc<OS>(desc, callnum, process, tc, 1);
699 /// Target unlinkat() handler.
702 unlinkatFunc(SyscallDesc *desc, int callnum, Process *process,
706 int dirfd = process->getSyscallArg(tc, index);
707 if (dirfd != OS::TGT_AT_FDCWD)
708 warn("unlinkat: first argument not AT_FDCWD; unlikely to work");
710 return unlinkHelper(desc, callnum, process, tc, 1);
713 /// Target facessat() handler
716 faccessatFunc(SyscallDesc *desc, int callnum, Process *process,
720 int dirfd = process->getSyscallArg(tc, index);
721 if (dirfd != OS::TGT_AT_FDCWD)
722 warn("faccessat: first argument not AT_FDCWD; unlikely to work");
723 return accessFunc(desc, callnum, process, tc, 1);
726 /// Target readlinkat() handler
729 readlinkatFunc(SyscallDesc *desc, int callnum, Process *process,
733 int dirfd = process->getSyscallArg(tc, index);
734 if (dirfd != OS::TGT_AT_FDCWD)
735 warn("openat: first argument not AT_FDCWD; unlikely to work");
736 return readlinkFunc(desc, callnum, process, tc, 1);
739 /// Target renameat() handler.
742 renameatFunc(SyscallDesc *desc, int callnum, Process *process,
747 int olddirfd = process->getSyscallArg(tc, index);
748 if (olddirfd != OS::TGT_AT_FDCWD)
749 warn("renameat: first argument not AT_FDCWD; unlikely to work");
751 std::string old_name;
753 if (!tc->getMemProxy().tryReadString(old_name,
754 process->getSyscallArg(tc, index)))
757 int newdirfd = process->getSyscallArg(tc, index);
758 if (newdirfd != OS::TGT_AT_FDCWD)
759 warn("renameat: third argument not AT_FDCWD; unlikely to work");
761 std::string new_name;
763 if (!tc->getMemProxy().tryReadString(new_name,
764 process->getSyscallArg(tc, index)))
767 // Adjust path for current working directory
768 old_name = process->fullPath(old_name);
769 new_name = process->fullPath(new_name);
771 int result = rename(old_name.c_str(), new_name.c_str());
772 return (result == -1) ? -errno : result;
775 /// Target sysinfo() handler.
778 sysinfoFunc(SyscallDesc *desc, int callnum, Process *process,
783 TypedBufferArg<typename OS::tgt_sysinfo>
784 sysinfo(process->getSyscallArg(tc, index));
786 sysinfo->uptime = seconds_since_epoch;
787 sysinfo->totalram = process->system->memSize();
788 sysinfo->mem_unit = 1;
790 sysinfo.copyOut(tc->getMemProxy());
795 /// Target chmod() handler.
798 chmodFunc(SyscallDesc *desc, int callnum, Process *process,
804 if (!tc->getMemProxy().tryReadString(path,
805 process->getSyscallArg(tc, index))) {
809 uint32_t mode = process->getSyscallArg(tc, index);
812 // XXX translate mode flags via OS::something???
815 // Adjust path for current working directory
816 path = process->fullPath(path);
819 int result = chmod(path.c_str(), hostMode);
827 /// Target fchmod() handler.
830 fchmodFunc(SyscallDesc *desc, int callnum, Process *process,
834 int tgt_fd = process->getSyscallArg(tc, index);
835 uint32_t mode = process->getSyscallArg(tc, index);
837 int sim_fd = process->getSimFD(tgt_fd);
843 // XXX translate mode flags via OS::someting???
847 int result = fchmod(sim_fd, hostMode);
854 /// Target mremap() handler.
857 mremapFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
860 Addr start = process->getSyscallArg(tc, index);
861 uint64_t old_length = process->getSyscallArg(tc, index);
862 uint64_t new_length = process->getSyscallArg(tc, index);
863 uint64_t flags = process->getSyscallArg(tc, index);
864 uint64_t provided_address = 0;
865 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
867 if (use_provided_address)
868 provided_address = process->getSyscallArg(tc, index);
870 if ((start % TheISA::PageBytes != 0) ||
871 (provided_address % TheISA::PageBytes != 0)) {
872 warn("mremap failing: arguments not page aligned");
876 new_length = roundUp(new_length, TheISA::PageBytes);
878 if (new_length > old_length) {
879 if ((start + old_length) == process->mmap_end &&
880 (!use_provided_address || provided_address == start)) {
881 uint64_t diff = new_length - old_length;
882 process->allocateMem(process->mmap_end, diff);
883 process->mmap_end += diff;
886 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
887 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
890 uint64_t new_start = use_provided_address ?
891 provided_address : process->mmap_end;
892 process->pTable->remap(start, old_length, new_start);
893 warn("mremapping to new vaddr %08p-%08p, adding %d\n",
894 new_start, new_start + new_length,
895 new_length - old_length);
896 // add on the remaining unallocated pages
897 process->allocateMem(new_start + old_length,
898 new_length - old_length,
899 use_provided_address /* clobber */);
900 if (!use_provided_address)
901 process->mmap_end += new_length;
902 if (use_provided_address &&
903 new_start + new_length > process->mmap_end) {
904 // something fishy going on here, at least notify the user
905 // @todo: increase mmap_end?
906 warn("mmap region limit exceeded with MREMAP_FIXED\n");
908 warn("returning %08p as start\n", new_start);
913 if (use_provided_address && provided_address != start)
914 process->pTable->remap(start, new_length, provided_address);
915 process->pTable->unmap(start + new_length, old_length - new_length);
916 return use_provided_address ? provided_address : start;
920 /// Target stat() handler.
923 statFunc(SyscallDesc *desc, int callnum, Process *process,
929 if (!tc->getMemProxy().tryReadString(path,
930 process->getSyscallArg(tc, index))) {
933 Addr bufPtr = process->getSyscallArg(tc, index);
935 // Adjust path for current working directory
936 path = process->fullPath(path);
939 int result = stat(path.c_str(), &hostBuf);
944 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
950 /// Target stat64() handler.
953 stat64Func(SyscallDesc *desc, int callnum, Process *process,
959 if (!tc->getMemProxy().tryReadString(path,
960 process->getSyscallArg(tc, index)))
962 Addr bufPtr = process->getSyscallArg(tc, index);
964 // Adjust path for current working directory
965 path = process->fullPath(path);
969 int result = stat(path.c_str(), &hostBuf);
971 struct stat64 hostBuf;
972 int result = stat64(path.c_str(), &hostBuf);
978 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
984 /// Target fstatat64() handler.
987 fstatat64Func(SyscallDesc *desc, int callnum, Process *process,
991 int dirfd = process->getSyscallArg(tc, index);
992 if (dirfd != OS::TGT_AT_FDCWD)
993 warn("fstatat64: first argument not AT_FDCWD; unlikely to work");
996 if (!tc->getMemProxy().tryReadString(path,
997 process->getSyscallArg(tc, index)))
999 Addr bufPtr = process->getSyscallArg(tc, index);
1001 // Adjust path for current working directory
1002 path = process->fullPath(path);
1005 struct stat hostBuf;
1006 int result = stat(path.c_str(), &hostBuf);
1008 struct stat64 hostBuf;
1009 int result = stat64(path.c_str(), &hostBuf);
1015 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1021 /// Target fstat64() handler.
1024 fstat64Func(SyscallDesc *desc, int callnum, Process *process,
1028 int tgt_fd = process->getSyscallArg(tc, index);
1029 Addr bufPtr = process->getSyscallArg(tc, index);
1031 int sim_fd = process->getSimFD(tgt_fd);
1036 struct stat hostBuf;
1037 int result = fstat(sim_fd, &hostBuf);
1039 struct stat64 hostBuf;
1040 int result = fstat64(sim_fd, &hostBuf);
1046 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1052 /// Target lstat() handler.
1055 lstatFunc(SyscallDesc *desc, int callnum, Process *process,
1061 if (!tc->getMemProxy().tryReadString(path,
1062 process->getSyscallArg(tc, index))) {
1065 Addr bufPtr = process->getSyscallArg(tc, index);
1067 // Adjust path for current working directory
1068 path = process->fullPath(path);
1070 struct stat hostBuf;
1071 int result = lstat(path.c_str(), &hostBuf);
1076 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1081 /// Target lstat64() handler.
1084 lstat64Func(SyscallDesc *desc, int callnum, Process *process,
1090 if (!tc->getMemProxy().tryReadString(path,
1091 process->getSyscallArg(tc, index))) {
1094 Addr bufPtr = process->getSyscallArg(tc, index);
1096 // Adjust path for current working directory
1097 path = process->fullPath(path);
1100 struct stat hostBuf;
1101 int result = lstat(path.c_str(), &hostBuf);
1103 struct stat64 hostBuf;
1104 int result = lstat64(path.c_str(), &hostBuf);
1110 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1115 /// Target fstat() handler.
1118 fstatFunc(SyscallDesc *desc, int callnum, Process *process,
1122 int tgt_fd = process->getSyscallArg(tc, index);
1123 Addr bufPtr = process->getSyscallArg(tc, index);
1125 DPRINTF_SYSCALL(Verbose, "fstat(%d, ...)\n", tgt_fd);
1127 int sim_fd = process->getSimFD(tgt_fd);
1131 struct stat hostBuf;
1132 int result = fstat(sim_fd, &hostBuf);
1137 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1143 /// Target statfs() handler.
1146 statfsFunc(SyscallDesc *desc, int callnum, Process *process,
1150 warn("Host OS cannot support calls to statfs. Ignoring syscall");
1155 if (!tc->getMemProxy().tryReadString(path,
1156 process->getSyscallArg(tc, index))) {
1159 Addr bufPtr = process->getSyscallArg(tc, index);
1161 // Adjust path for current working directory
1162 path = process->fullPath(path);
1164 struct statfs hostBuf;
1165 int result = statfs(path.c_str(), &hostBuf);
1170 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1176 /// Target fstatfs() handler.
1179 fstatfsFunc(SyscallDesc *desc, int callnum, Process *process,
1183 int tgt_fd = process->getSyscallArg(tc, index);
1184 Addr bufPtr = process->getSyscallArg(tc, index);
1186 int sim_fd = process->getSimFD(tgt_fd);
1190 struct statfs hostBuf;
1191 int result = fstatfs(sim_fd, &hostBuf);
1196 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1202 /// Target writev() handler.
1205 writevFunc(SyscallDesc *desc, int callnum, Process *process,
1209 int tgt_fd = process->getSyscallArg(tc, index);
1211 int sim_fd = process->getSimFD(tgt_fd);
1215 SETranslatingPortProxy &p = tc->getMemProxy();
1216 uint64_t tiov_base = process->getSyscallArg(tc, index);
1217 size_t count = process->getSyscallArg(tc, index);
1218 struct iovec hiov[count];
1219 for (size_t i = 0; i < count; ++i) {
1220 typename OS::tgt_iovec tiov;
1222 p.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1223 (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
1224 hiov[i].iov_len = TheISA::gtoh(tiov.iov_len);
1225 hiov[i].iov_base = new char [hiov[i].iov_len];
1226 p.readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
1230 int result = writev(sim_fd, hiov, count);
1232 for (size_t i = 0; i < count; ++i)
1233 delete [] (char *)hiov[i].iov_base;
1241 /// Real mmap handler.
1244 mmapImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc,
1248 Addr start = p->getSyscallArg(tc, index);
1249 uint64_t length = p->getSyscallArg(tc, index);
1250 int prot = p->getSyscallArg(tc, index);
1251 int tgt_flags = p->getSyscallArg(tc, index);
1252 int tgt_fd = p->getSyscallArg(tc, index);
1253 int offset = p->getSyscallArg(tc, index);
1256 offset *= TheISA::PageBytes;
1258 if (start & (TheISA::PageBytes - 1) ||
1259 offset & (TheISA::PageBytes - 1) ||
1260 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1261 tgt_flags & OS::TGT_MAP_SHARED) ||
1262 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1263 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1268 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1269 // With shared mmaps, there are two cases to consider:
1270 // 1) anonymous: writes should modify the mapping and this should be
1271 // visible to observers who share the mapping. Currently, it's
1272 // difficult to update the shared mapping because there's no
1273 // structure which maintains information about the which virtual
1274 // memory areas are shared. If that structure existed, it would be
1275 // possible to make the translations point to the same frames.
1276 // 2) file-backed: writes should modify the mapping and the file
1277 // which is backed by the mapping. The shared mapping problem is the
1278 // same as what was mentioned about the anonymous mappings. For
1279 // file-backed mappings, the writes to the file are difficult
1280 // because it requires syncing what the mapping holds with the file
1281 // that resides on the host system. So, any write on a real system
1282 // would cause the change to be propagated to the file mapping at
1283 // some point in the future (the inode is tracked along with the
1284 // mapping). This isn't guaranteed to always happen, but it usually
1285 // works well enough. The guarantee is provided by the msync system
1286 // call. We could force the change through with shared mappings with
1287 // a call to msync, but that again would require more information
1288 // than we currently maintain.
1289 warn("mmap: writing to shared mmap region is currently "
1290 "unsupported. The write succeeds on the target, but it "
1291 "will not be propagated to the host or shared mappings");
1294 length = roundUp(length, TheISA::PageBytes);
1297 uint8_t *pmap = nullptr;
1298 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1299 // Check for EmulatedDriver mmap
1300 FDEntry *fde = p->getFDEntry(tgt_fd);
1304 if (fde->driver != NULL) {
1305 return fde->driver->mmap(p, tc, start, length, prot,
1306 tgt_flags, tgt_fd, offset);
1313 pmap = (decltype(pmap))mmap(NULL, length, PROT_READ, MAP_PRIVATE,
1316 if (pmap == (decltype(pmap))-1) {
1317 warn("mmap: failed to map file into host address space");
1322 // Extend global mmap region if necessary. Note that we ignore the
1323 // start address unless MAP_FIXED is specified.
1324 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1325 start = p->mmapGrowsDown() ? p->mmap_end - length : p->mmap_end;
1326 p->mmap_end = p->mmapGrowsDown() ? start : p->mmap_end + length;
1329 DPRINTF_SYSCALL(Verbose, " mmap range is 0x%x - 0x%x\n",
1330 start, start + length - 1);
1332 // We only allow mappings to overwrite existing mappings if
1333 // TGT_MAP_FIXED is set. Otherwise it shouldn't be a problem
1334 // because we ignore the start hint if TGT_MAP_FIXED is not set.
1335 int clobber = tgt_flags & OS::TGT_MAP_FIXED;
1337 for (auto tc : p->system->threadContexts) {
1338 // If we might be overwriting old mappings, we need to
1339 // invalidate potentially stale mappings out of the TLBs.
1340 tc->getDTBPtr()->flushAll();
1341 tc->getITBPtr()->flushAll();
1345 // Allocate physical memory and map it in. If the page table is already
1346 // mapped and clobber is not set, the simulator will issue throw a
1347 // fatal and bail out of the simulation.
1348 p->allocateMem(start, length, clobber);
1350 // Transfer content into target address space.
1351 SETranslatingPortProxy &tp = tc->getMemProxy();
1352 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1353 // In general, we should zero the mapped area for anonymous mappings,
1354 // with something like:
1355 // tp.memsetBlob(start, 0, length);
1356 // However, given that we don't support sparse mappings, and
1357 // some applications can map a couple of gigabytes of space
1358 // (intending sparse usage), that can get painfully expensive.
1359 // Fortunately, since we don't properly implement munmap either,
1360 // there's no danger of remapping used memory, so for now all
1361 // newly mapped memory should already be zeroed so we can skip it.
1363 // It is possible to mmap an area larger than a file, however
1364 // accessing unmapped portions the system triggers a "Bus error"
1365 // on the host. We must know when to stop copying the file from
1366 // the host into the target address space.
1367 struct stat file_stat;
1368 if (fstat(sim_fd, &file_stat) > 0)
1369 fatal("mmap: cannot stat file");
1371 // Copy the portion of the file that is resident. This requires
1372 // checking both the mmap size and the filesize that we are
1373 // trying to mmap into this space; the mmap size also depends
1374 // on the specified offset into the file.
1375 uint64_t size = std::min((uint64_t)file_stat.st_size - offset,
1377 tp.writeBlob(start, pmap, size);
1379 // Cleanup the mmap region before exiting this function.
1380 munmap(pmap, length);
1382 // Maintain the symbol table for dynamic executables.
1383 // The loader will call mmap to map the images into its address
1384 // space and we intercept that here. We can verify that we are
1385 // executing inside the loader by checking the program counter value.
1386 // XXX: with multiprogrammed workloads or multi-node configurations,
1387 // this will not work since there is a single global symbol table.
1388 ObjectFile *interpreter = p->getInterpreter();
1390 Addr text_start = interpreter->textBase();
1391 Addr text_end = text_start + interpreter->textSize();
1393 Addr pc = tc->pcState().pc();
1395 if (pc >= text_start && pc < text_end) {
1396 FDEntry *fde = p->getFDEntry(tgt_fd);
1398 ObjectFile *lib = createObjectFile(fde->filename);
1401 lib->loadAllSymbols(debugSymbolTable,
1402 lib->textBase(), start);
1407 // Note that we do not zero out the remainder of the mapping. This
1408 // is done by a real system, but it probably will not affect
1409 // execution (hopefully).
1417 pwrite64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1420 int tgt_fd = p->getSyscallArg(tc, index);
1421 Addr bufPtr = p->getSyscallArg(tc, index);
1422 int nbytes = p->getSyscallArg(tc, index);
1423 int offset = p->getSyscallArg(tc, index);
1425 int sim_fd = p->getSimFD(tgt_fd);
1429 BufferArg bufArg(bufPtr, nbytes);
1430 bufArg.copyIn(tc->getMemProxy());
1432 int bytes_written = pwrite(sim_fd, bufArg.bufferPtr(), nbytes, offset);
1434 return (bytes_written == -1) ? -errno : bytes_written;
1437 /// Target mmap() handler.
1440 mmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1442 return mmapImpl<OS>(desc, num, p, tc, false);
1445 /// Target mmap2() handler.
1448 mmap2Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1450 return mmapImpl<OS>(desc, num, p, tc, true);
1453 /// Target getrlimit() handler.
1456 getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
1460 unsigned resource = process->getSyscallArg(tc, index);
1461 TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
1464 case OS::TGT_RLIMIT_STACK:
1465 // max stack size in bytes: make up a number (8MB for now)
1466 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1467 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1468 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1471 case OS::TGT_RLIMIT_DATA:
1472 // max data segment size in bytes: make up a number
1473 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1474 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1475 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1479 warn("getrlimit: unimplemented resource %d", resource);
1484 rlp.copyOut(tc->getMemProxy());
1488 /// Target clock_gettime() function.
1491 clock_gettimeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1494 //int clk_id = p->getSyscallArg(tc, index);
1495 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1497 getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
1498 tp->tv_sec += seconds_since_epoch;
1499 tp->tv_sec = TheISA::htog(tp->tv_sec);
1500 tp->tv_nsec = TheISA::htog(tp->tv_nsec);
1502 tp.copyOut(tc->getMemProxy());
1507 /// Target clock_getres() function.
1510 clock_getresFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1513 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1515 // Set resolution at ns, which is what clock_gettime() returns
1519 tp.copyOut(tc->getMemProxy());
1524 /// Target gettimeofday() handler.
1527 gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
1531 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1533 getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
1534 tp->tv_sec += seconds_since_epoch;
1535 tp->tv_sec = TheISA::htog(tp->tv_sec);
1536 tp->tv_usec = TheISA::htog(tp->tv_usec);
1538 tp.copyOut(tc->getMemProxy());
1544 /// Target utimes() handler.
1547 utimesFunc(SyscallDesc *desc, int callnum, Process *process,
1553 if (!tc->getMemProxy().tryReadString(path,
1554 process->getSyscallArg(tc, index))) {
1558 TypedBufferArg<typename OS::timeval [2]>
1559 tp(process->getSyscallArg(tc, index));
1560 tp.copyIn(tc->getMemProxy());
1562 struct timeval hostTimeval[2];
1563 for (int i = 0; i < 2; ++i)
1565 hostTimeval[i].tv_sec = TheISA::gtoh((*tp)[i].tv_sec);
1566 hostTimeval[i].tv_usec = TheISA::gtoh((*tp)[i].tv_usec);
1569 // Adjust path for current working directory
1570 path = process->fullPath(path);
1572 int result = utimes(path.c_str(), hostTimeval);
1579 /// Target getrusage() function.
1582 getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
1586 int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
1587 TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
1589 rup->ru_utime.tv_sec = 0;
1590 rup->ru_utime.tv_usec = 0;
1591 rup->ru_stime.tv_sec = 0;
1592 rup->ru_stime.tv_usec = 0;
1600 rup->ru_inblock = 0;
1601 rup->ru_oublock = 0;
1604 rup->ru_nsignals = 0;
1609 case OS::TGT_RUSAGE_SELF:
1610 getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1611 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1612 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1615 case OS::TGT_RUSAGE_CHILDREN:
1616 // do nothing. We have no child processes, so they take no time.
1620 // don't really handle THREAD or CHILDREN, but just warn and
1622 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
1626 rup.copyOut(tc->getMemProxy());
1631 /// Target times() function.
1634 timesFunc(SyscallDesc *desc, int callnum, Process *process,
1638 TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
1640 // Fill in the time structure (in clocks)
1641 int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s;
1642 bufp->tms_utime = clocks;
1643 bufp->tms_stime = 0;
1644 bufp->tms_cutime = 0;
1645 bufp->tms_cstime = 0;
1647 // Convert to host endianness
1648 bufp->tms_utime = TheISA::htog(bufp->tms_utime);
1651 bufp.copyOut(tc->getMemProxy());
1653 // Return clock ticks since system boot
1657 /// Target time() function.
1660 timeFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
1662 typename OS::time_t sec, usec;
1663 getElapsedTimeMicro(sec, usec);
1664 sec += seconds_since_epoch;
1667 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1669 typename OS::time_t t = sec;
1670 t = TheISA::htog(t);
1671 SETranslatingPortProxy &p = tc->getMemProxy();
1672 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1678 #endif // __SIM_SYSCALL_EMUL_HH__