wip: thread and processes handle
This commit is contained in:
57
src/multitasking/process.c
Normal file
57
src/multitasking/process.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include "process.h"
|
||||
#include "alloc.h"
|
||||
#include "interrupts.h"
|
||||
#include "memory.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
int8_t create_kernel_process(void)
|
||||
{
|
||||
struct pcb *new_pcb = vmalloc(sizeof(struct pcb));
|
||||
if (!new_pcb)
|
||||
return -1;
|
||||
new_pcb->pid = 0;
|
||||
new_pcb->uid = 0;
|
||||
new_pcb->heap = kernel_pd;
|
||||
new_pcb->cr3 = (uint32_t *)((uint32_t)kernel_pd - HEAP_END);
|
||||
new_pcb->next = new_pcb;
|
||||
new_pcb->prev = new_pcb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct pcb *create_process(uint8_t uid)
|
||||
{
|
||||
static uint32_t pid = 1;
|
||||
struct pcb *new_pcb = vmalloc(sizeof(struct pcb));
|
||||
if (!new_pcb)
|
||||
return NULL;
|
||||
new_pcb->uid = uid;
|
||||
new_pcb->pid = pid++;
|
||||
|
||||
new_pcb->heap = alloc_pages(4096, &new_pcb->cr3);
|
||||
if (!new_pcb->heap) {
|
||||
vfree(new_pcb);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(new_pcb->heap, current_pcb->heap, 4096);
|
||||
new_pcb->next = current_pcb->next;
|
||||
new_pcb->prev = current_pcb;
|
||||
current_pcb->next = new_pcb;
|
||||
if (current_pcb->prev == current_pcb)
|
||||
current_pcb->prev = new_pcb;
|
||||
|
||||
new_pcb->signals.pending = SIG_IGN;
|
||||
|
||||
return new_pcb;
|
||||
}
|
||||
|
||||
void remove_pcb(struct pcb *pcb)
|
||||
{
|
||||
struct pcb *left = pcb->prev;
|
||||
struct pcb *right = pcb->next;
|
||||
if (pcb->heap)
|
||||
free_pages(pcb->heap, 4096);
|
||||
left->next = right;
|
||||
right->prev = left;
|
||||
vfree(pcb);
|
||||
}
|
||||
Reference in New Issue
Block a user