Deleted Added
sdiff udiff text old ( 11906:4b99c1bb3b72 ) new ( 11907:48a3d32da9d8 )
full compact
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

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

608 * return something better here, but at least we issue the warning.
609 */
610 warn("Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
611 tgt_fd, req, tc->pcState());
612 return -ENOTTY;
613}
614
615template <class OS>
616static SyscallReturn
617openFunc(SyscallDesc *desc, int callnum, Process *process,
618 ThreadContext *tc, int index)
619{
620 std::string path;
621
622 if (!tc->getMemProxy().tryReadString(path,
623 process->getSyscallArg(tc, index)))
624 return -EFAULT;
625
626 int tgtFlags = process->getSyscallArg(tc, index);
627 int mode = process->getSyscallArg(tc, index);
628 int hostFlags = 0;
629
630 // translate open flags
631 for (int i = 0; i < OS::NUM_OPEN_FLAGS; i++) {
632 if (tgtFlags & OS::openFlagTable[i].tgtFlag) {
633 tgtFlags &= ~OS::openFlagTable[i].tgtFlag;
634 hostFlags |= OS::openFlagTable[i].hostFlag;
635 }
636 }
637
638 // any target flags left?
639 if (tgtFlags != 0)
640 warn("Syscall: open: cannot decode flags 0x%x", tgtFlags);
641
642#ifdef __CYGWIN32__
643 hostFlags |= O_BINARY;
644#endif
645
646 // Adjust path for current working directory
647 path = process->fullPath(path);
648
649 DPRINTF(SyscallVerbose, "opening file %s\n", path.c_str());
650
651 if (startswith(path, "/dev/")) {
652 std::string filename = path.substr(strlen("/dev/"));
653 if (filename == "sysdev0") {
654 // This is a memory-mapped high-resolution timer device on Alpha.
655 // We don't support it, so just punt.
656 warn("Ignoring open(%s, ...)\n", path);
657 return -ENOENT;
658 }
659
660 EmulatedDriver *drv = process->findDriver(filename);
661 if (drv) {
662 // the driver's open method will allocate a fd from the
663 // process if necessary.
664 return drv->open(process, tc, mode, hostFlags);
665 }
666
667 // fall through here for pass through to host devices, such as
668 // /dev/zero
669 }
670
671 int fd;
672 int local_errno;
673 if (startswith(path, "/proc/") || startswith(path, "/system/") ||
674 startswith(path, "/platform/") || startswith(path, "/sys/")) {
675 // It's a proc/sys entry and requires special handling
676 fd = OS::openSpecialFile(path, process, tc);
677 local_errno = ENOENT;
678 } else {
679 // open the file
680 fd = open(path.c_str(), hostFlags, mode);
681 local_errno = errno;
682 }
683
684 if (fd == -1)
685 return -local_errno;
686
687 std::shared_ptr<FileFDEntry> ffdp =
688 std::make_shared<FileFDEntry>(fd, hostFlags, path.c_str(), false);
689 return process->fds->allocFD(ffdp);
690}
691
692/// Target open() handler.
693template <class OS>
694SyscallReturn
695openFunc(SyscallDesc *desc, int callnum, Process *process,
696 ThreadContext *tc)
697{
698 return openFunc<OS>(desc, callnum, process, tc, 0);
699}
700
701/// Target openat() handler.
702template <class OS>
703SyscallReturn
704openatFunc(SyscallDesc *desc, int callnum, Process *process,
705 ThreadContext *tc)
706{
707 int index = 0;
708 int dirfd = process->getSyscallArg(tc, index);
709 if (dirfd != OS::TGT_AT_FDCWD)
710 warn("openat: first argument not AT_FDCWD; unlikely to work");
711 return openFunc<OS>(desc, callnum, process, tc, 1);
712}
713
714/// Target unlinkat() handler.
715template <class OS>
716SyscallReturn
717unlinkatFunc(SyscallDesc *desc, int callnum, Process *process,
718 ThreadContext *tc)
719{

--- 1194 unchanged lines hidden ---