syscall_emul.hh (8232:b28d06a175be) | syscall_emul.hh (8324:aa7a67647c7b) |
---|---|
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; --- 975 unchanged lines hidden (view full) --- 984} 985 986 987/// Target mmap() handler. 988/// 989/// We don't really handle mmap(). If the target is mmaping an 990/// anonymous region or /dev/zero, we can get away with doing basically 991/// nothing (since memory is initialized to zero and the simulator | 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; --- 975 unchanged lines hidden (view full) --- 984} 985 986 987/// Target mmap() handler. 988/// 989/// We don't really handle mmap(). If the target is mmaping an 990/// anonymous region or /dev/zero, we can get away with doing basically 991/// nothing (since memory is initialized to zero and the simulator |
992/// doesn't really check addresses anyway). Always print a warning, 993/// since this could be seriously broken if we're not mapping 994/// /dev/zero. 995// 996/// Someday we should explicitly check for /dev/zero in open, flag the 997/// file descriptor, and fail (or implement!) a non-anonymous mmap to 998/// anything else. | 992/// doesn't really check addresses anyway). 993/// |
999template <class OS> 1000SyscallReturn 1001mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 1002{ 1003 int index = 0; 1004 Addr start = p->getSyscallArg(tc, index); 1005 uint64_t length = p->getSyscallArg(tc, index); 1006 index++; // int prot = p->getSyscallArg(tc, index); 1007 int flags = p->getSyscallArg(tc, index); | 994template <class OS> 995SyscallReturn 996mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) 997{ 998 int index = 0; 999 Addr start = p->getSyscallArg(tc, index); 1000 uint64_t length = p->getSyscallArg(tc, index); 1001 index++; // int prot = p->getSyscallArg(tc, index); 1002 int flags = p->getSyscallArg(tc, index); |
1008 int fd = p->sim_fd(p->getSyscallArg(tc, index)); | 1003 int tgt_fd = p->getSyscallArg(tc, index); |
1009 // int offset = p->getSyscallArg(tc, index); 1010 | 1004 // int offset = p->getSyscallArg(tc, index); 1005 |
1006 if (!(flags & OS::TGT_MAP_ANONYMOUS)) { 1007 Process::FdMap *fd_map = p->sim_fd_obj(tgt_fd); 1008 if (!fd_map || fd_map->fd < 0) { 1009 warn("mmap failing: target fd %d is not valid\n", tgt_fd); 1010 return -EBADF; 1011 } |
|
1011 | 1012 |
1013 if (fd_map->filename != "/dev/zero") { 1014 // This is very likely broken, but leave a warning here 1015 // (rather than panic) in case /dev/zero is known by 1016 // another name on some platform 1017 warn("allowing mmap of file %s; mmap not supported on files" 1018 " other than /dev/zero\n", fd_map->filename); 1019 } 1020 } 1021 |
|
1012 if ((start % TheISA::VMPageSize) != 0 || 1013 (length % TheISA::VMPageSize) != 0) { 1014 warn("mmap failing: arguments not page-aligned: " 1015 "start 0x%x length 0x%x", 1016 start, length); 1017 return -EINVAL; 1018 } 1019 --- 7 unchanged lines hidden (view full) --- 1027 start = p->mmap_end - length; 1028 p->mmap_end = start; 1029 } else { 1030 start = p->mmap_end; 1031 p->mmap_end += length; 1032 } 1033 p->pTable->allocate(start, length); 1034 | 1022 if ((start % TheISA::VMPageSize) != 0 || 1023 (length % TheISA::VMPageSize) != 0) { 1024 warn("mmap failing: arguments not page-aligned: " 1025 "start 0x%x length 0x%x", 1026 start, length); 1027 return -EINVAL; 1028 } 1029 --- 7 unchanged lines hidden (view full) --- 1037 start = p->mmap_end - length; 1038 p->mmap_end = start; 1039 } else { 1040 start = p->mmap_end; 1041 p->mmap_end += length; 1042 } 1043 p->pTable->allocate(start, length); 1044 |
1035 if (!(flags & OS::TGT_MAP_ANONYMOUS)) { 1036 warn("allowing mmap of file @ fd %d. " 1037 "This will break if not /dev/zero.", fd); 1038 } 1039 | |
1040 return start; 1041} 1042 1043/// Target getrlimit() handler. 1044template <class OS> 1045SyscallReturn 1046getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1047 ThreadContext *tc) --- 187 unchanged lines hidden --- | 1045 return start; 1046} 1047 1048/// Target getrlimit() handler. 1049template <class OS> 1050SyscallReturn 1051getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 1052 ThreadContext *tc) --- 187 unchanged lines hidden --- |