1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-12-04 11:34:42 -05:00

Improve process code

This commit is contained in:
Alex Kotov 2020-11-26 17:07:08 +05:00
parent 09c5afb05e
commit 1138bfcb06
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 27 additions and 27 deletions

View file

@ -31,10 +31,10 @@ void init(const struct KernelMQ_Info *const kinfo_ptr)
paging_mapkernel(&kinfo);
paging_load();
const enum KernelMQ_Process_List_InitResult process_list_init_result =
const enum KernelMQ_Process_Error process_list_init_result =
KernelMQ_Process_List_init(&process_list, &kinfo);
if (process_list_init_result != KERNELMQ_PROCESS_LIST_INIT_RESULT_OK) {
if (process_list_init_result != KERNELMQ_PROCESS_ERROR_OK) {
logger_fail_from(
"init",
"Process list initialization failed with %u.",

View file

@ -2,16 +2,16 @@
#include "stdlib.h"
enum KernelMQ_Process_List_InitResult KernelMQ_Process_List_init(
enum KernelMQ_Process_Error KernelMQ_Process_List_init(
KernelMQ_Process_List *const process_list,
const struct KernelMQ_Info *const kinfo
) {
kmemset(process_list, 0, sizeof(*process_list));
const enum KernelMQ_Process_List_InitResult create_kernel_process_result =
const enum KernelMQ_Process_Error create_kernel_process_result =
KernelMQ_Process_create_from_kernel(&(*process_list)[0], kinfo);
if (create_kernel_process_result != KERNELMQ_PROCESS_LIST_INIT_RESULT_OK) {
if (create_kernel_process_result != KERNELMQ_PROCESS_ERROR_OK) {
kmemset(process_list, 0, sizeof(*process_list));
return create_kernel_process_result;
}
@ -20,26 +20,26 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_List_init(
if (modules_length > KERNELMQ_PROCESS_LIST_LENGTH - 1) {
kmemset(process_list, 0, sizeof(*process_list));
return KERNELMQ_PROCESS_LIST_INIT_RESULT_MODULES_TOO_MANY;
return KERNELMQ_PROCESS_ERROR_MODULES_TOO_MANY;
}
for (unsigned int mod_index = 0; mod_index < modules_length; ++mod_index) {
const enum KernelMQ_Process_List_InitResult create_mod_process_result =
const enum KernelMQ_Process_Error create_mod_process_result =
KernelMQ_Process_create_from_module(
&(*process_list)[mod_index + 1],
&kinfo->modules[mod_index]
);
if (create_mod_process_result != KERNELMQ_PROCESS_LIST_INIT_RESULT_OK) {
if (create_mod_process_result != KERNELMQ_PROCESS_ERROR_OK) {
kmemset(process_list, 0, sizeof(*process_list));
return create_mod_process_result;
}
}
return KERNELMQ_PROCESS_LIST_INIT_RESULT_OK;
return KERNELMQ_PROCESS_ERROR_OK;
}
enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_kernel(
enum KernelMQ_Process_Error KernelMQ_Process_create_from_kernel(
struct KernelMQ_Process *const process,
const struct KernelMQ_Info *const kinfo
) {
@ -49,13 +49,13 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_kernel(
const unsigned int cmdline_slen = kstrlen(kinfo->cmdline);
if (cmdline_slen > KERNELMQ_PROCESS_CMDLINE_SLEN_MAX) {
return KERNELMQ_PROCESS_LIST_INIT_RESULT_CMDLINE_TOO_LONG;
return KERNELMQ_PROCESS_ERROR_CMDLINE_TOO_LONG;
}
kstrncpy(process->cmdline, kinfo->cmdline, cmdline_slen);
if (kinfo->areas_count > KERNELMQ_PROCESS_AREAS_LENGTH_MAX) {
return KERNELMQ_PROCESS_LIST_INIT_RESULT_KERNEL_AREAS_LENGTH_TOO_LONG;
return KERNELMQ_PROCESS_ERROR_KERNEL_AREAS_LENGTH_TOO_LONG;
}
const unsigned int areas_length = kinfo->areas_count;
@ -68,7 +68,7 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_kernel(
const unsigned long long limit = kinfo->areas[area_index].limit;
if (base > 0xFFFFFFFF || size > 0xFFFFFFFF || limit > 0xFFFFFFFF) {
return KERNELMQ_PROCESS_LIST_INIT_RESULT_ADDR_TOO_BIG;
return KERNELMQ_PROCESS_ERROR_ADDR_TOO_BIG;
}
process->areas[area_index].base = base;
@ -76,10 +76,10 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_kernel(
process->areas[area_index].limit = limit;
}
return KERNELMQ_PROCESS_LIST_INIT_RESULT_OK;
return KERNELMQ_PROCESS_ERROR_OK;
}
enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_module(
enum KernelMQ_Process_Error KernelMQ_Process_create_from_module(
struct KernelMQ_Process *const process,
const struct KernelMQ_Info_Module *const kinfo_module
) {
@ -89,7 +89,7 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_module(
const unsigned int cmdline_slen = kstrlen(kinfo_module->cmdline);
if (cmdline_slen > KERNELMQ_PROCESS_CMDLINE_SLEN_MAX) {
return KERNELMQ_PROCESS_LIST_INIT_RESULT_CMDLINE_TOO_LONG;
return KERNELMQ_PROCESS_ERROR_CMDLINE_TOO_LONG;
}
kstrncpy(
@ -105,12 +105,12 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_module(
const unsigned long long limit = kinfo_module->limit;
if (base > 0xFFFFFFFF || size > 0xFFFFFFFF || limit > 0xFFFFFFFF) {
return KERNELMQ_PROCESS_LIST_INIT_RESULT_ADDR_TOO_BIG;
return KERNELMQ_PROCESS_ERROR_ADDR_TOO_BIG;
}
process->areas[0].base = base;
process->areas[0].size = size;
process->areas[0].limit = limit;
return KERNELMQ_PROCESS_LIST_INIT_RESULT_OK;
return KERNELMQ_PROCESS_ERROR_OK;
}

View file

@ -14,12 +14,12 @@
extern "C" {
#endif
enum KernelMQ_Process_List_InitResult {
KERNELMQ_PROCESS_LIST_INIT_RESULT_OK = 0,
KERNELMQ_PROCESS_LIST_INIT_RESULT_CMDLINE_TOO_LONG = 1,
KERNELMQ_PROCESS_LIST_INIT_RESULT_ADDR_TOO_BIG = 2,
KERNELMQ_PROCESS_LIST_INIT_RESULT_KERNEL_AREAS_LENGTH_TOO_LONG = 3,
KERNELMQ_PROCESS_LIST_INIT_RESULT_MODULES_TOO_MANY = 4,
enum KernelMQ_Process_Error {
KERNELMQ_PROCESS_ERROR_OK = 0,
KERNELMQ_PROCESS_ERROR_CMDLINE_TOO_LONG = 1,
KERNELMQ_PROCESS_ERROR_ADDR_TOO_BIG = 2,
KERNELMQ_PROCESS_ERROR_KERNEL_AREAS_LENGTH_TOO_LONG = 3,
KERNELMQ_PROCESS_ERROR_MODULES_TOO_MANY = 4,
};
enum KernelMQ_Process_CreatedFrom {
@ -47,19 +47,19 @@ struct KernelMQ_Process {
typedef struct KernelMQ_Process
KernelMQ_Process_List[KERNELMQ_PROCESS_LIST_LENGTH];
enum KernelMQ_Process_List_InitResult KernelMQ_Process_List_init(
enum KernelMQ_Process_Error KernelMQ_Process_List_init(
KernelMQ_Process_List *process_list,
const struct KernelMQ_Info *kinfo
)
__attribute__((nonnull));
enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_kernel(
enum KernelMQ_Process_Error KernelMQ_Process_create_from_kernel(
struct KernelMQ_Process *process,
const struct KernelMQ_Info *kinfo
)
__attribute__((nonnull));
enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_module(
enum KernelMQ_Process_Error KernelMQ_Process_create_from_module(
struct KernelMQ_Process *process,
const struct KernelMQ_Info_Module *kinfo_module
)