diff options
| author | Filip Strömbäck <filip.stromback@liu.se> | 2020-05-07 16:16:06 +0200 |
|---|---|---|
| committer | Filip Strömbäck <filip.stromback@liu.se> | 2020-05-07 16:16:06 +0200 |
| commit | d6d9677c93a6d5e710af704156f9a9dee3c66016 (patch) | |
| tree | 5b44ecc4223ccb84c8901a32b775470a26a82685 /src/tests/filst/sc-bad-exit.c | |
| parent | fa7324110fccec3c9c9ede4cf85b06e7bd0efe23 (diff) | |
| download | pintos-rs-d6d9677c93a6d5e710af704156f9a9dee3c66016.tar.gz | |
Added a few more parameter-validating tests.
Diffstat (limited to 'src/tests/filst/sc-bad-exit.c')
| -rw-r--r-- | src/tests/filst/sc-bad-exit.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/tests/filst/sc-bad-exit.c b/src/tests/filst/sc-bad-exit.c new file mode 100644 index 0000000..19945fc --- /dev/null +++ b/src/tests/filst/sc-bad-exit.c @@ -0,0 +1,47 @@ +#include <syscall-nr.h> +#include <stdio.h> +#include "tests/lib.h" +#include "tests/main.h" + +/** + * From threads/vaddr.h: + */ +#define BITMASK(SHIFT, CNT) (((1ul << (CNT)) - 1) << (SHIFT)) + +#define PGSHIFT 0 /* Index of first offset bit. */ +#define PGBITS 12 /* Number of offset bits. */ +#define PGSIZE (1 << PGBITS) /* Bytes in a page. */ +#define PGMASK BITMASK(PGSHIFT, PGBITS) /* Page offset bits (0:12). */ + +static inline void *pg_round_up (const void *va) { + return (void *) (((uintptr_t) va + PGSIZE - 1) & ~PGMASK); +} + +/** + * External symbol which address is the first address after all data in the BSS segment. + */ +extern int _end_bss; + +void test_main(void) +{ + // Get the address of the first unmapped page in the process. + unsigned page = (unsigned)pg_round_up(&_end_bss); + + // Reserve space for the syscall number and a part of the exit code (1 out of 4 bytes). + unsigned base = page - sizeof(int) - 1; + + // Call a syscall. + asm volatile ( + "movl %%esp, %%edi;" // Save the stack pointer in case we survive. + "movl %0, %%esp;" // Set stack pointer. + "movl %1, (%%esp);" // Try to call SYS_EXIT + "movb $1, 4(%%esp);" // Set the first byte of the syscall number to zero. + "int $0x30;" // Trigger syscall. + "movl %%edi, %%esp;" // Restore the old stack if we survivied. + : + : "r" (base), + "i" (SYS_EXIT) + : "%esp", "%eax", "%edi"); + + fail("should have died."); +} |
