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:
parent
09c5afb05e
commit
1138bfcb06
3 changed files with 27 additions and 27 deletions
|
@ -31,10 +31,10 @@ void init(const struct KernelMQ_Info *const kinfo_ptr)
|
||||||
paging_mapkernel(&kinfo);
|
paging_mapkernel(&kinfo);
|
||||||
paging_load();
|
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);
|
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(
|
logger_fail_from(
|
||||||
"init",
|
"init",
|
||||||
"Process list initialization failed with %u.",
|
"Process list initialization failed with %u.",
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
#include "stdlib.h"
|
#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,
|
KernelMQ_Process_List *const process_list,
|
||||||
const struct KernelMQ_Info *const kinfo
|
const struct KernelMQ_Info *const kinfo
|
||||||
) {
|
) {
|
||||||
kmemset(process_list, 0, sizeof(*process_list));
|
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);
|
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));
|
kmemset(process_list, 0, sizeof(*process_list));
|
||||||
return create_kernel_process_result;
|
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) {
|
if (modules_length > KERNELMQ_PROCESS_LIST_LENGTH - 1) {
|
||||||
kmemset(process_list, 0, sizeof(*process_list));
|
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) {
|
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(
|
KernelMQ_Process_create_from_module(
|
||||||
&(*process_list)[mod_index + 1],
|
&(*process_list)[mod_index + 1],
|
||||||
&kinfo->modules[mod_index]
|
&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));
|
kmemset(process_list, 0, sizeof(*process_list));
|
||||||
return create_mod_process_result;
|
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,
|
struct KernelMQ_Process *const process,
|
||||||
const struct KernelMQ_Info *const kinfo
|
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);
|
const unsigned int cmdline_slen = kstrlen(kinfo->cmdline);
|
||||||
|
|
||||||
if (cmdline_slen > KERNELMQ_PROCESS_CMDLINE_SLEN_MAX) {
|
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);
|
kstrncpy(process->cmdline, kinfo->cmdline, cmdline_slen);
|
||||||
|
|
||||||
if (kinfo->areas_count > KERNELMQ_PROCESS_AREAS_LENGTH_MAX) {
|
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;
|
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;
|
const unsigned long long limit = kinfo->areas[area_index].limit;
|
||||||
|
|
||||||
if (base > 0xFFFFFFFF || size > 0xFFFFFFFF || limit > 0xFFFFFFFF) {
|
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;
|
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;
|
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,
|
struct KernelMQ_Process *const process,
|
||||||
const struct KernelMQ_Info_Module *const kinfo_module
|
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);
|
const unsigned int cmdline_slen = kstrlen(kinfo_module->cmdline);
|
||||||
|
|
||||||
if (cmdline_slen > KERNELMQ_PROCESS_CMDLINE_SLEN_MAX) {
|
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(
|
kstrncpy(
|
||||||
|
@ -105,12 +105,12 @@ enum KernelMQ_Process_List_InitResult KernelMQ_Process_create_from_module(
|
||||||
const unsigned long long limit = kinfo_module->limit;
|
const unsigned long long limit = kinfo_module->limit;
|
||||||
|
|
||||||
if (base > 0xFFFFFFFF || size > 0xFFFFFFFF || limit > 0xFFFFFFFF) {
|
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].base = base;
|
||||||
process->areas[0].size = size;
|
process->areas[0].size = size;
|
||||||
process->areas[0].limit = limit;
|
process->areas[0].limit = limit;
|
||||||
|
|
||||||
return KERNELMQ_PROCESS_LIST_INIT_RESULT_OK;
|
return KERNELMQ_PROCESS_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum KernelMQ_Process_List_InitResult {
|
enum KernelMQ_Process_Error {
|
||||||
KERNELMQ_PROCESS_LIST_INIT_RESULT_OK = 0,
|
KERNELMQ_PROCESS_ERROR_OK = 0,
|
||||||
KERNELMQ_PROCESS_LIST_INIT_RESULT_CMDLINE_TOO_LONG = 1,
|
KERNELMQ_PROCESS_ERROR_CMDLINE_TOO_LONG = 1,
|
||||||
KERNELMQ_PROCESS_LIST_INIT_RESULT_ADDR_TOO_BIG = 2,
|
KERNELMQ_PROCESS_ERROR_ADDR_TOO_BIG = 2,
|
||||||
KERNELMQ_PROCESS_LIST_INIT_RESULT_KERNEL_AREAS_LENGTH_TOO_LONG = 3,
|
KERNELMQ_PROCESS_ERROR_KERNEL_AREAS_LENGTH_TOO_LONG = 3,
|
||||||
KERNELMQ_PROCESS_LIST_INIT_RESULT_MODULES_TOO_MANY = 4,
|
KERNELMQ_PROCESS_ERROR_MODULES_TOO_MANY = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum KernelMQ_Process_CreatedFrom {
|
enum KernelMQ_Process_CreatedFrom {
|
||||||
|
@ -47,19 +47,19 @@ struct KernelMQ_Process {
|
||||||
typedef struct KernelMQ_Process
|
typedef struct KernelMQ_Process
|
||||||
KernelMQ_Process_List[KERNELMQ_PROCESS_LIST_LENGTH];
|
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,
|
KernelMQ_Process_List *process_list,
|
||||||
const struct KernelMQ_Info *kinfo
|
const struct KernelMQ_Info *kinfo
|
||||||
)
|
)
|
||||||
__attribute__((nonnull));
|
__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,
|
struct KernelMQ_Process *process,
|
||||||
const struct KernelMQ_Info *kinfo
|
const struct KernelMQ_Info *kinfo
|
||||||
)
|
)
|
||||||
__attribute__((nonnull));
|
__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,
|
struct KernelMQ_Process *process,
|
||||||
const struct KernelMQ_Info_Module *kinfo_module
|
const struct KernelMQ_Info_Module *kinfo_module
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue