Files
mop3/libu/process.c
kamkow1 c8fb575bdd
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m7s
Build documentation / build-and-deploy (push) Successful in 39s
Change formatting rules
2026-04-24 01:54:48 +02:00

69 lines
1.3 KiB
C

#include <debugconsole.h>
#include <malloc.h>
#include <map.h>
#include <page_size.h>
#include <process.h>
#include <status.h>
#include <stddef.h>
#include <stdint.h>
#include <system.h>
static int e_pid;
static int e_pgid;
static int pid;
static int pgid;
void _clone_tramp(void);
struct process_data* process_spawn(process_func_t func, void* argument_ptr) {
void* stack = malloc(STACK_SIZE);
if (stack == NULL)
return NULL;
struct process_data* pdata = malloc(sizeof(*pdata));
if (pdata == NULL) {
free(stack);
return NULL;
}
pdata->stack = stack;
pdata->arg_ptr = argument_ptr;
pdata->fn = func;
uintptr_t top = (uintptr_t)stack + STACK_SIZE;
int pid = clone(top, &_clone_tramp, (void*)pdata);
if (pid < 0) {
free(stack);
free(pdata);
return NULL;
}
pdata->pid = pid;
return pdata;
}
void process_data_free(struct process_data* pdata) {
free(pdata->stack);
free(pdata);
}
void process_self_init(void) {
e_pid = get_exec_pid();
e_pgid = get_procgroup(e_pid);
pid = get_self_pid();
pgid = get_procgroup(pid);
}
int process_get_exec_pid(void) { return e_pid; }
int process_get_exec_pgid(void) { return e_pgid; }
int process_get_pid(void) { return pid; }
int process_get_pgid(void) { return pgid; }