From b0d716fdd1df9a93b4cfd22f50cbe92dd064dd4c Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 26 Nov 2020 14:43:20 +0500 Subject: [PATCH] Start working on process management --- kernelmq/Makefile | 1 + kernelmq/init.c | 18 ++++++++++++++++ kernelmq/process.c | 11 ++++++++++ kernelmq/process.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 kernelmq/process.c create mode 100644 kernelmq/process.h diff --git a/kernelmq/Makefile b/kernelmq/Makefile index 85924b3..222aef9 100644 --- a/kernelmq/Makefile +++ b/kernelmq/Makefile @@ -19,6 +19,7 @@ OBJS += page_dir.c.o # Architecture-independent OBJS += info.c.o +OBJS += process.c.o # Stdlib OBJS += memset.c.o diff --git a/kernelmq/init.c b/kernelmq/init.c index 2c6aa98..cd95650 100644 --- a/kernelmq/init.c +++ b/kernelmq/init.c @@ -5,6 +5,7 @@ #include "info.h" #include "stdlib.h" #include "module.h" +#include "process.h" #include "tasks.h" #include "elf.h" @@ -12,6 +13,8 @@ static struct KernelMQ_Info kinfo; +static KernelMQ_Process_List process_list; + void init(const struct KernelMQ_Info *const kinfo_ptr) { kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info)); @@ -28,6 +31,21 @@ void init(const struct KernelMQ_Info *const kinfo_ptr) paging_mapkernel(&kinfo); paging_load(); + const enum KernelMQ_Process_List_InitResult process_list_init_result = + KernelMQ_Process_List_init(&process_list); + + if (process_list_init_result != KERNELMQ_PROCESS_LIST_INIT_RESULT_OK) { + logger_fail_from( + "init", + "Process list initialization failed with %u.", + process_list_init_result + ); + + panic("Can not initialize process list."); + } + + logger_debug_from("init", "Process list initialized."); + if (kinfo.modules_count > 0) { const struct KernelMQ_ELF_Header *const elf_header = (void*)kinfo.modules[0].base; diff --git a/kernelmq/process.c b/kernelmq/process.c new file mode 100644 index 0000000..4f8d586 --- /dev/null +++ b/kernelmq/process.c @@ -0,0 +1,11 @@ +#include "process.h" + +#include "stdlib.h" + +enum KernelMQ_Process_List_InitResult KernelMQ_Process_List_init( + KernelMQ_Process_List *const process_list +) { + kmemset(process_list, 0, sizeof(*process_list)); + + return KERNELMQ_PROCESS_LIST_INIT_RESULT_OK; +} diff --git a/kernelmq/process.h b/kernelmq/process.h new file mode 100644 index 0000000..82f05ab --- /dev/null +++ b/kernelmq/process.h @@ -0,0 +1,52 @@ +#ifndef KERNELMQ_INCLUDED_PROCESS +#define KERNELMQ_INCLUDED_PROCESS 1 + +#define KERNELMQ_PROCESS_LIST_LENGTH 20 + +#define KERNELMQ_PROCESS_CMDLINE_SIZE_MAX 256 +#define KERNELMQ_PROCESS_CMDLINE_SLEN_MAX (KERNELMQ_PROCESS_CMDLINE_SIZE_MAX - 1) + +#define KERNELMQ_PROCESS_AREAS_LENGTH_MAX 20 + +#ifdef __cplusplus +extern "C" { +#endif + +enum KernelMQ_Process_List_InitResult { + KERNELMQ_PROCESS_LIST_INIT_RESULT_OK = 0, +}; + +enum KernelMQ_Process_CreatedFrom { + KERNELMQ_PROCESS_CREATED_FROM_KERNEL = 0, + KERNELMQ_PROCESS_CREATED_FROM_MODULE = 1, +}; + +struct KernelMQ_Process_Area { + unsigned long base; + unsigned long size; + unsigned long limit; +}; + +struct KernelMQ_Process { + unsigned char is_present; + + enum KernelMQ_Process_CreatedFrom created_from; + + char cmdline[KERNELMQ_PROCESS_CMDLINE_SIZE_MAX]; + + struct KernelMQ_Process_Area areas[KERNELMQ_PROCESS_AREAS_LENGTH_MAX]; + unsigned int areas_length; +}; + +typedef struct KernelMQ_Process + KernelMQ_Process_List[KERNELMQ_PROCESS_LIST_LENGTH]; + +enum KernelMQ_Process_List_InitResult KernelMQ_Process_List_init( + KernelMQ_Process_List *process_list +); + +#ifdef __cplusplus +} +#endif + +#endif