Threads have isolated memory spaces

This commit is contained in:
2018-02-20 20:38:32 +01:00
parent 2d0f539e23
commit 6523b10984
3 changed files with 17 additions and 9 deletions

View File

@@ -8,14 +8,14 @@
#include <thread.h>
#include <scheduler.h>
int thread_id;
int *thread_id = (int *)0x20000;
void thread_function()
{
thread_id = thread()->tid;
*thread_id = thread()->tid;
while(1)
{
debug("Thread %d\n", thread_id);
debug("Thread %d\n", *thread_id);
yield();
}
}
@@ -35,15 +35,19 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data)
cpu_init();
uintptr_t P4 = new_P4();
write_cr3(P4);
struct thread *th1 = new_thread(thread_function);
vmm_set_page(th1->P4, 0x20000, pmm_alloc(), PAGE_WRITE | PAGE_PRESENT);
struct thread *th2 = new_thread(thread_function);
vmm_set_page(th2->P4, 0x20000, pmm_alloc(), PAGE_WRITE | PAGE_PRESENT);
struct thread *th3 = new_thread(thread_function);
vmm_set_page(th3->P4, 0x20000, pmm_alloc(), PAGE_WRITE | PAGE_PRESENT);
ready(th1);
ready(th2);
ready(th3);
debug_ok("Boot \"Complete\"\n");
ready(new_thread(thread_function));
ready(new_thread(thread_function));
ready(new_thread(thread_function));
start_scheduler();
PANIC("Reached end of kernel main function\n");