2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
32 #ifndef __SIM_SYSCALL_EMUL_HH__
33 #define __SIM_SYSCALL_EMUL_HH__
35 #define NO_STAT64 (defined(__APPLE__) || defined(__OpenBSD__) || \
36 defined(__FreeBSD__) || defined(__CYGWIN__))
39 /// @file syscall_emul.hh
41 /// This file defines objects used to emulate syscalls from the target
42 /// application on the host machine.
47 #include <sys/fcntl.h> // for O_BINARY
53 #include "sim/host.hh" // for Addr
54 #include "base/chunk_generator.hh"
55 #include "base/intmath.hh" // for RoundUp
56 #include "base/misc.hh"
57 #include "base/trace.hh"
58 #include "cpu/base.hh"
59 #include "cpu/thread_context.hh"
60 #include "mem/translating_port.hh"
61 #include "mem/page_table.hh"
62 #include "sim/process.hh"
65 /// System call descriptor.
71 /// Typedef for target syscall handler functions.
72 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
73 LiveProcess *, ThreadContext *);
75 const char *name; //!< Syscall name (e.g., "open").
76 FuncPtr funcPtr; //!< Pointer to emulation function.
77 int flags; //!< Flags (see Flags enum).
79 /// Flag values for controlling syscall behavior.
81 /// Don't set return regs according to funcPtr return value.
82 /// Used for syscalls with non-standard return conventions
83 /// that explicitly set the ThreadContext regs (e.g.,
85 SuppressReturnValue = 1
89 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
90 : name(_name), funcPtr(_funcPtr), flags(_flags)
94 /// Emulate the syscall. Public interface for calling through funcPtr.
95 void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc);
103 BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size)
105 bufPtr = new uint8_t[size];
106 // clear out buffer: in case we only partially populate this,
107 // and then do a copyOut(), we want to make sure we don't
108 // introduce any random junk into the simulated address space
109 memset(bufPtr, 0, size);
112 virtual ~BaseBufferArg() { delete [] bufPtr; }
115 // copy data into simulator space (read from target memory)
117 virtual bool copyIn(TranslatingPort *memport)
119 memport->readBlob(addr, bufPtr, size);
120 return true; // no EFAULT detection for now
124 // copy data out of simulator space (write to target memory)
126 virtual bool copyOut(TranslatingPort *memport)
128 memport->writeBlob(addr, bufPtr, size);
129 return true; // no EFAULT detection for now
139 class BufferArg : public BaseBufferArg
142 BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
143 void *bufferPtr() { return bufPtr; }
147 class TypedBufferArg : public BaseBufferArg
150 // user can optionally specify a specific number of bytes to
151 // allocate to deal with those structs that have variable-size
153 TypedBufferArg(Addr _addr, int _size = sizeof(T))
154 : BaseBufferArg(_addr, _size)
158 operator T*() { return (T *)bufPtr; }
160 // dereference operators
161 T &operator*() { return *((T *)bufPtr); }
162 T* operator->() { return (T *)bufPtr; }
163 T &operator[](int i) { return ((T *)bufPtr)[i]; }
166 //////////////////////////////////////////////////////////////////////
168 // The following emulation functions are generic enough that they
169 // don't need to be recompiled for different emulated OS's. They are
170 // defined in sim/syscall_emul.cc.
172 //////////////////////////////////////////////////////////////////////
175 /// Handler for unimplemented syscalls that we haven't thought about.
176 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
177 LiveProcess *p, ThreadContext *tc);
179 /// Handler for unimplemented syscalls that we never intend to
180 /// implement (signal handling, etc.) and should not affect the correct
181 /// behavior of the program. Print a warning only if the appropriate
182 /// trace flag is enabled. Return success to the target program.
183 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
184 LiveProcess *p, ThreadContext *tc);
186 /// Target exit() handler: terminate simulation.
187 SyscallReturn exitFunc(SyscallDesc *desc, int num,
188 LiveProcess *p, ThreadContext *tc);
190 /// Target getpagesize() handler.
191 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
192 LiveProcess *p, ThreadContext *tc);
194 /// Target obreak() handler: set brk address.
195 SyscallReturn obreakFunc(SyscallDesc *desc, int num,
196 LiveProcess *p, ThreadContext *tc);
198 /// Target close() handler.
199 SyscallReturn closeFunc(SyscallDesc *desc, int num,
200 LiveProcess *p, ThreadContext *tc);
202 /// Target read() handler.
203 SyscallReturn readFunc(SyscallDesc *desc, int num,
204 LiveProcess *p, ThreadContext *tc);
206 /// Target write() handler.
207 SyscallReturn writeFunc(SyscallDesc *desc, int num,
208 LiveProcess *p, ThreadContext *tc);
210 /// Target lseek() handler.
211 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
212 LiveProcess *p, ThreadContext *tc);
214 /// Target munmap() handler.
215 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
216 LiveProcess *p, ThreadContext *tc);
218 /// Target gethostname() handler.
219 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
220 LiveProcess *p, ThreadContext *tc);
222 /// Target unlink() handler.
223 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
224 LiveProcess *p, ThreadContext *tc);
226 /// Target rename() handler.
227 SyscallReturn renameFunc(SyscallDesc *desc, int num,
228 LiveProcess *p, ThreadContext *tc);
231 /// Target truncate() handler.
232 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
233 LiveProcess *p, ThreadContext *tc);
236 /// Target ftruncate() handler.
237 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
238 LiveProcess *p, ThreadContext *tc);
241 /// Target chown() handler.
242 SyscallReturn chownFunc(SyscallDesc *desc, int num,
243 LiveProcess *p, ThreadContext *tc);
246 /// Target fchown() handler.
247 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
248 LiveProcess *p, ThreadContext *tc);
250 /// Target dup() handler.
251 SyscallReturn dupFunc(SyscallDesc *desc, int num,
252 LiveProcess *process, ThreadContext *tc);
254 /// Target fnctl() handler.
255 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
256 LiveProcess *process, ThreadContext *tc);
258 /// Target fcntl64() handler.
259 SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
260 LiveProcess *process, ThreadContext *tc);
262 /// Target setuid() handler.
263 SyscallReturn setuidFunc(SyscallDesc *desc, int num,
264 LiveProcess *p, ThreadContext *tc);
266 /// Target getpid() handler.
267 SyscallReturn getpidFunc(SyscallDesc *desc, int num,
268 LiveProcess *p, ThreadContext *tc);
270 /// Target getuid() handler.
271 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
272 LiveProcess *p, ThreadContext *tc);
274 /// Target getgid() handler.
275 SyscallReturn getgidFunc(SyscallDesc *desc, int num,
276 LiveProcess *p, ThreadContext *tc);
278 /// Target getppid() handler.
279 SyscallReturn getppidFunc(SyscallDesc *desc, int num,
280 LiveProcess *p, ThreadContext *tc);
282 /// Target geteuid() handler.
283 SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
284 LiveProcess *p, ThreadContext *tc);
286 /// Target getegid() handler.
287 SyscallReturn getegidFunc(SyscallDesc *desc, int num,
288 LiveProcess *p, ThreadContext *tc);
292 /// Pseudo Funcs - These functions use a different return convension,
293 /// returning a second value in a register other than the normal return register
294 SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
295 LiveProcess *process, ThreadContext *tc);
297 /// Target getpidPseudo() handler.
298 SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
299 LiveProcess *p, ThreadContext *tc);
301 /// Target getuidPseudo() handler.
302 SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
303 LiveProcess *p, ThreadContext *tc);
305 /// Target getgidPseudo() handler.
306 SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
307 LiveProcess *p, ThreadContext *tc);
310 /// A readable name for 1,000,000, for converting microseconds to seconds.
311 const int one_million = 1000000;
313 /// Approximate seconds since the epoch (1/1/1970). About a billion,
314 /// by my reckoning. We want to keep this a constant (not use the
315 /// real-world time) to keep simulations repeatable.
316 const unsigned seconds_since_epoch = 1000000000;
318 /// Helper function to convert current elapsed time to seconds and
320 template <class T1, class T2>
322 getElapsedTime(T1 &sec, T2 &usec)
324 int elapsed_usecs = curTick / Clock::Int::us;
325 sec = elapsed_usecs / one_million;
326 usec = elapsed_usecs % one_million;
329 //////////////////////////////////////////////////////////////////////
331 // The following emulation functions are generic, but need to be
332 // templated to account for differences in types, constants, etc.
334 //////////////////////////////////////////////////////////////////////
337 typedef struct stat hst_stat;
338 typedef struct stat hst_stat64;
340 typedef struct stat hst_stat;
341 typedef struct stat64 hst_stat64;
344 //// Helper function to convert a host stat buffer to a target stat
345 //// buffer. Also copies the target buffer out to the simulated
346 //// memory space. Used by stat(), fstat(), and lstat().
348 template <typename target_stat, typename host_stat>
350 convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
355 tgt->st_dev = host->st_dev;
356 tgt->st_dev = htog(tgt->st_dev);
357 tgt->st_ino = host->st_ino;
358 tgt->st_ino = htog(tgt->st_ino);
359 tgt->st_mode = host->st_mode;
360 tgt->st_mode = htog(tgt->st_mode);
361 tgt->st_nlink = host->st_nlink;
362 tgt->st_nlink = htog(tgt->st_nlink);
363 tgt->st_uid = host->st_uid;
364 tgt->st_uid = htog(tgt->st_uid);
365 tgt->st_gid = host->st_gid;
366 tgt->st_gid = htog(tgt->st_gid);
368 tgt->st_rdev = 0x880d;
370 tgt->st_rdev = host->st_rdev;
371 tgt->st_rdev = htog(tgt->st_rdev);
372 tgt->st_size = host->st_size;
373 tgt->st_size = htog(tgt->st_size);
374 tgt->st_atimeX = host->st_atime;
375 tgt->st_atimeX = htog(tgt->st_atimeX);
376 tgt->st_mtimeX = host->st_mtime;
377 tgt->st_mtimeX = htog(tgt->st_mtimeX);
378 tgt->st_ctimeX = host->st_ctime;
379 tgt->st_ctimeX = htog(tgt->st_ctimeX);
380 tgt->st_blksize = host->st_blksize;
381 tgt->st_blksize = htog(tgt->st_blksize);
382 tgt->st_blocks = host->st_blocks;
383 tgt->st_blocks = htog(tgt->st_blocks);
388 template <typename target_stat, typename host_stat64>
390 convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
392 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
393 #if defined(STAT_HAVE_NSEC)
394 tgt->st_atime_nsec = host->st_atime_nsec;
395 tgt->st_atime_nsec = htog(tgt->st_atime_nsec);
396 tgt->st_mtime_nsec = host->st_mtime_nsec;
397 tgt->st_mtime_nsec = htog(tgt->st_mtime_nsec);
398 tgt->st_ctime_nsec = host->st_ctime_nsec;
399 tgt->st_ctime_nsec = htog(tgt->st_ctime_nsec);
401 tgt->st_atime_nsec = 0;
402 tgt->st_mtime_nsec = 0;
403 tgt->st_ctime_nsec = 0;
407 //Here are a couple convenience functions
410 copyOutStatBuf(TranslatingPort * mem, Addr addr,
411 hst_stat *host, bool fakeTTY = false)
413 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
414 tgt_stat_buf tgt(addr);
415 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
421 copyOutStat64Buf(TranslatingPort * mem, Addr addr,
422 hst_stat64 *host, bool fakeTTY = false)
424 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
425 tgt_stat_buf tgt(addr);
426 convertStatBuf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
430 /// Target ioctl() handler. For the most part, programs call ioctl()
431 /// only to find out if their stdout is a tty, to determine whether to
432 /// do line or block buffering.
435 ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
438 int fd = tc->getSyscallArg(0);
439 unsigned req = tc->getSyscallArg(1);
441 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
443 if (fd < 0 || process->sim_fd(fd) < 0) {
444 // doesn't map to any simulator fd: not a valid target fd
460 fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ 0x%llx\n",
461 fd, req, tc->readPC());
465 /// Target open() handler.
468 openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
473 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
476 if (path == "/dev/sysdev0") {
477 // This is a memory-mapped high-resolution timer device on Alpha.
478 // We don't support it, so just punt.
479 warn("Ignoring open(%s, ...)\n", path);
483 int tgtFlags = tc->getSyscallArg(1);
484 int mode = tc->getSyscallArg(2);
487 // translate open flags
488 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
489 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
490 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
491 hostFlags |= OS::openFlagTable[i].hostFlag;
495 // any target flags left?
497 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
500 hostFlags |= O_BINARY;
503 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
506 int fd = open(path.c_str(), hostFlags, mode);
508 return (fd == -1) ? -errno : process->alloc_fd(fd);
512 /// Target chmod() handler.
515 chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
520 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
523 uint32_t mode = tc->getSyscallArg(1);
526 // XXX translate mode flags via OS::something???
530 int result = chmod(path.c_str(), hostMode);
538 /// Target fchmod() handler.
541 fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
544 int fd = tc->getSyscallArg(0);
545 if (fd < 0 || process->sim_fd(fd) < 0) {
546 // doesn't map to any simulator fd: not a valid target fd
550 uint32_t mode = tc->getSyscallArg(1);
553 // XXX translate mode flags via OS::someting???
557 int result = fchmod(process->sim_fd(fd), hostMode);
565 /// Target stat() handler.
568 statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
573 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
577 int result = stat(path.c_str(), &hostBuf);
582 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
588 /// Target fstat64() handler.
591 fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
594 int fd = tc->getSyscallArg(0);
595 if (fd < 0 || process->sim_fd(fd) < 0) {
596 // doesn't map to any simulator fd: not a valid target fd
602 int result = fstat(process->sim_fd(fd), &hostBuf);
604 struct stat64 hostBuf;
605 int result = fstat64(process->sim_fd(fd), &hostBuf);
611 copyOutStat64Buf<OS>(tc->getMemPort(), tc->getSyscallArg(1),
612 &hostBuf, (fd == 1));
618 /// Target lstat() handler.
621 lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
626 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
630 int result = lstat(path.c_str(), &hostBuf);
635 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
640 /// Target lstat64() handler.
643 lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
648 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
653 int result = lstat(path.c_str(), &hostBuf);
655 struct stat64 hostBuf;
656 int result = lstat64(path.c_str(), &hostBuf);
662 copyOutStat64Buf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
667 /// Target fstat() handler.
670 fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
673 int fd = process->sim_fd(tc->getSyscallArg(0));
675 DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
681 int result = fstat(fd, &hostBuf);
686 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1),
687 &hostBuf, (fd == 1));
693 /// Target statfs() handler.
696 statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
701 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
704 struct statfs hostBuf;
705 int result = statfs(path.c_str(), &hostBuf);
710 OS::copyOutStatfsBuf(tc->getMemPort(),
711 (Addr)(tc->getSyscallArg(1)), &hostBuf);
717 /// Target fstatfs() handler.
720 fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
723 int fd = process->sim_fd(tc->getSyscallArg(0));
728 struct statfs hostBuf;
729 int result = fstatfs(fd, &hostBuf);
734 OS::copyOutStatfsBuf(tc->getMemPort(), tc->getSyscallArg(1),
741 /// Target writev() handler.
744 writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
747 int fd = tc->getSyscallArg(0);
748 if (fd < 0 || process->sim_fd(fd) < 0) {
749 // doesn't map to any simulator fd: not a valid target fd
753 TranslatingPort *p = tc->getMemPort();
754 uint64_t tiov_base = tc->getSyscallArg(1);
755 size_t count = tc->getSyscallArg(2);
756 struct iovec hiov[count];
757 for (int i = 0; i < count; ++i)
759 typename OS::tgt_iovec tiov;
761 p->readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
762 (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
763 hiov[i].iov_len = gtoh(tiov.iov_len);
764 hiov[i].iov_base = new char [hiov[i].iov_len];
765 p->readBlob(gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
769 int result = writev(process->sim_fd(fd), hiov, count);
771 for (int i = 0; i < count; ++i)
773 delete [] (char *)hiov[i].iov_base;
783 /// Target mmap() handler.
785 /// We don't really handle mmap(). If the target is mmaping an
786 /// anonymous region or /dev/zero, we can get away with doing basically
787 /// nothing (since memory is initialized to zero and the simulator
788 /// doesn't really check addresses anyway). Always print a warning,
789 /// since this could be seriously broken if we're not mapping
792 /// Someday we should explicitly check for /dev/zero in open, flag the
793 /// file descriptor, and fail (or implement!) a non-anonymous mmap to
797 mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
799 Addr start = tc->getSyscallArg(0);
800 uint64_t length = tc->getSyscallArg(1);
801 // int prot = tc->getSyscallArg(2);
802 int flags = tc->getSyscallArg(3);
803 // int fd = p->sim_fd(tc->getSyscallArg(4));
804 // int offset = tc->getSyscallArg(5);
806 if ((start % TheISA::VMPageSize) != 0 ||
807 (length % TheISA::VMPageSize) != 0) {
808 warn("mmap failing: arguments not page-aligned: "
809 "start 0x%x length 0x%x",
815 warn("mmap: ignoring suggested map address 0x%x, using 0x%x",
819 // pick next address from our "mmap region"
821 p->pTable->allocate(start, length);
822 p->mmap_end += length;
824 if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
825 warn("allowing mmap of file @ fd %d. "
826 "This will break if not /dev/zero.", tc->getSyscallArg(4));
832 /// Target getrlimit() handler.
835 getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
838 unsigned resource = tc->getSyscallArg(0);
839 TypedBufferArg<typename OS::rlimit> rlp(tc->getSyscallArg(1));
842 case OS::TGT_RLIMIT_STACK:
843 // max stack size in bytes: make up a number (2MB for now)
844 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
845 rlp->rlim_cur = htog(rlp->rlim_cur);
846 rlp->rlim_max = htog(rlp->rlim_max);
850 std::cerr << "getrlimitFunc: unimplemented resource " << resource
856 rlp.copyOut(tc->getMemPort());
860 /// Target gettimeofday() handler.
863 gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
866 TypedBufferArg<typename OS::timeval> tp(tc->getSyscallArg(0));
868 getElapsedTime(tp->tv_sec, tp->tv_usec);
869 tp->tv_sec += seconds_since_epoch;
870 tp->tv_sec = htog(tp->tv_sec);
871 tp->tv_usec = htog(tp->tv_usec);
873 tp.copyOut(tc->getMemPort());
879 /// Target utimes() handler.
882 utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
887 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
890 TypedBufferArg<typename OS::timeval [2]> tp(tc->getSyscallArg(1));
891 tp.copyIn(tc->getMemPort());
893 struct timeval hostTimeval[2];
894 for (int i = 0; i < 2; ++i)
896 hostTimeval[i].tv_sec = gtoh((*tp)[i].tv_sec);
897 hostTimeval[i].tv_usec = gtoh((*tp)[i].tv_usec);
899 int result = utimes(path.c_str(), hostTimeval);
906 /// Target getrusage() function.
909 getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
912 int who = tc->getSyscallArg(0); // THREAD, SELF, or CHILDREN
913 TypedBufferArg<typename OS::rusage> rup(tc->getSyscallArg(1));
915 if (who != OS::TGT_RUSAGE_SELF) {
916 // don't really handle THREAD or CHILDREN, but just warn and
918 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
922 getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
923 rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec);
924 rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec);
926 rup->ru_stime.tv_sec = 0;
927 rup->ru_stime.tv_usec = 0;
939 rup->ru_nsignals = 0;
943 rup.copyOut(tc->getMemPort());
951 #endif // __SIM_SYSCALL_EMUL_HH__