diff options
author | Austin Clements <[email protected]> | 2010-08-31 21:49:49 -0400 |
---|---|---|
committer | Austin Clements <[email protected]> | 2010-08-31 21:49:49 -0400 |
commit | dd645ef11911596d73d128c1da53579678c56aee (patch) | |
tree | 1a2f65aa805829a21c8d65460180a14c385ac005 /usertests.c | |
parent | 5048762c7e27789a014cc1e74e1002e749c924ce (diff) | |
download | xv6-labs-dd645ef11911596d73d128c1da53579678c56aee.tar.gz xv6-labs-dd645ef11911596d73d128c1da53579678c56aee.tar.bz2 xv6-labs-dd645ef11911596d73d128c1da53579678c56aee.zip |
Cleanup if allocuvm fails to alloc. Add a test.
Diffstat (limited to 'usertests.c')
-rw-r--r-- | usertests.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/usertests.c b/usertests.c index 670a4a8..7ec03fc 100644 --- a/usertests.c +++ b/usertests.c @@ -324,6 +324,7 @@ mem(void) void *m1, *m2; int pid, ppid; + printf(1, "mem test\n"); ppid = getpid(); if((pid = fork()) == 0){ m1 = 0; @@ -1332,6 +1333,41 @@ sbrktest(void) wait(); } + // if we run the system out of memory, does it clean up the last + // failed allocation? + sbrk(-(sbrk(0) - oldbrk)); + int pids[32]; + int fds[2]; + if(pipe(fds) != 0){ + printf(1, "pipe() failed\n"); + exit(); + } + for (i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){ + if ((pids[i] = fork()) == 0) { + // allocate the full 640K + sbrk((640 * 1024) - (uint)sbrk(0)); + write(fds[1], "x", 1); + // sit around until killed + while (1) sleep(1000); + } + char scratch; + if (pids[i] != -1) + read(fds[0], &scratch, 1); + } + // if those failed allocations freed up the pages they did allocate, + // we'll be able to allocate here + c = sbrk(4096); + for (i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){ + if (pids[i] == -1) + continue; + kill(pids[i]); + wait(); + } + if (c == (char*)0xffffffff) { + printf(stdout, "failed sbrk leaked memory\n"); + exit(); + } + if(sbrk(0) > oldbrk) sbrk(-(sbrk(0) - oldbrk)); |