syscall_emul.hh (9455:31afddc29cd4) | syscall_emul.hh (10027:532929273927) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2012-2013 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
|
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; 9 * redistributions in binary form must reproduce the above copyright --- 585 unchanged lines hidden (view full) --- 595 return -ENOTTY; 596 } 597 598 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n", 599 fd, req, tc->pcState()); 600 return -ENOTTY; 601} 602 | 14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright --- 585 unchanged lines hidden (view full) --- 607 return -ENOTTY; 608 } 609 610 warn("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ \n", 611 fd, req, tc->pcState()); 612 return -ENOTTY; 613} 614 |
603/// Target open() handler. | |
604template <class OS> | 615template <class OS> |
605SyscallReturn | 616static SyscallReturn |
606openFunc(SyscallDesc *desc, int callnum, LiveProcess *process, | 617openFunc(SyscallDesc *desc, int callnum, LiveProcess *process, |
607 ThreadContext *tc) | 618 ThreadContext *tc, int index) |
608{ 609 std::string path; 610 | 619{ 620 std::string path; 621 |
611 int index = 0; | |
612 if (!tc->getMemProxy().tryReadString(path, 613 process->getSyscallArg(tc, index))) 614 return -EFAULT; 615 616 if (path == "/dev/sysdev0") { 617 // This is a memory-mapped high-resolution timer device on Alpha. 618 // We don't support it, so just punt. 619 warn("Ignoring open(%s, ...)\n", path); --- 39 unchanged lines hidden (view full) --- 659 } 660 661 if (fd == -1) 662 return -local_errno; 663 664 return process->alloc_fd(fd, path.c_str(), hostFlags, mode, false); 665} 666 | 622 if (!tc->getMemProxy().tryReadString(path, 623 process->getSyscallArg(tc, index))) 624 return -EFAULT; 625 626 if (path == "/dev/sysdev0") { 627 // This is a memory-mapped high-resolution timer device on Alpha. 628 // We don't support it, so just punt. 629 warn("Ignoring open(%s, ...)\n", path); --- 39 unchanged lines hidden (view full) --- 669 } 670 671 if (fd == -1) 672 return -local_errno; 673 674 return process->alloc_fd(fd, path.c_str(), hostFlags, mode, false); 675} 676 |
677/// Target open() handler. 678template <class OS> 679SyscallReturn 680openFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 681 ThreadContext *tc) 682{ 683 return openFunc<OS>(desc, callnum, process, tc, 0); 684} 685 686/// Target openat() handler. 687template <class OS> 688SyscallReturn 689openatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 690 ThreadContext *tc) 691{ 692 int index = 0; 693 int dirfd = process->getSyscallArg(tc, index); 694 if (dirfd != OS::TGT_AT_FDCWD) 695 warn("openat: first argument not AT_FDCWD; unlikely to work"); 696 return openFunc<OS>(desc, callnum, process, tc, 1); 697} 698 |
|
667/// Target sysinfo() handler. 668template <class OS> 669SyscallReturn 670sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 671 ThreadContext *tc) 672{ 673 674 int index = 0; --- 72 unchanged lines hidden (view full) --- 747SyscallReturn 748mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) 749{ 750 int index = 0; 751 Addr start = process->getSyscallArg(tc, index); 752 uint64_t old_length = process->getSyscallArg(tc, index); 753 uint64_t new_length = process->getSyscallArg(tc, index); 754 uint64_t flags = process->getSyscallArg(tc, index); | 699/// Target sysinfo() handler. 700template <class OS> 701SyscallReturn 702sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 703 ThreadContext *tc) 704{ 705 706 int index = 0; --- 72 unchanged lines hidden (view full) --- 779SyscallReturn 780mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) 781{ 782 int index = 0; 783 Addr start = process->getSyscallArg(tc, index); 784 uint64_t old_length = process->getSyscallArg(tc, index); 785 uint64_t new_length = process->getSyscallArg(tc, index); 786 uint64_t flags = process->getSyscallArg(tc, index); |
787 uint64_t provided_address = 0; 788 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED; |
|
755 | 789 |
790 if (use_provided_address) 791 provided_address = process->getSyscallArg(tc, index); 792 |
|
756 if ((start % TheISA::VMPageSize != 0) || | 793 if ((start % TheISA::VMPageSize != 0) || |
757 (new_length % TheISA::VMPageSize != 0)) { | 794 (new_length % TheISA::VMPageSize != 0) || 795 (provided_address % TheISA::VMPageSize != 0)) { |
758 warn("mremap failing: arguments not page aligned"); 759 return -EINVAL; 760 } 761 762 if (new_length > old_length) { | 796 warn("mremap failing: arguments not page aligned"); 797 return -EINVAL; 798 } 799 800 if (new_length > old_length) { |
763 if ((start + old_length) == process->mmap_end) { | 801 if ((start + old_length) == process->mmap_end && 802 (!use_provided_address || provided_address == start)) { |
764 uint64_t diff = new_length - old_length; 765 process->allocateMem(process->mmap_end, diff); 766 process->mmap_end += diff; 767 return start; 768 } else { | 803 uint64_t diff = new_length - old_length; 804 process->allocateMem(process->mmap_end, diff); 805 process->mmap_end += diff; 806 return start; 807 } else { |
769 // sys/mman.h defined MREMAP_MAYMOVE 770 if (!(flags & 1)) { | 808 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) { |
771 warn("can't remap here and MREMAP_MAYMOVE flag not set\n"); 772 return -ENOMEM; 773 } else { | 809 warn("can't remap here and MREMAP_MAYMOVE flag not set\n"); 810 return -ENOMEM; 811 } else { |
774 process->pTable->remap(start, old_length, process->mmap_end); 775 warn("mremapping to totally new vaddr %08p-%08p, adding %d\n", 776 process->mmap_end, process->mmap_end + new_length, new_length); 777 start = process->mmap_end; | 812 uint64_t new_start = use_provided_address ? 813 provided_address : process->mmap_end; 814 process->pTable->remap(start, old_length, new_start); 815 warn("mremapping to new vaddr %08p-%08p, adding %d\n", 816 new_start, new_start + new_length, 817 new_length - old_length); |
778 // add on the remaining unallocated pages | 818 // add on the remaining unallocated pages |
779 process->allocateMem(start + old_length, 780 new_length - old_length); 781 process->mmap_end += new_length; 782 warn("returning %08p as start\n", start); 783 return start; | 819 process->allocateMem(new_start + old_length, 820 new_length - old_length, 821 use_provided_address /* clobber */); 822 if (!use_provided_address) 823 process->mmap_end += new_length; 824 if (use_provided_address && 825 new_start + new_length > process->mmap_end) { 826 // something fishy going on here, at least notify the user 827 // @todo: increase mmap_end? 828 warn("mmap region limit exceeded with MREMAP_FIXED\n"); 829 } 830 warn("returning %08p as start\n", new_start); 831 return new_start; |
784 } 785 } 786 } else { | 832 } 833 } 834 } else { |
835 if (use_provided_address && provided_address != start) 836 process->pTable->remap(start, new_length, provided_address); |
|
787 process->pTable->unmap(start + new_length, old_length - new_length); | 837 process->pTable->unmap(start + new_length, old_length - new_length); |
788 return start; | 838 return use_provided_address ? provided_address : start; |
789 } 790} 791 792/// Target stat() handler. 793template <class OS> 794SyscallReturn 795statFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 796 ThreadContext *tc) --- 51 unchanged lines hidden (view full) --- 848 return -errno; 849 850 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf); 851 852 return 0; 853} 854 855 | 839 } 840} 841 842/// Target stat() handler. 843template <class OS> 844SyscallReturn 845statFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 846 ThreadContext *tc) --- 51 unchanged lines hidden (view full) --- 898 return -errno; 899 900 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf); 901 902 return 0; 903} 904 905 |
906/// Target fstatat64() handler. 907template <class OS> 908SyscallReturn 909fstatat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 910 ThreadContext *tc) 911{ 912 int index = 0; 913 int dirfd = process->getSyscallArg(tc, index); 914 if (dirfd != OS::TGT_AT_FDCWD) 915 warn("openat: first argument not AT_FDCWD; unlikely to work"); 916 917 std::string path; 918 if (!tc->getMemProxy().tryReadString(path, 919 process->getSyscallArg(tc, index))) 920 return -EFAULT; 921 Addr bufPtr = process->getSyscallArg(tc, index); 922 923 // Adjust path for current working directory 924 path = process->fullPath(path); 925 926#if NO_STAT64 927 struct stat hostBuf; 928 int result = stat(path.c_str(), &hostBuf); 929#else 930 struct stat64 hostBuf; 931 int result = stat64(path.c_str(), &hostBuf); 932#endif 933 934 if (result < 0) 935 return -errno; 936 937 copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf); 938 939 return 0; 940} 941 942 |
|
856/// Target fstat64() handler. 857template <class OS> 858SyscallReturn 859fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 860 ThreadContext *tc) 861{ 862 int index = 0; 863 int fd = process->getSyscallArg(tc, index); --- 489 unchanged lines hidden --- | 943/// Target fstat64() handler. 944template <class OS> 945SyscallReturn 946fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, 947 ThreadContext *tc) 948{ 949 int index = 0; 950 int fd = process->getSyscallArg(tc, index); --- 489 unchanged lines hidden --- |