summaryrefslogtreecommitdiff
path: root/src/sim/syscall_emul.hh
diff options
context:
space:
mode:
authorSteve Reinhardt <steve.reinhardt@amd.com>2011-05-23 14:29:23 -0700
committerSteve Reinhardt <steve.reinhardt@amd.com>2011-05-23 14:29:23 -0700
commit8d29bda74211f4ff1804aeeb05b2795b549036f7 (patch)
treeddf4ed45b6f56efab93e27812f1fca0eb3cbfece /src/sim/syscall_emul.hh
parent19bb896bfeffc0b49197f5b2d8395a6ee4c5e94d (diff)
downloadgem5-8d29bda74211f4ff1804aeeb05b2795b549036f7.tar.xz
syscall emul: fix Power Linux mmap constant, plus other cleanup
We were getting a spurious warning in the regressions that turned out to be due to having the wrong value for TGT_MAP_ANONYMOUS for Power Linux, but in the process of tracking it down I ended up doing some cleanup of the mmap handling in general.
Diffstat (limited to 'src/sim/syscall_emul.hh')
-rw-r--r--src/sim/syscall_emul.hh31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index e685a0f30..d119adc24 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -989,13 +989,8 @@ writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
/// We don't really handle mmap(). If the target is mmaping an
/// anonymous region or /dev/zero, we can get away with doing basically
/// nothing (since memory is initialized to zero and the simulator
-/// doesn't really check addresses anyway). Always print a warning,
-/// since this could be seriously broken if we're not mapping
-/// /dev/zero.
-//
-/// Someday we should explicitly check for /dev/zero in open, flag the
-/// file descriptor, and fail (or implement!) a non-anonymous mmap to
-/// anything else.
+/// doesn't really check addresses anyway).
+///
template <class OS>
SyscallReturn
mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
@@ -1005,9 +1000,24 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
uint64_t length = p->getSyscallArg(tc, index);
index++; // int prot = p->getSyscallArg(tc, index);
int flags = p->getSyscallArg(tc, index);
- int fd = p->sim_fd(p->getSyscallArg(tc, index));
+ int tgt_fd = p->getSyscallArg(tc, index);
// int offset = p->getSyscallArg(tc, index);
+ if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
+ Process::FdMap *fd_map = p->sim_fd_obj(tgt_fd);
+ if (!fd_map || fd_map->fd < 0) {
+ warn("mmap failing: target fd %d is not valid\n", tgt_fd);
+ return -EBADF;
+ }
+
+ if (fd_map->filename != "/dev/zero") {
+ // This is very likely broken, but leave a warning here
+ // (rather than panic) in case /dev/zero is known by
+ // another name on some platform
+ warn("allowing mmap of file %s; mmap not supported on files"
+ " other than /dev/zero\n", fd_map->filename);
+ }
+ }
if ((start % TheISA::VMPageSize) != 0 ||
(length % TheISA::VMPageSize) != 0) {
@@ -1032,11 +1042,6 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
}
p->pTable->allocate(start, length);
- if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
- warn("allowing mmap of file @ fd %d. "
- "This will break if not /dev/zero.", fd);
- }
-
return start;
}