syscall_emul.hh (3113:a6811aaea654) syscall_emul.hh (3114:7a4771b9b720)
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;

--- 56 unchanged lines hidden (view full) ---

65/// System call descriptor.
66///
67class SyscallDesc {
68
69 public:
70
71 /// Typedef for target syscall handler functions.
72 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
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;

--- 56 unchanged lines hidden (view full) ---

65/// System call descriptor.
66///
67class SyscallDesc {
68
69 public:
70
71 /// Typedef for target syscall handler functions.
72 typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
73 Process *, ThreadContext *);
73 LiveProcess *, ThreadContext *);
74
75 const char *name; //!< Syscall name (e.g., "open").
76 FuncPtr funcPtr; //!< Pointer to emulation function.
77 int flags; //!< Flags (see Flags enum).
78
79 /// Flag values for controlling syscall behavior.
80 enum Flags {
81 /// Don't set return regs according to funcPtr return value.

--- 5 unchanged lines hidden (view full) ---

87
88 /// Constructor.
89 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
90 : name(_name), funcPtr(_funcPtr), flags(_flags)
91 {
92 }
93
94 /// Emulate the syscall. Public interface for calling through funcPtr.
74
75 const char *name; //!< Syscall name (e.g., "open").
76 FuncPtr funcPtr; //!< Pointer to emulation function.
77 int flags; //!< Flags (see Flags enum).
78
79 /// Flag values for controlling syscall behavior.
80 enum Flags {
81 /// Don't set return regs according to funcPtr return value.

--- 5 unchanged lines hidden (view full) ---

87
88 /// Constructor.
89 SyscallDesc(const char *_name, FuncPtr _funcPtr, int _flags = 0)
90 : name(_name), funcPtr(_funcPtr), flags(_flags)
91 {
92 }
93
94 /// Emulate the syscall. Public interface for calling through funcPtr.
95 void doSyscall(int callnum, Process *proc, ThreadContext *tc);
95 void doSyscall(int callnum, LiveProcess *proc, ThreadContext *tc);
96};
97
98
99class BaseBufferArg {
100
101 public:
102
103 BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size)

--- 65 unchanged lines hidden (view full) ---

169// don't need to be recompiled for different emulated OS's. They are
170// defined in sim/syscall_emul.cc.
171//
172//////////////////////////////////////////////////////////////////////
173
174
175/// Handler for unimplemented syscalls that we haven't thought about.
176SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
96};
97
98
99class BaseBufferArg {
100
101 public:
102
103 BaseBufferArg(Addr _addr, int _size) : addr(_addr), size(_size)

--- 65 unchanged lines hidden (view full) ---

169// don't need to be recompiled for different emulated OS's. They are
170// defined in sim/syscall_emul.cc.
171//
172//////////////////////////////////////////////////////////////////////
173
174
175/// Handler for unimplemented syscalls that we haven't thought about.
176SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
177 Process *p, ThreadContext *tc);
177 LiveProcess *p, ThreadContext *tc);
178
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.
183SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
178
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.
183SyscallReturn ignoreFunc(SyscallDesc *desc, int num,
184 Process *p, ThreadContext *tc);
184 LiveProcess *p, ThreadContext *tc);
185
186/// Target exit() handler: terminate simulation.
187SyscallReturn exitFunc(SyscallDesc *desc, int num,
185
186/// Target exit() handler: terminate simulation.
187SyscallReturn exitFunc(SyscallDesc *desc, int num,
188 Process *p, ThreadContext *tc);
188 LiveProcess *p, ThreadContext *tc);
189
190/// Target getpagesize() handler.
191SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
189
190/// Target getpagesize() handler.
191SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
192 Process *p, ThreadContext *tc);
192 LiveProcess *p, ThreadContext *tc);
193
194/// Target obreak() handler: set brk address.
195SyscallReturn obreakFunc(SyscallDesc *desc, int num,
193
194/// Target obreak() handler: set brk address.
195SyscallReturn obreakFunc(SyscallDesc *desc, int num,
196 Process *p, ThreadContext *tc);
196 LiveProcess *p, ThreadContext *tc);
197
198/// Target close() handler.
199SyscallReturn closeFunc(SyscallDesc *desc, int num,
197
198/// Target close() handler.
199SyscallReturn closeFunc(SyscallDesc *desc, int num,
200 Process *p, ThreadContext *tc);
200 LiveProcess *p, ThreadContext *tc);
201
202/// Target read() handler.
203SyscallReturn readFunc(SyscallDesc *desc, int num,
201
202/// Target read() handler.
203SyscallReturn readFunc(SyscallDesc *desc, int num,
204 Process *p, ThreadContext *tc);
204 LiveProcess *p, ThreadContext *tc);
205
206/// Target write() handler.
207SyscallReturn writeFunc(SyscallDesc *desc, int num,
205
206/// Target write() handler.
207SyscallReturn writeFunc(SyscallDesc *desc, int num,
208 Process *p, ThreadContext *tc);
208 LiveProcess *p, ThreadContext *tc);
209
210/// Target lseek() handler.
211SyscallReturn lseekFunc(SyscallDesc *desc, int num,
209
210/// Target lseek() handler.
211SyscallReturn lseekFunc(SyscallDesc *desc, int num,
212 Process *p, ThreadContext *tc);
212 LiveProcess *p, ThreadContext *tc);
213
214/// Target munmap() handler.
215SyscallReturn munmapFunc(SyscallDesc *desc, int num,
213
214/// Target munmap() handler.
215SyscallReturn munmapFunc(SyscallDesc *desc, int num,
216 Process *p, ThreadContext *tc);
216 LiveProcess *p, ThreadContext *tc);
217
218/// Target gethostname() handler.
219SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
217
218/// Target gethostname() handler.
219SyscallReturn gethostnameFunc(SyscallDesc *desc, int num,
220 Process *p, ThreadContext *tc);
220 LiveProcess *p, ThreadContext *tc);
221
222/// Target unlink() handler.
223SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
221
222/// Target unlink() handler.
223SyscallReturn unlinkFunc(SyscallDesc *desc, int num,
224 Process *p, ThreadContext *tc);
224 LiveProcess *p, ThreadContext *tc);
225
226/// Target rename() handler.
227SyscallReturn renameFunc(SyscallDesc *desc, int num,
225
226/// Target rename() handler.
227SyscallReturn renameFunc(SyscallDesc *desc, int num,
228 Process *p, ThreadContext *tc);
228 LiveProcess *p, ThreadContext *tc);
229
230
231/// Target truncate() handler.
232SyscallReturn truncateFunc(SyscallDesc *desc, int num,
229
230
231/// Target truncate() handler.
232SyscallReturn truncateFunc(SyscallDesc *desc, int num,
233 Process *p, ThreadContext *tc);
233 LiveProcess *p, ThreadContext *tc);
234
235
236/// Target ftruncate() handler.
237SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
234
235
236/// Target ftruncate() handler.
237SyscallReturn ftruncateFunc(SyscallDesc *desc, int num,
238 Process *p, ThreadContext *tc);
238 LiveProcess *p, ThreadContext *tc);
239
240
241/// Target chown() handler.
242SyscallReturn chownFunc(SyscallDesc *desc, int num,
239
240
241/// Target chown() handler.
242SyscallReturn chownFunc(SyscallDesc *desc, int num,
243 Process *p, ThreadContext *tc);
243 LiveProcess *p, ThreadContext *tc);
244
245
246/// Target fchown() handler.
247SyscallReturn fchownFunc(SyscallDesc *desc, int num,
244
245
246/// Target fchown() handler.
247SyscallReturn fchownFunc(SyscallDesc *desc, int num,
248 Process *p, ThreadContext *tc);
248 LiveProcess *p, ThreadContext *tc);
249
250/// Target dup() handler.
251SyscallReturn dupFunc(SyscallDesc *desc, int num,
249
250/// Target dup() handler.
251SyscallReturn dupFunc(SyscallDesc *desc, int num,
252 Process *process, ThreadContext *tc);
252 LiveProcess *process, ThreadContext *tc);
253
254/// Target fnctl() handler.
255SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
253
254/// Target fnctl() handler.
255SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
256 Process *process, ThreadContext *tc);
256 LiveProcess *process, ThreadContext *tc);
257
258/// Target fcntl64() handler.
259SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
257
258/// Target fcntl64() handler.
259SyscallReturn fcntl64Func(SyscallDesc *desc, int num,
260 Process *process, ThreadContext *tc);
260 LiveProcess *process, ThreadContext *tc);
261
262/// Target setuid() handler.
263SyscallReturn setuidFunc(SyscallDesc *desc, int num,
261
262/// Target setuid() handler.
263SyscallReturn setuidFunc(SyscallDesc *desc, int num,
264 Process *p, ThreadContext *tc);
264 LiveProcess *p, ThreadContext *tc);
265
266/// Target getpid() handler.
267SyscallReturn getpidFunc(SyscallDesc *desc, int num,
265
266/// Target getpid() handler.
267SyscallReturn getpidFunc(SyscallDesc *desc, int num,
268 Process *p, ThreadContext *tc);
268 LiveProcess *p, ThreadContext *tc);
269
270/// Target getuid() handler.
271SyscallReturn getuidFunc(SyscallDesc *desc, int num,
269
270/// Target getuid() handler.
271SyscallReturn getuidFunc(SyscallDesc *desc, int num,
272 Process *p, ThreadContext *tc);
272 LiveProcess *p, ThreadContext *tc);
273
274/// Target getgid() handler.
275SyscallReturn getgidFunc(SyscallDesc *desc, int num,
273
274/// Target getgid() handler.
275SyscallReturn getgidFunc(SyscallDesc *desc, int num,
276 Process *p, ThreadContext *tc);
276 LiveProcess *p, ThreadContext *tc);
277
278/// Target getppid() handler.
279SyscallReturn getppidFunc(SyscallDesc *desc, int num,
277
278/// Target getppid() handler.
279SyscallReturn getppidFunc(SyscallDesc *desc, int num,
280 Process *p, ThreadContext *tc);
280 LiveProcess *p, ThreadContext *tc);
281
282/// Target geteuid() handler.
283SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
281
282/// Target geteuid() handler.
283SyscallReturn geteuidFunc(SyscallDesc *desc, int num,
284 Process *p, ThreadContext *tc);
284 LiveProcess *p, ThreadContext *tc);
285
286/// Target getegid() handler.
287SyscallReturn getegidFunc(SyscallDesc *desc, int num,
285
286/// Target getegid() handler.
287SyscallReturn getegidFunc(SyscallDesc *desc, int num,
288 Process *p, ThreadContext *tc);
288 LiveProcess *p, ThreadContext *tc);
289
290
291
292/// Pseudo Funcs - These functions use a different return convension,
293/// returning a second value in a register other than the normal return register
294SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
289
290
291
292/// Pseudo Funcs - These functions use a different return convension,
293/// returning a second value in a register other than the normal return register
294SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num,
295 Process *process, ThreadContext *tc);
295 LiveProcess *process, ThreadContext *tc);
296
297/// Target getpidPseudo() handler.
298SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
296
297/// Target getpidPseudo() handler.
298SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num,
299 Process *p, ThreadContext *tc);
299 LiveProcess *p, ThreadContext *tc);
300
301/// Target getuidPseudo() handler.
302SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
300
301/// Target getuidPseudo() handler.
302SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
303 Process *p, ThreadContext *tc);
303 LiveProcess *p, ThreadContext *tc);
304
305/// Target getgidPseudo() handler.
306SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
304
305/// Target getgidPseudo() handler.
306SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
307 Process *p, ThreadContext *tc);
307 LiveProcess *p, ThreadContext *tc);
308
309
310/// A readable name for 1,000,000, for converting microseconds to seconds.
311const int one_million = 1000000;
312
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.

--- 42 unchanged lines hidden (view full) ---

358 tgt->st_ino = htog(tgt->st_ino);
359 if (fakeTTY)
360 tgt->st_rdev = 0x880d;
361 else
362 tgt->st_rdev = host->st_rdev;
363 tgt->st_rdev = htog(tgt->st_rdev);
364 tgt->st_size = host->st_size;
365 tgt->st_size = htog(tgt->st_size);
308
309
310/// A readable name for 1,000,000, for converting microseconds to seconds.
311const int one_million = 1000000;
312
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.

--- 42 unchanged lines hidden (view full) ---

358 tgt->st_ino = htog(tgt->st_ino);
359 if (fakeTTY)
360 tgt->st_rdev = 0x880d;
361 else
362 tgt->st_rdev = host->st_rdev;
363 tgt->st_rdev = htog(tgt->st_rdev);
364 tgt->st_size = host->st_size;
365 tgt->st_size = htog(tgt->st_size);
366 tgt->st_atimeX = host->st_atimeX;
366 tgt->st_atimeX = host->st_atime;
367 tgt->st_atimeX = htog(tgt->st_atimeX);
367 tgt->st_atimeX = htog(tgt->st_atimeX);
368 tgt->st_mtimeX = host->st_mtimeX;
368 tgt->st_mtimeX = host->st_mtime;
369 tgt->st_mtimeX = htog(tgt->st_mtimeX);
369 tgt->st_mtimeX = htog(tgt->st_mtimeX);
370 tgt->st_ctimeX = host->st_ctimeX;
370 tgt->st_ctimeX = host->st_ctime;
371 tgt->st_ctimeX = htog(tgt->st_ctimeX);
372 tgt->st_blksize = host->st_blksize;
373 tgt->st_blksize = htog(tgt->st_blksize);
374 tgt->st_blocks = host->st_blocks;
375 tgt->st_blocks = htog(tgt->st_blocks);
376}
377
378// Same for stat64

--- 40 unchanged lines hidden (view full) ---

419 tgt.copyOut(mem);
420}
421
422/// Target ioctl() handler. For the most part, programs call ioctl()
423/// only to find out if their stdout is a tty, to determine whether to
424/// do line or block buffering.
425template <class OS>
426SyscallReturn
371 tgt->st_ctimeX = htog(tgt->st_ctimeX);
372 tgt->st_blksize = host->st_blksize;
373 tgt->st_blksize = htog(tgt->st_blksize);
374 tgt->st_blocks = host->st_blocks;
375 tgt->st_blocks = htog(tgt->st_blocks);
376}
377
378// Same for stat64

--- 40 unchanged lines hidden (view full) ---

419 tgt.copyOut(mem);
420}
421
422/// Target ioctl() handler. For the most part, programs call ioctl()
423/// only to find out if their stdout is a tty, to determine whether to
424/// do line or block buffering.
425template <class OS>
426SyscallReturn
427ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
427ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
428 ThreadContext *tc)
429{
430 int fd = tc->getSyscallArg(0);
431 unsigned req = tc->getSyscallArg(1);
432
433 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
434
435 if (fd < 0 || process->sim_fd(fd) < 0) {

--- 16 unchanged lines hidden (view full) ---

452 fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ 0x%llx\n",
453 fd, req, tc->readPC());
454 }
455}
456
457/// Target open() handler.
458template <class OS>
459SyscallReturn
428 ThreadContext *tc)
429{
430 int fd = tc->getSyscallArg(0);
431 unsigned req = tc->getSyscallArg(1);
432
433 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
434
435 if (fd < 0 || process->sim_fd(fd) < 0) {

--- 16 unchanged lines hidden (view full) ---

452 fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ 0x%llx\n",
453 fd, req, tc->readPC());
454 }
455}
456
457/// Target open() handler.
458template <class OS>
459SyscallReturn
460openFunc(SyscallDesc *desc, int callnum, Process *process,
460openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
461 ThreadContext *tc)
462{
463 std::string path;
464
465 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
466 return -EFAULT;
467
468 if (path == "/dev/sysdev0") {

--- 30 unchanged lines hidden (view full) ---

499
500 return (fd == -1) ? -errno : process->alloc_fd(fd);
501}
502
503
504/// Target chmod() handler.
505template <class OS>
506SyscallReturn
461 ThreadContext *tc)
462{
463 std::string path;
464
465 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
466 return -EFAULT;
467
468 if (path == "/dev/sysdev0") {

--- 30 unchanged lines hidden (view full) ---

499
500 return (fd == -1) ? -errno : process->alloc_fd(fd);
501}
502
503
504/// Target chmod() handler.
505template <class OS>
506SyscallReturn
507chmodFunc(SyscallDesc *desc, int callnum, Process *process,
507chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
508 ThreadContext *tc)
509{
510 std::string path;
511
512 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
513 return -EFAULT;
514
515 uint32_t mode = tc->getSyscallArg(1);

--- 9 unchanged lines hidden (view full) ---

525
526 return 0;
527}
528
529
530/// Target fchmod() handler.
531template <class OS>
532SyscallReturn
508 ThreadContext *tc)
509{
510 std::string path;
511
512 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
513 return -EFAULT;
514
515 uint32_t mode = tc->getSyscallArg(1);

--- 9 unchanged lines hidden (view full) ---

525
526 return 0;
527}
528
529
530/// Target fchmod() handler.
531template <class OS>
532SyscallReturn
533fchmodFunc(SyscallDesc *desc, int callnum, Process *process,
533fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
534 ThreadContext *tc)
535{
536 int fd = tc->getSyscallArg(0);
537 if (fd < 0 || process->sim_fd(fd) < 0) {
538 // doesn't map to any simulator fd: not a valid target fd
539 return -EBADF;
540 }
541

--- 10 unchanged lines hidden (view full) ---

552
553 return 0;
554}
555
556
557/// Target stat() handler.
558template <class OS>
559SyscallReturn
534 ThreadContext *tc)
535{
536 int fd = tc->getSyscallArg(0);
537 if (fd < 0 || process->sim_fd(fd) < 0) {
538 // doesn't map to any simulator fd: not a valid target fd
539 return -EBADF;
540 }
541

--- 10 unchanged lines hidden (view full) ---

552
553 return 0;
554}
555
556
557/// Target stat() handler.
558template <class OS>
559SyscallReturn
560statFunc(SyscallDesc *desc, int callnum, Process *process,
560statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
561 ThreadContext *tc)
562{
563 std::string path;
564
565 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
566 return -EFAULT;
567
568 struct stat hostBuf;

--- 6 unchanged lines hidden (view full) ---

575
576 return 0;
577}
578
579
580/// Target fstat64() handler.
581template <class OS>
582SyscallReturn
561 ThreadContext *tc)
562{
563 std::string path;
564
565 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
566 return -EFAULT;
567
568 struct stat hostBuf;

--- 6 unchanged lines hidden (view full) ---

575
576 return 0;
577}
578
579
580/// Target fstat64() handler.
581template <class OS>
582SyscallReturn
583fstat64Func(SyscallDesc *desc, int callnum, Process *process,
583fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
584 ThreadContext *tc)
585{
586 int fd = tc->getSyscallArg(0);
587 if (fd < 0 || process->sim_fd(fd) < 0) {
588 // doesn't map to any simulator fd: not a valid target fd
589 return -EBADF;
590 }
591
592#if NO_STAT64
593 struct stat hostBuf;
594 int result = fstat(process->sim_fd(fd), &hostBuf);
595#else
596 struct stat64 hostBuf;
597 int result = fstat64(process->sim_fd(fd), &hostBuf);
598#endif
599
600 if (result < 0)
601 return -errno;
602
584 ThreadContext *tc)
585{
586 int fd = tc->getSyscallArg(0);
587 if (fd < 0 || process->sim_fd(fd) < 0) {
588 // doesn't map to any simulator fd: not a valid target fd
589 return -EBADF;
590 }
591
592#if NO_STAT64
593 struct stat hostBuf;
594 int result = fstat(process->sim_fd(fd), &hostBuf);
595#else
596 struct stat64 hostBuf;
597 int result = fstat64(process->sim_fd(fd), &hostBuf);
598#endif
599
600 if (result < 0)
601 return -errno;
602
603 copyOutStat64Buf<OS>(tc->getMemPort(), fd, tc->getSyscallArg(1), &hostBuf);
603 copyOutStat64Buf<OS>(tc->getMemPort(), tc->getSyscallArg(1),
604 &hostBuf, (fd == 1));
604
605 return 0;
606}
607
608
609/// Target lstat() handler.
610template <class OS>
611SyscallReturn
605
606 return 0;
607}
608
609
610/// Target lstat() handler.
611template <class OS>
612SyscallReturn
612lstatFunc(SyscallDesc *desc, int callnum, Process *process,
613lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
613 ThreadContext *tc)
614{
615 std::string path;
616
617 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
618 return -EFAULT;
619
620 struct stat hostBuf;

--- 5 unchanged lines hidden (view full) ---

626 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
627
628 return 0;
629}
630
631/// Target lstat64() handler.
632template <class OS>
633SyscallReturn
614 ThreadContext *tc)
615{
616 std::string path;
617
618 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
619 return -EFAULT;
620
621 struct stat hostBuf;

--- 5 unchanged lines hidden (view full) ---

627 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
628
629 return 0;
630}
631
632/// Target lstat64() handler.
633template <class OS>
634SyscallReturn
634lstat64Func(SyscallDesc *desc, int callnum, Process *process,
635lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
635 ThreadContext *tc)
636{
637 std::string path;
638
639 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
640 return -EFAULT;
641
642#if NO_STAT64
643 struct stat hostBuf;
644 int result = lstat(path.c_str(), &hostBuf);
645#else
646 struct stat64 hostBuf;
647 int result = lstat64(path.c_str(), &hostBuf);
648#endif
649
650 if (result < 0)
651 return -errno;
652
636 ThreadContext *tc)
637{
638 std::string path;
639
640 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
641 return -EFAULT;
642
643#if NO_STAT64
644 struct stat hostBuf;
645 int result = lstat(path.c_str(), &hostBuf);
646#else
647 struct stat64 hostBuf;
648 int result = lstat64(path.c_str(), &hostBuf);
649#endif
650
651 if (result < 0)
652 return -errno;
653
653 copyOutStat64Buf<OS>(tc->getMemPort(), -1, tc->getSyscallArg(1), &hostBuf);
654 copyOutStat64Buf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
654
655 return 0;
656}
657
658/// Target fstat() handler.
659template <class OS>
660SyscallReturn
655
656 return 0;
657}
658
659/// Target fstat() handler.
660template <class OS>
661SyscallReturn
661fstatFunc(SyscallDesc *desc, int callnum, Process *process,
662fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
662 ThreadContext *tc)
663{
664 int fd = process->sim_fd(tc->getSyscallArg(0));
665
666 DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
667
668 if (fd < 0)
669 return -EBADF;
670
671 struct stat hostBuf;
672 int result = fstat(fd, &hostBuf);
673
674 if (result < 0)
675 return -errno;
676
663 ThreadContext *tc)
664{
665 int fd = process->sim_fd(tc->getSyscallArg(0));
666
667 DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
668
669 if (fd < 0)
670 return -EBADF;
671
672 struct stat hostBuf;
673 int result = fstat(fd, &hostBuf);
674
675 if (result < 0)
676 return -errno;
677
677 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
678 copyOutStatBuf(tc->getMemPort(), tc->getSyscallArg(1),
679 &hostBuf, (fd == 1));
678
679 return 0;
680}
681
682
683/// Target statfs() handler.
684template <class OS>
685SyscallReturn
680
681 return 0;
682}
683
684
685/// Target statfs() handler.
686template <class OS>
687SyscallReturn
686statfsFunc(SyscallDesc *desc, int callnum, Process *process,
688statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
687 ThreadContext *tc)
688{
689 std::string path;
690
691 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
692 return -EFAULT;
693
694 struct statfs hostBuf;
695 int result = statfs(path.c_str(), &hostBuf);
696
697 if (result < 0)
698 return -errno;
699
689 ThreadContext *tc)
690{
691 std::string path;
692
693 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
694 return -EFAULT;
695
696 struct statfs hostBuf;
697 int result = statfs(path.c_str(), &hostBuf);
698
699 if (result < 0)
700 return -errno;
701
700 copyOutStatfsBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
702 OS::copyOutStatfsBuf(tc->getMemPort(),
703 (Addr)(tc->getSyscallArg(1)), &hostBuf);
701
702 return 0;
703}
704
705
706/// Target fstatfs() handler.
707template <class OS>
708SyscallReturn
704
705 return 0;
706}
707
708
709/// Target fstatfs() handler.
710template <class OS>
711SyscallReturn
709fstatfsFunc(SyscallDesc *desc, int callnum, Process *process,
712fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
710 ThreadContext *tc)
711{
712 int fd = process->sim_fd(tc->getSyscallArg(0));
713
714 if (fd < 0)
715 return -EBADF;
716
717 struct statfs hostBuf;
718 int result = fstatfs(fd, &hostBuf);
719
720 if (result < 0)
721 return -errno;
722
713 ThreadContext *tc)
714{
715 int fd = process->sim_fd(tc->getSyscallArg(0));
716
717 if (fd < 0)
718 return -EBADF;
719
720 struct statfs hostBuf;
721 int result = fstatfs(fd, &hostBuf);
722
723 if (result < 0)
724 return -errno;
725
723 copyOutStatfsBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
726 OS::copyOutStatfsBuf(tc->getMemPort(), tc->getSyscallArg(1),
727 &hostBuf);
724
725 return 0;
726}
727
728
729/// Target writev() handler.
730template <class OS>
731SyscallReturn
728
729 return 0;
730}
731
732
733/// Target writev() handler.
734template <class OS>
735SyscallReturn
732writevFunc(SyscallDesc *desc, int callnum, Process *process,
736writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
733 ThreadContext *tc)
734{
735 int fd = tc->getSyscallArg(0);
736 if (fd < 0 || process->sim_fd(fd) < 0) {
737 // doesn't map to any simulator fd: not a valid target fd
738 return -EBADF;
739 }
740

--- 36 unchanged lines hidden (view full) ---

777/// since this could be seriously broken if we're not mapping
778/// /dev/zero.
779//
780/// Someday we should explicitly check for /dev/zero in open, flag the
781/// file descriptor, and fail (or implement!) a non-anonymous mmap to
782/// anything else.
783template <class OS>
784SyscallReturn
737 ThreadContext *tc)
738{
739 int fd = tc->getSyscallArg(0);
740 if (fd < 0 || process->sim_fd(fd) < 0) {
741 // doesn't map to any simulator fd: not a valid target fd
742 return -EBADF;
743 }
744

--- 36 unchanged lines hidden (view full) ---

781/// since this could be seriously broken if we're not mapping
782/// /dev/zero.
783//
784/// Someday we should explicitly check for /dev/zero in open, flag the
785/// file descriptor, and fail (or implement!) a non-anonymous mmap to
786/// anything else.
787template <class OS>
788SyscallReturn
785mmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
789mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
786{
787 Addr start = tc->getSyscallArg(0);
788 uint64_t length = tc->getSyscallArg(1);
789 // int prot = tc->getSyscallArg(2);
790 int flags = tc->getSyscallArg(3);
791 // int fd = p->sim_fd(tc->getSyscallArg(4));
792 // int offset = tc->getSyscallArg(5);
793

--- 21 unchanged lines hidden (view full) ---

815 }
816
817 return start;
818}
819
820/// Target getrlimit() handler.
821template <class OS>
822SyscallReturn
790{
791 Addr start = tc->getSyscallArg(0);
792 uint64_t length = tc->getSyscallArg(1);
793 // int prot = tc->getSyscallArg(2);
794 int flags = tc->getSyscallArg(3);
795 // int fd = p->sim_fd(tc->getSyscallArg(4));
796 // int offset = tc->getSyscallArg(5);
797

--- 21 unchanged lines hidden (view full) ---

819 }
820
821 return start;
822}
823
824/// Target getrlimit() handler.
825template <class OS>
826SyscallReturn
823getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
827getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
824 ThreadContext *tc)
825{
826 unsigned resource = tc->getSyscallArg(0);
827 TypedBufferArg<typename OS::rlimit> rlp(tc->getSyscallArg(1));
828
829 switch (resource) {
830 case OS::TGT_RLIMIT_STACK:
831 // max stack size in bytes: make up a number (2MB for now)

--- 11 unchanged lines hidden (view full) ---

843
844 rlp.copyOut(tc->getMemPort());
845 return 0;
846}
847
848/// Target gettimeofday() handler.
849template <class OS>
850SyscallReturn
828 ThreadContext *tc)
829{
830 unsigned resource = tc->getSyscallArg(0);
831 TypedBufferArg<typename OS::rlimit> rlp(tc->getSyscallArg(1));
832
833 switch (resource) {
834 case OS::TGT_RLIMIT_STACK:
835 // max stack size in bytes: make up a number (2MB for now)

--- 11 unchanged lines hidden (view full) ---

847
848 rlp.copyOut(tc->getMemPort());
849 return 0;
850}
851
852/// Target gettimeofday() handler.
853template <class OS>
854SyscallReturn
851gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
855gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
852 ThreadContext *tc)
853{
854 TypedBufferArg<typename OS::timeval> tp(tc->getSyscallArg(0));
855
856 getElapsedTime(tp->tv_sec, tp->tv_usec);
857 tp->tv_sec += seconds_since_epoch;
858 tp->tv_sec = htog(tp->tv_sec);
859 tp->tv_usec = htog(tp->tv_usec);
860
861 tp.copyOut(tc->getMemPort());
862
863 return 0;
864}
865
866
867/// Target utimes() handler.
868template <class OS>
869SyscallReturn
856 ThreadContext *tc)
857{
858 TypedBufferArg<typename OS::timeval> tp(tc->getSyscallArg(0));
859
860 getElapsedTime(tp->tv_sec, tp->tv_usec);
861 tp->tv_sec += seconds_since_epoch;
862 tp->tv_sec = htog(tp->tv_sec);
863 tp->tv_usec = htog(tp->tv_usec);
864
865 tp.copyOut(tc->getMemPort());
866
867 return 0;
868}
869
870
871/// Target utimes() handler.
872template <class OS>
873SyscallReturn
870utimesFunc(SyscallDesc *desc, int callnum, Process *process,
874utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
871 ThreadContext *tc)
872{
873 std::string path;
874
875 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
876 return -EFAULT;
877
878 TypedBufferArg<typename OS::timeval [2]> tp(tc->getSyscallArg(1));

--- 10 unchanged lines hidden (view full) ---

889 if (result < 0)
890 return -errno;
891
892 return 0;
893}
894/// Target getrusage() function.
895template <class OS>
896SyscallReturn
875 ThreadContext *tc)
876{
877 std::string path;
878
879 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
880 return -EFAULT;
881
882 TypedBufferArg<typename OS::timeval [2]> tp(tc->getSyscallArg(1));

--- 10 unchanged lines hidden (view full) ---

893 if (result < 0)
894 return -errno;
895
896 return 0;
897}
898/// Target getrusage() function.
899template <class OS>
900SyscallReturn
897getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
901getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
898 ThreadContext *tc)
899{
900 int who = tc->getSyscallArg(0); // THREAD, SELF, or CHILDREN
901 TypedBufferArg<typename OS::rusage> rup(tc->getSyscallArg(1));
902
903 if (who != OS::TGT_RUSAGE_SELF) {
904 // don't really handle THREAD or CHILDREN, but just warn and
905 // plow ahead

--- 34 unchanged lines hidden ---
902 ThreadContext *tc)
903{
904 int who = tc->getSyscallArg(0); // THREAD, SELF, or CHILDREN
905 TypedBufferArg<typename OS::rusage> rup(tc->getSyscallArg(1));
906
907 if (who != OS::TGT_RUSAGE_SELF) {
908 // don't really handle THREAD or CHILDREN, but just warn and
909 // plow ahead

--- 34 unchanged lines hidden ---