Feat: POSIX signal
This commit is contained in:
@@ -11,15 +11,16 @@
|
||||
#include <interrupt.h>
|
||||
|
||||
int32_t global_pid_counter = 0;
|
||||
vector_t *global_processes = 0x0;
|
||||
|
||||
static inline
|
||||
process_t *_make_process(const char *filename)
|
||||
process_t *_make_process()
|
||||
{
|
||||
process_t *ret = kmalloc(sizeof(process_t));
|
||||
|
||||
file_node_t *file = initrd_get(initrd_root, filename);
|
||||
if (file == 0x0)
|
||||
panic(ERR_NOT_EXIST);
|
||||
|
||||
if (!global_processes)
|
||||
global_processes = make_vector(0);
|
||||
VEC_PUSH(global_processes, ret);
|
||||
|
||||
*ret = (process_t){
|
||||
.pid = global_pid_counter++,
|
||||
@@ -33,26 +34,46 @@ process_t *_make_process(const char *filename)
|
||||
.mem = allocate_page(256),
|
||||
.mem_size = 256 << 12,
|
||||
|
||||
.sigstack = allocate_page(256),
|
||||
.sigstack_size = 256 << 12,
|
||||
|
||||
.current_signal = 0,
|
||||
|
||||
.regs = kmalloc(sizeof(trapframe_t)),
|
||||
};
|
||||
memcpy(ret->mem, file->filecontent, file->filesize);
|
||||
|
||||
memset(ret->sigstate, 0x0, SIGNAL_NUM * sizeof(bool));
|
||||
memset(ret->sighandlers, 0x0, SIGNAL_NUM * sizeof(signal_handler_t));
|
||||
memset(ret->regs, 0x0, sizeof(trapframe_t));
|
||||
*ret->regs = (trapframe_t){
|
||||
.spsr_el1 = 0x0, // enable all interrupt
|
||||
.elr_el1 = (uint64_t)ret->mem,
|
||||
.sp_el0 = ((uint64_t)ret->stack + ret->stack_size - 64),
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline
|
||||
void _init_process(process_t *process, const char *filename)
|
||||
{
|
||||
file_node_t *file = initrd_get(initrd_root, filename);
|
||||
if (file == 0x0)
|
||||
panic(ERR_NOT_EXIST);
|
||||
|
||||
memcpy(process->mem, file->filecontent, file->filesize);
|
||||
*process->regs = (trapframe_t){
|
||||
.spsr_el1 = 0x0, // enable all interrupt
|
||||
.elr_el1 = (uint64_t)process->mem,
|
||||
.sp_el0 = ((uint64_t)process->stack + process->stack_size - 64),
|
||||
};
|
||||
}
|
||||
|
||||
// void run_process_by_name(const char *filename)
|
||||
int32_t run_process_by_name(uint64_t param)
|
||||
{
|
||||
const char *filename = (void *)param;
|
||||
thread_t *th = get_current();
|
||||
|
||||
th->process = _make_process(filename);
|
||||
if (!th->process)
|
||||
th->process = _make_process();
|
||||
_init_process(th->process, filename);
|
||||
|
||||
th->process->th = th;
|
||||
LOG("Run process by name"); DEBUG_THREAD(filename);
|
||||
LOG(th->process->stack); DEBUG_THREAD(th->process->regs->sp_el0);
|
||||
@@ -84,21 +105,7 @@ int32_t run_process(uint64_t param)
|
||||
|
||||
process_t *fork_process(const process_t *from)
|
||||
{
|
||||
process_t *ret = kmalloc(sizeof(process_t));
|
||||
*ret = (process_t){
|
||||
.pid = global_pid_counter++,
|
||||
.th = 0x0,
|
||||
|
||||
.exitcode = from->exitcode,
|
||||
|
||||
.stack = allocate_page(256),
|
||||
.stack_size = 256 << 12,
|
||||
|
||||
.mem = allocate_page(256),
|
||||
.mem_size = 256 << 12,
|
||||
|
||||
.regs = kmalloc(sizeof(trapframe_t)),
|
||||
};
|
||||
process_t *ret = _make_process();
|
||||
memcpy(ret->stack, from->stack, from->stack_size);
|
||||
memcpy(ret->mem, from->mem, from->mem_size);
|
||||
*ret->regs = (trapframe_t){
|
||||
|
||||
Reference in New Issue
Block a user