syscall_emul.cc (11856:103e2f92c965) syscall_emul.cc (11875:8e928c0f98d1)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

615
616 std::shared_ptr<FDEntry> new_fdep = old_hbfdp->clone();
617 auto new_hbfdp = std::dynamic_pointer_cast<HBFDEntry>(new_fdep);
618 new_hbfdp->setSimFD(result);
619
620 return (result == -1) ? -local_errno : p->fds->allocFD(new_fdep);
621}
622
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

615
616 std::shared_ptr<FDEntry> new_fdep = old_hbfdp->clone();
617 auto new_hbfdp = std::dynamic_pointer_cast<HBFDEntry>(new_fdep);
618 new_hbfdp->setSimFD(result);
619
620 return (result == -1) ? -local_errno : p->fds->allocFD(new_fdep);
621}
622
623
624SyscallReturn
625fcntlFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
626{
623SyscallReturn
624fcntlFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
625{
626 int arg;
627 int index = 0;
628 int tgt_fd = p->getSyscallArg(tc, index);
627 int index = 0;
628 int tgt_fd = p->getSyscallArg(tc, index);
629 int cmd = p->getSyscallArg(tc, index);
629
630 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
631 if (!hbfdp)
632 return -EBADF;
633 int sim_fd = hbfdp->getSimFD();
634
630
631 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
632 if (!hbfdp)
633 return -EBADF;
634 int sim_fd = hbfdp->getSimFD();
635
635 int cmd = p->getSyscallArg(tc, index);
636 int coe = hbfdp->getCOE();
637
636 switch (cmd) {
638 switch (cmd) {
637 case 0: // F_DUPFD
638 // if we really wanted to support this, we'd need to do it
639 // in the target fd space.
640 warn("fcntl(%d, F_DUPFD) not supported, error returned\n", tgt_fd);
641 return -EMFILE;
639 case F_GETFD:
640 return coe & FD_CLOEXEC;
642
641
643 case 1: // F_GETFD (get close-on-exec flag)
644 case 2: // F_SETFD (set close-on-exec flag)
642 case F_SETFD: {
643 arg = p->getSyscallArg(tc, index);
644 arg ? hbfdp->setCOE(true) : hbfdp->setCOE(false);
645 return 0;
645 return 0;
646 }
646
647
647 case 3: // F_GETFL (get file flags)
648 case 4: // F_SETFL (set file flags)
649 // not sure if this is totally valid, but we'll pass it through
650 // to the underlying OS
651 warn("fcntl(%d, %d) passed through to host\n", tgt_fd, cmd);
652 return fcntl(sim_fd, cmd);
653 // return 0;
648 // Rely on the host to maintain the file status flags for this file
649 // description rather than maintain it ourselves. Admittedly, this
650 // is suboptimal (and possibly error prone), but it is difficult to
651 // maintain the flags by tracking them across the different descriptors
652 // (that refer to this file description) caused by clone, dup, and
653 // subsequent fcntls.
654 case F_GETFL:
655 case F_SETFL: {
656 arg = p->getSyscallArg(tc, index);
657 int rv = fcntl(sim_fd, cmd, arg);
658 return (rv == -1) ? -errno : rv;
659 }
654
660
655 case 7: // F_GETLK (get lock)
656 case 8: // F_SETLK (set lock)
657 case 9: // F_SETLKW (set lock and wait)
658 // don't mess with file locking... just act like it's OK
659 warn("File lock call (fcntl(%d, %d)) ignored.\n", tgt_fd, cmd);
660 return 0;
661
662 default:
661 default:
663 warn("Unknown fcntl command %d\n", cmd);
662 warn("fcntl: unsupported command %d\n", cmd);
664 return 0;
665 }
666}
667
668SyscallReturn
669fcntl64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
670{
671 int index = 0;

--- 285 unchanged lines hidden ---
663 return 0;
664 }
665}
666
667SyscallReturn
668fcntl64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
669{
670 int index = 0;

--- 285 unchanged lines hidden ---