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:
11
ce/interp.c
11
ce/interp.c
@@ -289,8 +289,8 @@ static void help (struct context* context) {
|
|||||||
cprintf (context, "quit\n");
|
cprintf (context, "quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_cancel_proc (void) {
|
static void cmd_cancel_proc (void* arg) {
|
||||||
int pid = *(int*)argument_ptr ();
|
int pid = *(int*)arg;
|
||||||
|
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -301,8 +301,6 @@ static void cmd_cancel_proc (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kill (pid);
|
kill (pid);
|
||||||
|
|
||||||
quit ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
||||||
@@ -342,11 +340,12 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cancel_pid = process_spawn (&cmd_cancel_proc, &pid);
|
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, &pid);
|
||||||
|
|
||||||
wait_for_pid (pid);
|
wait_for_pid (pid);
|
||||||
|
|
||||||
kill (cancel_pid);
|
if (kill (cancel_pdata->pid) < 0)
|
||||||
|
free (cancel_pdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
static int ce_pgid;
|
static int ce_pgid;
|
||||||
|
|
||||||
void receiver (void) {
|
void receiver (void* arg) {
|
||||||
|
(void)arg;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char recv[RECV_MAX];
|
char recv[RECV_MAX];
|
||||||
memset (recv, 0, sizeof (recv));
|
memset (recv, 0, sizeof (recv));
|
||||||
|
|||||||
1
libprocess/amd64/.gitignore
vendored
Normal file
1
libprocess/amd64/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.o
|
||||||
7
libprocess/amd64/clone_tramp.S
Normal file
7
libprocess/amd64/clone_tramp.S
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.global _clone_tramp
|
||||||
|
_clone_tramp:
|
||||||
|
xorq %rbp, %rbp
|
||||||
|
movq %rsp, %rbp
|
||||||
|
andq $-16, %rsp
|
||||||
|
|
||||||
|
callq _clone_tramp1
|
||||||
12
libprocess/amd64/clone_tramp1.c
Normal file
12
libprocess/amd64/clone_tramp1.c
Normal 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
6
libprocess/amd64/src.mk
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
c += amd64/clone_tramp1.c
|
||||||
|
|
||||||
|
S += amd64/clone_tramp.S
|
||||||
|
|
||||||
|
o += amd64/clone_tramp.o \
|
||||||
|
amd64/clone_tramp1.o
|
||||||
@@ -7,11 +7,32 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <system.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);
|
void* stack = malloc (STACK_SIZE);
|
||||||
if (stack == NULL)
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,15 @@
|
|||||||
#define STACK_SIZE (256 * PAGE_SIZE)
|
#define STACK_SIZE (256 * PAGE_SIZE)
|
||||||
|
|
||||||
/* Process entry function */
|
/* 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 */
|
/* 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
|
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
include $(platform)/src.mk
|
||||||
|
|
||||||
c += process.c
|
c += process.c
|
||||||
|
|
||||||
o += process.o
|
o += process.o
|
||||||
|
|||||||
Reference in New Issue
Block a user