From 62091abae9613f9b6ac971b72411e5ee722cc530 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Mon, 22 Jul 2019 18:08:52 -0400 Subject: [PATCH] Test whether writing below stack fails --- user/usertests.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/user/usertests.c b/user/usertests.c index 5cc5099..98a5838 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -6,6 +6,7 @@ #include "kernel/fcntl.h" #include "kernel/syscall.h" #include "kernel/memlayout.h" +#include "kernel/riscv.h" char buf[8192]; char name[3]; @@ -1883,6 +1884,28 @@ rand() 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 main(int argc, char *argv[]) { @@ -1912,7 +1935,8 @@ main(int argc, char *argv[]) bsstest(); sbrktest(); validatetest(); - + stacktest(); + opentest(); writetest(); writetest1();