Merge zizzer:/bk/m5
[gem5.git] / sim / syscall_emul.hh
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 #ifndef __SIM_SYSCALL_EMUL_HH__
30 #define __SIM_SYSCALL_EMUL_HH__
31
32 #define BSD_HOST (defined(__APPLE__) || defined(__OpenBSD__) || \
33 defined(__FreeBSD__))
34
35 ///
36 /// @file syscall_emul.hh
37 ///
38 /// This file defines objects used to emulate syscalls from the target
39 /// application on the host machine.
40
41 #include <errno.h>
42 #include <string>
43 #ifdef __CYGWIN32__
44 #include <sys/fcntl.h> // for O_BINARY
45 #endif
46 #include <sys/uio.h>
47
48 #include "base/intmath.hh" // for RoundUp
49 #include "mem/functional/functional.hh"
50 #include "arch/isa_traits.hh" // for Addr
51
52 #include "base/trace.hh"
53 #include "cpu/exec_context.hh"
54 #include "sim/process.hh"
55
56 ///
57 /// System call descriptor.
58 ///
59 class SyscallDesc {
60
61 public:
62
63 /// Typedef for target syscall handler functions.
64 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
65 Process *, ExecContext *);
66
67 const char *name; //!< Syscall name (e.g., "open").
68 FuncPtr funcPtr; //!< Pointer to emulation function.
69 int flags; //!< Flags (see Flags enum).
70
71 /// Flag values for controlling syscall behavior.
72 enum Flags {
73 /// Don't set return regs according to funcPtr return value.
74 /// Used for syscalls with non-standard return conventions
75 /// that explicitly set the ExecContext regs (e.g.,
76 /// sigreturn).
77 SuppressReturnValue = 1
78 };
79
80 /// Constructor.
81 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
82 : name(_name), funcPtr(_funcPtr), flags(_flags)
83 {
84 }
85
86 /// Emulate the syscall. Public interface for calling through funcPtr.
87 void doSyscall(int callnum, Process *proc, ExecContext *xc);
88 };
89
90
91 class BaseBufferArg {
92
93 public:
94
95 BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size)
96 {
97 bufPtr = new uint8_t[size];
98 // clear out buffer: in case we only partially populate this,
99 // and then do a copyOut(), we want to make sure we don't
100 // introduce any random junk into the simulated address space
101 memset(bufPtr, 0, size);
102 }
103
104 virtual ~BaseBufferArg() { delete [] bufPtr; }
105
106 //
107 // copy data into simulator space (read from target memory)
108 //
109 virtual bool copyIn(FunctionalMemory *mem)
110 {
111 mem->access(Read, addr, bufPtr, size);
112 return true; // no EFAULT detection for now
113 }
114
115 //
116 // copy data out of simulator space (write to target memory)
117 //
118 virtual bool copyOut(FunctionalMemory *mem)
119 {
120 mem->access(Write, addr, bufPtr, size);
121 return true; // no EFAULT detection for now
122 }
123
124 protected:
125 Addr addr;
126 int size;
127 uint8_t *bufPtr;
128 };
129
130
131 class BufferArg : public BaseBufferArg
132 {
133 public:
134 BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
135 void *bufferPtr() { return bufPtr; }
136 };
137
138 template <class T>
139 class TypedBufferArg : public BaseBufferArg
140 {
141 public:
142 // user can optionally specify a specific number of bytes to
143 // allocate to deal with those structs that have variable-size
144 // arrays at the end
145 TypedBufferArg(Addr _addr, int _size = sizeof(T))
146 : BaseBufferArg(_addr, _size)
147 { }
148
149 // type case
150 operator T*() { return (T *)bufPtr; }
151
152 // dereference operators
153 T &operator*() { return *((T *)bufPtr); }
154 T* operator->() { return (T *)bufPtr; }
155 T &operator[](int i) { return ((T *)bufPtr)[i]; }
156 };
157
158 //////////////////////////////////////////////////////////////////////
159 //
160 // The following emulation functions are generic enough that they
161 // don't need to be recompiled for different emulated OS's. They are
162 // defined in sim/syscall_emul.cc.
163 //
164 //////////////////////////////////////////////////////////////////////
165
166
167 /// Handler for unimplemented syscalls that we haven't thought about.
168 SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
169 Process *p, ExecContext *xc);
170
171 /// Handler for unimplemented syscalls that we never intend to
172 /// implement (signal handling, etc.) and should not affect the correct
173 /// behavior of the program. Print a warning only if the appropriate
174 /// trace flag is enabled. Return success to the target program.
175 SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
176 Process *p, ExecContext *xc);
177
178 /// Target exit() handler: terminate simulation.
179 SyscallReturn exitFunc(SyscallDesc *desc, int num,
180 Process *p, ExecContext *xc);
181
182 /// Target getpagesize() handler.
183 SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
184 Process *p, ExecContext *xc);
185
186 /// Target obreak() handler: set brk address.
187 SyscallReturn obreakFunc(SyscallDesc *desc, int num,
188 Process *p, ExecContext *xc);
189
190 /// Target close() handler.
191 SyscallReturn closeFunc(SyscallDesc *desc, int num,
192 Process *p, ExecContext *xc);
193
194 /// Target read() handler.
195 SyscallReturn readFunc(SyscallDesc *desc, int num,
196 Process *p, ExecContext *xc);
197
198 /// Target write() handler.
199 SyscallReturn writeFunc(SyscallDesc *desc, int num,
200 Process *p, ExecContext *xc);
201
202 /// Target lseek() handler.
203 SyscallReturn lseekFunc(SyscallDesc *desc, int num,
204 Process *p, ExecContext *xc);
205
206 /// Target munmap() handler.
207 SyscallReturn munmapFunc(SyscallDesc *desc, int num,
208 Process *p, ExecContext *xc);
209
210 /// Target gethostname() handler.
211 SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
212 Process *p, ExecContext *xc);
213
214 /// Target unlink() handler.
215 SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
216 Process *p, ExecContext *xc);
217
218 /// Target rename() handler.
219 SyscallReturn renameFunc(SyscallDesc *desc, int num,
220 Process *p, ExecContext *xc);
221
222
223 /// Target truncate() handler.
224 SyscallReturn truncateFunc(SyscallDesc *desc, int num,
225 Process *p, ExecContext *xc);
226
227
228 /// Target ftruncate() handler.
229 SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
230 Process *p, ExecContext *xc);
231
232
233 /// Target chown() handler.
234 SyscallReturn chownFunc(SyscallDesc *desc, int num,
235 Process *p, ExecContext *xc);
236
237
238 /// Target fchown() handler.
239 SyscallReturn fchownFunc(SyscallDesc *desc, int num,
240 Process *p, ExecContext *xc);
241
242 /// Target fnctl() handler.
243 SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
244 Process *process, ExecContext *xc);
245
246 /// This struct is used to build an target-OS-dependent table that
247 /// maps the target's open() flags to the host open() flags.
248 struct OpenFlagTransTable {
249 int tgtFlag; //!< Target system flag value.
250 int hostFlag; //!< Corresponding host system flag value.
251 };
252
253
254
255 /// A readable name for 1,000,000, for converting microseconds to seconds.
256 const int one_million = 1000000;
257
258 /// Approximate seconds since the epoch (1/1/1970). About a billion,
259 /// by my reckoning. We want to keep this a constant (not use the
260 /// real-world time) to keep simulations repeatable.
261 const unsigned seconds_since_epoch = 1000000000;
262
263 /// Helper function to convert current elapsed time to seconds and
264 /// microseconds.
265 template <class T1, class T2>
266 void
267 getElapsedTime(T1 &sec, T2 &usec)
268 {
269 int elapsed_usecs = curTick / Clock::Int::us;
270 sec = elapsed_usecs / one_million;
271 usec = elapsed_usecs % one_million;
272 }
273
274 //////////////////////////////////////////////////////////////////////
275 //
276 // The following emulation functions are generic, but need to be
277 // templated to account for differences in types, constants, etc.
278 //
279 //////////////////////////////////////////////////////////////////////
280
281 /// Target ioctl() handler. For the most part, programs call ioctl()
282 /// only to find out if their stdout is a tty, to determine whether to
283 /// do line or block buffering.
284 template <class OS>
285 SyscallReturn
286 ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
287 ExecContext *xc)
288 {
289 int fd = xc->getSyscallArg(0);
290 unsigned req = xc->getSyscallArg(1);
291
292 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
293
294 if (fd < 0 || process->sim_fd(fd) < 0) {
295 // doesn't map to any simulator fd: not a valid target fd
296 return -EBADF;
297 }
298
299 switch (req) {
300 case OS::TIOCISATTY:
301 case OS::TIOCGETP:
302 case OS::TIOCSETP:
303 case OS::TIOCSETN:
304 case OS::TIOCSETC:
305 case OS::TIOCGETC:
306 case OS::TIOCGETS:
307 case OS::TIOCGETA:
308 return -ENOTTY;
309
310 default:
311 fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ 0x%llx\n",
312 fd, req, xc->readPC());
313 }
314 }
315
316 /// Target open() handler.
317 template <class OS>
318 SyscallReturn
319 openFunc(SyscallDesc *desc, int callnum, Process *process,
320 ExecContext *xc)
321 {
322 std::string path;
323
324 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
325 return -EFAULT;
326
327 if (path == "/dev/sysdev0") {
328 // This is a memory-mapped high-resolution timer device on Alpha.
329 // We don't support it, so just punt.
330 warn("Ignoring open(%s, ...)\n", path);
331 return -ENOENT;
332 }
333
334 int tgtFlags = xc->getSyscallArg(1);
335 int mode = xc->getSyscallArg(2);
336 int hostFlags = 0;
337
338 // translate open flags
339 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
340 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
341 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
342 hostFlags |= OS::openFlagTable[i].hostFlag;
343 }
344 }
345
346 // any target flags left?
347 if (tgtFlags != 0)
348 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
349
350 #ifdef __CYGWIN32__
351 hostFlags |= O_BINARY;
352 #endif
353
354 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
355
356 // open the file
357 int fd = open(path.c_str(), hostFlags, mode);
358
359 return (fd == -1) ? -errno : process->alloc_fd(fd);
360 }
361
362
363 /// Target chmod() handler.
364 template <class OS>
365 SyscallReturn
366 chmodFunc(SyscallDesc *desc, int callnum, Process *process,
367 ExecContext *xc)
368 {
369 std::string path;
370
371 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
372 return -EFAULT;
373
374 uint32_t mode = xc->getSyscallArg(1);
375 mode_t hostMode = 0;
376
377 // XXX translate mode flags via OS::something???
378 hostMode = mode;
379
380 // do the chmod
381 int result = chmod(path.c_str(), hostMode);
382 if (result < 0)
383 return errno;
384
385 return 0;
386 }
387
388
389 /// Target fchmod() handler.
390 template <class OS>
391 SyscallReturn
392 fchmodFunc(SyscallDesc *desc, int callnum, Process *process,
393 ExecContext *xc)
394 {
395 int fd = xc->getSyscallArg(0);
396 if (fd < 0 || process->sim_fd(fd) < 0) {
397 // doesn't map to any simulator fd: not a valid target fd
398 return -EBADF;
399 }
400
401 uint32_t mode = xc->getSyscallArg(1);
402 mode_t hostMode = 0;
403
404 // XXX translate mode flags via OS::someting???
405 hostMode = mode;
406
407 // do the fchmod
408 int result = fchmod(process->sim_fd(fd), hostMode);
409 if (result < 0)
410 return errno;
411
412 return 0;
413 }
414
415
416 /// Target stat() handler.
417 template <class OS>
418 SyscallReturn
419 statFunc(SyscallDesc *desc, int callnum, Process *process,
420 ExecContext *xc)
421 {
422 std::string path;
423
424 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
425 return -EFAULT;
426
427 struct stat hostBuf;
428 int result = stat(path.c_str(), &hostBuf);
429
430 if (result < 0)
431 return errno;
432
433 OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
434
435 return 0;
436 }
437
438
439 /// Target fstat64() handler.
440 template <class OS>
441 SyscallReturn
442 fstat64Func(SyscallDesc *desc, int callnum, Process *process,
443 ExecContext *xc)
444 {
445 int fd = xc->getSyscallArg(0);
446 if (fd < 0 || process->sim_fd(fd) < 0) {
447 // doesn't map to any simulator fd: not a valid target fd
448 return -EBADF;
449 }
450
451 #if BSD_HOST
452 struct stat hostBuf;
453 int result = fstat(process->sim_fd(fd), &hostBuf);
454 #else
455 struct stat64 hostBuf;
456 int result = fstat64(process->sim_fd(fd), &hostBuf);
457 #endif
458
459 if (result < 0)
460 return errno;
461
462 OS::copyOutStat64Buf(xc->mem, fd, xc->getSyscallArg(1), &hostBuf);
463
464 return 0;
465 }
466
467
468 /// Target lstat() handler.
469 template <class OS>
470 SyscallReturn
471 lstatFunc(SyscallDesc *desc, int callnum, Process *process,
472 ExecContext *xc)
473 {
474 std::string path;
475
476 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
477 return -EFAULT;
478
479 struct stat hostBuf;
480 int result = lstat(path.c_str(), &hostBuf);
481
482 if (result < 0)
483 return -errno;
484
485 OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
486
487 return 0;
488 }
489
490 /// Target lstat64() handler.
491 template <class OS>
492 SyscallReturn
493 lstat64Func(SyscallDesc *desc, int callnum, Process *process,
494 ExecContext *xc)
495 {
496 std::string path;
497
498 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
499 return -EFAULT;
500
501 #if BSD_HOST
502 struct stat hostBuf;
503 int result = lstat(path.c_str(), &hostBuf);
504 #else
505 struct stat64 hostBuf;
506 int result = lstat64(path.c_str(), &hostBuf);
507 #endif
508
509 if (result < 0)
510 return -errno;
511
512 OS::copyOutStat64Buf(xc->mem, -1, xc->getSyscallArg(1), &hostBuf);
513
514 return 0;
515 }
516
517 /// Target fstat() handler.
518 template <class OS>
519 SyscallReturn
520 fstatFunc(SyscallDesc *desc, int callnum, Process *process,
521 ExecContext *xc)
522 {
523 int fd = process->sim_fd(xc->getSyscallArg(0));
524
525 DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
526
527 if (fd < 0)
528 return -EBADF;
529
530 struct stat hostBuf;
531 int result = fstat(fd, &hostBuf);
532
533 if (result < 0)
534 return -errno;
535
536 OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
537 return 0;
538 }
539
540
541 /// Target statfs() handler.
542 template <class OS>
543 SyscallReturn
544 statfsFunc(SyscallDesc *desc, int callnum, Process *process,
545 ExecContext *xc)
546 {
547 std::string path;
548
549 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
550 return -EFAULT;
551
552 struct statfs hostBuf;
553 int result = statfs(path.c_str(), &hostBuf);
554
555 if (result < 0)
556 return errno;
557
558 OS::copyOutStatfsBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
559
560 return 0;
561 }
562
563
564 /// Target fstatfs() handler.
565 template <class OS>
566 SyscallReturn
567 fstatfsFunc(SyscallDesc *desc, int callnum, Process *process,
568 ExecContext *xc)
569 {
570 int fd = process->sim_fd(xc->getSyscallArg(0));
571
572 if (fd < 0)
573 return -EBADF;
574
575 struct statfs hostBuf;
576 int result = fstatfs(fd, &hostBuf);
577
578 if (result < 0)
579 return errno;
580
581 OS::copyOutStatfsBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
582
583 return 0;
584 }
585
586
587 /// Target writev() handler.
588 template <class OS>
589 SyscallReturn
590 writevFunc(SyscallDesc *desc, int callnum, Process *process,
591 ExecContext *xc)
592 {
593 int fd = xc->getSyscallArg(0);
594 if (fd < 0 || process->sim_fd(fd) < 0) {
595 // doesn't map to any simulator fd: not a valid target fd
596 return -EBADF;
597 }
598
599 uint64_t tiov_base = xc->getSyscallArg(1);
600 size_t count = xc->getSyscallArg(2);
601 struct iovec hiov[count];
602 for (int i = 0; i < count; ++i)
603 {
604 typename OS::tgt_iovec tiov;
605 xc->mem->access(Read, tiov_base + i*sizeof(typename OS::tgt_iovec),
606 &tiov, sizeof(typename OS::tgt_iovec));
607 hiov[i].iov_len = gtoh(tiov.iov_len);
608 hiov[i].iov_base = new char [hiov[i].iov_len];
609 xc->mem->access(Read, gtoh(tiov.iov_base),
610 hiov[i].iov_base, hiov[i].iov_len);
611 }
612
613 int result = writev(process->sim_fd(fd), hiov, count);
614
615 for (int i = 0; i < count; ++i)
616 {
617 delete [] (char *)hiov[i].iov_base;
618 }
619
620 if (result < 0)
621 return errno;
622
623 return 0;
624 }
625
626
627 /// Target mmap() handler.
628 ///
629 /// We don't really handle mmap(). If the target is mmaping an
630 /// anonymous region or /dev/zero, we can get away with doing basically
631 /// nothing (since memory is initialized to zero and the simulator
632 /// doesn't really check addresses anyway). Always print a warning,
633 /// since this could be seriously broken if we're not mapping
634 /// /dev/zero.
635 //
636 /// Someday we should explicitly check for /dev/zero in open, flag the
637 /// file descriptor, and fail (or implement!) a non-anonymous mmap to
638 /// anything else.
639 template <class OS>
640 SyscallReturn
641 mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
642 {
643 Addr start = xc->getSyscallArg(0);
644 uint64_t length = xc->getSyscallArg(1);
645 // int prot = xc->getSyscallArg(2);
646 int flags = xc->getSyscallArg(3);
647 // int fd = p->sim_fd(xc->getSyscallArg(4));
648 // int offset = xc->getSyscallArg(5);
649
650 if (start == 0) {
651 // user didn't give an address... pick one from our "mmap region"
652 start = p->mmap_end;
653 p->mmap_end += roundUp(length, TheISA::VMPageSize);
654 if (p->nxm_start != 0) {
655 //If we have an nxm space, make sure we haven't colided
656 assert(p->mmap_end < p->nxm_start);
657 }
658 }
659
660 if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
661 warn("allowing mmap of file @ fd %d. "
662 "This will break if not /dev/zero.", xc->getSyscallArg(4));
663 }
664
665 return start;
666 }
667
668 /// Target getrlimit() handler.
669 template <class OS>
670 SyscallReturn
671 getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
672 ExecContext *xc)
673 {
674 unsigned resource = xc->getSyscallArg(0);
675 TypedBufferArg<typename OS::rlimit> rlp(xc->getSyscallArg(1));
676
677 switch (resource) {
678 case OS::TGT_RLIMIT_STACK:
679 // max stack size in bytes: make up a number (2MB for now)
680 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
681 rlp->rlim_cur = htog(rlp->rlim_cur);
682 rlp->rlim_max = htog(rlp->rlim_max);
683 break;
684
685 default:
686 std::cerr << "getrlimitFunc: unimplemented resource " << resource
687 << std::endl;
688 abort();
689 break;
690 }
691
692 rlp.copyOut(xc->mem);
693 return 0;
694 }
695
696 /// Target gettimeofday() handler.
697 template <class OS>
698 SyscallReturn
699 gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
700 ExecContext *xc)
701 {
702 TypedBufferArg<typename OS::timeval> tp(xc->getSyscallArg(0));
703
704 getElapsedTime(tp->tv_sec, tp->tv_usec);
705 tp->tv_sec += seconds_since_epoch;
706 tp->tv_sec = htog(tp->tv_sec);
707 tp->tv_usec = htog(tp->tv_usec);
708
709 tp.copyOut(xc->mem);
710
711 return 0;
712 }
713
714
715 /// Target utimes() handler.
716 template <class OS>
717 SyscallReturn
718 utimesFunc(SyscallDesc *desc, int callnum, Process *process,
719 ExecContext *xc)
720 {
721 std::string path;
722
723 if (xc->mem->readString(path, xc->getSyscallArg(0)) != NoFault)
724 return -EFAULT;
725
726 TypedBufferArg<typename OS::timeval [2]> tp(xc->getSyscallArg(1));
727 tp.copyIn(xc->mem);
728
729 struct timeval hostTimeval[2];
730 for (int i = 0; i < 2; ++i)
731 {
732 hostTimeval[i].tv_sec = gtoh((*tp)[i].tv_sec);
733 hostTimeval[i].tv_usec = gtoh((*tp)[i].tv_usec);
734 }
735 int result = utimes(path.c_str(), hostTimeval);
736
737 if (result < 0)
738 return -errno;
739
740 return 0;
741 }
742 /// Target getrusage() function.
743 template <class OS>
744 SyscallReturn
745 getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
746 ExecContext *xc)
747 {
748 int who = xc->getSyscallArg(0); // THREAD, SELF, or CHILDREN
749 TypedBufferArg<typename OS::rusage> rup(xc->getSyscallArg(1));
750
751 if (who != OS::TGT_RUSAGE_SELF) {
752 // don't really handle THREAD or CHILDREN, but just warn and
753 // plow ahead
754 warn("getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
755 who);
756 }
757
758 getElapsedTime(rup->ru_utime.tv_sec, rup->ru_utime.tv_usec);
759 rup->ru_utime.tv_sec = htog(rup->ru_utime.tv_sec);
760 rup->ru_utime.tv_usec = htog(rup->ru_utime.tv_usec);
761
762 rup->ru_stime.tv_sec = 0;
763 rup->ru_stime.tv_usec = 0;
764 rup->ru_maxrss = 0;
765 rup->ru_ixrss = 0;
766 rup->ru_idrss = 0;
767 rup->ru_isrss = 0;
768 rup->ru_minflt = 0;
769 rup->ru_majflt = 0;
770 rup->ru_nswap = 0;
771 rup->ru_inblock = 0;
772 rup->ru_oublock = 0;
773 rup->ru_msgsnd = 0;
774 rup->ru_msgrcv = 0;
775 rup->ru_nsignals = 0;
776 rup->ru_nvcsw = 0;
777 rup->ru_nivcsw = 0;
778
779 rup.copyOut(xc->mem);
780
781 return 0;
782 }
783
784 #endif // __SIM_SYSCALL_EMUL_HH__