syscall_emul.hh (8766:b0773af78423) syscall_emul.hh (8795:0909f8ed7aa0)
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;

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

673 (new_length % TheISA::VMPageSize != 0)) {
674 warn("mremap failing: arguments not page aligned");
675 return -EINVAL;
676 }
677
678 if (new_length > old_length) {
679 if ((start + old_length) == process->mmap_end) {
680 uint64_t diff = new_length - old_length;
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;

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

673 (new_length % TheISA::VMPageSize != 0)) {
674 warn("mremap failing: arguments not page aligned");
675 return -EINVAL;
676 }
677
678 if (new_length > old_length) {
679 if ((start + old_length) == process->mmap_end) {
680 uint64_t diff = new_length - old_length;
681 process->pTable->allocate(process->mmap_end, diff);
681 process->allocateMem(process->mmap_end, diff);
682 process->mmap_end += diff;
683 return start;
684 } else {
685 // sys/mman.h defined MREMAP_MAYMOVE
686 if (!(flags & 1)) {
687 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
688 return -ENOMEM;
689 } else {
690 process->pTable->remap(start, old_length, process->mmap_end);
691 warn("mremapping to totally new vaddr %08p-%08p, adding %d\n",
692 process->mmap_end, process->mmap_end + new_length, new_length);
693 start = process->mmap_end;
694 // add on the remaining unallocated pages
682 process->mmap_end += diff;
683 return start;
684 } else {
685 // sys/mman.h defined MREMAP_MAYMOVE
686 if (!(flags & 1)) {
687 warn("can't remap here and MREMAP_MAYMOVE flag not set\n");
688 return -ENOMEM;
689 } else {
690 process->pTable->remap(start, old_length, process->mmap_end);
691 warn("mremapping to totally new vaddr %08p-%08p, adding %d\n",
692 process->mmap_end, process->mmap_end + new_length, new_length);
693 start = process->mmap_end;
694 // add on the remaining unallocated pages
695 process->pTable->allocate(start + old_length, new_length - old_length);
695 process->allocateMem(start + old_length,
696 new_length - old_length);
696 process->mmap_end += new_length;
697 warn("returning %08p as start\n", start);
698 return start;
699 }
700 }
701 } else {
697 process->mmap_end += new_length;
698 warn("returning %08p as start\n", start);
699 return start;
700 }
701 }
702 } else {
702 process->pTable->deallocate(start + new_length, old_length -
703 new_length);
703 process->pTable->unmap(start + new_length, old_length - new_length);
704 return start;
705 }
706}
707
708/// Target stat() handler.
709template <class OS>
710SyscallReturn
711statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,

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

1023 if ((start % TheISA::VMPageSize) != 0 ||
1024 (length % TheISA::VMPageSize) != 0) {
1025 warn("mmap failing: arguments not page-aligned: "
1026 "start 0x%x length 0x%x",
1027 start, length);
1028 return -EINVAL;
1029 }
1030
704 return start;
705 }
706}
707
708/// Target stat() handler.
709template <class OS>
710SyscallReturn
711statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,

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

1023 if ((start % TheISA::VMPageSize) != 0 ||
1024 (length % TheISA::VMPageSize) != 0) {
1025 warn("mmap failing: arguments not page-aligned: "
1026 "start 0x%x length 0x%x",
1027 start, length);
1028 return -EINVAL;
1029 }
1030
1031 if (start != 0) {
1032 warn("mmap: ignoring suggested map address 0x%x, using 0x%x",
1033 start, p->mmap_end);
1031 // are we ok with clobbering existing mappings? only set this to
1032 // true if the user has been warned.
1033 bool clobber = false;
1034
1035 // try to use the caller-provided address if there is one
1036 bool use_provided_address = (start != 0);
1037
1038 if (use_provided_address) {
1039 // check to see if the desired address is already in use
1040 if (!p->pTable->isUnmapped(start, length)) {
1041 // there are existing mappings in the desired range
1042 // whether we clobber them or not depends on whether the caller
1043 // specified MAP_FIXED
1044 if (flags & OS::TGT_MAP_FIXED) {
1045 // MAP_FIXED specified: clobber existing mappings
1046 warn("mmap: MAP_FIXED at 0x%x overwrites existing mappings\n",
1047 start);
1048 clobber = true;
1049 } else {
1050 // MAP_FIXED not specified: ignore suggested start address
1051 warn("mmap: ignoring suggested map address 0x%x\n", start);
1052 use_provided_address = false;
1053 }
1054 }
1034 }
1035
1055 }
1056
1036 // pick next address from our "mmap region"
1037 if (OS::mmapGrowsDown()) {
1038 start = p->mmap_end - length;
1039 p->mmap_end = start;
1040 } else {
1041 start = p->mmap_end;
1042 p->mmap_end += length;
1057 if (!use_provided_address) {
1058 // no address provided, or provided address unusable:
1059 // pick next address from our "mmap region"
1060 if (OS::mmapGrowsDown()) {
1061 start = p->mmap_end - length;
1062 p->mmap_end = start;
1063 } else {
1064 start = p->mmap_end;
1065 p->mmap_end += length;
1066 }
1043 }
1067 }
1044 p->pTable->allocate(start, length);
1045
1068
1069 p->allocateMem(start, length, clobber);
1070
1046 return start;
1047}
1048
1049/// Target getrlimit() handler.
1050template <class OS>
1051SyscallReturn
1052getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1053 ThreadContext *tc)

--- 187 unchanged lines hidden ---
1071 return start;
1072}
1073
1074/// Target getrlimit() handler.
1075template <class OS>
1076SyscallReturn
1077getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
1078 ThreadContext *tc)

--- 187 unchanged lines hidden ---