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 --- 39 unchanged lines hidden (view full) --- 48#if (defined(__APPLE__) || defined(__OpenBSD__) || \ 49 defined(__FreeBSD__) || defined(__CYGWIN__) || \ 50 defined(__NetBSD__)) 51#define NO_STAT64 1 52#else 53#define NO_STAT64 0 54#endif 55 |
56/// 57/// @file syscall_emul.hh 58/// 59/// This file defines objects used to emulate syscalls from the target 60/// application on the host machine. 61 |
62#ifdef __linux__ 63#include <sys/eventfd.h> 64#include <sys/statfs.h> 65 66#endif 67 |
68#ifdef __CYGWIN32__ 69#include <sys/fcntl.h> 70 71#endif 72#include <fcntl.h> 73#include <net/if.h> 74#include <poll.h> 75#include <sys/ioctl.h> 76#include <sys/mman.h> 77#include <sys/socket.h> 78#include <sys/stat.h> |
79#include <sys/time.h> 80#include <sys/types.h> 81#include <sys/uio.h> 82#include <unistd.h> 83 84#include <cerrno> 85#include <memory> 86#include <string> --- 25 unchanged lines hidden (view full) --- 112////////////////////////////////////////////////////////////////////// 113// 114// The following emulation functions are generic enough that they 115// don't need to be recompiled for different emulated OS's. They are 116// defined in sim/syscall_emul.cc. 117// 118////////////////////////////////////////////////////////////////////// 119 |
120void warnUnsupportedOS(std::string syscall_name); |
121 122/// Handler for unimplemented syscalls that we haven't thought about. 123SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, 124 Process *p, ThreadContext *tc); 125 126/// Handler for unimplemented syscalls that we never intend to 127/// implement (signal handling, etc.) and should not affect the correct 128/// behavior of the program. Print a warning only if the appropriate --- 1381 unchanged lines hidden (view full) --- 1510} 1511 1512/// Target statfs() handler. 1513template <class OS> 1514SyscallReturn 1515statfsFunc(SyscallDesc *desc, int callnum, Process *process, 1516 ThreadContext *tc) 1517{ |
1518#ifdef __linux__ |
1519 std::string path; 1520 1521 int index = 0; 1522 if (!tc->getMemProxy().tryReadString(path, 1523 process->getSyscallArg(tc, index))) { 1524 return -EFAULT; 1525 } 1526 Addr bufPtr = process->getSyscallArg(tc, index); 1527 1528 // Adjust path for cwd and redirection 1529 path = process->checkPathRedirect(path); 1530 1531 struct statfs hostBuf; 1532 int result = statfs(path.c_str(), &hostBuf); 1533 1534 if (result < 0) 1535 return -errno; 1536 1537 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf); |
1538 return 0; |
1539#else 1540 warnUnsupportedOS("statfs"); 1541 return -1; 1542#endif |
1543} 1544 1545template <class OS> 1546SyscallReturn 1547cloneFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) 1548{ 1549 int index = 0; 1550 --- 1290 unchanged lines hidden (view full) --- 2841 delete(lenBufPtr); 2842 } 2843 2844 auto afdp = std::make_shared<SocketFDEntry>(host_fd, sfdp->_domain, 2845 sfdp->_type, sfdp->_protocol); 2846 return p->fds->allocFD(afdp); 2847} 2848 |
2849/// Target eventfd() function. 2850template <class OS> 2851SyscallReturn 2852eventfdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) 2853{ 2854#ifdef __linux__ 2855 int index = 0; 2856 unsigned initval = p->getSyscallArg(tc, index); 2857 int in_flags = p->getSyscallArg(tc, index); 2858 2859 int sim_fd = eventfd(initval, in_flags); 2860 if (sim_fd == -1) 2861 return -errno; 2862 2863 bool cloexec = in_flags & OS::TGT_O_CLOEXEC; 2864 2865 int flags = cloexec ? OS::TGT_O_CLOEXEC : 0; 2866 flags |= (in_flags & OS::TGT_O_NONBLOCK) ? OS::TGT_O_NONBLOCK : 0; 2867 2868 auto hbfdp = std::make_shared<HBFDEntry>(flags, sim_fd, cloexec); 2869 int tgt_fd = p->fds->allocFD(hbfdp); 2870 return tgt_fd; 2871#else 2872 warnUnsupportedOS("eventfd"); 2873 return -1; 2874#endif 2875} 2876 |
2877#endif // __SIM_SYSCALL_EMUL_HH__ |