summaryrefslogtreecommitdiff
path: root/src/user/tests/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/tests/main.c')
-rw-r--r--src/user/tests/main.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/user/tests/main.c b/src/user/tests/main.c
index b4587f9..ab6b4a8 100644
--- a/src/user/tests/main.c
+++ b/src/user/tests/main.c
@@ -189,13 +189,35 @@ static void test_malloc(void) {
}
static void test_efault(void) {
+ const char *str = "o, 16 characters";
+ char str2[16];
char *invalid = (void*)0x1000;
handle_t h;
+ memcpy(str2, str, 16);
+
assert((h = _syscall_open(tmpfilepath, strlen(tmpfilepath), OPEN_CREATE)));
- assert(_syscall_write(h, "dzwdz sucks ass!", 16, 0) == 16);
+ assert(_syscall_write(h, str, 16, 0) == 16);
+ assert(_syscall_write(h, str2, 16, 0) == 16);
+
assert(_syscall_write(h, invalid, 16, 0) == -EFAULT);
- assert(_syscall_write(h, "dzwdz is cool!!!", 16, 0) == 16);
+
+ /* x64 canonical pointers */
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0) == -EFAULT);
+
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0) == -EFAULT);
+
+ assert(_syscall_write(h, str, 16, 0) == 16);
close(h);
}