944d6c3249fec52f4906304488d83f49f714cbf2
[tpg/acess2.git] / Usermode / Applications / bomb_src / main.c
1 /*
2  * Acess2 Stress Tester
3  */
4 #include <acess/sys.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7
8  //int  giMallocSize = 1024;
9  int    gbOverrideCOW = 0;
10  int    gbForkBomb = 0;
11
12 /**
13  * \fn int main(int argc, char *argv[])
14  * \brief Entrypoint
15  */
16 int main(int argc, char *argv[])
17 {
18          int    i;
19         
20         for( i = 1; i < argc; i ++ )
21         {
22                 if( argv[i][0] != '-' ) {
23                         //PrintUsage(argv[0]);
24                         return 1;
25                 }
26                 
27                 switch( argv[i][1] )
28                 {
29                 case 'f':
30                         gbForkBomb = 1;
31                         break;
32                 case 'c':
33                         gbOverrideCOW = 1;
34                         break;
35                 //case 'm':
36                 //      giMallocSize = atoi(argv[++i]);
37                 //      break;
38                 case 'h':
39                         //PrintHelp(argv[0]);
40                         return 0;
41                 }
42         }
43
44         if( gbForkBomb )
45         {
46                 for(;;) clone(CLONE_VM, 0);
47         }
48         else {
49                 for(;;)
50                 {
51                         const int stackSize = 512-16; 
52                         const int stackOffset = 65; 
53                         char *stack = calloc(1, stackSize);
54                          int    tid;
55                         if( !stack ) {
56                                 printf("Outta heap space!\n");
57                                 return 0;
58                         }
59                         tid = clone(0, stack+stackSize-stackOffset);
60                         if( tid == 0 )
61                         {
62                                 // Sleep forever (TODO: Fix up the stack so it can nuke)
63                                 for(;;) sleep();
64                         }
65                         if( tid < 0 ) {
66                                 printf("Clone failed\n");
67                                 return 0;
68                         }
69                         printf("stack = %p, tid = %i\n", stack, tid);
70                 }
71         }
72
73         printf("RETURN!?\n");
74         return 0;
75 }

UCC git Repository :: git.ucc.asn.au