wip: allocate user process stack on the right PD

This commit is contained in:
0x35c
2025-11-28 19:16:32 +01:00
parent f9cb7a6a8a
commit 700864cbf2
3 changed files with 9 additions and 3 deletions

View File

@ -24,8 +24,9 @@ struct pcb *create_process(uid_t uid)
} }
new_pcb->cr3 = new_pcb->cr3 =
(void *)((uint32_t)VA2PTE((uint32_t)new_pcb->heap) & PAGE_MASK); (void *)((uint32_t)VA2PTE((uint32_t)new_pcb->heap) & PAGE_MASK);
memcpy(new_pcb->heap, PD, 4096); memcpy(new_pcb->heap, PD,
new_pcb->heap[1023] = (uint32_t) new_pcb->cr3 | INIT_FLAGS; 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->daddy = NULL;
new_pcb->children = NULL; new_pcb->children = NULL;

View File

@ -20,7 +20,8 @@ static struct list *get_thread_to_switch(void)
it_t = current_tcb == NULL ? NULL : current_tcb->next; it_t = current_tcb == NULL ? NULL : current_tcb->next;
while (it_p) { while (it_p) {
while (it_t != NULL) { 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; return it_t;
it_t = it_t->next; it_t = it_t->next;
} }

View File

@ -16,11 +16,15 @@ struct tcb *create_thread(struct pcb *process, void (*entry)(void))
return NULL; return NULL;
new_tcb->tid = process->tid++; 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)); new_tcb->esp0 = valloc_pages(CEIL(STACK_SIZE, PAGE_SIZE));
if (!new_tcb->esp0) { if (!new_tcb->esp0) {
vfree(new_tcb); vfree(new_tcb);
return NULL; 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 *stack = (uint32_t *)((uint8_t *)new_tcb->esp0 + STACK_SIZE);
uint32_t *esp = stack; uint32_t *esp = stack;