diff --git a/src/multitasking/process.c b/src/multitasking/process.c index 32fd3a5..817103b 100644 --- a/src/multitasking/process.c +++ b/src/multitasking/process.c @@ -24,8 +24,9 @@ struct pcb *create_process(uid_t uid) } new_pcb->cr3 = (void *)((uint32_t)VA2PTE((uint32_t)new_pcb->heap) & PAGE_MASK); - memcpy(new_pcb->heap, PD, 4096); - new_pcb->heap[1023] = (uint32_t) new_pcb->cr3 | INIT_FLAGS; + memcpy(new_pcb->heap, PD, + 4096); // TODO optimize to copy only used bytes + new_pcb->heap[1023] = (uint32_t)new_pcb->cr3 | INIT_FLAGS; new_pcb->daddy = NULL; new_pcb->children = NULL; diff --git a/src/multitasking/scheduler.c b/src/multitasking/scheduler.c index d36c189..cec7a18 100644 --- a/src/multitasking/scheduler.c +++ b/src/multitasking/scheduler.c @@ -20,7 +20,8 @@ static struct list *get_thread_to_switch(void) it_t = current_tcb == NULL ? NULL : current_tcb->next; while (it_p) { while (it_t != NULL) { - if (it_t != NULL && ((struct tcb*)it_t->content)->state != WAITING) + if (it_t != NULL && + ((struct tcb *)it_t->content)->state != WAITING) return it_t; it_t = it_t->next; } diff --git a/src/multitasking/thread.c b/src/multitasking/thread.c index 123ebc9..6647cec 100644 --- a/src/multitasking/thread.c +++ b/src/multitasking/thread.c @@ -16,11 +16,15 @@ struct tcb *create_thread(struct pcb *process, void (*entry)(void)) return NULL; new_tcb->tid = process->tid++; + memcpy(PD, process->heap, + (USER_PT_END - USER_PT_START) * sizeof(uint32_t)); new_tcb->esp0 = valloc_pages(CEIL(STACK_SIZE, PAGE_SIZE)); if (!new_tcb->esp0) { vfree(new_tcb); return NULL; } + memcpy(process->heap, PD, + (USER_PT_END - USER_PT_START) * sizeof(uint32_t)); uint32_t *stack = (uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE); uint32_t *esp = stack;