processctl() PCTL_SPAWN cmd, scheduler embryo state, redirected pipes
This commit is contained in:
@ -43,12 +43,14 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = ipc_pipeinit(pipe)) < 0) {
|
||||
if ((ret = ipc_pipeinit(pipe, proc->pid)) < 0) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
proc->pipes[pipenum] = pipe;
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
|
||||
ret = E_OK;
|
||||
} break;
|
||||
@ -64,7 +66,9 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
IpcPipe *pipe = proc->pipes[pipenum];
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
|
||||
if (pipe == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
@ -85,7 +89,9 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
IpcPipe *pipe = proc->pipes[pipenum];
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
|
||||
if (pipe == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
@ -100,7 +106,9 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
IpcPipe *pipe = proc->pipes[pipenum];
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
|
||||
if (pipe == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
@ -125,6 +133,43 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
|
||||
ret = E_OK;
|
||||
} break;
|
||||
case IPCPIPE_REPLACE: {
|
||||
if (pipenum >= PROC_PIPEHANDLES_MAX) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
uint64_t pid2 = buffer1;
|
||||
uint64_t pipenum2 = len1;
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc2 = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc2, pid, pid2);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc2 == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (pipenum2 >= PROC_PIPEHANDLES_MAX) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc2->pipes_spinlock);
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
|
||||
if (proc->pipes[pipenum] != NULL) {
|
||||
ipc_pipefree(proc->pipes[pipenum]);
|
||||
dlfree(proc->pipes[pipenum]);
|
||||
proc->pipes[pipenum] = NULL;
|
||||
}
|
||||
proc->pipes[pipenum] = proc2->pipes[pipenum2];
|
||||
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
spinlock_release(&proc2->pipes_spinlock);
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
} break;
|
||||
|
@ -5,13 +5,19 @@
|
||||
#include "errors.h"
|
||||
#include "util/util.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "path/path.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
#define PCTL_MP_MAX 0xff
|
||||
#define PCTL_PATH_MAX VFS_PATH_MAX
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1) {
|
||||
uint64_t pid = pid1;
|
||||
uint64_t cmd = cmd1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == -1) {
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
@ -21,6 +27,10 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc == NULL) {
|
||||
if (cmd == PCTL_POLLSTATE) {
|
||||
ret = 2;
|
||||
goto done;
|
||||
}
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
@ -30,6 +40,36 @@ int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1) {
|
||||
proc_kill(proc);
|
||||
ret = E_DOSCHEDULING;
|
||||
} break;
|
||||
case PCTL_SPAWN: {
|
||||
const char *opath = (const char *)arg1;
|
||||
|
||||
if (opath == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
char mp[PCTL_MP_MAX];
|
||||
char path[PCTL_PATH_MAX];
|
||||
|
||||
path_parse(opath, mp, path);
|
||||
|
||||
Proc *newproc = proc_spawnuser(mp, path);
|
||||
if (newproc == NULL) {
|
||||
ret = E_NOMEMORY;
|
||||
goto done;
|
||||
}
|
||||
proc_register(newproc);
|
||||
ret = newproc->pid;
|
||||
} break;
|
||||
case PCTL_POLLSTATE: {
|
||||
ret = proc->state;
|
||||
} break;
|
||||
case PCTL_RUN: {
|
||||
proc->state = PROC_READY;
|
||||
} break;
|
||||
case PCTL_GETPID: {
|
||||
ret = proc->pid;
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
} break;
|
||||
|
@ -4,6 +4,6 @@
|
||||
#include <stdint.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, optsptr1);
|
||||
int32_t SYSCALL3(sys_processctl, pid1, cmd1, arg1);
|
||||
|
||||
#endif // SYSCALL_PROCESSCTL_H_
|
||||
|
Reference in New Issue
Block a user