summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-08-19 13:10:14 -0400
committerFrans Kaashoek <[email protected]>2020-08-21 11:00:45 -0400
commit2a4a8764a52cccc128aa1a6d7b321bafc14b48e6 (patch)
tree7506496d44b1da45dec810160405581244b9b09e /user
parent5860dcd07d9a9cba5c7ebf7488636d131015316d (diff)
downloadxv6-labs-2a4a8764a52cccc128aa1a6d7b321bafc14b48e6.tar.gz
xv6-labs-2a4a8764a52cccc128aa1a6d7b321bafc14b48e6.tar.bz2
xv6-labs-2a4a8764a52cccc128aa1a6d7b321bafc14b48e6.zip
touch sbrk()-allocated memory to make sure it exists
Diffstat (limited to 'user')
-rw-r--r--user/usertests.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/user/usertests.c b/user/usertests.c
index acdba0f..502621a 100644
--- a/user/usertests.c
+++ b/user/usertests.c
@@ -2006,6 +2006,12 @@ sbrkmuch(char *s)
printf("%s: sbrk test failed to grow big address space; enough phys mem?\n", s);
exit(1);
}
+
+ // touch each page to make sure it exists.
+ char *eee = sbrk(0);
+ for(char *pp = a; pp < eee; pp += 4096)
+ *pp = 1;
+
lastaddr = (char*) (BIG-1);
*lastaddr = 99;
@@ -2087,7 +2093,12 @@ sbrkfail(char *s)
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
if((pids[i] = fork()) == 0){
// allocate a lot of memory
- sbrk(BIG - (uint64)sbrk(0));
+ char *p0 = sbrk(BIG - (uint64)sbrk(0));
+ if((uint64)p0 != 0xffffffffffffffffLL){
+ char *p1 = sbrk(0);
+ for(char *p2 = p0; p2 < p1; p2 += 4096)
+ *p2 = 1;
+ }
write(fds[1], "x", 1);
// sit around until killed
for(;;) sleep(1000);
@@ -2469,6 +2480,7 @@ execout(char *s)
uint64 a = (uint64) sbrk(4096);
if(a == 0xffffffffffffffffLL)
break;
+ *(char*)(a + 4096 - 1) = 1;
}
// free a few pages, in order to let exec() make some
@@ -2503,7 +2515,7 @@ countfree()
break;
}
// modify the memory to make sure it's really allocated.
- *(char *)(a - 1) = 1;
+ *(char *)(a + 4096 - 1) = 1;
n += 1;
}
sbrk(-((uint64)sbrk(0) - sz0));