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__) || \
53 /// @file syscall_emul.hh
55 /// This file defines objects used to emulate syscalls from the target
56 /// application on the host machine.
59 #include <sys/fcntl.h> // for O_BINARY
71 #include "base/chunk_generator.hh"
72 #include "base/intmath.hh" // for RoundUp
73 #include "base/loader/object_file.hh"
74 #include "base/misc.hh"
75 #include "base/trace.hh"
76 #include "base/types.hh"
77 #include "config/the_isa.hh"
78 #include "cpu/base.hh"
79 #include "cpu/thread_context.hh"
80 #include "debug/SyscallBase.hh"
81 #include "debug/SyscallVerbose.hh"
82 #include "mem/page_table.hh"
83 #include "sim/byteswap.hh"
84 #include "sim/emul_driver.hh"
85 #include "sim/process.hh"
86 #include "sim/syscall_emul_buf.hh"
87 #include "sim/syscallreturn.hh"
88 #include "sim/system.hh"
90 // This wrapper macro helps out with readability a bit. FLAGEXT specifies
91 // the verbosity and FMT is the message to be appended to the syscall
92 // header information. The syscall header information contains the cpuid
94 #define DPRINTF_SYSCALL(FLAGEXT, FMT, ...) \
95 DPRINTFS(Syscall##FLAGEXT, tc->getCpuPtr(), "T%d : syscall " FMT, \
96 tc->threadId(), __VA_ARGS__)
99 /// System call descriptor.
105 /// Typedef for target syscall handler functions.
106 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
107 LiveProcess *, ThreadContext *);
109 const char *name; //!< Syscall name (e.g., "open").
110 FuncPtr funcPtr; //!< Pointer to emulation function.
111 int flags; //!< Flags (see Flags enum).
112 bool warned; //!< Have we warned about unimplemented syscall?
114 /// Flag values for controlling syscall behavior.
116 /// Don't set return regs according to funcPtr return value.
117 /// Used for syscalls with non-standard return conventions
118 /// that explicitly set the ThreadContext regs (e.g.,
120 SuppressReturnValue = 1,
125 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
126 : name(_name), funcPtr(_funcPtr), flags(_flags), warned(false)
130 /// Emulate the syscall. Public interface for calling through funcPtr.
131 void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc);
133 /// Is the WarnOnce flag set?
134 bool warnOnce() const { return (flags & WarnOnce); }
138 //////////////////////////////////////////////////////////////////////
140 // The following emulation functions are generic enough that they
141 // don't need to be recompiled for different emulated OS's. They are
142 // defined in sim/syscall_emul.cc.
144 //////////////////////////////////////////////////////////////////////
147 /// Handler for unimplemented syscalls that we haven't thought about.
148 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
149 LiveProcess *p, ThreadContext *tc);
151 /// Handler for unimplemented syscalls that we never intend to
152 /// implement (signal handling, etc.) and should not affect the correct
153 /// behavior of the program. Print a warning only if the appropriate
154 /// trace flag is enabled. Return success to the target program.
155 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
156 LiveProcess *p, ThreadContext *tc);
158 /// Target exit() handler: terminate current context.
159 SyscallReturn exitFunc(SyscallDesc *desc, int num,
160 LiveProcess *p, ThreadContext *tc);
162 /// Target exit_group() handler: terminate simulation. (exit all threads)
163 SyscallReturn exitGroupFunc(SyscallDesc *desc, int num,
164 LiveProcess *p, ThreadContext *tc);
166 /// Target getpagesize() handler.
167 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
168 LiveProcess *p, ThreadContext *tc);
170 /// Target brk() handler: set brk address.
171 SyscallReturn brkFunc(SyscallDesc *desc, int num,
172 LiveProcess *p, ThreadContext *tc);
174 /// Target close() handler.
175 SyscallReturn closeFunc(SyscallDesc *desc, int num,
176 LiveProcess *p, ThreadContext *tc);
178 /// Target read() handler.
179 SyscallReturn readFunc(SyscallDesc *desc, int num,
180 LiveProcess *p, ThreadContext *tc);
182 /// Target write() handler.
183 SyscallReturn writeFunc(SyscallDesc *desc, int num,
184 LiveProcess *p, ThreadContext *tc);
186 /// Target lseek() handler.
187 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
188 LiveProcess *p, ThreadContext *tc);
190 /// Target _llseek() handler.
191 SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
192 LiveProcess *p, ThreadContext *tc);
194 /// Target munmap() handler.
195 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
196 LiveProcess *p, ThreadContext *tc);
198 /// Target gethostname() handler.
199 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
200 LiveProcess *p, ThreadContext *tc);
202 /// Target getcwd() handler.
203 SyscallReturn getcwdFunc(SyscallDesc *desc, int num,
204 LiveProcess *p, ThreadContext *tc);
206 /// Target readlink() handler.
207 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
208 LiveProcess *p, ThreadContext *tc,
210 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
211 LiveProcess *p, ThreadContext *tc);
213 /// Target unlink() handler.
214 SyscallReturn unlinkHelper(SyscallDesc *desc, int num,
215 LiveProcess *p, ThreadContext *tc,
217 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
218 LiveProcess *p, ThreadContext *tc);
220 /// Target mkdir() handler.
221 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
222 LiveProcess *p, ThreadContext *tc);
224 /// Target rename() handler.
225 SyscallReturn renameFunc(SyscallDesc *desc, int num,
226 LiveProcess *p, ThreadContext *tc);
229 /// Target truncate() handler.
230 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
231 LiveProcess *p, ThreadContext *tc);
234 /// Target ftruncate() handler.
235 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
236 LiveProcess *p, ThreadContext *tc);
239 /// Target truncate64() handler.
240 SyscallReturn truncate64Func(SyscallDesc *desc, int num,
241 LiveProcess *p, ThreadContext *tc);
243 /// Target ftruncate64() handler.
244 SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
245 LiveProcess *p, ThreadContext *tc);
248 /// Target umask() handler.
249 SyscallReturn umaskFunc(SyscallDesc *desc, int num,
250 LiveProcess *p, ThreadContext *tc);
253 /// Target chown() handler.
254 SyscallReturn chownFunc(SyscallDesc *desc, int num,
255 LiveProcess *p, ThreadContext *tc);
258 /// Target fchown() handler.
259 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
260 LiveProcess *p, ThreadContext *tc);
262 /// Target dup() handler.
263 SyscallReturn dupFunc(SyscallDesc *desc, int num,
264 LiveProcess *process, ThreadContext *tc);
266 /// Target fnctl() handler.
267 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
268 LiveProcess *process, ThreadContext *tc);
270 /// Target fcntl64() handler.
271 SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
272 LiveProcess *process, ThreadContext *tc);
274 /// Target setuid() handler.
275 SyscallReturn setuidFunc(SyscallDesc *desc, int num,
276 LiveProcess *p, ThreadContext *tc);
278 /// Target getpid() handler.
279 SyscallReturn getpidFunc(SyscallDesc *desc, int num,
280 LiveProcess *p, ThreadContext *tc);
282 /// Target getuid() handler.
283 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
284 LiveProcess *p, ThreadContext *tc);
286 /// Target getgid() handler.
287 SyscallReturn getgidFunc(SyscallDesc *desc, int num,
288 LiveProcess *p, ThreadContext *tc);
290 /// Target getppid() handler.
291 SyscallReturn getppidFunc(SyscallDesc *desc, int num,
292 LiveProcess *p, ThreadContext *tc);
294 /// Target geteuid() handler.
295 SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
296 LiveProcess *p, ThreadContext *tc);
298 /// Target getegid() handler.
299 SyscallReturn getegidFunc(SyscallDesc *desc, int num,
300 LiveProcess *p, ThreadContext *tc);
302 /// Target clone() handler.
303 SyscallReturn cloneFunc(SyscallDesc *desc, int num,
304 LiveProcess *p, ThreadContext *tc);
306 /// Target access() handler
307 SyscallReturn accessFunc(SyscallDesc *desc, int num,
308 LiveProcess *p, ThreadContext *tc);
309 SyscallReturn accessFunc(SyscallDesc *desc, int num,
310 LiveProcess *p, ThreadContext *tc,
313 /// Futex system call
314 /// Implemented by Daniel Sanchez
315 /// Used by printf's in multi-threaded apps
318 futexFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
324 int index_timeout = 3;
326 uint64_t uaddr = process->getSyscallArg(tc, index_uaddr);
327 int op = process->getSyscallArg(tc, index_op);
328 int val = process->getSyscallArg(tc, index_val);
329 uint64_t timeout = process->getSyscallArg(tc, index_timeout);
331 std::map<uint64_t, std::list<ThreadContext *> * >
332 &futex_map = tc->getSystemPtr()->futexMap;
334 DPRINTF(SyscallVerbose, "In sys_futex: Address=%llx, op=%d, val=%d\n",
337 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
339 if (op == OS::TGT_FUTEX_WAIT) {
341 warn("sys_futex: FUTEX_WAIT with non-null timeout unimplemented;"
342 "we'll wait indefinitely");
345 uint8_t *buf = new uint8_t[sizeof(int)];
346 tc->getMemProxy().readBlob((Addr)uaddr, buf, (int)sizeof(int));
347 int mem_val = *((int *)buf);
350 if (val != mem_val) {
351 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, read: %d, "
352 "expected: %d\n", mem_val, val);
353 return -OS::TGT_EWOULDBLOCK;
356 // Queue the thread context
357 std::list<ThreadContext *> * tcWaitList;
358 if (futex_map.count(uaddr)) {
359 tcWaitList = futex_map.find(uaddr)->second;
361 tcWaitList = new std::list<ThreadContext *>();
362 futex_map.insert(std::pair< uint64_t,
363 std::list<ThreadContext *> * >(uaddr, tcWaitList));
365 tcWaitList->push_back(tc);
366 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAIT, suspending calling "
370 } else if (op == OS::TGT_FUTEX_WAKE){
372 std::list<ThreadContext *> * tcWaitList;
373 if (futex_map.count(uaddr)) {
374 tcWaitList = futex_map.find(uaddr)->second;
375 while (tcWaitList->size() > 0 && wokenUp < val) {
376 tcWaitList->front()->activate();
377 tcWaitList->pop_front();
380 if (tcWaitList->empty()) {
381 futex_map.erase(uaddr);
385 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, activated %d waiting "
386 "thread contexts\n", wokenUp);
389 warn("sys_futex: op %d is not implemented, just returning...", op);
396 /// Pseudo Funcs - These functions use a different return convension,
397 /// returning a second value in a register other than the normal return register
398 SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
399 LiveProcess *process, ThreadContext *tc);
401 /// Target getpidPseudo() handler.
402 SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
403 LiveProcess *p, ThreadContext *tc);
405 /// Target getuidPseudo() handler.
406 SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
407 LiveProcess *p, ThreadContext *tc);
409 /// Target getgidPseudo() handler.
410 SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
411 LiveProcess *p, ThreadContext *tc);
414 /// A readable name for 1,000,000, for converting microseconds to seconds.
415 const int one_million = 1000000;
416 /// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
417 const int one_billion = 1000000000;
419 /// Approximate seconds since the epoch (1/1/1970). About a billion,
420 /// by my reckoning. We want to keep this a constant (not use the
421 /// real-world time) to keep simulations repeatable.
422 const unsigned seconds_since_epoch = 1000000000;
424 /// Helper function to convert current elapsed time to seconds and
426 template <class T1, class T2>
428 getElapsedTimeMicro(T1 &sec, T2 &usec)
430 uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
431 sec = elapsed_usecs / one_million;
432 usec = elapsed_usecs % one_million;
435 /// Helper function to convert current elapsed time to seconds and
437 template <class T1, class T2>
439 getElapsedTimeNano(T1 &sec, T2 &nsec)
441 uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
442 sec = elapsed_nsecs / one_billion;
443 nsec = elapsed_nsecs % one_billion;
446 //////////////////////////////////////////////////////////////////////
448 // The following emulation functions are generic, but need to be
449 // templated to account for differences in types, constants, etc.
451 //////////////////////////////////////////////////////////////////////
454 typedef struct stat hst_stat;
455 typedef struct stat hst_stat64;
457 typedef struct stat hst_stat;
458 typedef struct stat64 hst_stat64;
461 //// Helper function to convert a host stat buffer to a target stat
462 //// buffer. Also copies the target buffer out to the simulated
463 //// memory space. Used by stat(), fstat(), and lstat().
465 template <typename target_stat, typename host_stat>
467 convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
469 using namespace TheISA;
474 tgt->st_dev = host->st_dev;
475 tgt->st_dev = TheISA::htog(tgt->st_dev);
476 tgt->st_ino = host->st_ino;
477 tgt->st_ino = TheISA::htog(tgt->st_ino);
478 tgt->st_mode = host->st_mode;
480 // Claim to be a character device
481 tgt->st_mode &= ~S_IFMT; // Clear S_IFMT
482 tgt->st_mode |= S_IFCHR; // Set S_IFCHR
484 tgt->st_mode = TheISA::htog(tgt->st_mode);
485 tgt->st_nlink = host->st_nlink;
486 tgt->st_nlink = TheISA::htog(tgt->st_nlink);
487 tgt->st_uid = host->st_uid;
488 tgt->st_uid = TheISA::htog(tgt->st_uid);
489 tgt->st_gid = host->st_gid;
490 tgt->st_gid = TheISA::htog(tgt->st_gid);
492 tgt->st_rdev = 0x880d;
494 tgt->st_rdev = host->st_rdev;
495 tgt->st_rdev = TheISA::htog(tgt->st_rdev);
496 tgt->st_size = host->st_size;
497 tgt->st_size = TheISA::htog(tgt->st_size);
498 tgt->st_atimeX = host->st_atime;
499 tgt->st_atimeX = TheISA::htog(tgt->st_atimeX);
500 tgt->st_mtimeX = host->st_mtime;
501 tgt->st_mtimeX = TheISA::htog(tgt->st_mtimeX);
502 tgt->st_ctimeX = host->st_ctime;
503 tgt->st_ctimeX = TheISA::htog(tgt->st_ctimeX);
504 // Force the block size to be 8k. This helps to ensure buffered io works
505 // consistently across different hosts.
506 tgt->st_blksize = 0x2000;
507 tgt->st_blksize = TheISA::htog(tgt->st_blksize);
508 tgt->st_blocks = host->st_blocks;
509 tgt->st_blocks = TheISA::htog(tgt->st_blocks);
514 template <typename target_stat, typename host_stat64>
516 convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
518 using namespace TheISA;
520 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
521 #if defined(STAT_HAVE_NSEC)
522 tgt->st_atime_nsec = host->st_atime_nsec;
523 tgt->st_atime_nsec = TheISA::htog(tgt->st_atime_nsec);
524 tgt->st_mtime_nsec = host->st_mtime_nsec;
525 tgt->st_mtime_nsec = TheISA::htog(tgt->st_mtime_nsec);
526 tgt->st_ctime_nsec = host->st_ctime_nsec;
527 tgt->st_ctime_nsec = TheISA::htog(tgt->st_ctime_nsec);
529 tgt->st_atime_nsec = 0;
530 tgt->st_mtime_nsec = 0;
531 tgt->st_ctime_nsec = 0;
535 //Here are a couple convenience functions
538 copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
539 hst_stat *host, bool fakeTTY = false)
541 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
542 tgt_stat_buf tgt(addr);
543 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
549 copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
550 hst_stat64 *host, bool fakeTTY = false)
552 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
553 tgt_stat_buf tgt(addr);
554 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
558 /// Target ioctl() handler. For the most part, programs call ioctl()
559 /// only to find out if their stdout is a tty, to determine whether to
560 /// do line or block buffering. We always claim that output fds are
561 /// not TTYs to provide repeatable results.
564 ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
568 int tgt_fd = process->getSyscallArg(tc, index);
569 unsigned req = process->getSyscallArg(tc, index);
571 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
573 FDEntry *fde = process->getFDEntry(tgt_fd);
576 // doesn't map to any simulator fd: not a valid target fd
580 if (fde->driver != NULL) {
581 return fde->driver->ioctl(process, tc, req);
584 if (OS::isTtyReq(req)) {
588 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n",
589 tgt_fd, req, tc->pcState());
595 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
596 ThreadContext *tc, int index)
600 if (!tc->getMemProxy().tryReadString(path,
601 process->getSyscallArg(tc, index)))
604 int tgtFlags = process->getSyscallArg(tc, index);
605 int mode = process->getSyscallArg(tc, index);
608 // translate open flags
609 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
610 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
611 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
612 hostFlags |= OS::openFlagTable[i].hostFlag;
616 // any target flags left?
618 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
621 hostFlags |= O_BINARY;
624 // Adjust path for current working directory
625 path = process->fullPath(path);
627 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
629 if (startswith(path, "/dev/")) {
630 std::string filename = path.substr(strlen("/dev/"));
631 if (filename == "sysdev0") {
632 // This is a memory-mapped high-resolution timer device on Alpha.
633 // We don't support it, so just punt.
634 warn("Ignoring open(%s, ...)\n", path);
638 EmulatedDriver *drv = process->findDriver(filename);
640 // the driver's open method will allocate a fd from the
641 // process if necessary.
642 return drv->open(process, tc, mode, hostFlags);
645 // fall through here for pass through to host devices, such as
651 if (startswith(path, "/proc/") || startswith(path, "/system/") ||
652 startswith(path, "/platform/") || startswith(path, "/sys/")) {
653 // It's a proc/sys entry and requires special handling
654 fd = OS::openSpecialFile(path, process, tc);
655 local_errno = ENOENT;
658 fd = open(path.c_str(), hostFlags, mode);
665 return process->allocFD(fd, path.c_str(), hostFlags, mode, false);
668 /// Target open() handler.
671 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
674 return openFunc<OS>(desc, callnum, process, tc, 0);
677 /// Target openat() handler.
680 openatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
684 int dirfd = process->getSyscallArg(tc, index);
685 if (dirfd != OS::TGT_AT_FDCWD)
686 warn("openat: first argument not AT_FDCWD; unlikely to work");
687 return openFunc<OS>(desc, callnum, process, tc, 1);
690 /// Target unlinkat() handler.
693 unlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
697 int dirfd = process->getSyscallArg(tc, index);
698 if (dirfd != OS::TGT_AT_FDCWD)
699 warn("unlinkat: first argument not AT_FDCWD; unlikely to work");
701 return unlinkHelper(desc, callnum, process, tc, 1);
704 /// Target facessat() handler
707 faccessatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
711 int dirfd = process->getSyscallArg(tc, index);
712 if (dirfd != OS::TGT_AT_FDCWD)
713 warn("faccessat: first argument not AT_FDCWD; unlikely to work");
714 return accessFunc(desc, callnum, process, tc, 1);
717 /// Target readlinkat() handler
720 readlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
724 int dirfd = process->getSyscallArg(tc, index);
725 if (dirfd != OS::TGT_AT_FDCWD)
726 warn("openat: first argument not AT_FDCWD; unlikely to work");
727 return readlinkFunc(desc, callnum, process, tc, 1);
730 /// Target renameat() handler.
733 renameatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
738 int olddirfd = process->getSyscallArg(tc, index);
739 if (olddirfd != OS::TGT_AT_FDCWD)
740 warn("renameat: first argument not AT_FDCWD; unlikely to work");
742 std::string old_name;
744 if (!tc->getMemProxy().tryReadString(old_name,
745 process->getSyscallArg(tc, index)))
748 int newdirfd = process->getSyscallArg(tc, index);
749 if (newdirfd != OS::TGT_AT_FDCWD)
750 warn("renameat: third argument not AT_FDCWD; unlikely to work");
752 std::string new_name;
754 if (!tc->getMemProxy().tryReadString(new_name,
755 process->getSyscallArg(tc, index)))
758 // Adjust path for current working directory
759 old_name = process->fullPath(old_name);
760 new_name = process->fullPath(new_name);
762 int result = rename(old_name.c_str(), new_name.c_str());
763 return (result == -1) ? -errno : result;
766 /// Target sysinfo() handler.
769 sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
774 TypedBufferArg<typename OS::tgt_sysinfo>
775 sysinfo(process->getSyscallArg(tc, index));
777 sysinfo->uptime=seconds_since_epoch;
778 sysinfo->totalram=process->system->memSize();
780 sysinfo.copyOut(tc->getMemProxy());
785 /// Target chmod() handler.
788 chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
794 if (!tc->getMemProxy().tryReadString(path,
795 process->getSyscallArg(tc, index))) {
799 uint32_t mode = process->getSyscallArg(tc, index);
802 // XXX translate mode flags via OS::something???
805 // Adjust path for current working directory
806 path = process->fullPath(path);
809 int result = chmod(path.c_str(), hostMode);
817 /// Target fchmod() handler.
820 fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
824 int tgt_fd = process->getSyscallArg(tc, index);
825 uint32_t mode = process->getSyscallArg(tc, index);
827 int sim_fd = process->getSimFD(tgt_fd);
833 // XXX translate mode flags via OS::someting???
837 int result = fchmod(sim_fd, hostMode);
844 /// Target mremap() handler.
847 mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc)
850 Addr start = process->getSyscallArg(tc, index);
851 uint64_t old_length = process->getSyscallArg(tc, index);
852 uint64_t new_length = process->getSyscallArg(tc, index);
853 uint64_t flags = process->getSyscallArg(tc, index);
854 uint64_t provided_address = 0;
855 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
857 if (use_provided_address)
858 provided_address = process->getSyscallArg(tc, index);
860 if ((start % TheISA::PageBytes != 0) ||
861 (provided_address % TheISA::PageBytes != 0)) {
862 warn("mremap failing: arguments not page aligned");
866 new_length = roundUp(new_length, TheISA::PageBytes);
868 if (new_length > old_length) {
869 if ((start + old_length) == process->mmap_end &&
870 (!use_provided_address || provided_address == start)) {
871 uint64_t diff = new_length - old_length;
872 process->allocateMem(process->mmap_end, diff);
873 process->mmap_end += diff;
876 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
877 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
880 uint64_t new_start = use_provided_address ?
881 provided_address : process->mmap_end;
882 process->pTable->remap(start, old_length, new_start);
883 warn("mremapping to new vaddr %08p-%08p, adding %d\n",
884 new_start, new_start + new_length,
885 new_length - old_length);
886 // add on the remaining unallocated pages
887 process->allocateMem(new_start + old_length,
888 new_length - old_length,
889 use_provided_address /* clobber */);
890 if (!use_provided_address)
891 process->mmap_end += new_length;
892 if (use_provided_address &&
893 new_start + new_length > process->mmap_end) {
894 // something fishy going on here, at least notify the user
895 // @todo: increase mmap_end?
896 warn("mmap region limit exceeded with MREMAP_FIXED\n");
898 warn("returning %08p as start\n", new_start);
903 if (use_provided_address && provided_address != start)
904 process->pTable->remap(start, new_length, provided_address);
905 process->pTable->unmap(start + new_length, old_length - new_length);
906 return use_provided_address ? provided_address : start;
910 /// Target stat() handler.
913 statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
919 if (!tc->getMemProxy().tryReadString(path,
920 process->getSyscallArg(tc, index))) {
923 Addr bufPtr = process->getSyscallArg(tc, index);
925 // Adjust path for current working directory
926 path = process->fullPath(path);
929 int result = stat(path.c_str(), &hostBuf);
934 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
940 /// Target stat64() handler.
943 stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
949 if (!tc->getMemProxy().tryReadString(path,
950 process->getSyscallArg(tc, index)))
952 Addr bufPtr = process->getSyscallArg(tc, index);
954 // Adjust path for current working directory
955 path = process->fullPath(path);
959 int result = stat(path.c_str(), &hostBuf);
961 struct stat64 hostBuf;
962 int result = stat64(path.c_str(), &hostBuf);
968 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
974 /// Target fstatat64() handler.
977 fstatat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
981 int dirfd = process->getSyscallArg(tc, index);
982 if (dirfd != OS::TGT_AT_FDCWD)
983 warn("fstatat64: first argument not AT_FDCWD; unlikely to work");
986 if (!tc->getMemProxy().tryReadString(path,
987 process->getSyscallArg(tc, index)))
989 Addr bufPtr = process->getSyscallArg(tc, index);
991 // Adjust path for current working directory
992 path = process->fullPath(path);
996 int result = stat(path.c_str(), &hostBuf);
998 struct stat64 hostBuf;
999 int result = stat64(path.c_str(), &hostBuf);
1005 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1011 /// Target fstat64() handler.
1014 fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1018 int tgt_fd = process->getSyscallArg(tc, index);
1019 Addr bufPtr = process->getSyscallArg(tc, index);
1021 int sim_fd = process->getSimFD(tgt_fd);
1026 struct stat hostBuf;
1027 int result = fstat(sim_fd, &hostBuf);
1029 struct stat64 hostBuf;
1030 int result = fstat64(sim_fd, &hostBuf);
1036 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1042 /// Target lstat() handler.
1045 lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1051 if (!tc->getMemProxy().tryReadString(path,
1052 process->getSyscallArg(tc, index))) {
1055 Addr bufPtr = process->getSyscallArg(tc, index);
1057 // Adjust path for current working directory
1058 path = process->fullPath(path);
1060 struct stat hostBuf;
1061 int result = lstat(path.c_str(), &hostBuf);
1066 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1071 /// Target lstat64() handler.
1074 lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1080 if (!tc->getMemProxy().tryReadString(path,
1081 process->getSyscallArg(tc, index))) {
1084 Addr bufPtr = process->getSyscallArg(tc, index);
1086 // Adjust path for current working directory
1087 path = process->fullPath(path);
1090 struct stat hostBuf;
1091 int result = lstat(path.c_str(), &hostBuf);
1093 struct stat64 hostBuf;
1094 int result = lstat64(path.c_str(), &hostBuf);
1100 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1105 /// Target fstat() handler.
1108 fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1112 int tgt_fd = process->getSyscallArg(tc, index);
1113 Addr bufPtr = process->getSyscallArg(tc, index);
1115 DPRINTF_SYSCALL(Verbose, "fstat(%d, ...)\n", tgt_fd);
1117 int sim_fd = process->getSimFD(tgt_fd);
1121 struct stat hostBuf;
1122 int result = fstat(sim_fd, &hostBuf);
1127 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1133 /// Target statfs() handler.
1136 statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1142 if (!tc->getMemProxy().tryReadString(path,
1143 process->getSyscallArg(tc, index))) {
1146 Addr bufPtr = process->getSyscallArg(tc, index);
1148 // Adjust path for current working directory
1149 path = process->fullPath(path);
1151 struct statfs hostBuf;
1152 int result = statfs(path.c_str(), &hostBuf);
1157 OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
1163 /// Target fstatfs() handler.
1166 fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1170 int tgt_fd = process->getSyscallArg(tc, index);
1171 Addr bufPtr = process->getSyscallArg(tc, index);
1173 int sim_fd = process->getSimFD(tgt_fd);
1177 struct statfs hostBuf;
1178 int result = fstatfs(sim_fd, &hostBuf);
1183 OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
1189 /// Target writev() handler.
1192 writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1196 int tgt_fd = process->getSyscallArg(tc, index);
1198 int sim_fd = process->getSimFD(tgt_fd);
1202 SETranslatingPortProxy &p = tc->getMemProxy();
1203 uint64_t tiov_base = process->getSyscallArg(tc, index);
1204 size_t count = process->getSyscallArg(tc, index);
1205 struct iovec hiov[count];
1206 for (size_t i = 0; i < count; ++i) {
1207 typename OS::tgt_iovec tiov;
1209 p.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1210 (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
1211 hiov[i].iov_len = TheISA::gtoh(tiov.iov_len);
1212 hiov[i].iov_base = new char [hiov[i].iov_len];
1213 p.readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
1217 int result = writev(sim_fd, hiov, count);
1219 for (size_t i = 0; i < count; ++i)
1220 delete [] (char *)hiov[i].iov_base;
1228 /// Real mmap handler.
1231 mmapImpl(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
1235 Addr start = p->getSyscallArg(tc, index);
1236 uint64_t length = p->getSyscallArg(tc, index);
1237 int prot = p->getSyscallArg(tc, index);
1238 int tgt_flags = p->getSyscallArg(tc, index);
1239 int tgt_fd = p->getSyscallArg(tc, index);
1240 int offset = p->getSyscallArg(tc, index);
1243 offset *= TheISA::PageBytes;
1245 if (start & (TheISA::PageBytes - 1) ||
1246 offset & (TheISA::PageBytes - 1) ||
1247 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1248 tgt_flags & OS::TGT_MAP_SHARED) ||
1249 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1250 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1255 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1256 // With shared mmaps, there are two cases to consider:
1257 // 1) anonymous: writes should modify the mapping and this should be
1258 // visible to observers who share the mapping. Currently, it's
1259 // difficult to update the shared mapping because there's no
1260 // structure which maintains information about the which virtual
1261 // memory areas are shared. If that structure existed, it would be
1262 // possible to make the translations point to the same frames.
1263 // 2) file-backed: writes should modify the mapping and the file
1264 // which is backed by the mapping. The shared mapping problem is the
1265 // same as what was mentioned about the anonymous mappings. For
1266 // file-backed mappings, the writes to the file are difficult
1267 // because it requires syncing what the mapping holds with the file
1268 // that resides on the host system. So, any write on a real system
1269 // would cause the change to be propagated to the file mapping at
1270 // some point in the future (the inode is tracked along with the
1271 // mapping). This isn't guaranteed to always happen, but it usually
1272 // works well enough. The guarantee is provided by the msync system
1273 // call. We could force the change through with shared mappings with
1274 // a call to msync, but that again would require more information
1275 // than we currently maintain.
1276 warn("mmap: writing to shared mmap region is currently "
1277 "unsupported. The write succeeds on the target, but it "
1278 "will not be propagated to the host or shared mappings");
1281 length = roundUp(length, TheISA::PageBytes);
1284 uint8_t *pmap = nullptr;
1285 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1286 sim_fd = p->getSimFD(tgt_fd);
1290 pmap = (decltype(pmap))mmap(NULL, length, PROT_READ, MAP_PRIVATE,
1293 if (pmap == (decltype(pmap))-1) {
1294 warn("mmap: failed to map file into host address space");
1299 // Extend global mmap region if necessary. Note that we ignore the
1300 // start address unless MAP_FIXED is specified.
1301 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1302 start = p->mmapGrowsDown() ? p->mmap_end - length : p->mmap_end;
1303 p->mmap_end = p->mmapGrowsDown() ? start : p->mmap_end + length;
1306 DPRINTF_SYSCALL(Verbose, " mmap range is 0x%x - 0x%x\n",
1307 start, start + length - 1);
1309 // We only allow mappings to overwrite existing mappings if
1310 // TGT_MAP_FIXED is set. Otherwise it shouldn't be a problem
1311 // because we ignore the start hint if TGT_MAP_FIXED is not set.
1312 int clobber = tgt_flags & OS::TGT_MAP_FIXED;
1314 for (auto tc : p->system->threadContexts) {
1315 // If we might be overwriting old mappings, we need to
1316 // invalidate potentially stale mappings out of the TLBs.
1317 tc->getDTBPtr()->flushAll();
1318 tc->getITBPtr()->flushAll();
1322 // Allocate physical memory and map it in. If the page table is already
1323 // mapped and clobber is not set, the simulator will issue throw a
1324 // fatal and bail out of the simulation.
1325 p->allocateMem(start, length, clobber);
1327 // Transfer content into target address space.
1328 SETranslatingPortProxy &tp = tc->getMemProxy();
1329 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1330 // In general, we should zero the mapped area for anonymous mappings,
1331 // with something like:
1332 // tp.memsetBlob(start, 0, length);
1333 // However, given that we don't support sparse mappings, and
1334 // some applications can map a couple of gigabytes of space
1335 // (intending sparse usage), that can get painfully expensive.
1336 // Fortunately, since we don't properly implement munmap either,
1337 // there's no danger of remapping used memory, so for now all
1338 // newly mapped memory should already be zeroed so we can skip it.
1340 // It is possible to mmap an area larger than a file, however
1341 // accessing unmapped portions the system triggers a "Bus error"
1342 // on the host. We must know when to stop copying the file from
1343 // the host into the target address space.
1344 struct stat file_stat;
1345 if (fstat(sim_fd, &file_stat) > 0)
1346 fatal("mmap: cannot stat file");
1348 // Copy the portion of the file that is resident. This requires
1349 // checking both the mmap size and the filesize that we are
1350 // trying to mmap into this space; the mmap size also depends
1351 // on the specified offset into the file.
1352 uint64_t size = std::min((uint64_t)file_stat.st_size - offset,
1354 tp.writeBlob(start, pmap, size);
1356 // Cleanup the mmap region before exiting this function.
1357 munmap(pmap, length);
1359 // Maintain the symbol table for dynamic executables.
1360 // The loader will call mmap to map the images into its address
1361 // space and we intercept that here. We can verify that we are
1362 // executing inside the loader by checking the program counter value.
1363 // XXX: with multiprogrammed workloads or multi-node configurations,
1364 // this will not work since there is a single global symbol table.
1365 ObjectFile *interpreter = p->getInterpreter();
1367 Addr text_start = interpreter->textBase();
1368 Addr text_end = text_start + interpreter->textSize();
1370 Addr pc = tc->pcState().pc();
1372 if (pc >= text_start && pc < text_end) {
1373 FDEntry *fde = p->getFDEntry(tgt_fd);
1375 ObjectFile *lib = createObjectFile(fde->filename);
1378 lib->loadAllSymbols(debugSymbolTable,
1379 lib->textBase(), start);
1384 // Note that we do not zero out the remainder of the mapping. This
1385 // is done by a real system, but it probably will not affect
1386 // execution (hopefully).
1392 /// Target mmap() handler.
1395 mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1397 return mmapImpl<OS>(desc, num, p, tc, false);
1400 /// Target mmap2() handler.
1403 mmap2Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1405 return mmapImpl<OS>(desc, num, p, tc, true);
1408 /// Target getrlimit() handler.
1411 getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1415 unsigned resource = process->getSyscallArg(tc, index);
1416 TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
1419 case OS::TGT_RLIMIT_STACK:
1420 // max stack size in bytes: make up a number (8MB for now)
1421 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1422 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1423 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1426 case OS::TGT_RLIMIT_DATA:
1427 // max data segment size in bytes: make up a number
1428 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1429 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1430 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1434 warn("getrlimit: unimplemented resource %d", resource);
1439 rlp.copyOut(tc->getMemProxy());
1443 /// Target clock_gettime() function.
1446 clock_gettimeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1449 //int clk_id = p->getSyscallArg(tc, index);
1450 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1452 getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
1453 tp->tv_sec += seconds_since_epoch;
1454 tp->tv_sec = TheISA::htog(tp->tv_sec);
1455 tp->tv_nsec = TheISA::htog(tp->tv_nsec);
1457 tp.copyOut(tc->getMemProxy());
1462 /// Target clock_getres() function.
1465 clock_getresFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1468 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1470 // Set resolution at ns, which is what clock_gettime() returns
1474 tp.copyOut(tc->getMemProxy());
1479 /// Target gettimeofday() handler.
1482 gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1486 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1488 getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
1489 tp->tv_sec += seconds_since_epoch;
1490 tp->tv_sec = TheISA::htog(tp->tv_sec);
1491 tp->tv_usec = TheISA::htog(tp->tv_usec);
1493 tp.copyOut(tc->getMemProxy());
1499 /// Target utimes() handler.
1502 utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1508 if (!tc->getMemProxy().tryReadString(path,
1509 process->getSyscallArg(tc, index))) {
1513 TypedBufferArg<typename OS::timeval [2]>
1514 tp(process->getSyscallArg(tc, index));
1515 tp.copyIn(tc->getMemProxy());
1517 struct timeval hostTimeval[2];
1518 for (int i = 0; i < 2; ++i)
1520 hostTimeval[i].tv_sec = TheISA::gtoh((*tp)[i].tv_sec);
1521 hostTimeval[i].tv_usec = TheISA::gtoh((*tp)[i].tv_usec);
1524 // Adjust path for current working directory
1525 path = process->fullPath(path);
1527 int result = utimes(path.c_str(), hostTimeval);
1534 /// Target getrusage() function.
1537 getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1541 int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
1542 TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
1544 rup->ru_utime.tv_sec = 0;
1545 rup->ru_utime.tv_usec = 0;
1546 rup->ru_stime.tv_sec = 0;
1547 rup->ru_stime.tv_usec = 0;
1555 rup->ru_inblock = 0;
1556 rup->ru_oublock = 0;
1559 rup->ru_nsignals = 0;
1564 case OS::TGT_RUSAGE_SELF:
1565 getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1566 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1567 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1570 case OS::TGT_RUSAGE_CHILDREN:
1571 // do nothing. We have no child processes, so they take no time.
1575 // don't really handle THREAD or CHILDREN, but just warn and
1577 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
1581 rup.copyOut(tc->getMemProxy());
1586 /// Target times() function.
1589 timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1593 TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
1595 // Fill in the time structure (in clocks)
1596 int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s;
1597 bufp->tms_utime = clocks;
1598 bufp->tms_stime = 0;
1599 bufp->tms_cutime = 0;
1600 bufp->tms_cstime = 0;
1602 // Convert to host endianness
1603 bufp->tms_utime = TheISA::htog(bufp->tms_utime);
1606 bufp.copyOut(tc->getMemProxy());
1608 // Return clock ticks since system boot
1612 /// Target time() function.
1615 timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1618 typename OS::time_t sec, usec;
1619 getElapsedTimeMicro(sec, usec);
1620 sec += seconds_since_epoch;
1623 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1625 typename OS::time_t t = sec;
1626 t = TheISA::htog(t);
1627 SETranslatingPortProxy &p = tc->getMemProxy();
1628 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1634 #endif // __SIM_SYSCALL_EMUL_HH__