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
72 #include "base/chunk_generator.hh"
73 #include "base/intmath.hh" // for RoundUp
74 #include "base/loader/object_file.hh"
75 #include "base/misc.hh"
76 #include "base/trace.hh"
77 #include "base/types.hh"
78 #include "config/the_isa.hh"
79 #include "cpu/base.hh"
80 #include "cpu/thread_context.hh"
81 #include "debug/SyscallBase.hh"
82 #include "debug/SyscallVerbose.hh"
83 #include "mem/page_table.hh"
84 #include "sim/byteswap.hh"
85 #include "sim/emul_driver.hh"
86 #include "sim/process.hh"
87 #include "sim/syscall_emul_buf.hh"
88 #include "sim/syscallreturn.hh"
89 #include "sim/system.hh"
91 // This wrapper macro helps out with readability a bit. FLAGEXT specifies
92 // the verbosity and FMT is the message to be appended to the syscall
93 // header information. The syscall header information contains the cpuid
95 #define DPRINTF_SYSCALL(FLAGEXT, FMT, ...) \
96 DPRINTFS(Syscall##FLAGEXT, tc->getCpuPtr(), "T%d : syscall " FMT, \
97 tc->threadId(), __VA_ARGS__)
100 /// System call descriptor.
106 /// Typedef for target syscall handler functions.
107 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
108 LiveProcess *, ThreadContext *);
110 const char *name; //!< Syscall name (e.g., "open").
111 FuncPtr funcPtr; //!< Pointer to emulation function.
112 int flags; //!< Flags (see Flags enum).
113 bool warned; //!< Have we warned about unimplemented syscall?
115 /// Flag values for controlling syscall behavior.
117 /// Don't set return regs according to funcPtr return value.
118 /// Used for syscalls with non-standard return conventions
119 /// that explicitly set the ThreadContext regs (e.g.,
121 SuppressReturnValue = 1,
126 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
127 : name(_name), funcPtr(_funcPtr), flags(_flags), warned(false)
131 /// Emulate the syscall. Public interface for calling through funcPtr.
132 void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc);
134 /// Is the WarnOnce flag set?
135 bool warnOnce() const { return (flags & WarnOnce); }
139 //////////////////////////////////////////////////////////////////////
141 // The following emulation functions are generic enough that they
142 // don't need to be recompiled for different emulated OS's. They are
143 // defined in sim/syscall_emul.cc.
145 //////////////////////////////////////////////////////////////////////
148 /// Handler for unimplemented syscalls that we haven't thought about.
149 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
150 LiveProcess *p, ThreadContext *tc);
152 /// Handler for unimplemented syscalls that we never intend to
153 /// implement (signal handling, etc.) and should not affect the correct
154 /// behavior of the program. Print a warning only if the appropriate
155 /// trace flag is enabled. Return success to the target program.
156 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
157 LiveProcess *p, ThreadContext *tc);
159 /// Target exit() handler: terminate current context.
160 SyscallReturn exitFunc(SyscallDesc *desc, int num,
161 LiveProcess *p, ThreadContext *tc);
163 /// Target exit_group() handler: terminate simulation. (exit all threads)
164 SyscallReturn exitGroupFunc(SyscallDesc *desc, int num,
165 LiveProcess *p, ThreadContext *tc);
167 /// Target getpagesize() handler.
168 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
169 LiveProcess *p, ThreadContext *tc);
171 /// Target brk() handler: set brk address.
172 SyscallReturn brkFunc(SyscallDesc *desc, int num,
173 LiveProcess *p, ThreadContext *tc);
175 /// Target close() handler.
176 SyscallReturn closeFunc(SyscallDesc *desc, int num,
177 LiveProcess *p, ThreadContext *tc);
179 /// Target read() handler.
180 SyscallReturn readFunc(SyscallDesc *desc, int num,
181 LiveProcess *p, ThreadContext *tc);
183 /// Target write() handler.
184 SyscallReturn writeFunc(SyscallDesc *desc, int num,
185 LiveProcess *p, ThreadContext *tc);
187 /// Target lseek() handler.
188 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
189 LiveProcess *p, ThreadContext *tc);
191 /// Target _llseek() handler.
192 SyscallReturn _llseekFunc(SyscallDesc *desc, int num,
193 LiveProcess *p, ThreadContext *tc);
195 /// Target munmap() handler.
196 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
197 LiveProcess *p, ThreadContext *tc);
199 /// Target gethostname() handler.
200 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
201 LiveProcess *p, ThreadContext *tc);
203 /// Target getcwd() handler.
204 SyscallReturn getcwdFunc(SyscallDesc *desc, int num,
205 LiveProcess *p, ThreadContext *tc);
207 /// Target readlink() handler.
208 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
209 LiveProcess *p, ThreadContext *tc,
211 SyscallReturn readlinkFunc(SyscallDesc *desc, int num,
212 LiveProcess *p, ThreadContext *tc);
214 /// Target unlink() handler.
215 SyscallReturn unlinkHelper(SyscallDesc *desc, int num,
216 LiveProcess *p, ThreadContext *tc,
218 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
219 LiveProcess *p, ThreadContext *tc);
221 /// Target mkdir() handler.
222 SyscallReturn mkdirFunc(SyscallDesc *desc, int num,
223 LiveProcess *p, ThreadContext *tc);
225 /// Target rename() handler.
226 SyscallReturn renameFunc(SyscallDesc *desc, int num,
227 LiveProcess *p, ThreadContext *tc);
230 /// Target truncate() handler.
231 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
232 LiveProcess *p, ThreadContext *tc);
235 /// Target ftruncate() handler.
236 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
237 LiveProcess *p, ThreadContext *tc);
240 /// Target truncate64() handler.
241 SyscallReturn truncate64Func(SyscallDesc *desc, int num,
242 LiveProcess *p, ThreadContext *tc);
244 /// Target ftruncate64() handler.
245 SyscallReturn ftruncate64Func(SyscallDesc *desc, int num,
246 LiveProcess *p, ThreadContext *tc);
249 /// Target umask() handler.
250 SyscallReturn umaskFunc(SyscallDesc *desc, int num,
251 LiveProcess *p, ThreadContext *tc);
254 /// Target chown() handler.
255 SyscallReturn chownFunc(SyscallDesc *desc, int num,
256 LiveProcess *p, ThreadContext *tc);
259 /// Target fchown() handler.
260 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
261 LiveProcess *p, ThreadContext *tc);
263 /// Target dup() handler.
264 SyscallReturn dupFunc(SyscallDesc *desc, int num,
265 LiveProcess *process, ThreadContext *tc);
267 /// Target fnctl() handler.
268 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
269 LiveProcess *process, ThreadContext *tc);
271 /// Target fcntl64() handler.
272 SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
273 LiveProcess *process, ThreadContext *tc);
275 /// Target setuid() handler.
276 SyscallReturn setuidFunc(SyscallDesc *desc, int num,
277 LiveProcess *p, ThreadContext *tc);
279 /// Target getpid() handler.
280 SyscallReturn getpidFunc(SyscallDesc *desc, int num,
281 LiveProcess *p, ThreadContext *tc);
283 /// Target getuid() handler.
284 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
285 LiveProcess *p, ThreadContext *tc);
287 /// Target getgid() handler.
288 SyscallReturn getgidFunc(SyscallDesc *desc, int num,
289 LiveProcess *p, ThreadContext *tc);
291 /// Target getppid() handler.
292 SyscallReturn getppidFunc(SyscallDesc *desc, int num,
293 LiveProcess *p, ThreadContext *tc);
295 /// Target geteuid() handler.
296 SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
297 LiveProcess *p, ThreadContext *tc);
299 /// Target getegid() handler.
300 SyscallReturn getegidFunc(SyscallDesc *desc, int num,
301 LiveProcess *p, ThreadContext *tc);
303 /// Target clone() handler.
304 SyscallReturn cloneFunc(SyscallDesc *desc, int num,
305 LiveProcess *p, ThreadContext *tc);
307 /// Target access() handler
308 SyscallReturn accessFunc(SyscallDesc *desc, int num,
309 LiveProcess *p, ThreadContext *tc);
310 SyscallReturn accessFunc(SyscallDesc *desc, int num,
311 LiveProcess *p, ThreadContext *tc,
314 /// Futex system call
315 /// Implemented by Daniel Sanchez
316 /// Used by printf's in multi-threaded apps
319 futexFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
325 int index_timeout = 3;
327 uint64_t uaddr = process->getSyscallArg(tc, index_uaddr);
328 int op = process->getSyscallArg(tc, index_op);
329 int val = process->getSyscallArg(tc, index_val);
330 uint64_t timeout = process->getSyscallArg(tc, index_timeout);
332 std::map<uint64_t, std::list<ThreadContext *> * >
333 &futex_map = tc->getSystemPtr()->futexMap;
335 DPRINTF(SyscallVerbose, "In sys_futex: Address=%llx, op=%d, val=%d\n",
338 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
340 if (op == OS::TGT_FUTEX_WAIT) {
342 warn("sys_futex: FUTEX_WAIT with non-null timeout unimplemented;"
343 "we'll wait indefinitely");
346 uint8_t *buf = new uint8_t[sizeof(int)];
347 tc->getMemProxy().readBlob((Addr)uaddr, buf, (int)sizeof(int));
348 int mem_val = *((int *)buf);
351 if (val != mem_val) {
352 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, read: %d, "
353 "expected: %d\n", mem_val, val);
354 return -OS::TGT_EWOULDBLOCK;
357 // Queue the thread context
358 std::list<ThreadContext *> * tcWaitList;
359 if (futex_map.count(uaddr)) {
360 tcWaitList = futex_map.find(uaddr)->second;
362 tcWaitList = new std::list<ThreadContext *>();
363 futex_map.insert(std::pair< uint64_t,
364 std::list<ThreadContext *> * >(uaddr, tcWaitList));
366 tcWaitList->push_back(tc);
367 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAIT, suspending calling "
371 } else if (op == OS::TGT_FUTEX_WAKE){
373 std::list<ThreadContext *> * tcWaitList;
374 if (futex_map.count(uaddr)) {
375 tcWaitList = futex_map.find(uaddr)->second;
376 while (tcWaitList->size() > 0 && wokenUp < val) {
377 tcWaitList->front()->activate();
378 tcWaitList->pop_front();
381 if (tcWaitList->empty()) {
382 futex_map.erase(uaddr);
386 DPRINTF(SyscallVerbose, "sys_futex: FUTEX_WAKE, activated %d waiting "
387 "thread contexts\n", wokenUp);
390 warn("sys_futex: op %d is not implemented, just returning...", op);
397 /// Pseudo Funcs - These functions use a different return convension,
398 /// returning a second value in a register other than the normal return register
399 SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
400 LiveProcess *process, ThreadContext *tc);
402 /// Target getpidPseudo() handler.
403 SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
404 LiveProcess *p, ThreadContext *tc);
406 /// Target getuidPseudo() handler.
407 SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
408 LiveProcess *p, ThreadContext *tc);
410 /// Target getgidPseudo() handler.
411 SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
412 LiveProcess *p, ThreadContext *tc);
415 /// A readable name for 1,000,000, for converting microseconds to seconds.
416 const int one_million = 1000000;
417 /// A readable name for 1,000,000,000, for converting nanoseconds to seconds.
418 const int one_billion = 1000000000;
420 /// Approximate seconds since the epoch (1/1/1970). About a billion,
421 /// by my reckoning. We want to keep this a constant (not use the
422 /// real-world time) to keep simulations repeatable.
423 const unsigned seconds_since_epoch = 1000000000;
425 /// Helper function to convert current elapsed time to seconds and
427 template <class T1, class T2>
429 getElapsedTimeMicro(T1 &sec, T2 &usec)
431 uint64_t elapsed_usecs = curTick() / SimClock::Int::us;
432 sec = elapsed_usecs / one_million;
433 usec = elapsed_usecs % one_million;
436 /// Helper function to convert current elapsed time to seconds and
438 template <class T1, class T2>
440 getElapsedTimeNano(T1 &sec, T2 &nsec)
442 uint64_t elapsed_nsecs = curTick() / SimClock::Int::ns;
443 sec = elapsed_nsecs / one_billion;
444 nsec = elapsed_nsecs % one_billion;
447 //////////////////////////////////////////////////////////////////////
449 // The following emulation functions are generic, but need to be
450 // templated to account for differences in types, constants, etc.
452 //////////////////////////////////////////////////////////////////////
455 typedef struct stat hst_stat;
456 typedef struct stat hst_stat64;
458 typedef struct stat hst_stat;
459 typedef struct stat64 hst_stat64;
462 //// Helper function to convert a host stat buffer to a target stat
463 //// buffer. Also copies the target buffer out to the simulated
464 //// memory space. Used by stat(), fstat(), and lstat().
466 template <typename target_stat, typename host_stat>
468 convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
470 using namespace TheISA;
475 tgt->st_dev = host->st_dev;
476 tgt->st_dev = TheISA::htog(tgt->st_dev);
477 tgt->st_ino = host->st_ino;
478 tgt->st_ino = TheISA::htog(tgt->st_ino);
479 tgt->st_mode = host->st_mode;
481 // Claim to be a character device
482 tgt->st_mode &= ~S_IFMT; // Clear S_IFMT
483 tgt->st_mode |= S_IFCHR; // Set S_IFCHR
485 tgt->st_mode = TheISA::htog(tgt->st_mode);
486 tgt->st_nlink = host->st_nlink;
487 tgt->st_nlink = TheISA::htog(tgt->st_nlink);
488 tgt->st_uid = host->st_uid;
489 tgt->st_uid = TheISA::htog(tgt->st_uid);
490 tgt->st_gid = host->st_gid;
491 tgt->st_gid = TheISA::htog(tgt->st_gid);
493 tgt->st_rdev = 0x880d;
495 tgt->st_rdev = host->st_rdev;
496 tgt->st_rdev = TheISA::htog(tgt->st_rdev);
497 tgt->st_size = host->st_size;
498 tgt->st_size = TheISA::htog(tgt->st_size);
499 tgt->st_atimeX = host->st_atime;
500 tgt->st_atimeX = TheISA::htog(tgt->st_atimeX);
501 tgt->st_mtimeX = host->st_mtime;
502 tgt->st_mtimeX = TheISA::htog(tgt->st_mtimeX);
503 tgt->st_ctimeX = host->st_ctime;
504 tgt->st_ctimeX = TheISA::htog(tgt->st_ctimeX);
505 // Force the block size to be 8k. This helps to ensure buffered io works
506 // consistently across different hosts.
507 tgt->st_blksize = 0x2000;
508 tgt->st_blksize = TheISA::htog(tgt->st_blksize);
509 tgt->st_blocks = host->st_blocks;
510 tgt->st_blocks = TheISA::htog(tgt->st_blocks);
515 template <typename target_stat, typename host_stat64>
517 convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
519 using namespace TheISA;
521 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
522 #if defined(STAT_HAVE_NSEC)
523 tgt->st_atime_nsec = host->st_atime_nsec;
524 tgt->st_atime_nsec = TheISA::htog(tgt->st_atime_nsec);
525 tgt->st_mtime_nsec = host->st_mtime_nsec;
526 tgt->st_mtime_nsec = TheISA::htog(tgt->st_mtime_nsec);
527 tgt->st_ctime_nsec = host->st_ctime_nsec;
528 tgt->st_ctime_nsec = TheISA::htog(tgt->st_ctime_nsec);
530 tgt->st_atime_nsec = 0;
531 tgt->st_mtime_nsec = 0;
532 tgt->st_ctime_nsec = 0;
536 //Here are a couple convenience functions
539 copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
540 hst_stat *host, bool fakeTTY = false)
542 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
543 tgt_stat_buf tgt(addr);
544 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
550 copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
551 hst_stat64 *host, bool fakeTTY = false)
553 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
554 tgt_stat_buf tgt(addr);
555 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
559 /// Target ioctl() handler. For the most part, programs call ioctl()
560 /// only to find out if their stdout is a tty, to determine whether to
561 /// do line or block buffering. We always claim that output fds are
562 /// not TTYs to provide repeatable results.
565 ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
569 int tgt_fd = process->getSyscallArg(tc, index);
570 unsigned req = process->getSyscallArg(tc, index);
572 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
574 FDEntry *fde = process->getFDEntry(tgt_fd);
577 // doesn't map to any simulator fd: not a valid target fd
581 if (fde->driver != NULL) {
582 return fde->driver->ioctl(process, tc, req);
585 if (OS::isTtyReq(req)) {
589 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n",
590 tgt_fd, req, tc->pcState());
596 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
597 ThreadContext *tc, int index)
601 if (!tc->getMemProxy().tryReadString(path,
602 process->getSyscallArg(tc, index)))
605 int tgtFlags = process->getSyscallArg(tc, index);
606 int mode = process->getSyscallArg(tc, index);
609 // translate open flags
610 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
611 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
612 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
613 hostFlags |= OS::openFlagTable[i].hostFlag;
617 // any target flags left?
619 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
622 hostFlags |= O_BINARY;
625 // Adjust path for current working directory
626 path = process->fullPath(path);
628 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
630 if (startswith(path, "/dev/")) {
631 std::string filename = path.substr(strlen("/dev/"));
632 if (filename == "sysdev0") {
633 // This is a memory-mapped high-resolution timer device on Alpha.
634 // We don't support it, so just punt.
635 warn("Ignoring open(%s, ...)\n", path);
639 EmulatedDriver *drv = process->findDriver(filename);
641 // the driver's open method will allocate a fd from the
642 // process if necessary.
643 return drv->open(process, tc, mode, hostFlags);
646 // fall through here for pass through to host devices, such as
652 if (startswith(path, "/proc/") || startswith(path, "/system/") ||
653 startswith(path, "/platform/") || startswith(path, "/sys/")) {
654 // It's a proc/sys entry and requires special handling
655 fd = OS::openSpecialFile(path, process, tc);
656 local_errno = ENOENT;
659 fd = open(path.c_str(), hostFlags, mode);
666 return process->allocFD(fd, path.c_str(), hostFlags, mode, false);
669 /// Target open() handler.
672 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
675 return openFunc<OS>(desc, callnum, process, tc, 0);
678 /// Target openat() handler.
681 openatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
685 int dirfd = process->getSyscallArg(tc, index);
686 if (dirfd != OS::TGT_AT_FDCWD)
687 warn("openat: first argument not AT_FDCWD; unlikely to work");
688 return openFunc<OS>(desc, callnum, process, tc, 1);
691 /// Target unlinkat() handler.
694 unlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
698 int dirfd = process->getSyscallArg(tc, index);
699 if (dirfd != OS::TGT_AT_FDCWD)
700 warn("unlinkat: first argument not AT_FDCWD; unlikely to work");
702 return unlinkHelper(desc, callnum, process, tc, 1);
705 /// Target facessat() handler
708 faccessatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
712 int dirfd = process->getSyscallArg(tc, index);
713 if (dirfd != OS::TGT_AT_FDCWD)
714 warn("faccessat: first argument not AT_FDCWD; unlikely to work");
715 return accessFunc(desc, callnum, process, tc, 1);
718 /// Target readlinkat() handler
721 readlinkatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
725 int dirfd = process->getSyscallArg(tc, index);
726 if (dirfd != OS::TGT_AT_FDCWD)
727 warn("openat: first argument not AT_FDCWD; unlikely to work");
728 return readlinkFunc(desc, callnum, process, tc, 1);
731 /// Target renameat() handler.
734 renameatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
739 int olddirfd = process->getSyscallArg(tc, index);
740 if (olddirfd != OS::TGT_AT_FDCWD)
741 warn("renameat: first argument not AT_FDCWD; unlikely to work");
743 std::string old_name;
745 if (!tc->getMemProxy().tryReadString(old_name,
746 process->getSyscallArg(tc, index)))
749 int newdirfd = process->getSyscallArg(tc, index);
750 if (newdirfd != OS::TGT_AT_FDCWD)
751 warn("renameat: third argument not AT_FDCWD; unlikely to work");
753 std::string new_name;
755 if (!tc->getMemProxy().tryReadString(new_name,
756 process->getSyscallArg(tc, index)))
759 // Adjust path for current working directory
760 old_name = process->fullPath(old_name);
761 new_name = process->fullPath(new_name);
763 int result = rename(old_name.c_str(), new_name.c_str());
764 return (result == -1) ? -errno : result;
767 /// Target sysinfo() handler.
770 sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
775 TypedBufferArg<typename OS::tgt_sysinfo>
776 sysinfo(process->getSyscallArg(tc, index));
778 sysinfo->uptime=seconds_since_epoch;
779 sysinfo->totalram=process->system->memSize();
781 sysinfo.copyOut(tc->getMemProxy());
786 /// Target chmod() handler.
789 chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
795 if (!tc->getMemProxy().tryReadString(path,
796 process->getSyscallArg(tc, index))) {
800 uint32_t mode = process->getSyscallArg(tc, index);
803 // XXX translate mode flags via OS::something???
806 // Adjust path for current working directory
807 path = process->fullPath(path);
810 int result = chmod(path.c_str(), hostMode);
818 /// Target fchmod() handler.
821 fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
825 int tgt_fd = process->getSyscallArg(tc, index);
826 uint32_t mode = process->getSyscallArg(tc, index);
828 int sim_fd = process->getSimFD(tgt_fd);
834 // XXX translate mode flags via OS::someting???
838 int result = fchmod(sim_fd, hostMode);
845 /// Target mremap() handler.
848 mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc)
851 Addr start = process->getSyscallArg(tc, index);
852 uint64_t old_length = process->getSyscallArg(tc, index);
853 uint64_t new_length = process->getSyscallArg(tc, index);
854 uint64_t flags = process->getSyscallArg(tc, index);
855 uint64_t provided_address = 0;
856 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
858 if (use_provided_address)
859 provided_address = process->getSyscallArg(tc, index);
861 if ((start % TheISA::PageBytes != 0) ||
862 (provided_address % TheISA::PageBytes != 0)) {
863 warn("mremap failing: arguments not page aligned");
867 new_length = roundUp(new_length, TheISA::PageBytes);
869 if (new_length > old_length) {
870 if ((start + old_length) == process->mmap_end &&
871 (!use_provided_address || provided_address == start)) {
872 uint64_t diff = new_length - old_length;
873 process->allocateMem(process->mmap_end, diff);
874 process->mmap_end += diff;
877 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
878 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
881 uint64_t new_start = use_provided_address ?
882 provided_address : process->mmap_end;
883 process->pTable->remap(start, old_length, new_start);
884 warn("mremapping to new vaddr %08p-%08p, adding %d\n",
885 new_start, new_start + new_length,
886 new_length - old_length);
887 // add on the remaining unallocated pages
888 process->allocateMem(new_start + old_length,
889 new_length - old_length,
890 use_provided_address /* clobber */);
891 if (!use_provided_address)
892 process->mmap_end += new_length;
893 if (use_provided_address &&
894 new_start + new_length > process->mmap_end) {
895 // something fishy going on here, at least notify the user
896 // @todo: increase mmap_end?
897 warn("mmap region limit exceeded with MREMAP_FIXED\n");
899 warn("returning %08p as start\n", new_start);
904 if (use_provided_address && provided_address != start)
905 process->pTable->remap(start, new_length, provided_address);
906 process->pTable->unmap(start + new_length, old_length - new_length);
907 return use_provided_address ? provided_address : start;
911 /// Target stat() handler.
914 statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
920 if (!tc->getMemProxy().tryReadString(path,
921 process->getSyscallArg(tc, index))) {
924 Addr bufPtr = process->getSyscallArg(tc, index);
926 // Adjust path for current working directory
927 path = process->fullPath(path);
930 int result = stat(path.c_str(), &hostBuf);
935 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
941 /// Target stat64() handler.
944 stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
950 if (!tc->getMemProxy().tryReadString(path,
951 process->getSyscallArg(tc, index)))
953 Addr bufPtr = process->getSyscallArg(tc, index);
955 // Adjust path for current working directory
956 path = process->fullPath(path);
960 int result = stat(path.c_str(), &hostBuf);
962 struct stat64 hostBuf;
963 int result = stat64(path.c_str(), &hostBuf);
969 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
975 /// Target fstatat64() handler.
978 fstatat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
982 int dirfd = process->getSyscallArg(tc, index);
983 if (dirfd != OS::TGT_AT_FDCWD)
984 warn("fstatat64: first argument not AT_FDCWD; unlikely to work");
987 if (!tc->getMemProxy().tryReadString(path,
988 process->getSyscallArg(tc, index)))
990 Addr bufPtr = process->getSyscallArg(tc, index);
992 // Adjust path for current working directory
993 path = process->fullPath(path);
997 int result = stat(path.c_str(), &hostBuf);
999 struct stat64 hostBuf;
1000 int result = stat64(path.c_str(), &hostBuf);
1006 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1012 /// Target fstat64() handler.
1015 fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1019 int tgt_fd = process->getSyscallArg(tc, index);
1020 Addr bufPtr = process->getSyscallArg(tc, index);
1022 int sim_fd = process->getSimFD(tgt_fd);
1027 struct stat hostBuf;
1028 int result = fstat(sim_fd, &hostBuf);
1030 struct stat64 hostBuf;
1031 int result = fstat64(sim_fd, &hostBuf);
1037 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1043 /// Target lstat() handler.
1046 lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1052 if (!tc->getMemProxy().tryReadString(path,
1053 process->getSyscallArg(tc, index))) {
1056 Addr bufPtr = process->getSyscallArg(tc, index);
1058 // Adjust path for current working directory
1059 path = process->fullPath(path);
1061 struct stat hostBuf;
1062 int result = lstat(path.c_str(), &hostBuf);
1067 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1072 /// Target lstat64() handler.
1075 lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
1081 if (!tc->getMemProxy().tryReadString(path,
1082 process->getSyscallArg(tc, index))) {
1085 Addr bufPtr = process->getSyscallArg(tc, index);
1087 // Adjust path for current working directory
1088 path = process->fullPath(path);
1091 struct stat hostBuf;
1092 int result = lstat(path.c_str(), &hostBuf);
1094 struct stat64 hostBuf;
1095 int result = lstat64(path.c_str(), &hostBuf);
1101 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
1106 /// Target fstat() handler.
1109 fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1113 int tgt_fd = process->getSyscallArg(tc, index);
1114 Addr bufPtr = process->getSyscallArg(tc, index);
1116 DPRINTF_SYSCALL(Verbose, "fstat(%d, ...)\n", tgt_fd);
1118 int sim_fd = process->getSimFD(tgt_fd);
1122 struct stat hostBuf;
1123 int result = fstat(sim_fd, &hostBuf);
1128 copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1134 /// Target statfs() handler.
1137 statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1143 if (!tc->getMemProxy().tryReadString(path,
1144 process->getSyscallArg(tc, index))) {
1147 Addr bufPtr = process->getSyscallArg(tc, index);
1149 // Adjust path for current working directory
1150 path = process->fullPath(path);
1152 struct statfs hostBuf;
1153 int result = statfs(path.c_str(), &hostBuf);
1158 OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
1164 /// Target fstatfs() handler.
1167 fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1171 int tgt_fd = process->getSyscallArg(tc, index);
1172 Addr bufPtr = process->getSyscallArg(tc, index);
1174 int sim_fd = process->getSimFD(tgt_fd);
1178 struct statfs hostBuf;
1179 int result = fstatfs(sim_fd, &hostBuf);
1184 OS::copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf);
1190 /// Target writev() handler.
1193 writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1197 int tgt_fd = process->getSyscallArg(tc, index);
1199 int sim_fd = process->getSimFD(tgt_fd);
1203 SETranslatingPortProxy &p = tc->getMemProxy();
1204 uint64_t tiov_base = process->getSyscallArg(tc, index);
1205 size_t count = process->getSyscallArg(tc, index);
1206 struct iovec hiov[count];
1207 for (size_t i = 0; i < count; ++i) {
1208 typename OS::tgt_iovec tiov;
1210 p.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1211 (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
1212 hiov[i].iov_len = TheISA::gtoh(tiov.iov_len);
1213 hiov[i].iov_base = new char [hiov[i].iov_len];
1214 p.readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
1218 int result = writev(sim_fd, hiov, count);
1220 for (size_t i = 0; i < count; ++i)
1221 delete [] (char *)hiov[i].iov_base;
1229 /// Real mmap handler.
1232 mmapImpl(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
1236 Addr start = p->getSyscallArg(tc, index);
1237 uint64_t length = p->getSyscallArg(tc, index);
1238 int prot = p->getSyscallArg(tc, index);
1239 int tgt_flags = p->getSyscallArg(tc, index);
1240 int tgt_fd = p->getSyscallArg(tc, index);
1241 int offset = p->getSyscallArg(tc, index);
1244 offset *= TheISA::PageBytes;
1246 if (start & (TheISA::PageBytes - 1) ||
1247 offset & (TheISA::PageBytes - 1) ||
1248 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1249 tgt_flags & OS::TGT_MAP_SHARED) ||
1250 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1251 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1256 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1257 // With shared mmaps, there are two cases to consider:
1258 // 1) anonymous: writes should modify the mapping and this should be
1259 // visible to observers who share the mapping. Currently, it's
1260 // difficult to update the shared mapping because there's no
1261 // structure which maintains information about the which virtual
1262 // memory areas are shared. If that structure existed, it would be
1263 // possible to make the translations point to the same frames.
1264 // 2) file-backed: writes should modify the mapping and the file
1265 // which is backed by the mapping. The shared mapping problem is the
1266 // same as what was mentioned about the anonymous mappings. For
1267 // file-backed mappings, the writes to the file are difficult
1268 // because it requires syncing what the mapping holds with the file
1269 // that resides on the host system. So, any write on a real system
1270 // would cause the change to be propagated to the file mapping at
1271 // some point in the future (the inode is tracked along with the
1272 // mapping). This isn't guaranteed to always happen, but it usually
1273 // works well enough. The guarantee is provided by the msync system
1274 // call. We could force the change through with shared mappings with
1275 // a call to msync, but that again would require more information
1276 // than we currently maintain.
1277 warn("mmap: writing to shared mmap region is currently "
1278 "unsupported. The write succeeds on the target, but it "
1279 "will not be propagated to the host or shared mappings");
1282 length = roundUp(length, TheISA::PageBytes);
1285 uint8_t *pmap = nullptr;
1286 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1287 sim_fd = p->getSimFD(tgt_fd);
1291 pmap = (decltype(pmap))mmap(NULL, length, PROT_READ, MAP_PRIVATE,
1294 if (pmap == (decltype(pmap))-1) {
1295 warn("mmap: failed to map file into host address space");
1300 // Extend global mmap region if necessary. Note that we ignore the
1301 // start address unless MAP_FIXED is specified.
1302 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1303 start = p->mmapGrowsDown() ? p->mmap_end - length : p->mmap_end;
1304 p->mmap_end = p->mmapGrowsDown() ? start : p->mmap_end + length;
1307 DPRINTF_SYSCALL(Verbose, " mmap range is 0x%x - 0x%x\n",
1308 start, start + length - 1);
1310 // We only allow mappings to overwrite existing mappings if
1311 // TGT_MAP_FIXED is set. Otherwise it shouldn't be a problem
1312 // because we ignore the start hint if TGT_MAP_FIXED is not set.
1313 int clobber = tgt_flags & OS::TGT_MAP_FIXED;
1315 for (auto tc : p->system->threadContexts) {
1316 // If we might be overwriting old mappings, we need to
1317 // invalidate potentially stale mappings out of the TLBs.
1318 tc->getDTBPtr()->flushAll();
1319 tc->getITBPtr()->flushAll();
1323 // Allocate physical memory and map it in. If the page table is already
1324 // mapped and clobber is not set, the simulator will issue throw a
1325 // fatal and bail out of the simulation.
1326 p->allocateMem(start, length, clobber);
1328 // Transfer content into target address space.
1329 SETranslatingPortProxy &tp = tc->getMemProxy();
1330 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1331 // In general, we should zero the mapped area for anonymous mappings,
1332 // with something like:
1333 // tp.memsetBlob(start, 0, length);
1334 // However, given that we don't support sparse mappings, and
1335 // some applications can map a couple of gigabytes of space
1336 // (intending sparse usage), that can get painfully expensive.
1337 // Fortunately, since we don't properly implement munmap either,
1338 // there's no danger of remapping used memory, so for now all
1339 // newly mapped memory should already be zeroed so we can skip it.
1341 // It is possible to mmap an area larger than a file, however
1342 // accessing unmapped portions the system triggers a "Bus error"
1343 // on the host. We must know when to stop copying the file from
1344 // the host into the target address space.
1345 struct stat file_stat;
1346 if (fstat(sim_fd, &file_stat) > 0)
1347 fatal("mmap: cannot stat file");
1349 // Copy the portion of the file that is resident. This requires
1350 // checking both the mmap size and the filesize that we are
1351 // trying to mmap into this space; the mmap size also depends
1352 // on the specified offset into the file.
1353 uint64_t size = std::min((uint64_t)file_stat.st_size - offset,
1355 tp.writeBlob(start, pmap, size);
1357 // Cleanup the mmap region before exiting this function.
1358 munmap(pmap, length);
1360 // Maintain the symbol table for dynamic executables.
1361 // The loader will call mmap to map the images into its address
1362 // space and we intercept that here. We can verify that we are
1363 // executing inside the loader by checking the program counter value.
1364 // XXX: with multiprogrammed workloads or multi-node configurations,
1365 // this will not work since there is a single global symbol table.
1366 ObjectFile *interpreter = p->getInterpreter();
1368 Addr text_start = interpreter->textBase();
1369 Addr text_end = text_start + interpreter->textSize();
1371 Addr pc = tc->pcState().pc();
1373 if (pc >= text_start && pc < text_end) {
1374 FDEntry *fde = p->getFDEntry(tgt_fd);
1376 ObjectFile *lib = createObjectFile(fde->filename);
1379 lib->loadAllSymbols(debugSymbolTable,
1380 lib->textBase(), start);
1385 // Note that we do not zero out the remainder of the mapping. This
1386 // is done by a real system, but it probably will not affect
1387 // execution (hopefully).
1395 pwrite64Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1398 int tgt_fd = p->getSyscallArg(tc, index);
1399 Addr bufPtr = p->getSyscallArg(tc, index);
1400 int nbytes = p->getSyscallArg(tc, index);
1401 int offset = p->getSyscallArg(tc, index);
1403 int sim_fd = p->getSimFD(tgt_fd);
1407 BufferArg bufArg(bufPtr, nbytes);
1408 bufArg.copyIn(tc->getMemProxy());
1410 int bytes_written = pwrite(sim_fd, bufArg.bufferPtr(), nbytes, offset);
1412 return (bytes_written == -1) ? -errno : bytes_written;
1415 /// Target mmap() handler.
1418 mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1420 return mmapImpl<OS>(desc, num, p, tc, false);
1423 /// Target mmap2() handler.
1426 mmap2Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1428 return mmapImpl<OS>(desc, num, p, tc, true);
1431 /// Target getrlimit() handler.
1434 getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1438 unsigned resource = process->getSyscallArg(tc, index);
1439 TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
1442 case OS::TGT_RLIMIT_STACK:
1443 // max stack size in bytes: make up a number (8MB for now)
1444 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1445 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1446 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1449 case OS::TGT_RLIMIT_DATA:
1450 // max data segment size in bytes: make up a number
1451 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1452 rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
1453 rlp->rlim_max = TheISA::htog(rlp->rlim_max);
1457 warn("getrlimit: unimplemented resource %d", resource);
1462 rlp.copyOut(tc->getMemProxy());
1466 /// Target clock_gettime() function.
1469 clock_gettimeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1472 //int clk_id = p->getSyscallArg(tc, index);
1473 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1475 getElapsedTimeNano(tp->tv_sec, tp->tv_nsec);
1476 tp->tv_sec += seconds_since_epoch;
1477 tp->tv_sec = TheISA::htog(tp->tv_sec);
1478 tp->tv_nsec = TheISA::htog(tp->tv_nsec);
1480 tp.copyOut(tc->getMemProxy());
1485 /// Target clock_getres() function.
1488 clock_getresFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
1491 TypedBufferArg<typename OS::timespec> tp(p->getSyscallArg(tc, index));
1493 // Set resolution at ns, which is what clock_gettime() returns
1497 tp.copyOut(tc->getMemProxy());
1502 /// Target gettimeofday() handler.
1505 gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1509 TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
1511 getElapsedTimeMicro(tp->tv_sec, tp->tv_usec);
1512 tp->tv_sec += seconds_since_epoch;
1513 tp->tv_sec = TheISA::htog(tp->tv_sec);
1514 tp->tv_usec = TheISA::htog(tp->tv_usec);
1516 tp.copyOut(tc->getMemProxy());
1522 /// Target utimes() handler.
1525 utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1531 if (!tc->getMemProxy().tryReadString(path,
1532 process->getSyscallArg(tc, index))) {
1536 TypedBufferArg<typename OS::timeval [2]>
1537 tp(process->getSyscallArg(tc, index));
1538 tp.copyIn(tc->getMemProxy());
1540 struct timeval hostTimeval[2];
1541 for (int i = 0; i < 2; ++i)
1543 hostTimeval[i].tv_sec = TheISA::gtoh((*tp)[i].tv_sec);
1544 hostTimeval[i].tv_usec = TheISA::gtoh((*tp)[i].tv_usec);
1547 // Adjust path for current working directory
1548 path = process->fullPath(path);
1550 int result = utimes(path.c_str(), hostTimeval);
1557 /// Target getrusage() function.
1560 getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1564 int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
1565 TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
1567 rup->ru_utime.tv_sec = 0;
1568 rup->ru_utime.tv_usec = 0;
1569 rup->ru_stime.tv_sec = 0;
1570 rup->ru_stime.tv_usec = 0;
1578 rup->ru_inblock = 0;
1579 rup->ru_oublock = 0;
1582 rup->ru_nsignals = 0;
1587 case OS::TGT_RUSAGE_SELF:
1588 getElapsedTimeMicro(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
1589 rup->ru_utime.tv_sec = TheISA::htog(rup->ru_utime.tv_sec);
1590 rup->ru_utime.tv_usec = TheISA::htog(rup->ru_utime.tv_usec);
1593 case OS::TGT_RUSAGE_CHILDREN:
1594 // do nothing. We have no child processes, so they take no time.
1598 // don't really handle THREAD or CHILDREN, but just warn and
1600 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
1604 rup.copyOut(tc->getMemProxy());
1609 /// Target times() function.
1612 timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1616 TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
1618 // Fill in the time structure (in clocks)
1619 int64_t clocks = curTick() * OS::M5_SC_CLK_TCK / SimClock::Int::s;
1620 bufp->tms_utime = clocks;
1621 bufp->tms_stime = 0;
1622 bufp->tms_cutime = 0;
1623 bufp->tms_cstime = 0;
1625 // Convert to host endianness
1626 bufp->tms_utime = TheISA::htog(bufp->tms_utime);
1629 bufp.copyOut(tc->getMemProxy());
1631 // Return clock ticks since system boot
1635 /// Target time() function.
1638 timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1641 typename OS::time_t sec, usec;
1642 getElapsedTimeMicro(sec, usec);
1643 sec += seconds_since_epoch;
1646 Addr taddr = (Addr)process->getSyscallArg(tc, index);
1648 typename OS::time_t t = sec;
1649 t = TheISA::htog(t);
1650 SETranslatingPortProxy &p = tc->getMemProxy();
1651 p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
1657 #endif // __SIM_SYSCALL_EMUL_HH__