syscall_emul.hh (13907:3a7a5838ef50) syscall_emul.hh (13933:b4382461066d)
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
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#if (defined(__APPLE__) || defined(__OpenBSD__) || \
57 defined(__FreeBSD__) || defined(__NetBSD__))
58#define NO_STATFS 1
59#else
60#define NO_STATFS 0
61#endif
62
63#if (defined(__APPLE__) || defined(__OpenBSD__) || \
64 defined(__FreeBSD__) || defined(__NetBSD__))
65#define NO_FALLOCATE 1
66#else
67#define NO_FALLOCATE 0
68#endif
69
70///
71/// @file syscall_emul.hh
72///
73/// This file defines objects used to emulate syscalls from the target
74/// application on the host machine.
75
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
76#ifdef __CYGWIN32__
77#include <sys/fcntl.h>
78
79#endif
80#include <fcntl.h>
81#include <net/if.h>
82#include <poll.h>
83#include <sys/ioctl.h>
84#include <sys/mman.h>
85#include <sys/socket.h>
86#include <sys/stat.h>
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>
87
88#if (NO_STATFS == 0)
89#include <sys/statfs.h>
90
91#else
92#include <sys/mount.h>
93
94#endif
95#include <sys/time.h>
96#include <sys/types.h>
97#include <sys/uio.h>
98#include <unistd.h>
99
100#include <cerrno>
101#include <memory>
102#include <string>

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

128//////////////////////////////////////////////////////////////////////
129//
130// The following emulation functions are generic enough that they
131// don't need to be recompiled for different emulated OS's. They are
132// defined in sim/syscall_emul.cc.
133//
134//////////////////////////////////////////////////////////////////////
135
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);
136
137/// Handler for unimplemented syscalls that we haven't thought about.
138SyscallReturn unimplementedFunc(SyscallDesc *desc, int num,
139 Process *p, ThreadContext *tc);
140
141/// Handler for unimplemented syscalls that we never intend to
142/// implement (signal handling, etc.) and should not affect the correct
143/// behavior of the program. Print a warning only if the appropriate

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

1525}
1526
1527/// Target statfs() handler.
1528template <class OS>
1529SyscallReturn
1530statfsFunc(SyscallDesc *desc, int callnum, Process *process,
1531 ThreadContext *tc)
1532{
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{
1533#if NO_STATFS
1534 warn("Host OS cannot support calls to statfs. Ignoring syscall");
1535#else
1518#ifdef __linux__
1536 std::string path;
1537
1538 int index = 0;
1539 if (!tc->getMemProxy().tryReadString(path,
1540 process->getSyscallArg(tc, index))) {
1541 return -EFAULT;
1542 }
1543 Addr bufPtr = process->getSyscallArg(tc, index);
1544
1545 // Adjust path for cwd and redirection
1546 path = process->checkPathRedirect(path);
1547
1548 struct statfs hostBuf;
1549 int result = statfs(path.c_str(), &hostBuf);
1550
1551 if (result < 0)
1552 return -errno;
1553
1554 copyOutStatfsBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf);
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);
1555#endif
1556 return 0;
1538 return 0;
1539#else
1540 warnUnsupportedOS("statfs");
1541 return -1;
1542#endif
1557}
1558
1559template <class OS>
1560SyscallReturn
1561cloneFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
1562{
1563 int index = 0;
1564

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

2855 delete(lenBufPtr);
2856 }
2857
2858 auto afdp = std::make_shared<SocketFDEntry>(host_fd, sfdp->_domain,
2859 sfdp->_type, sfdp->_protocol);
2860 return p->fds->allocFD(afdp);
2861}
2862
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
2863#endif // __SIM_SYSCALL_EMUL_HH__
2877#endif // __SIM_SYSCALL_EMUL_HH__