aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tests/filst/Make.tests2
-rw-r--r--src/tests/filst/sc-bad-align.c45
-rw-r--r--src/tests/filst/sc-bad-align.ck9
-rw-r--r--src/tests/filst/sc-bad-exit.c47
-rw-r--r--src/tests/filst/sc-bad-exit.ck9
-rw-r--r--src/tests/filst/sc-bad-write.c4
6 files changed, 113 insertions, 3 deletions
diff --git a/src/tests/filst/Make.tests b/src/tests/filst/Make.tests
index dfd179f..c9ad119 100644
--- a/src/tests/filst/Make.tests
+++ b/src/tests/filst/Make.tests
@@ -3,7 +3,7 @@
tests/%.output: FSDISK = 2
tests/%.output: PUTFILES = $(filter-out os.dsk, $^)
-tests/filst_TESTS = $(addprefix tests/filst/,sc-bad-write sc-bad-close sc-bad-nr-1 sc-bad-nr-2 sc-bad-nr-3)
+tests/filst_TESTS = $(addprefix tests/filst/,sc-bad-write sc-bad-close sc-bad-nr-1 sc-bad-nr-2 sc-bad-nr-3 sc-bad-align sc-bad-exit)
tests/filst_PROGS = $(tests/filst_TESTS)
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.");
+}
diff --git a/src/tests/filst/sc-bad-align.ck b/src/tests/filst/sc-bad-align.ck
new file mode 100644
index 0000000..aeb7020
--- /dev/null
+++ b/src/tests/filst/sc-bad-align.ck
@@ -0,0 +1,9 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected ([<<'EOF']);
+(sc-bad-align) begin
+sc-bad-align: exit(-1)
+EOF
+pass;
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.");
+}
diff --git a/src/tests/filst/sc-bad-exit.ck b/src/tests/filst/sc-bad-exit.ck
new file mode 100644
index 0000000..1e6fa95
--- /dev/null
+++ b/src/tests/filst/sc-bad-exit.ck
@@ -0,0 +1,9 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected ([<<'EOF']);
+(sc-bad-exit) begin
+sc-bad-exit: exit(-1)
+EOF
+pass;
diff --git a/src/tests/filst/sc-bad-write.c b/src/tests/filst/sc-bad-write.c
index 18e8f4d..c6f23f7 100644
--- a/src/tests/filst/sc-bad-write.c
+++ b/src/tests/filst/sc-bad-write.c
@@ -31,7 +31,7 @@ const char *FAIL = "FAIL\n";
void test_main(void)
{
- // Get the addres of the first unmapped page in the system.
+ // Get the address of the first unmapped page in the process.
unsigned page = (unsigned)pg_round_up(&_end_bss);
// Reserve space for 4 parameters.
@@ -44,7 +44,7 @@ void test_main(void)
"movl %1, (%%esp);" // Try to call SYS_WRITE
"movl %2, 4(%%esp);" // Write to STDOUT
"movl %3, 8(%%esp);" // Load buffer.
- "movl $6, 12(%%esp);" // Write length of string
+ "movl $6, 12(%%esp);" // Write length of string
"int $0x30;"
"movl %%edi, %%esp;" // Restore esp.
: