vm: fix a null dereference on out-of-memory

. also make other out-of-memory conditions less fatal
	. add a test case for a user program using all the memory
	  it can
	. remove some diagnostic prints for situations that are normal
	  when running out of memory so running the test isn't noisy
This commit is contained in:
Ben Gras
2012-11-09 16:50:31 +01:00
parent ff84d11216
commit b1da7fafd0
8 changed files with 65 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ OBJS.test57=test57loop.o
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
61 62
61 62 64
PROG+= test$(t)
.endfor

View File

@@ -14,7 +14,7 @@ badones= # list of tests that failed
tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
61 62 63 \
61 62 63 64 \
sh1.sh sh2.sh interp.sh"
tests_no=`expr 0`

48
test/test64.c Normal file
View File

@@ -0,0 +1,48 @@
/* Code to test reasonable response to out-of-memory condition
* of regular processes.
*/
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <sys/wait.h>
#define MAX_ERROR 2
#include "magic.h"
#include "common.c"
int main (int argc, char *argv[])
{
pid_t f;
start(64);
#define NADDRS 500
#define LEN 4096
static void *addrs[NADDRS];
int i = 0;
int st;
if((f=fork()) == -1) {
e(1);
exit(1);
}
if(f == 0) {
/* child: use up as much memory as we can */
while((addrs[i++ % NADDRS] = minix_mmap(0, LEN, PROT_READ|PROT_WRITE,
MAP_PREALLOC|MAP_CONTIG|MAP_ANON, -1, 0)) != MAP_FAILED)
;
exit(0);
}
/* parent: wait for child */
if(waitpid(f, &st, 0) < 0)
perror("waitpid");
quit();
return(0);
}