From d4522b8e9854178473adcea0fbb84f23f6e744bd Mon Sep 17 00:00:00 2001 From: Felipe Boeira Date: Tue, 8 Jan 2019 18:39:03 +0100 Subject: Initial commit --- src/examples/create-bad.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/examples/create-bad.c (limited to 'src/examples/create-bad.c') diff --git a/src/examples/create-bad.c b/src/examples/create-bad.c new file mode 100644 index 0000000..4a9688a --- /dev/null +++ b/src/examples/create-bad.c @@ -0,0 +1,32 @@ +/* The following program should be killed by the kernel because the + string sent with create starts at one page (the BSS page) and ends + outside of it in a page that is not allocated. + + If user memory accesses are not handled correctly by the kernel, + then pintos will crash with a page fault exception. + + Author: Mattias Eriksson +*/ + +#include +#include +#include + +#define PGS 4096 /* page size */ +#define PMASK 0xfffff000 + +static char inbss; + +int +main (void) +{ + char * bss_page = (char*) ((int)(&inbss) & PMASK); + printf("inbss and bss_page: %p, %p\n", &inbss, bss_page); + printf("This program should be killed by the kernel.\n"); + + memset ( bss_page, 'a', PGS ); + create (bss_page+PGS-5, 1024); + printf("ERROR: this point should not be reached\n"); + + exit(0); +} -- cgit v1.2.1