From d6d9677c93a6d5e710af704156f9a9dee3c66016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Str=C3=B6mb=C3=A4ck?= Date: Thu, 7 May 2020 16:16:06 +0200 Subject: Added a few more parameter-validating tests. --- src/tests/filst/sc-bad-align.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/tests/filst/sc-bad-align.c (limited to 'src/tests/filst/sc-bad-align.c') diff --git a/src/tests/filst/sc-bad-align.c b/src/tests/filst/sc-bad-align.c new file mode 100644 index 0000000..51b0065 --- /dev/null +++ b/src/tests/filst/sc-bad-align.c @@ -0,0 +1,45 @@ +#include +#include +#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 a part of the syscall number (1 out of 4 bytes). + unsigned base = page - 1; + + // Call a syscall. + asm volatile ( + "movl %%esp, %%edi;" // Save the stack pointer in case we survive. + "movl %0, %%esp;" // Set stack pointer. + "movb $0, (%%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) + : "%esp", "%eax", "%edi"); + + fail("should have died."); +} -- cgit v1.2.1