Implement process clone trampoline
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m10s

This commit is contained in:
2026-03-07 20:20:29 +01:00
parent bf99bedfc5
commit ab8856cf4b
9 changed files with 68 additions and 12 deletions

1
libprocess/amd64/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

View File

@@ -0,0 +1,7 @@
.global _clone_tramp
_clone_tramp:
xorq %rbp, %rbp
movq %rsp, %rbp
andq $-16, %rsp
callq _clone_tramp1

View File

@@ -0,0 +1,12 @@
#include <liballoc.h>
#include <process.h>
#include <system.h>
void _clone_tramp1 (void) {
struct process_data* pdata = argument_ptr ();
pdata->fn (pdata->arg_ptr);
free (pdata);
quit ();
}

6
libprocess/amd64/src.mk Normal file
View File

@@ -0,0 +1,6 @@
c += amd64/clone_tramp1.c
S += amd64/clone_tramp.S
o += amd64/clone_tramp.o \
amd64/clone_tramp1.o

View File

@@ -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;
}

View File

@@ -8,9 +8,15 @@
#define STACK_SIZE (256 * PAGE_SIZE)
/* Process entry function */
typedef void (*process_func_t) (void);
typedef void (*process_func_t) (void*);
struct process_data {
void* arg_ptr;
process_func_t fn;
int pid;
};
/* Spawn a new process within the same procgroup with argument */
int process_spawn (process_func_t func, void* argument_ptr);
struct process_data* process_spawn (process_func_t func, void* argument_ptr);
#endif // _LIBPROCESS_PROCESS_PROCESS_H

View File

@@ -1,3 +1,5 @@
include $(platform)/src.mk
c += process.c
o += process.o