From 54178ad94d758e557bfa369b7f137e2844e030e1 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 23 Jul 2019 12:17:17 -0400 Subject: simplify kernel mapping calls --- user/usertests.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'user') diff --git a/user/usertests.c b/user/usertests.c index 98a5838..42065f4 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -1884,26 +1884,30 @@ rand() return randstate; } +// check that there's an invalid page beneath +// the user stack, to catch stack overflow. void stacktest() { int pid; + int ppid = getpid(); - printf(1, "stack test\n"); + printf(1, "stack guard test\n"); pid = fork(); if(pid == 0) { char *sp = (char *) r_sp(); - printf(1, "%p\n", sp); sp -= 4096; + // the *sp should cause a trap. printf(1, "stacktest: read below stack %p\n", *sp); printf(1, "stacktest: test FAILED\n"); + kill(ppid); exit(); } else if(pid < 0){ printf (1, "fork failed\n"); exit(); } wait(); - printf(1, "stack test done\n"); + printf(1, "stack guard test ok\n"); } int -- cgit v1.2.3