Files
mop3/libprocess/process.c
kamkow1 b1648a146a
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m24s
Environment variables WIP, fix waiting scheduling issues + CE cancel proc
2026-03-17 00:01:15 +01:00

46 lines
882 B
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>
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);
}