From 1138bfcb06f79a0ae8a2e5dfa509919c688ba388 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 26 Nov 2020 17:07:08 +0500 Subject: [PATCH] Improve process code --- kernelmq/init.c | 4 ++-- kernelmq/process.c | 32 ++++++++++++++++---------------- kernelmq/process.h | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/kernelmq/init.c b/kernelmq/init.c index 0ca956a..cfeea53 100644 --- a/kernelmq/init.c +++ b/kernelmq/init.c @@ -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.", diff --git a/kernelmq/process.c b/kernelmq/process.c index bc72190..f80bfda 100644 --- a/kernelmq/process.c +++ b/kernelmq/process.c @@ -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; } diff --git a/kernelmq/process.h b/kernelmq/process.h index a17b293..4860e6a 100644 --- a/kernelmq/process.h +++ b/kernelmq/process.h @@ -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 )