diff options
author | dzwdz | 2022-05-21 18:26:54 +0200 |
---|---|---|
committer | dzwdz | 2022-05-21 18:26:54 +0200 |
commit | 0fd9c19c5d66a380ad4b2b881881ce7fba9a6d27 (patch) | |
tree | 369757199f469b390f89d20abd293d6a96fd8719 /src/init/tests | |
parent | 6ed683618151359159e10dff872eee50005eb015 (diff) |
syscall/memflag: implement freeing memory
Diffstat (limited to 'src/init/tests')
-rw-r--r-- | src/init/tests/main.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/init/tests/main.c b/src/init/tests/main.c index 182c545..20923b0 100644 --- a/src/init/tests/main.c +++ b/src/init/tests/main.c @@ -1,5 +1,6 @@ #include <init/stdlib.h> #include <init/tests/main.h> +#include <shared/flags.h> #include <shared/syscalls.h> #define argify(str) str, sizeof(str) - 1 @@ -91,6 +92,23 @@ static void test_orphaned_fs(void) { } } +static void test_memflag(void) { + void *page = (void*)0x77777000; + _syscall_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page + memset(page, 77, 4096); // write to it + _syscall_memflag(page, 4096, 0); // free it + + if (!_syscall_fork(0, NULL)) { + memset(page, 11, 4096); // should segfault + _syscall_exit(0); + } else { + assert(_syscall_await() != 0); // test if the process crashed + } + + _syscall_memflag((void*)0x100000, 4096, 0); // try to free kernel memory + // TODO the kernel shouldn't even be mapped in userland +} + static void stress_fork(void) { /* run a lot of processes */ for (size_t i = 0; i < 2048; i++) { @@ -105,5 +123,6 @@ void test_all(void) { run_forked(test_faults); run_forked(test_interrupted_fs); run_forked(test_orphaned_fs); + run_forked(test_memflag); run_forked(stress_fork); } |