1*433d6423SLionel Sambuc 2*433d6423SLionel Sambuc /* Code to test reasonable response to out-of-memory condition 3*433d6423SLionel Sambuc * of regular processes. 4*433d6423SLionel Sambuc */ 5*433d6423SLionel Sambuc 6*433d6423SLionel Sambuc #include <stdlib.h> 7*433d6423SLionel Sambuc #include <stdio.h> 8*433d6423SLionel Sambuc #include <dlfcn.h> 9*433d6423SLionel Sambuc 10*433d6423SLionel Sambuc #include <sys/mman.h> 11*433d6423SLionel Sambuc #include <sys/wait.h> 12*433d6423SLionel Sambuc 13*433d6423SLionel Sambuc int max_error = 2; 14*433d6423SLionel Sambuc #include "common.h" 15*433d6423SLionel Sambuc 16*433d6423SLionel Sambuc 17*433d6423SLionel Sambuc #include "magic.h" 18*433d6423SLionel Sambuc main(int argc,char * argv[])19*433d6423SLionel Sambucint main (int argc, char *argv[]) 20*433d6423SLionel Sambuc { 21*433d6423SLionel Sambuc pid_t f; 22*433d6423SLionel Sambuc start(64); 23*433d6423SLionel Sambuc #define NADDRS 500 24*433d6423SLionel Sambuc #define LEN 4096 25*433d6423SLionel Sambuc static void *addrs[NADDRS]; 26*433d6423SLionel Sambuc int i = 0; 27*433d6423SLionel Sambuc int st; 28*433d6423SLionel Sambuc 29*433d6423SLionel Sambuc if((f=fork()) == -1) { 30*433d6423SLionel Sambuc e(1); 31*433d6423SLionel Sambuc exit(1); 32*433d6423SLionel Sambuc } 33*433d6423SLionel Sambuc 34*433d6423SLionel Sambuc if(f == 0) { 35*433d6423SLionel Sambuc /* child: use up as much memory as we can */ 36*433d6423SLionel Sambuc while((addrs[i++ % NADDRS] = mmap(0, LEN, PROT_READ|PROT_WRITE, 37*433d6423SLionel Sambuc MAP_PREALLOC|MAP_CONTIG|MAP_ANON, -1, 0)) != MAP_FAILED) 38*433d6423SLionel Sambuc ; 39*433d6423SLionel Sambuc exit(0); 40*433d6423SLionel Sambuc } 41*433d6423SLionel Sambuc 42*433d6423SLionel Sambuc /* parent: wait for child */ 43*433d6423SLionel Sambuc if(waitpid(f, &st, 0) < 0) 44*433d6423SLionel Sambuc perror("waitpid"); 45*433d6423SLionel Sambuc 46*433d6423SLionel Sambuc quit(); 47*433d6423SLionel Sambuc 48*433d6423SLionel Sambuc return(0); 49*433d6423SLionel Sambuc } 50