diff options
Diffstat (limited to 'src/tests/filst/sc-bad-align.c')
| -rw-r--r-- | src/tests/filst/sc-bad-align.c | 45 |
1 files changed, 45 insertions, 0 deletions
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 <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 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."); +} |
