Implement process clone trampoline
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s
This commit is contained in:
@@ -7,11 +7,32 @@
|
||||
#include <stdint.h>
|
||||
#include <system.h>
|
||||
|
||||
int process_spawn (process_func_t func, void* argument_ptr) {
|
||||
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 -ST_OOM_ERROR;
|
||||
return NULL;
|
||||
|
||||
struct process_data* pdata = malloc (sizeof (*pdata));
|
||||
|
||||
if (pdata == NULL) {
|
||||
free (stack);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdata->arg_ptr = argument_ptr;
|
||||
pdata->fn = func;
|
||||
|
||||
uintptr_t top = (uintptr_t)stack + STACK_SIZE;
|
||||
return clone (top, func, argument_ptr);
|
||||
int pid = clone (top, &_clone_tramp, (void*)pdata);
|
||||
|
||||
if (pid < 0) {
|
||||
free (stack);
|
||||
free (pdata);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdata->pid = pid;
|
||||
return pdata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user