summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorSteve Reinhardt <Steve.Reinhardt@amd.com>2008-11-15 09:30:10 -0800
committerSteve Reinhardt <Steve.Reinhardt@amd.com>2008-11-15 09:30:10 -0800
commit4514f565e3dfe1de41bbaec05f3f0074e5299bac (patch)
treee70dc0c3c09f7b035a7c33c69b98562a6c198a23 /src/sim
parentba8936120e4de7a4cdf6093a0e0cb04e0d1b8a59 (diff)
downloadgem5-4514f565e3dfe1de41bbaec05f3f0074e5299bac.tar.xz
syscalls: fix latent brk/obreak bug.
Bogus calls to ChunkGenerator with negative size were triggering a new assertion that was added there. Also did a little renaming and cleanup in the process.
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/syscall_emul.cc18
-rw-r--r--src/sim/syscall_emul.hh6
2 files changed, 15 insertions, 9 deletions
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index e0e703815..fb6af0b0c 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -107,21 +107,27 @@ getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
-obreakFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
- Addr junk;
-
// change brk addr to first arg
Addr new_brk = tc->getSyscallArg(0);
- if (new_brk != 0) {
+
+ // in Linux at least, brk(0) returns the current break value
+ // (note that the syscall and the glibc function have different behavior)
+ if (new_brk == 0)
+ return p->brk_point;
+
+ if (new_brk > p->brk_point) {
+ // might need to allocate some new pages
for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
VMPageSize); !gen.done(); gen.next()) {
- if (!p->pTable->translate(gen.addr(), junk))
+ if (!p->pTable->translate(gen.addr()))
p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
VMPageSize);
}
- p->brk_point = new_brk;
}
+
+ p->brk_point = new_brk;
DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point);
return p->brk_point;
}
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 2e8071196..57403ab27 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -191,9 +191,9 @@ SyscallReturn exitFunc(SyscallDesc *desc, int num,
SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num,
LiveProcess *p, ThreadContext *tc);
-/// Target obreak() handler: set brk address.
-SyscallReturn obreakFunc(SyscallDesc *desc, int num,
- LiveProcess *p, ThreadContext *tc);
+/// Target brk() handler: set brk address.
+SyscallReturn brkFunc(SyscallDesc *desc, int num,
+ LiveProcess *p, ThreadContext *tc);
/// Target close() handler.
SyscallReturn closeFunc(SyscallDesc *desc, int num,