syscall_emul.hh (3079:13d9c24a7bba) syscall_emul.hh (3113:a6811aaea654)
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;

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

41/// This file defines objects used to emulate syscalls from the target
42/// application on the host machine.
43
44#include <errno.h>
45#include <string>
46#ifdef __CYGWIN32__
47#include <sys/fcntl.h> // for O_BINARY
48#endif
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;

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

41/// This file defines objects used to emulate syscalls from the target
42/// application on the host machine.
43
44#include <errno.h>
45#include <string>
46#ifdef __CYGWIN32__
47#include <sys/fcntl.h> // for O_BINARY
48#endif
49#include <sys/stat.h>
50#include <fcntl.h>
49#include <sys/uio.h>
50
51#include <sys/uio.h>
52
51#include "arch/isa_traits.hh" // for Addr
53#include "sim/host.hh" // for Addr
52#include "base/chunk_generator.hh"
53#include "base/intmath.hh" // for RoundUp
54#include "base/misc.hh"
55#include "base/trace.hh"
56#include "cpu/base.hh"
57#include "cpu/thread_context.hh"
58#include "mem/translating_port.hh"
59#include "mem/page_table.hh"

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

300SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
301 Process *p, ThreadContext *tc);
302
303/// Target getgidPseudo() handler.
304SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
305 Process *p, ThreadContext *tc);
306
307
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"

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

302SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num,
303 Process *p, ThreadContext *tc);
304
305/// Target getgidPseudo() handler.
306SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num,
307 Process *p, ThreadContext *tc);
308
309
308/// This struct is used to build an target-OS-dependent table that
309/// maps the target's open() flags to the host open() flags.
310struct OpenFlagTransTable {
311 int tgtFlag; //!< Target system flag value.
312 int hostFlag; //!< Corresponding host system flag value.
313};
314
315
316
317/// A readable name for 1,000,000, for converting microseconds to seconds.
318const int one_million = 1000000;
319
320/// Approximate seconds since the epoch (1/1/1970). About a billion,
321/// by my reckoning. We want to keep this a constant (not use the
322/// real-world time) to keep simulations repeatable.
323const unsigned seconds_since_epoch = 1000000000;
324

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

335
336//////////////////////////////////////////////////////////////////////
337//
338// The following emulation functions are generic, but need to be
339// templated to account for differences in types, constants, etc.
340//
341//////////////////////////////////////////////////////////////////////
342
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.
316const unsigned seconds_since_epoch = 1000000000;
317

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

328
329//////////////////////////////////////////////////////////////////////
330//
331// The following emulation functions are generic, but need to be
332// templated to account for differences in types, constants, etc.
333//
334//////////////////////////////////////////////////////////////////////
335
336#if NO_STAT64
337 typedef struct stat hst_stat;
338 typedef struct stat hst_stat64;
339#else
340 typedef struct stat hst_stat;
341 typedef struct stat64 hst_stat64;
342#endif
343
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().
347
348template <typename target_stat, typename host_stat>
349static void
350convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY = false)
351{
352 if (fakeTTY)
353 tgt->st_dev = 0xA;
354 else
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 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;
367 tgt->st_atimeX = htog(tgt->st_atimeX);
368 tgt->st_mtimeX = host->st_mtimeX;
369 tgt->st_mtimeX = htog(tgt->st_mtimeX);
370 tgt->st_ctimeX = host->st_ctimeX;
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
379
380template <typename target_stat, typename host_stat64>
381static void
382convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
383{
384 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
385#if defined(STAT_HAVE_NSEC)
386 tgt->st_atime_nsec = host->st_atime_nsec;
387 tgt->st_atime_nsec = htog(tgt->st_atime_nsec);
388 tgt->st_mtime_nsec = host->st_mtime_nsec;
389 tgt->st_mtime_nsec = htog(tgt->st_mtime_nsec);
390 tgt->st_ctime_nsec = host->st_ctime_nsec;
391 tgt->st_ctime_nsec = htog(tgt->st_ctime_nsec);
392#else
393 tgt->st_atime_nsec = 0;
394 tgt->st_mtime_nsec = 0;
395 tgt->st_ctime_nsec = 0;
396#endif
397}
398
399//Here are a couple convenience functions
400template<class OS>
401static void
402copyOutStatBuf(TranslatingPort * mem, Addr addr,
403 hst_stat *host, bool fakeTTY = false)
404{
405 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
406 tgt_stat_buf tgt(addr);
407 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
408 tgt.copyOut(mem);
409}
410
411template<class OS>
412static void
413copyOutStat64Buf(TranslatingPort * mem, Addr addr,
414 hst_stat64 *host, bool fakeTTY = false)
415{
416 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
417 tgt_stat_buf tgt(addr);
418 convertStatBuf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
419 tgt.copyOut(mem);
420}
421
343/// Target ioctl() handler. For the most part, programs call ioctl()
344/// only to find out if their stdout is a tty, to determine whether to
345/// do line or block buffering.
346template <class OS>
347SyscallReturn
348ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
349 ThreadContext *tc)
350{

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

487 return -EFAULT;
488
489 struct stat hostBuf;
490 int result = stat(path.c_str(), &hostBuf);
491
492 if (result < 0)
493 return -errno;
494
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,
428 ThreadContext *tc)
429{

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

566 return -EFAULT;
567
568 struct stat hostBuf;
569 int result = stat(path.c_str(), &hostBuf);
570
571 if (result < 0)
572 return -errno;
573
495 OS::copyOutStatBuf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
574 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
496
497 return 0;
498}
499
500
501/// Target fstat64() handler.
502template <class OS>
503SyscallReturn

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

516#else
517 struct stat64 hostBuf;
518 int result = fstat64(process->sim_fd(fd), &hostBuf);
519#endif
520
521 if (result < 0)
522 return -errno;
523
575
576 return 0;
577}
578
579
580/// Target fstat64() handler.
581template <class OS>
582SyscallReturn

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

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
524 OS::copyOutStat64Buf(tc->getMemPort(), fd, tc->getSyscallArg(1), &hostBuf);
603 copyOutStat64Buf<OS>(tc->getMemPort(), fd, tc->getSyscallArg(1), &hostBuf);
525
526 return 0;
527}
528
529
530/// Target lstat() handler.
531template <class OS>
532SyscallReturn

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

539 return -EFAULT;
540
541 struct stat hostBuf;
542 int result = lstat(path.c_str(), &hostBuf);
543
544 if (result < 0)
545 return -errno;
546
604
605 return 0;
606}
607
608
609/// Target lstat() handler.
610template <class OS>
611SyscallReturn

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

618 return -EFAULT;
619
620 struct stat hostBuf;
621 int result = lstat(path.c_str(), &hostBuf);
622
623 if (result < 0)
624 return -errno;
625
547 OS::copyOutStatBuf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
626 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
548
549 return 0;
550}
551
552/// Target lstat64() handler.
553template <class OS>
554SyscallReturn
555lstat64Func(SyscallDesc *desc, int callnum, Process *process,

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

566#else
567 struct stat64 hostBuf;
568 int result = lstat64(path.c_str(), &hostBuf);
569#endif
570
571 if (result < 0)
572 return -errno;
573
627
628 return 0;
629}
630
631/// Target lstat64() handler.
632template <class OS>
633SyscallReturn
634lstat64Func(SyscallDesc *desc, int callnum, Process *process,

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

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
574 OS::copyOutStat64Buf(tc->getMemPort(), -1, tc->getSyscallArg(1), &hostBuf);
653 copyOutStat64Buf<OS>(tc->getMemPort(), -1, tc->getSyscallArg(1), &hostBuf);
575
576 return 0;
577}
578
579/// Target fstat() handler.
580template <class OS>
581SyscallReturn
582fstatFunc(SyscallDesc *desc, int callnum, Process *process,

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

590 return -EBADF;
591
592 struct stat hostBuf;
593 int result = fstat(fd, &hostBuf);
594
595 if (result < 0)
596 return -errno;
597
654
655 return 0;
656}
657
658/// Target fstat() handler.
659template <class OS>
660SyscallReturn
661fstatFunc(SyscallDesc *desc, int callnum, Process *process,

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

669 return -EBADF;
670
671 struct stat hostBuf;
672 int result = fstat(fd, &hostBuf);
673
674 if (result < 0)
675 return -errno;
676
598 OS::copyOutStatBuf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
677 copyOutStatBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
599
600 return 0;
601}
602
603
604/// Target statfs() handler.
605template <class OS>
606SyscallReturn

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

613 return -EFAULT;
614
615 struct statfs hostBuf;
616 int result = statfs(path.c_str(), &hostBuf);
617
618 if (result < 0)
619 return -errno;
620
678
679 return 0;
680}
681
682
683/// Target statfs() handler.
684template <class OS>
685SyscallReturn

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

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
621 OS::copyOutStatfsBuf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
700 copyOutStatfsBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
622
623 return 0;
624}
625
626
627/// Target fstatfs() handler.
628template <class OS>
629SyscallReturn

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

636 return -EBADF;
637
638 struct statfs hostBuf;
639 int result = fstatfs(fd, &hostBuf);
640
641 if (result < 0)
642 return -errno;
643
701
702 return 0;
703}
704
705
706/// Target fstatfs() handler.
707template <class OS>
708SyscallReturn

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

715 return -EBADF;
716
717 struct statfs hostBuf;
718 int result = fstatfs(fd, &hostBuf);
719
720 if (result < 0)
721 return -errno;
722
644 OS::copyOutStatfsBuf(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
723 copyOutStatfsBuf<OS>(tc->getMemPort(), tc->getSyscallArg(1), &hostBuf);
645
646 return 0;
647}
648
649
650/// Target writev() handler.
651template <class OS>
652SyscallReturn

--- 208 unchanged lines hidden ---
724
725 return 0;
726}
727
728
729/// Target writev() handler.
730template <class OS>
731SyscallReturn

--- 208 unchanged lines hidden ---