diff options
Diffstat (limited to 'src/cmd/tests/kernel/misc.c')
-rw-r--r-- | src/cmd/tests/kernel/misc.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/cmd/tests/kernel/misc.c b/src/cmd/tests/kernel/misc.c new file mode 100644 index 0000000..5d6b531 --- /dev/null +++ b/src/cmd/tests/kernel/misc.c @@ -0,0 +1,66 @@ +#include "../tests.h" +#include <camellia/errno.h> +#include <camellia/flags.h> +#include <camellia/syscalls.h> +#include <string.h> +#include <unistd.h> + +static void test_fault_kill(void) { + if (!fork()) { /* invalid memory access */ + asm volatile("movb $69, 0" ::: "memory"); + test_fail(); + } + if (!fork()) { /* #GP */ + asm volatile("hlt" ::: "memory"); + test_fail(); + } + + int await_cnt = 0; + while (_sys_await() != ~0) await_cnt++; + test(await_cnt == 2); +} + +static void test_efault(void) { +#if 0 + const char *str = "o, 16 characters"; + char str2[16]; + char *invalid = (void*)0x1000; + hid_t h; + + memcpy(str2, str, 16); + + test((h = _sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE)) >= 0); + test(_sys_write(h, str, 16, 0, 0) == 16); + test(_sys_write(h, str2, 16, 0, 0) == 16); + + test(_sys_write(h, invalid, 16, 0, 0) == -EFAULT); + + /* x64 non-canonical pointers */ + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0, 0) == -EFAULT); + + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0, 0) == -EFAULT); + test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0, 0) == -EFAULT); + + test(_sys_write(h, str, 16, 0, 0) == 16); + close(h); +#endif +} + +static void test_invalid_syscall(void) { + test(_syscall(~0, 0, 0, 0, 0, 0) < 0); +} + +void r_k_misc(void) { + run_test(test_fault_kill); + run_test(test_efault); + run_test(test_invalid_syscall); +} |