Handle process arguments
This commit is contained in:
@ -186,7 +186,7 @@ void intr_handleintr(IntrStackFrame *frame) {
|
||||
if (frame->trapnum <= 31) {
|
||||
kprintf("ERROR %s, 0x%lX\n", exceptions[frame->trapnum], frame->errnum);
|
||||
intr_dumpframe(frame);
|
||||
if (frame->trapnum == 14 && frame->errnum & 0x4) {
|
||||
if ((frame->trapnum == 14 && frame->errnum & 0x4) || frame->trapnum == 0x6) {
|
||||
kprintf("killed pid %ld %s\n", PROCS.current->pid, PROCS.current->name);
|
||||
proc_killself();
|
||||
proc_sched((void *)frame);
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include "regs.S"
|
||||
|
||||
siema:
|
||||
jmp siema
|
||||
|
||||
.global hal_switchproc
|
||||
hal_switchproc:
|
||||
mov %cr3, %rcx
|
||||
|
@ -198,7 +198,6 @@ Proc *proc_nextready(void) {
|
||||
}
|
||||
proc = proc->next;
|
||||
}
|
||||
return proc;
|
||||
}
|
||||
|
||||
void proc_reaper(void) {
|
||||
@ -243,6 +242,14 @@ void proc_reaper(void) {
|
||||
}
|
||||
|
||||
pmm_free((uintptr_t)zombie->platformdata.cr3, 1);
|
||||
|
||||
ProcArg *arg = zombie->procargs.list;
|
||||
while (arg) {
|
||||
dlfree(arg->string);
|
||||
ProcArg *tmp = arg;
|
||||
arg = arg->next;
|
||||
dlfree(tmp);
|
||||
}
|
||||
}
|
||||
dlfree(zombie);
|
||||
} else {
|
||||
@ -251,19 +258,21 @@ void proc_reaper(void) {
|
||||
}
|
||||
}
|
||||
|
||||
extern void hal_zombiespin(void);
|
||||
|
||||
void proc_sched(void *cpustate) {
|
||||
hal_intr_disable();
|
||||
sched_ticks++;
|
||||
|
||||
if (sched_ticks % PROC_REAPER_FREQ == 0) {
|
||||
proc_reaper();
|
||||
}
|
||||
|
||||
IntrStackFrame *frame = cpustate;
|
||||
|
||||
PROCS.current->platformdata.trapframe = *frame;
|
||||
|
||||
|
||||
PROCS.current = proc_nextready();
|
||||
|
||||
if (sched_ticks % PROC_REAPER_FREQ == 0) {
|
||||
proc_reaper();
|
||||
}
|
||||
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "bitmap/bitmap.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
|
||||
#define PROC_NAME_MAX 0x100
|
||||
|
||||
@ -33,6 +34,11 @@ enum {
|
||||
PROC_WAITING = 3,
|
||||
};
|
||||
|
||||
typedef struct ProcArg {
|
||||
struct ProcArg *next;
|
||||
char string[PROC_ARG_MAX];
|
||||
} ProcArg;
|
||||
|
||||
typedef struct Proc {
|
||||
struct Proc *next;
|
||||
|
||||
@ -53,6 +59,10 @@ typedef struct Proc {
|
||||
IpcPipe *list;
|
||||
SpinLock spinlock;
|
||||
} bcast_pipes;
|
||||
struct {
|
||||
ProcArg *list;
|
||||
size_t len;
|
||||
} procargs;
|
||||
|
||||
uint64_t mman_map_base;
|
||||
} Proc;
|
||||
@ -79,4 +89,12 @@ void proc_kill(Proc *proc);
|
||||
for(;;); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define PROC_ARG(proc, str) \
|
||||
do { \
|
||||
ProcArg *__arg = dlmalloc(sizeof(*__arg)); \
|
||||
hal_strcpy(__arg->string, (str)); \
|
||||
LL_APPEND((proc)->procargs.list, __arg); \
|
||||
(proc)->procargs.len++; \
|
||||
} while(0)
|
||||
#endif // PROC_PROC_H_
|
||||
|
@ -8,11 +8,12 @@
|
||||
#include "vfs/vfs.h"
|
||||
#include "path/path.h"
|
||||
#include "kprintf.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
|
||||
#define PCTL_MP_MAX 0xff
|
||||
#define PCTL_PATH_MAX VFS_PATH_MAX
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1) {
|
||||
int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3) {
|
||||
uint64_t pid = pid1;
|
||||
uint64_t cmd = cmd1;
|
||||
int32_t ret = E_OK;
|
||||
@ -58,6 +59,13 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
size_t argslen = arg3;
|
||||
char **args = (char **)arg2;
|
||||
for (size_t i = 0; i < argslen; i++) {
|
||||
PROC_ARG(newproc, args[i]);
|
||||
}
|
||||
|
||||
proc_register(newproc);
|
||||
ret = newproc->pid;
|
||||
} break;
|
||||
@ -70,6 +78,32 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1) {
|
||||
case PCTL_GETPID: {
|
||||
ret = proc->pid;
|
||||
} break;
|
||||
case PCTL_ARGLEN: {
|
||||
ret = proc->procargs.len;
|
||||
} break;
|
||||
case PCTL_ARGV: {
|
||||
char **argbuf = (char **)arg1;
|
||||
if (argbuf == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
size_t len = arg2;
|
||||
ProcArg *arg = proc->procargs.list;
|
||||
size_t i = 0;
|
||||
while (arg) {
|
||||
if (i == len) {
|
||||
break;
|
||||
}
|
||||
if (argbuf[i] == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
hal_strcpy(argbuf[i], arg->string);
|
||||
arg = arg->next;
|
||||
i++;
|
||||
}
|
||||
ret = E_OK;
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
} break;
|
||||
|
@ -4,6 +4,6 @@
|
||||
#include <stdint.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1);
|
||||
int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3);
|
||||
|
||||
#endif // SYSCALL_PROCESSCTL_H_
|
||||
|
Reference in New Issue
Block a user