Simple IPC with pipes
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include "errors.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "bootinfo/bootinfo.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
|
||||
#define PROC_REAPER_FREQ 30
|
||||
|
||||
@ -162,6 +163,9 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
||||
proc->state = PROC_READY;
|
||||
proc->pid = pids++;
|
||||
|
||||
proc->pipes[0] = dlmalloc(sizeof(IpcPipe));
|
||||
ipc_pipeinit(proc->pipes[0]);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
@ -201,6 +205,14 @@ void proc_reaper(void) {
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
|
||||
if (zombie->pipes[i] != NULL) {
|
||||
dlfree(zombie->pipes[i]);
|
||||
ipc_pipefree(zombie->pipes[i]);
|
||||
zombie->pipes[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pmm_free((uintptr_t)(zombie->platformdata.kstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
|
||||
|
||||
if (!zombie->kern) {
|
||||
@ -278,16 +290,31 @@ void proc_status(void) {
|
||||
}
|
||||
}
|
||||
|
||||
Proc *init_proc = NULL;
|
||||
#define PIPEREADER_BUF_SIZE 100
|
||||
|
||||
void proc_init_pipereader(void) {
|
||||
char buf[PIPEREADER_BUF_SIZE];
|
||||
hal_memset(buf, 0, sizeof(buf));
|
||||
for (;;) {
|
||||
int32_t read = ipc_piperead(init_proc->pipes[0], buf, PIPEREADER_BUF_SIZE);
|
||||
kprintf("%.*s", read, buf);
|
||||
hal_memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
}
|
||||
|
||||
void proc_init(void) {
|
||||
spinlock_init(&PROCS.spinlock);
|
||||
PROCS.procs = NULL;
|
||||
|
||||
Proc *idle = proc_spawnkern(&proc_idle, "kIDLE");
|
||||
Proc *idle = proc_spawnkern(&proc_idle, "k-idle");
|
||||
proc_register(idle);
|
||||
PROCS.current = idle;
|
||||
|
||||
/* proc_register(proc_spawnkern(&proc_status, "status")); */
|
||||
proc_register(proc_spawnuser("base", "/bin/init"));
|
||||
init_proc = proc_spawnuser("base", "/bin/init");
|
||||
proc_register(init_proc);
|
||||
proc_register(proc_spawnkern(&proc_init_pipereader, "k-init-pipereader"));
|
||||
|
||||
hal_switchproc(&PROCS.current->platformdata.trapframe, (void *)PROCS.current->platformdata.cr3);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "bitmap/bitmap.h"
|
||||
#include "vfs/vfs.h"
|
||||
#include "ipc/pipe/pipe.h"
|
||||
|
||||
#define PROC_NAME_MAX 0x100
|
||||
|
||||
@ -13,7 +14,9 @@
|
||||
#define PROC_STACKSIZE (PROC_STACKBLOCKS * BITMAP_BLOCK_SIZE)
|
||||
|
||||
#define PROC_MAX 0x100 // max amount of processes
|
||||
#define PROC_VFSHANDLES_MAX 0x80
|
||||
|
||||
#define PROC_VFSHANDLES_MAX 0x80
|
||||
#define PROC_PIPEHANDLES_MAX 0x20
|
||||
|
||||
typedef struct {
|
||||
IntrStackFrame trapframe;
|
||||
@ -42,6 +45,8 @@ typedef struct Proc {
|
||||
|
||||
VfsObj *vobjs[PROC_VFSHANDLES_MAX];
|
||||
uint64_t vobjcnt;
|
||||
|
||||
IpcPipe *pipes[PROC_PIPEHANDLES_MAX];
|
||||
} Proc;
|
||||
|
||||
typedef struct {
|
||||
|
Reference in New Issue
Block a user