syscall_emul.hh (14010:0e1e887507c0) syscall_emul.hh (14020:c9bf7a011602)
1/*
2 * Copyright (c) 2012-2013, 2015 ARM Limited
3 * Copyright (c) 2015 Advanced Micro Devices, Inc.
4 * All rights reserved
5 *
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

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

598 tgt->st_mtime_nsec = 0;
599 tgt->st_ctime_nsec = 0;
600#endif
601}
602
603// Here are a couple of convenience functions
604template<class OS>
605void
1/*
2 * Copyright (c) 2012-2013, 2015 ARM Limited
3 * Copyright (c) 2015 Advanced Micro Devices, Inc.
4 * All rights reserved
5 *
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

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

598 tgt->st_mtime_nsec = 0;
599 tgt->st_ctime_nsec = 0;
600#endif
601}
602
603// Here are a couple of convenience functions
604template<class OS>
605void
606copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
606copyOutStatBuf(PortProxy &mem, Addr addr,
607 hst_stat *host, bool fakeTTY = false)
608{
609 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
610 tgt_stat_buf tgt(addr);
611 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
612 tgt.copyOut(mem);
613}
614
615template<class OS>
616void
607 hst_stat *host, bool fakeTTY = false)
608{
609 typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
610 tgt_stat_buf tgt(addr);
611 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
612 tgt.copyOut(mem);
613}
614
615template<class OS>
616void
617copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
617copyOutStat64Buf(PortProxy &mem, Addr addr,
618 hst_stat64 *host, bool fakeTTY = false)
619{
620 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
621 tgt_stat_buf tgt(addr);
622 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
623 tgt.copyOut(mem);
624}
625
626template <class OS>
627void
618 hst_stat64 *host, bool fakeTTY = false)
619{
620 typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
621 tgt_stat_buf tgt(addr);
622 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
623 tgt.copyOut(mem);
624}
625
626template <class OS>
627void
628copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr,
628copyOutStatfsBuf(PortProxy &mem, Addr addr,
629 hst_statfs *host)
630{
631 TypedBufferArg<typename OS::tgt_statfs> tgt(addr);
632
633 tgt->f_type = TheISA::htog(host->f_type);
634#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
635 tgt->f_bsize = TheISA::htog(host->f_iosize);
636#else

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

1658 auto p = tc->getProcessPtr();
1659 int tgt_fd = p->getSyscallArg(tc, index);
1660
1661 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
1662 if (!ffdp)
1663 return -EBADF;
1664 int sim_fd = ffdp->getSimFD();
1665
629 hst_statfs *host)
630{
631 TypedBufferArg<typename OS::tgt_statfs> tgt(addr);
632
633 tgt->f_type = TheISA::htog(host->f_type);
634#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
635 tgt->f_bsize = TheISA::htog(host->f_iosize);
636#else

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

1658 auto p = tc->getProcessPtr();
1659 int tgt_fd = p->getSyscallArg(tc, index);
1660
1661 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
1662 if (!ffdp)
1663 return -EBADF;
1664 int sim_fd = ffdp->getSimFD();
1665
1666 SETranslatingPortProxy &prox = tc->getMemProxy();
1666 PortProxy &prox = tc->getMemProxy();
1667 uint64_t tiov_base = p->getSyscallArg(tc, index);
1668 size_t count = p->getSyscallArg(tc, index);
1669 typename OS::tgt_iovec tiov[count];
1670 struct iovec hiov[count];
1671 for (size_t i = 0; i < count; ++i) {
1672 prox.readBlob(tiov_base + (i * sizeof(typename OS::tgt_iovec)),
1673 &tiov[i], sizeof(typename OS::tgt_iovec));
1674 hiov[i].iov_len = TheISA::gtoh(tiov[i].iov_len);

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

1698 auto p = tc->getProcessPtr();
1699 int tgt_fd = p->getSyscallArg(tc, index);
1700
1701 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
1702 if (!hbfdp)
1703 return -EBADF;
1704 int sim_fd = hbfdp->getSimFD();
1705
1667 uint64_t tiov_base = p->getSyscallArg(tc, index);
1668 size_t count = p->getSyscallArg(tc, index);
1669 typename OS::tgt_iovec tiov[count];
1670 struct iovec hiov[count];
1671 for (size_t i = 0; i < count; ++i) {
1672 prox.readBlob(tiov_base + (i * sizeof(typename OS::tgt_iovec)),
1673 &tiov[i], sizeof(typename OS::tgt_iovec));
1674 hiov[i].iov_len = TheISA::gtoh(tiov[i].iov_len);

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

1698 auto p = tc->getProcessPtr();
1699 int tgt_fd = p->getSyscallArg(tc, index);
1700
1701 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
1702 if (!hbfdp)
1703 return -EBADF;
1704 int sim_fd = hbfdp->getSimFD();
1705
1706 SETranslatingPortProxy &prox = tc->getMemProxy();
1706 PortProxy &prox = tc->getMemProxy();
1707 uint64_t tiov_base = p->getSyscallArg(tc, index);
1708 size_t count = p->getSyscallArg(tc, index);
1709 struct iovec hiov[count];
1710 for (size_t i = 0; i < count; ++i) {
1711 typename OS::tgt_iovec tiov;
1712
1713 prox.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1714 &tiov, sizeof(typename OS::tgt_iovec));

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

1836 }
1837
1838 // Allocate physical memory and map it in. If the page table is already
1839 // mapped and clobber is not set, the simulator will issue throw a
1840 // fatal and bail out of the simulation.
1841 p->allocateMem(start, length, clobber);
1842
1843 // Transfer content into target address space.
1707 uint64_t tiov_base = p->getSyscallArg(tc, index);
1708 size_t count = p->getSyscallArg(tc, index);
1709 struct iovec hiov[count];
1710 for (size_t i = 0; i < count; ++i) {
1711 typename OS::tgt_iovec tiov;
1712
1713 prox.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
1714 &tiov, sizeof(typename OS::tgt_iovec));

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

1836 }
1837
1838 // Allocate physical memory and map it in. If the page table is already
1839 // mapped and clobber is not set, the simulator will issue throw a
1840 // fatal and bail out of the simulation.
1841 p->allocateMem(start, length, clobber);
1842
1843 // Transfer content into target address space.
1844 SETranslatingPortProxy &tp = tc->getMemProxy();
1844 PortProxy &tp = tc->getMemProxy();
1845 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1846 // In general, we should zero the mapped area for anonymous mappings,
1847 // with something like:
1848 // tp.memsetBlob(start, 0, length);
1849 // However, given that we don't support sparse mappings, and
1850 // some applications can map a couple of gigabytes of space
1851 // (intending sparse usage), that can get painfully expensive.
1852 // Fortunately, since we don't properly implement munmap either,

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

2119SyscallReturn
2120execveFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
2121{
2122 desc->setFlags(0);
2123 auto p = tc->getProcessPtr();
2124
2125 int index = 0;
2126 std::string path;
1845 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1846 // In general, we should zero the mapped area for anonymous mappings,
1847 // with something like:
1848 // tp.memsetBlob(start, 0, length);
1849 // However, given that we don't support sparse mappings, and
1850 // some applications can map a couple of gigabytes of space
1851 // (intending sparse usage), that can get painfully expensive.
1852 // Fortunately, since we don't properly implement munmap either,

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

2119SyscallReturn
2120execveFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
2121{
2122 desc->setFlags(0);
2123 auto p = tc->getProcessPtr();
2124
2125 int index = 0;
2126 std::string path;
2127 SETranslatingPortProxy & mem_proxy = tc->getMemProxy();
2127 PortProxy & mem_proxy = tc->getMemProxy();
2128 if (!mem_proxy.tryReadString(path, p->getSyscallArg(tc, index)))
2129 return -EFAULT;
2130
2131 if (access(path.c_str(), F_OK) == -1)
2132 return -EACCES;
2133
2128 if (!mem_proxy.tryReadString(path, p->getSyscallArg(tc, index)))
2129 return -EFAULT;
2130
2131 if (access(path.c_str(), F_OK) == -1)
2132 return -EACCES;
2133
2134 auto read_in = [](std::vector<std::string> & vect,
2135 SETranslatingPortProxy & mem_proxy,
2136 Addr mem_loc)
2134 auto read_in = [](std::vector &vect,
2135 PortProxy &mem_proxy, Addr mem_loc)
2137 {
2138 for (int inc = 0; ; inc++) {
2139 BufferArg b((mem_loc + sizeof(Addr) * inc), sizeof(Addr));
2140 b.copyIn(mem_proxy);
2141
2142 if (!*(Addr*)b.bufferPtr())
2143 break;
2144

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

2296 sec += seconds_since_epoch;
2297
2298 int index = 0;
2299 auto process = tc->getProcessPtr();
2300 Addr taddr = (Addr)process->getSyscallArg(tc, index);
2301 if (taddr != 0) {
2302 typename OS::time_t t = sec;
2303 t = TheISA::htog(t);
2136 {
2137 for (int inc = 0; ; inc++) {
2138 BufferArg b((mem_loc + sizeof(Addr) * inc), sizeof(Addr));
2139 b.copyIn(mem_proxy);
2140
2141 if (!*(Addr*)b.bufferPtr())
2142 break;
2143

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

2295 sec += seconds_since_epoch;
2296
2297 int index = 0;
2298 auto process = tc->getProcessPtr();
2299 Addr taddr = (Addr)process->getSyscallArg(tc, index);
2300 if (taddr != 0) {
2301 typename OS::time_t t = sec;
2302 t = TheISA::htog(t);
2304 SETranslatingPortProxy &p = tc->getMemProxy();
2303 PortProxy &p = tc->getMemProxy();
2305 p.writeBlob(taddr, &t, (int)sizeof(typename OS::time_t));
2306 }
2307 return sec;
2308}
2309
2310template <class OS>
2311SyscallReturn
2312tgkillFunc(SyscallDesc *desc, int num, ThreadContext *tc)

--- 525 unchanged lines hidden ---
2304 p.writeBlob(taddr, &t, (int)sizeof(typename OS::time_t));
2305 }
2306 return sec;
2307}
2308
2309template <class OS>
2310SyscallReturn
2311tgkillFunc(SyscallDesc *desc, int num, ThreadContext *tc)

--- 525 unchanged lines hidden ---