Split processctl() syscall into multiple smaller ones
This commit is contained in:
@ -13,7 +13,7 @@
|
||||
#include "vfs/vfs.h"
|
||||
#include "bootinfo/bootinfo.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
#include "sysdefs/proc.h"
|
||||
#include "sysdefs/ioctl.h"
|
||||
|
||||
#define PROC_REAPER_FREQ 30
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "bitmap/bitmap.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
#include "sysdefs/proc.h"
|
||||
#include "dev/dev.h"
|
||||
|
||||
#define PROC_NAME_MAX 0x100
|
||||
|
||||
237
kernel/syscall/proc.c
Normal file
237
kernel/syscall/proc.c
Normal file
@ -0,0 +1,237 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "syscall.h"
|
||||
#include "proc/proc.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "errors.h"
|
||||
#include "util/util.h"
|
||||
#include "sysdefs/proc.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "path/path.h"
|
||||
#include "kprintf.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
|
||||
#define _MP_MAX 0xff
|
||||
#define _PATH_MAX VFS_PATH_MAX
|
||||
|
||||
int32_t SYSCALL1(sys_proc_kill, pid1) {
|
||||
uint64_t pid = pid1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
proc_kill(proc);
|
||||
ret = E_DOSCHEDULING;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL3(sys_proc_spawn, opath1, args1, argslen1) {
|
||||
int32_t ret = E_OK;
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = PROCS.current;
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
const char *opath = (const char *)opath1;
|
||||
|
||||
if (opath == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
char mp[_MP_MAX];
|
||||
char path[_PATH_MAX];
|
||||
|
||||
path_parse(opath, mp, path);
|
||||
|
||||
Proc *newproc = proc_spawnuser(mp, path);
|
||||
if (newproc == NULL) {
|
||||
ret = E_SPAWNERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
size_t argslen = argslen1;
|
||||
char **args = (char **)args1;
|
||||
if (args != NULL && argslen > 0) {
|
||||
for (size_t i = 0; i < argslen; i++) {
|
||||
PROC_ARG(newproc, args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
|
||||
if (newproc->pipes[i] != NULL) {
|
||||
ipc_pipefree(newproc->pipes[i]);
|
||||
dlfree(newproc->pipes[i]);
|
||||
}
|
||||
newproc->pipes[i] = proc->pipes[i];
|
||||
}
|
||||
|
||||
proc_register(newproc);
|
||||
ret = newproc->pid;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL1(sys_proc_pollstate, pid1) {
|
||||
uint64_t pid = pid1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc == NULL) {
|
||||
ret = PROC_DIED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = proc->state;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL0(sys_proc_getpid) {
|
||||
int32_t ret = E_OK;
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = PROCS.current;
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
ret = proc->pid;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL1(sys_proc_run, pid1) {
|
||||
uint64_t pid = pid1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
proc->state = PROC_READY;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL1(sys_proc_arglen, pid1) {
|
||||
uint64_t pid = pid1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
ret = proc->procargs.len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL4(sys_proc_argv, pid1, argslen1, argbuf1, maxargs1) {
|
||||
uint64_t pid = pid1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
size_t *argslen = (size_t *)argslen1;
|
||||
char **argbuf = (char **)argbuf1;
|
||||
if (argbuf == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
size_t maxargs = (size_t)maxargs1;
|
||||
|
||||
ProcArg *arg, *argtmp;
|
||||
size_t i;
|
||||
LL_FOREACH_SAFE_IDX_LIMIT(proc->procargs.list, arg, argtmp, i, maxargs) {
|
||||
if (argbuf[i] == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
hal_strcpy(argbuf[i], arg->string);
|
||||
}
|
||||
*argslen = i;
|
||||
|
||||
ret = E_OK;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL0(sys_proc_listsize) {
|
||||
int32_t ret;
|
||||
Proc *p, *ptmp;
|
||||
size_t i;
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
LL_FOREACH_SAFE_IDX(PROCS.procs, p, ptmp, i);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
ret = i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t SYSCALL2(sys_proc_stat, pidx, pstat1) {
|
||||
int32_t ret;
|
||||
ProcStat *stat = (ProcStat *)pstat1;
|
||||
|
||||
if (stat == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
Proc *p, *ptmp;
|
||||
size_t i;
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
LL_FOREACH_SAFE_IDX(PROCS.procs, p, ptmp, i) {
|
||||
if (i == pidx) {
|
||||
stat->pid = p->pid;
|
||||
hal_strcpy(stat->name, p->name);
|
||||
stat->state = p->state;
|
||||
|
||||
VasRange *vas, *vastmp;
|
||||
LL_FOREACH_SAFE(p->vas, vas, vastmp) {
|
||||
stat->usemem += vas->size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
ret = E_OK;
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
18
kernel/syscall/proc.h
Normal file
18
kernel/syscall/proc.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef SYSCALL_PROC_H_
|
||||
#define SYSCALL_PROC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int32_t SYSCALL1(sys_proc_kill, pid1);
|
||||
int32_t SYSCALL3(sys_proc_spawn, opath1, args1, argslen1);
|
||||
int32_t SYSCALL1(sys_proc_pollstate, pid1);
|
||||
int32_t SYSCALL0(sys_proc_getpid);
|
||||
int32_t SYSCALL1(sys_proc_run, pid1);
|
||||
int32_t SYSCALL1(sys_proc_arglen, pid1);
|
||||
int32_t SYSCALL4(sys_proc_argv, pid1, argslen1, argbuf1, maxargs1);
|
||||
int32_t SYSCALL0(sys_proc_listsize);
|
||||
int32_t SYSCALL2(sys_proc_stat, pidx, pstat1);
|
||||
|
||||
#endif // SYSCALL_PROC_H_
|
||||
@ -1,160 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include "syscall.h"
|
||||
#include "proc/proc.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "errors.h"
|
||||
#include "util/util.h"
|
||||
#include "sysdefs/processctl.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "path/path.h"
|
||||
#include "kprintf.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
|
||||
#define PCTL_MP_MAX 0xff
|
||||
#define PCTL_PATH_MAX VFS_PATH_MAX
|
||||
|
||||
int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3) {
|
||||
uint64_t pid = pid1;
|
||||
uint64_t cmd = cmd1;
|
||||
int32_t ret = E_OK;
|
||||
|
||||
if (pid == (uint64_t)-1) {
|
||||
pid = PROCS.current->pid;
|
||||
}
|
||||
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
Proc *proc = NULL;
|
||||
LL_FINDPROP(PROCS.procs, proc, pid, pid);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
|
||||
if (proc == NULL) {
|
||||
if (cmd == PCTL_POLLSTATE) {
|
||||
ret = PROC_DIED;
|
||||
goto done;
|
||||
}
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case PCTL_KILL: {
|
||||
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_SPAWNERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
size_t argslen = arg3;
|
||||
char **args = (char **)arg2;
|
||||
if (args != NULL && argslen > 0) {
|
||||
for (size_t i = 0; i < argslen; i++) {
|
||||
PROC_ARG(newproc, args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
|
||||
if (newproc->pipes[i] != NULL) {
|
||||
ipc_pipefree(newproc->pipes[i]);
|
||||
dlfree(newproc->pipes[i]);
|
||||
}
|
||||
newproc->pipes[i] = proc->pipes[i];
|
||||
}
|
||||
|
||||
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;
|
||||
case PCTL_ARGLEN: {
|
||||
ret = proc->procargs.len;
|
||||
} break;
|
||||
case PCTL_ARGV: {
|
||||
size_t *argslen = (size_t *)arg1;
|
||||
char **argbuf = (char **)arg2;
|
||||
if (argbuf == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
size_t maxargs = (size_t)arg3;
|
||||
|
||||
ProcArg *arg, *argtmp;
|
||||
size_t i;
|
||||
LL_FOREACH_SAFE_IDX_LIMIT(proc->procargs.list, arg, argtmp, i, maxargs) {
|
||||
if (argbuf[i] == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
hal_strcpy(argbuf[i], arg->string);
|
||||
}
|
||||
*argslen = i;
|
||||
|
||||
ret = E_OK;
|
||||
} break;
|
||||
case PCTL_PLS_SZ: {
|
||||
Proc *p, *ptmp;
|
||||
size_t i;
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
LL_FOREACH_SAFE_IDX(PROCS.procs, p, ptmp, i);
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
ret = i;
|
||||
} break;
|
||||
case PCTL_PLS_STAT: {
|
||||
uint64_t pidx = arg1;
|
||||
ProcStat *stat = (ProcStat *)arg2;
|
||||
|
||||
if (stat == NULL) {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
goto done;
|
||||
}
|
||||
|
||||
Proc *p, *ptmp;
|
||||
size_t i;
|
||||
spinlock_acquire(&PROCS.spinlock);
|
||||
LL_FOREACH_SAFE_IDX(PROCS.procs, p, ptmp, i) {
|
||||
if (i == pidx) {
|
||||
stat->pid = p->pid;
|
||||
hal_strcpy(stat->name, p->name);
|
||||
stat->state = p->state;
|
||||
|
||||
VasRange *vas, *vastmp;
|
||||
LL_FOREACH_SAFE(p->vas, vas, vastmp) {
|
||||
stat->usemem += vas->size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
spinlock_release(&PROCS.spinlock);
|
||||
ret = E_OK;
|
||||
} break;
|
||||
default: {
|
||||
ret = E_INVALIDARGUMENT;
|
||||
} break;
|
||||
}
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
#ifndef SYSCALL_PROCESSCTL_H_
|
||||
#define SYSCALL_PROCESSCTL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3);
|
||||
|
||||
#endif // SYSCALL_PROCESSCTL_H_
|
||||
@ -2,7 +2,6 @@
|
||||
#include "syscall.h"
|
||||
#include "errors.h"
|
||||
#include "kprintf.h"
|
||||
#include "processctl.h"
|
||||
#include "sysdefs/syscall.h"
|
||||
#include "ioctl.h"
|
||||
#include "ipcpipe.h"
|
||||
@ -11,6 +10,7 @@
|
||||
#include "devctl.h"
|
||||
#include "randcrypto.h"
|
||||
#include "vfs.h"
|
||||
#include "proc.h"
|
||||
|
||||
int32_t SYSCALL1(sys_debugprint, string) {
|
||||
char *p = (char *)string;
|
||||
@ -20,7 +20,6 @@ int32_t SYSCALL1(sys_debugprint, string) {
|
||||
|
||||
SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
|
||||
[SYS_DEBUGPRINT] = &sys_debugprint,
|
||||
[SYS_PROCESSCTL] = &sys_processctl,
|
||||
[SYS_IOCTL] = &sys_ioctl,
|
||||
[SYS_MMAN_MAP] = &sys_mman_map,
|
||||
[SYS_MMAN_UNMAP] = &sys_mman_unmap,
|
||||
@ -34,4 +33,13 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
|
||||
[SYS_IPC_PIPEMAKE] = &sys_ipc_pipemake,
|
||||
[SYS_IPC_PIPEDELETE] = &sys_ipc_pipedelete,
|
||||
[SYS_IPC_PIPECONNECT] = &sys_ipc_pipeconnect,
|
||||
[SYS_PROC_KILL] = &sys_proc_kill,
|
||||
[SYS_PROC_SPAWN] = &sys_proc_spawn,
|
||||
[SYS_PROC_POLLSTATE] = &sys_proc_pollstate,
|
||||
[SYS_PROC_GETPID] = &sys_proc_getpid,
|
||||
[SYS_PROC_RUN] = &sys_proc_run,
|
||||
[SYS_PROC_ARGLEN] = &sys_proc_arglen,
|
||||
[SYS_PROC_ARGV] = &sys_proc_argv,
|
||||
[SYS_PROC_LISTSIZE] = &sys_proc_listsize,
|
||||
[SYS_PROC_STAT] = &sys_proc_stat,
|
||||
};
|
||||
|
||||
15
share/sysdefs/proc.h
Normal file
15
share/sysdefs/proc.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef SHARE_SYSDEFS_PROC_H_
|
||||
#define SHARE_SYSDEFS_PROC_H_
|
||||
|
||||
#define PROC_ARG_MAX 128
|
||||
|
||||
typedef struct {
|
||||
uint64_t pid;
|
||||
char name[0x100];
|
||||
uint8_t state;
|
||||
size_t usemem;
|
||||
} ProcStat;
|
||||
|
||||
typedef uint64_t PID_t;
|
||||
|
||||
#endif // SHARE_SYSDEFS_PROC_H_
|
||||
@ -1,29 +0,0 @@
|
||||
#ifndef SHARE_HDRS_PROCESSCTL_H_
|
||||
#define SHARE_HDRS_PROCESSCTL_H_
|
||||
|
||||
#define PROC_ARG_MAX 128
|
||||
|
||||
#define PCTL_KILL 0
|
||||
#define PCTL_SPAWN 1
|
||||
#define PCTL_POLLSTATE 2
|
||||
#define PCTL_RUN 3
|
||||
#define PCTL_GETPID 4
|
||||
#define PCTL_ARGLEN 5
|
||||
#define PCTL_ARGV 6
|
||||
#define PCTL_PLS_SZ 7
|
||||
#define PCTL_PLS_STAT 8
|
||||
|
||||
#if !defined(__ASSEMBLER__)
|
||||
|
||||
typedef struct {
|
||||
uint64_t pid;
|
||||
char name[0x100];
|
||||
uint8_t state;
|
||||
size_t usemem;
|
||||
} ProcStat;
|
||||
|
||||
typedef uint64_t PID_t;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SHARE_HDRS_PROCESSCTL_H_
|
||||
@ -2,7 +2,6 @@
|
||||
#define SHARE_HDRS_SYSCALL_H_
|
||||
|
||||
#define SYS_DEBUGPRINT 1
|
||||
#define SYS_PROCESSCTL 2
|
||||
#define SYS_IOCTL 3
|
||||
#define SYS_MMAN_MAP 5
|
||||
#define SYS_MMAN_UNMAP 6
|
||||
@ -16,6 +15,15 @@
|
||||
#define SYS_IPC_PIPEMAKE 14
|
||||
#define SYS_IPC_PIPEDELETE 15
|
||||
#define SYS_IPC_PIPECONNECT 16
|
||||
#define SYS_PROC_KILL 17
|
||||
#define SYS_PROC_SPAWN 18
|
||||
#define SYS_PROC_POLLSTATE 19
|
||||
#define SYS_PROC_RUN 20
|
||||
#define SYS_PROC_GETPID 21
|
||||
#define SYS_PROC_ARGLEN 22
|
||||
#define SYS_PROC_ARGV 23
|
||||
#define SYS_PROC_LISTSIZE 24
|
||||
#define SYS_PROC_STAT 25
|
||||
|
||||
|
||||
#endif // SHARE_HDRS_SYSCALL_H_
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <system/system.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <sysdefs/proc.h>
|
||||
#include <errors.h>
|
||||
#include <uprintf.h>
|
||||
#include <log.h>
|
||||
@ -40,8 +40,9 @@ void _premain(void) {
|
||||
_args[i] = umalloc(PROC_ARG_MAX);
|
||||
}
|
||||
|
||||
processctl(-1, PCTL_ARGV, (uint64_t)&_argslen, (uint64_t)_args, MAX_ARGS);
|
||||
proc_argv(-1, &_argslen, _args, MAX_ARGS);
|
||||
|
||||
main();
|
||||
proc_kill(proc_getpid());
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,3 @@
|
||||
.global _start
|
||||
_start:
|
||||
call _premain
|
||||
|
||||
movq $2, %rax // sys processctl
|
||||
movq $-1, %rdi // self magic num
|
||||
movq $0, %rsi // kill cmd
|
||||
|
||||
int $0x80
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <syscall/syscall.h>
|
||||
#include <sysdefs/syscall.h>
|
||||
#include <sysdefs/ioctl.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <sysdefs/proc.h>
|
||||
#include <sysdefs/devctl.h>
|
||||
#include <uprintf.h>
|
||||
|
||||
@ -15,10 +15,6 @@ int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t
|
||||
return syscall(SYS_IOCTL, ioh, cmd, arg1, arg2, arg3, 0);
|
||||
}
|
||||
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
|
||||
return syscall(SYS_PROCESSCTL, pid, cmd, arg1, arg2, arg3, 0);
|
||||
}
|
||||
|
||||
int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint8_t **out) {
|
||||
return syscall(SYS_MMAN_MAP, (uint64_t)addr, (uint64_t)size, prot, flags, (uint64_t)out, 0);
|
||||
}
|
||||
@ -66,3 +62,40 @@ int32_t ipc_pipedelete(uint64_t pipenum) {
|
||||
int32_t ipc_pipeconnect(PID_t pid1, uint64_t pipenum1, PID_t pid2, uint64_t pipenum2) {
|
||||
return syscall(SYS_IPC_PIPECONNECT, pid1, pipenum1, pid2, pipenum2, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_kill(PID_t pid) {
|
||||
return syscall(SYS_PROC_KILL, (uint64_t)pid, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_spawn(char *path, char **args1, size_t argslen1) {
|
||||
return syscall(SYS_PROC_SPAWN, (uint64_t)path, (uint64_t)args1, (uint64_t)argslen1, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_pollstate(PID_t pid) {
|
||||
return syscall(SYS_PROC_POLLSTATE, (uint64_t)pid, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_getpid(void) {
|
||||
return syscall(SYS_PROC_GETPID, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_run(PID_t pid) {
|
||||
return syscall(SYS_PROC_RUN, (uint64_t)pid, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_arglen(PID_t pid) {
|
||||
return syscall(SYS_PROC_ARGLEN, (uint64_t)pid, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_argv(PID_t pid, size_t *argslen1, char **argbuf1, size_t maxargs) {
|
||||
return syscall(SYS_PROC_ARGV, (uint64_t)pid, (uint64_t)argslen1, (uint64_t)argbuf1, (uint64_t)maxargs, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_listsize(void) {
|
||||
return syscall(SYS_PROC_LISTSIZE, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int32_t proc_stat(size_t idx, ProcStat *pstat) {
|
||||
return syscall(SYS_PROC_STAT, (uint64_t)idx, (uint64_t)pstat, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -5,11 +5,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <sysdefs/devctl.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <sysdefs/proc.h>
|
||||
|
||||
void debugprint(const char *string);
|
||||
int32_t ioctl(uint64_t ioh, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
int32_t processctl(uint64_t pid, uint64_t cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
int32_t mman_map(uint8_t *addr, size_t size, uint64_t prot, uint64_t flags, uint8_t **out);
|
||||
int32_t mman_unmap(uint8_t *addr);
|
||||
int32_t schedrelease(void);
|
||||
@ -22,5 +21,14 @@ int32_t ipc_pipewrite(PID_t pid, uint64_t pipenum, const uint8_t *buffer, size_t
|
||||
int32_t ipc_pipemake(uint64_t pipenum);
|
||||
int32_t ipc_pipedelete(uint64_t pipenum);
|
||||
int32_t ipc_pipeconnect(PID_t pid1, uint64_t pipenum1, PID_t pid2, uint64_t pipenum2);
|
||||
int32_t proc_kill(PID_t pid);
|
||||
int32_t proc_spawn(char *path, char **args1, size_t argslen1);
|
||||
int32_t proc_pollstate(PID_t pid);
|
||||
int32_t proc_getpid(void);
|
||||
int32_t proc_run(PID_t pid);
|
||||
int32_t proc_arglen(PID_t pid);
|
||||
int32_t proc_argv(PID_t pid, size_t *argslen1, char **argbuf1, size_t maxargs);
|
||||
int32_t proc_listsize(void);
|
||||
int32_t proc_stat(size_t idx, ProcStat *pstat);
|
||||
|
||||
#endif // ULIB_SYSTEM_SYSTEM_H_
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
#include <errors.h>
|
||||
#include <sysdefs/ioctl.h>
|
||||
#include <sysdefs/mman.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
#include <sysdefs/proc.h>
|
||||
#include <sysdefs/sched.h>
|
||||
#include <sysdefs/syscall.h>
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include <system/system.h>
|
||||
#include <sysdefs/processctl.h>
|
||||
|
||||
void quit(void) {
|
||||
processctl(-1, PCTL_KILL, 0, 0, 0);
|
||||
proc_kill(proc_getpid());
|
||||
}
|
||||
|
||||
@ -9,11 +9,11 @@ void tb_runinitscript(void) {
|
||||
devctl(&termdev, DEVCTL_GET_HANDLE, (uint8_t *)"termdev", 0, 0);
|
||||
|
||||
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb" };
|
||||
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)(char **)tbargs, ARRLEN(tbargs));
|
||||
int32_t tb = proc_spawn("base:/bin/tb", tbargs, ARRLEN(tbargs));
|
||||
|
||||
processctl(tb, PCTL_RUN, 0, 0, 0);
|
||||
proc_run(tb);
|
||||
|
||||
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
||||
while(proc_pollstate(tb) != 4) {
|
||||
int32_t r;
|
||||
|
||||
char buf[100];
|
||||
@ -28,7 +28,7 @@ void tb_runinitscript(void) {
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
PID = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
|
||||
PID = proc_getpid();
|
||||
devctl(&ps2kbdev, DEVCTL_GET_HANDLE, (uint8_t *)"ps2kbdev", 0, 0);
|
||||
devctl(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, (uint8_t *)PID, 0, 0);
|
||||
|
||||
|
||||
@ -22,6 +22,6 @@ void pctl_kill(void) {
|
||||
}
|
||||
|
||||
if (PCTL_KILL_CONFIG.pid != -1) {
|
||||
processctl(PCTL_KILL_CONFIG.pid, PCTL_KILL, 0, 0, 0);
|
||||
proc_kill(PCTL_KILL_CONFIG.pid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ void pctl_ls(void) {
|
||||
|
||||
static const char *states[] = {"embryo", "ready", "zombie", "waiting", "died"};
|
||||
|
||||
uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0);
|
||||
int32_t procslen = proc_listsize();
|
||||
|
||||
char *namebuf = umalloc(34);
|
||||
char *membuf = umalloc(20);
|
||||
@ -38,7 +38,7 @@ void pctl_ls(void) {
|
||||
string_memset(namebuf, 0, 34);
|
||||
string_memset(membuf, 0, 20);
|
||||
|
||||
int32_t r = processctl(-1, PCTL_PLS_STAT, i, (uint64_t)&stat, 0);
|
||||
int32_t r = proc_stat(i, &stat);
|
||||
if (r == E_OK) {
|
||||
if (PCTL_LS_CONFIG.specificproc != NULL
|
||||
&& string_strcmp(stat.name, PCTL_LS_CONFIG.specificproc) != 0) {
|
||||
|
||||
@ -206,20 +206,20 @@ bool interp_runstring(char *string, InterpResult **res, bool logcmds, bool inter
|
||||
string_memcpy(args1[i], argtk->str, MIN(string_len(argtk->str), PROC_ARG_MAX));
|
||||
}
|
||||
|
||||
int32_t app = processctl(-1, PCTL_SPAWN, (uint64_t)cmdtk->str, (uint64_t)args1, argslen1);
|
||||
int32_t app = proc_spawn(cmdtk->str, args1, argslen1);
|
||||
if (app < 0) {
|
||||
usprintf(RES.errmsg, "Could not run %s: %s\n", cmdtk->str, ERRSTRING(app));
|
||||
ok = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
processctl(app, PCTL_RUN, 0, 0, 0);
|
||||
proc_run(app);
|
||||
|
||||
while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
||||
while(proc_pollstate(app) != 4) {
|
||||
if (interactive) {
|
||||
int32_t key = devctl(&ps2kbdev, DEV_PS2KBDEV_READCH, (uint8_t *)PID, 0, 0);
|
||||
if (key > 0 && (uint8_t)key == C('S')) {
|
||||
processctl(app, PCTL_KILL, 0, 0, 0);
|
||||
proc_kill(app);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ void do_mode_interactive(void) {
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
PID = processctl(-1, PCTL_GETPID, 0, 0, 0);
|
||||
PID = proc_getpid();
|
||||
|
||||
set_config();
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ bool rt_do(Token *tks) {
|
||||
args1[ARRLEN(prepended_args)] = umalloc(PROC_ARG_MAX);
|
||||
string_strcpy(args1[ARRLEN(prepended_args)], s);
|
||||
|
||||
int32_t app = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)args1, ARRLEN(prepended_args)+1);
|
||||
int32_t app = proc_spawn("base:/bin/tb", args1, ARRLEN(prepended_args)+1);
|
||||
if (app < 0) {
|
||||
ok = false;
|
||||
goto done;
|
||||
@ -123,9 +123,9 @@ bool rt_do(Token *tks) {
|
||||
ipc_pipemake(10);
|
||||
ipc_pipeconnect(app, 0, PID, 10);
|
||||
|
||||
processctl(app, PCTL_RUN, 0, 0, 0);
|
||||
proc_run(app);
|
||||
|
||||
while (processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
||||
while (proc_pollstate(app) != 4) {
|
||||
int32_t r;
|
||||
char buf[100];
|
||||
string_memset(buf, 0, sizeof(buf));
|
||||
|
||||
Reference in New Issue
Block a user