wip: thread and processes handle

This commit is contained in:
0x35c
2025-11-05 16:19:21 +01:00
parent 56cfe9f2be
commit 374ea13173
25 changed files with 243 additions and 340 deletions

11
headers/assert.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "kpanic.h"
#define assert(X) \
do { \
if (!(X)) { \
kpanic("ASSERT_FAIL %s:%u %s\n", __FILE__, __LINE__, \
#X); \
} \
} while (0)

View File

@ -9,13 +9,6 @@
#define PRINT_STR(X) kprintf("%s:%u %s: %s\n", __FILE__, __LINE__, #X, X)
#define PRINT_UINT(X) kprintf("%s:%u %s: %u\n", __FILE__, __LINE__, #X, X)
#define PRINT_INT(X) kprintf("%s:%u %s: %d\n", __FILE__, __LINE__, #X, X)
#define assert(X) \
do { \
if (!(X)) { \
kpanic("ASSERT_FAIL %s:%u %s\n", __FILE__, __LINE__, \
#X); \
} \
} while (0)
struct function_entry {
uint32_t addr;

25
headers/process.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include "signal.h"
#include <stdint.h>
extern struct pcb *current_pcb;
enum owner { OWNER_KERNEL, OWNER_USER };
struct pcb {
void *cr3;
uint32_t *heap;
uint16_t pid;
uint8_t uid;
struct signal_data signals;
struct pcb *next;
struct pcb *prev;
struct tcb *thread_list;
};
void switch_process(struct pcb *next_pcb);
struct pcb *create_process(uint8_t uid);
int8_t create_kernel_process(void);
void remove_process(struct pcb *pcb);

3
headers/scheduler.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void scheduler(void);

View File

@ -1,44 +0,0 @@
#pragma once
#include "list.h"
#include "memory.h"
#include "signal.h"
#include <stdint.h>
extern struct task *current_task;
enum status { ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED };
enum owner { OWNER_KERNEL, OWNER_USER };
#define STACK_SIZE PAGE_SIZE * 4
struct task {
uint8_t *esp;
uint8_t *esp0;
uint32_t *cr3; // physical
uint32_t *heap; // virtual
uint32_t *eip;
uint16_t pid;
uint8_t status;
uint8_t uid;
struct task *daddy;
struct task *child;
struct signal_data signals;
struct task *next;
struct task *prev;
};
void scheduler(void);
void switch_to_task(struct task *next_task);
struct task *create_task(uint8_t uid);
int8_t create_kernel_task(void);
void remove_task(struct task *task);
struct task *copy_task(const struct task *task);
void kfork(struct task *daddy);
void zombify_task(struct task *task);
// utils
void exec_fn(void (*fn)(void));
uint16_t fork(void);
uint16_t wait(void);

27
headers/thread.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include "process.h"
#include <stdint.h>
#define STACK_SIZE PAGE_SIZE * 4
typedef enum {
NEW,
RUNNING,
WAITING,
STOPPED,
} state_t;
struct tcb {
uint8_t *esp;
uint8_t *esp0;
uint16_t tid;
state_t state;
struct pcb *process;
struct tcb *next;
};
struct tcb *create_thread(struct pcb *process, void (*routine)(void));
void delete_thread(struct tcb *thread);
void switch_thread(struct tcb *thread_to_switch);