Test whether writing below stack fails
This commit is contained in:
		
							parent
							
								
									b2e9c8eea5
								
							
						
					
					
						commit
						62091abae9
					
				
					 1 changed files with 25 additions and 1 deletions
				
			
		| 
						 | 
					@ -6,6 +6,7 @@
 | 
				
			||||||
#include "kernel/fcntl.h"
 | 
					#include "kernel/fcntl.h"
 | 
				
			||||||
#include "kernel/syscall.h"
 | 
					#include "kernel/syscall.h"
 | 
				
			||||||
#include "kernel/memlayout.h"
 | 
					#include "kernel/memlayout.h"
 | 
				
			||||||
 | 
					#include "kernel/riscv.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char buf[8192];
 | 
					char buf[8192];
 | 
				
			||||||
char name[3];
 | 
					char name[3];
 | 
				
			||||||
| 
						 | 
					@ -1883,6 +1884,28 @@ rand()
 | 
				
			||||||
  return randstate;
 | 
					  return randstate;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					stacktest()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int pid;
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  printf(1, "stack test\n");
 | 
				
			||||||
 | 
					  pid = fork();
 | 
				
			||||||
 | 
					  if(pid == 0) {
 | 
				
			||||||
 | 
					    char *sp = (char *) r_sp();
 | 
				
			||||||
 | 
					    printf(1, "%p\n", sp);
 | 
				
			||||||
 | 
					    sp -= 4096;
 | 
				
			||||||
 | 
					    printf(1, "stacktest: read below stack %p\n", *sp);
 | 
				
			||||||
 | 
					    printf(1, "stacktest: test FAILED\n");
 | 
				
			||||||
 | 
					    exit();
 | 
				
			||||||
 | 
					  } else if(pid < 0){
 | 
				
			||||||
 | 
					    printf (1, "fork failed\n");
 | 
				
			||||||
 | 
					    exit();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  wait();
 | 
				
			||||||
 | 
					  printf(1, "stack test done\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main(int argc, char *argv[])
 | 
					main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -1912,7 +1935,8 @@ main(int argc, char *argv[])
 | 
				
			||||||
  bsstest();
 | 
					  bsstest();
 | 
				
			||||||
  sbrktest();
 | 
					  sbrktest();
 | 
				
			||||||
  validatetest();
 | 
					  validatetest();
 | 
				
			||||||
 | 
					  stacktest();
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  opentest();
 | 
					  opentest();
 | 
				
			||||||
  writetest();
 | 
					  writetest();
 | 
				
			||||||
  writetest1();
 | 
					  writetest1();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue