syscall_emul.hh (13883:f44e21d3aaa7) syscall_emul.hh (13902:a43851662ce3)
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

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

73/// This file defines objects used to emulate syscalls from the target
74/// application on the host machine.
75
76#ifdef __CYGWIN32__
77#include <sys/fcntl.h>
78
79#endif
80#include <fcntl.h>
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

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

73/// This file defines objects used to emulate syscalls from the target
74/// application on the host machine.
75
76#ifdef __CYGWIN32__
77#include <sys/fcntl.h>
78
79#endif
80#include <fcntl.h>
81#include <net/if.h>
81#include <poll.h>
82#include <poll.h>
83#include <sys/ioctl.h>
82#include <sys/mman.h>
83#include <sys/socket.h>
84#include <sys/stat.h>
84#include <sys/mman.h>
85#include <sys/socket.h>
86#include <sys/stat.h>
87
85#if (NO_STATFS == 0)
86#include <sys/statfs.h>
88#if (NO_STATFS == 0)
89#include <sys/statfs.h>
90
87#else
88#include <sys/mount.h>
91#else
92#include <sys/mount.h>
93
89#endif
90#include <sys/time.h>
91#include <sys/types.h>
92#include <sys/uio.h>
93#include <unistd.h>
94
95#include <cerrno>
96#include <memory>

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

750 unsigned req = p->getSyscallArg(tc, index);
751
752 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
753
754 if (OS::isTtyReq(req))
755 return -ENOTTY;
756
757 auto dfdp = std::dynamic_pointer_cast<DeviceFDEntry>((*p->fds)[tgt_fd]);
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>

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

755 unsigned req = p->getSyscallArg(tc, index);
756
757 DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
758
759 if (OS::isTtyReq(req))
760 return -ENOTTY;
761
762 auto dfdp = std::dynamic_pointer_cast<DeviceFDEntry>((*p->fds)[tgt_fd]);
758 if (!dfdp)
759 return -EBADF;
763 if (dfdp) {
764 EmulatedDriver *emul_driver = dfdp->getDriver();
765 if (emul_driver)
766 return emul_driver->ioctl(p, tc, req);
767 }
760
768
761 /**
762 * If the driver is valid, issue the ioctl through it. Otherwise,
763 * there's an implicit assumption that the device is a TTY type and we
764 * return that we do not have a valid TTY.
765 */
766 EmulatedDriver *emul_driver = dfdp->getDriver();
767 if (emul_driver)
768 return emul_driver->ioctl(p, tc, req);
769 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*p->fds)[tgt_fd]);
770 if (sfdp) {
771 int status;
769
772
773 switch (req) {
774 case SIOCGIFCONF: {
775 Addr conf_addr = p->getSyscallArg(tc, index);
776 BufferArg conf_arg(conf_addr, sizeof(ifconf));
777 conf_arg.copyIn(tc->getMemProxy());
778
779 ifconf *conf = (ifconf*)conf_arg.bufferPtr();
780 Addr ifc_buf_addr = (Addr)conf->ifc_buf;
781 BufferArg ifc_buf_arg(ifc_buf_addr, conf->ifc_len);
782 ifc_buf_arg.copyIn(tc->getMemProxy());
783
784 conf->ifc_buf = (char*)ifc_buf_arg.bufferPtr();
785
786 status = ioctl(sfdp->getSimFD(), req, conf_arg.bufferPtr());
787 if (status != -1) {
788 conf->ifc_buf = (char*)ifc_buf_addr;
789 ifc_buf_arg.copyOut(tc->getMemProxy());
790 conf_arg.copyOut(tc->getMemProxy());
791 }
792
793 return status;
794 }
795 case SIOCGIFFLAGS:
796#ifdef __linux__
797 case SIOCGIFINDEX:
798#endif
799 case SIOCGIFNETMASK:
800 case SIOCGIFADDR:
801#ifdef __linux__
802 case SIOCGIFHWADDR:
803#endif
804 case SIOCGIFMTU: {
805 Addr req_addr = p->getSyscallArg(tc, index);
806 BufferArg req_arg(req_addr, sizeof(ifreq));
807 req_arg.copyIn(tc->getMemProxy());
808
809 status = ioctl(sfdp->getSimFD(), req, req_arg.bufferPtr());
810 if (status != -1)
811 req_arg.copyOut(tc->getMemProxy());
812 return status;
813 }
814 }
815 }
816
770 /**
771 * For lack of a better return code, return ENOTTY. Ideally, we should
772 * return something better here, but at least we issue the warning.
773 */
774 warn("Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
775 tgt_fd, req, tc->pcState());
776 return -ENOTTY;
777}

--- 2040 unchanged lines hidden ---
817 /**
818 * For lack of a better return code, return ENOTTY. Ideally, we should
819 * return something better here, but at least we issue the warning.
820 */
821 warn("Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
822 tgt_fd, req, tc->pcState());
823 return -ENOTTY;
824}

--- 2040 unchanged lines hidden ---