Test whether writing below stack fails

This commit is contained in:
Frans Kaashoek 2019-07-22 18:08:52 -04:00
parent b2e9c8eea5
commit 62091abae9

View file

@ -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,6 +1935,7 @@ main(int argc, char *argv[])
bsstest(); bsstest();
sbrktest(); sbrktest();
validatetest(); validatetest();
stacktest();
opentest(); opentest();
writetest(); writetest();