summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-11-28 18:56:18 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-11-28 18:56:18 -0500
commit9bbab96664a53a0290e402182aadf691d6ed52d5 (patch)
tree8f839c03270ca564dfac4fb12e16ee4c0b9e8f19
parentb0e7de879227c8bd9f01dc57ea28aef412a7fb44 (diff)
downloadmodit-slim-9bbab96664a53a0290e402182aadf691d6ed52d5.tar.gz
modit-slim-9bbab96664a53a0290e402182aadf691d6ed52d5.tar.bz2
modit-slim-9bbab96664a53a0290e402182aadf691d6ed52d5.zip
fix rpc vlv mangling; fix message bypass; add simple vfs function
-rw-r--r--app/init/ird.c25
-rw-r--r--app/init/rpcsrv.c75
-rw-r--r--app/init/scheduler.c63
-rw-r--r--app/init/scheduler.h8
-rw-r--r--app/vfs/main.c30
m---------kernel0
-rw-r--r--lib/c/stdio/vsnprintf.c39
-rw-r--r--lib/c/stdlib/heap.c2
-rw-r--r--lib/c/string/strdup.c10
-rw-r--r--lib/modit/ipc/msg_recv.c5
-rw-r--r--lib/modit/pid/detach.c16
-rw-r--r--lib/rpc/call.c9
-rw-r--r--lib/rpc/export.c8
-rw-r--r--lib/rpc/getarg.c37
-rw-r--r--lib/rpc/handle.c20
-rw-r--r--root/include/rpc/api.h11
-rw-r--r--root/include/string.h1
-rw-r--r--root/include/sys/pid.h9
-rw-r--r--root/include/vfs/vfs.h5
19 files changed, 272 insertions, 101 deletions
diff --git a/app/init/ird.c b/app/init/ird.c
index 260df48..3ca39ab 100644
--- a/app/init/ird.c
+++ b/app/init/ird.c
@@ -2,10 +2,13 @@
#include "scheduler.h"
#include <sys/mem.h>
#include <sys/cid.h>
+#include <sys/pid.h>
+#include <rpc/api.h>
#include <modit/syscall.h>
#include <modit/task.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
DEFN_SYSCALL(initrd, SYSCALL_INITRD_GET)
DEFN_SYSCALL(spawn, SYSCALL_SPAWN)
@@ -55,7 +58,7 @@ tar_parse(uintptr_t addr)
initrd_files[filei].size = filesz;
initrd_files[filei].data = (char*)((uintptr_t)block + TAR_BLOCKSIZE);
- printf("FILE %-16s SIZE %8i bytes\n", block->name, filesz);
+ printf("FILE %-16s SIZE %8i bytes\n", block->name, (int)filesz);
blocks += fileblocks + 1;
filei++;
@@ -72,7 +75,9 @@ ird_get(const char *name)
return NULL;
}
-static void
+RPC_IMPORT(scheduler_addprocess)
+
+static pid_t
ird_spawn(const char *prg)
{
struct initrd_file *ldfile = ird_get("bin/ld");
@@ -81,18 +86,17 @@ ird_spawn(const char *prg)
//Standard spawn call requires vfs and drivers; we need to do this manually
//These programs need to be able to run without environment variables
- printf("Preparing to spawn %s\n", prg);
uint8_t *ldstk = malloc(prgfile->size + 2);
memset(ldstk, 0, 2);
memcpy(&ldstk[2], prgfile->data, prgfile->size);
struct syscall_exec_data spawndata = {
- .program = ldfile->data,
+ .program = (uint8_t*)ldfile->data,
.programsz = ldfile->size,
.stack = ldstk,
.stacksz = prgfile->size + 2 };
- cid_t prgcid = _syscall_spawn(&spawndata);
- scheduler_addproc(1, prgcid, prg);
+ cid_t prgid = _syscall_spawn(&spawndata);
+ return RPC_CALL(scheduler_addprocess, prgid, prg);
}
void
@@ -105,9 +109,12 @@ ird_setup(void)
//Detach ird server from init
cid_t icid = fork_ghost();
if(icid != 0) {
- scheduler_addctx(1, icid, 0);
+ scheduler_addproc(proctree_root, icid, "initrd server");
+ swapto(icid);
return;
}
+ detach_ghost();
+ rpcc = 0;
_syscall_initrd(&data);
@@ -119,5 +126,7 @@ ird_setup(void)
}
tar_parse(tar_start);
- ird_spawn("bin/vfs");
+ pid_t vfspid = ird_spawn("bin/vfs");
+
+ rpc_handle(0);
}
diff --git a/app/init/rpcsrv.c b/app/init/rpcsrv.c
index 015d96a..b4ba1db 100644
--- a/app/init/rpcsrv.c
+++ b/app/init/rpcsrv.c
@@ -3,6 +3,7 @@
#include "rpc/rpc.h"
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
struct rpcsrv_entry {
char *name;
@@ -10,7 +11,7 @@ struct rpcsrv_entry {
};
static struct rpcsrv_entry *srv_entries;
-static size_t srv_entc;
+static size_t srv_entc = 0;
RPCFUNC*
rpcs_find(const char *name)
@@ -41,8 +42,8 @@ rpcs_export_internal(const char *name, size_t funclen, RPCFUNC *func) {
if(exists) return -1;
//Make room for new rpc entry
- struct rpcsrv_entry *tmp = malloc(sizeof(struct rpcsrv_entry) * (rpcc + 1));
- if(srv_entries != NULL) memcpy(tmp, srv_entries, sizeof(struct rpcsrv_entry) * rpcc);
+ struct rpcsrv_entry *tmp = malloc(sizeof(struct rpcsrv_entry) * (srv_entc + 1));
+ if(srv_entries != NULL) memcpy(tmp, srv_entries, sizeof(struct rpcsrv_entry) * srv_entc);
free(srv_entries);
srv_entries = tmp;
@@ -50,12 +51,13 @@ rpcs_export_internal(const char *name, size_t funclen, RPCFUNC *func) {
exists = malloc(funclen);
memcpy(exists, func, funclen);
- srv_entries[rpcc].func = exists;
- srv_entries[rpcc].name = malloc(strlen(name));
- strcpy(srv_entries[rpcc].name, name);
- rpcc++;
+ srv_entries[srv_entc].func = exists;
+ srv_entries[srv_entc].name = malloc(strlen(name));
+ strcpy(srv_entries[srv_entc].name, name);
+ srv_entc++;
- return rpcc - 1;
+ printf("Added rpcfunc %s handled by %i to list\n", name, func->handler);
+ return srv_entc - 1;
}
@@ -64,7 +66,7 @@ rpcs_export(struct rpc_args *args)
{
char *name = rpc_getarg(args, char*);
struct rpc_vlvpack *funcpk = rpc_getarg(args, struct rpc_vlvpack*);
-
+
return rpcs_export_internal(name, funcpk->len, (RPCFUNC*)funcpk->data);
}
@@ -74,10 +76,13 @@ rpcs_scheduler_addctx(struct rpc_args *args)
cid_t pntid = args->sender;
cid_t id = rpc_getarg(args, cid_t);
+ struct context *test = scheduler_findctx(proctree_root, id);
+ if(test != NULL) return -1;
+
struct context *ctx = scheduler_findctx(proctree_root, pntid);
struct process *parent = ctx->parent;
- return scheduler_addctx(parent->pid, id, 0);
+ return scheduler_addctx(parent, id, 0);
}
intmax_t
@@ -87,10 +92,33 @@ rpcs_scheduler_addproc(struct rpc_args *args)
cid_t ctxid = rpc_getarg(args, cid_t);
char *name = rpc_getarg(args, char*);
+ struct context *test = scheduler_findctx(proctree_root, ctxid);
+ if(test != NULL) return -1;
+
struct context *ctx = scheduler_findctx(proctree_root, pntid);
struct process *parent = ctx->parent;
- return scheduler_addproc(parent->pid, ctxid, name);
+ return scheduler_addproc(parent, ctxid, name);
+}
+
+intmax_t
+rpcs_scheduler_getpid(struct rpc_args *args)
+{
+ cid_t senderid = args->sender;
+ struct context *ctx = scheduler_findctx(proctree_root, senderid);
+ return ctx->parent->pid;
+}
+
+intmax_t
+rpcs_scheduler_detach(struct rpc_args *args)
+{
+ cid_t ctxid = args->sender;
+ char *name = rpc_getarg(args, char*);
+
+ struct context *ctx = scheduler_findctx(proctree_root, ctxid);
+ struct process *prc = ctx->parent;
+
+ return scheduler_detach(prc, ctx, name);
}
void
@@ -99,16 +127,31 @@ rpcsrv_setup(void)
srv_entries = NULL;
srv_entc = 0;
- rpc_export_internal(rpc_define(0, 0, "s", 'v'), rpcs_import);
- rpc_export_internal(rpc_define(0, 1, "sv", 'i'), rpcs_export);
+ RPCFUNC *tmpfunc = rpc_define(0, 0, "s", 'v'); //import rpc entry (str[name]) => vlv[rpcfunc[return]]
+ rpcs_export_internal("rpcsrv_import", sizeof(RPCFUNC) + 2, tmpfunc);
+ rpc_export_internal(tmpfunc, rpcs_import);
+ free(tmpfunc);
- RPCFUNC *tmpfunc = rpc_define(0, 0, "i", 'i'); //register context (int[ctxid]) => int[success]
- rpcs_export_internal("scheduler_addcontext", sizeof(RPCFUNC) + 3, tmpfunc);
+ tmpfunc = rpc_define(0, 1, "sv", 'i');
+ rpcs_export_internal("rpcsrv_export", sizeof(RPCFUNC) + 3, tmpfunc);
+ rpc_export_internal(tmpfunc, rpcs_export);
+ free(tmpfunc);
+
+ tmpfunc = rpc_define(0, 2, "i", 'i'); //register context (int[ctxid]) => cid_t[contextid]
+ rpcs_export_internal("scheduler_addcontext", sizeof(RPCFUNC) + 2, tmpfunc);
rpc_export_internal(tmpfunc, rpcs_scheduler_addctx);
free(tmpfunc);
- tmpfunc = rpc_define(0, 0, "is", 'i'); //register context (int[ctxid], str[arg0]) => int[success]
+ tmpfunc = rpc_define(0, 3, "is", 'i'); //register context (int[ctxid], str[arg0]) => pid_t[processid]
rpcs_export_internal("scheduler_addprocess", sizeof(RPCFUNC) + 3, tmpfunc);
rpc_export_internal(tmpfunc, rpcs_scheduler_addproc);
+
+ tmpfunc = rpc_define(0, 4, "", 'i'); //get context's process id (void) => pid_t[processid]
+ rpcs_export_internal("scheduler_getpid", sizeof(RPCFUNC) + 1, tmpfunc);
+ rpc_export_internal(tmpfunc, rpcs_scheduler_getpid);
+
+ tmpfunc = rpc_define(0, 5, "s", 'i'); //detach context from process (str[name]) => pid_t[processid]
+ rpcs_export_internal("scheduler_detach", sizeof(RPCFUNC) + 2, tmpfunc);
+ rpc_export_internal(tmpfunc, rpcs_scheduler_detach);
free(tmpfunc);
}
diff --git a/app/init/scheduler.c b/app/init/scheduler.c
index f024f81..4476536 100644
--- a/app/init/scheduler.c
+++ b/app/init/scheduler.c
@@ -40,10 +40,9 @@ scheduler_findctx(struct process *base, cid_t id)
}
int
-scheduler_addctx(pid_t pid, cid_t id, uint8_t p)
+scheduler_addctx(struct process *parent, cid_t id, uint8_t p)
{
mutex_take(&proctree_mutex);
- struct process *parent = scheduler_findproc(proctree_root, pid);
if(scheduler_findctx(proctree_root, id) != NULL) {
mutex_leave(&proctree_mutex);
return -1;
@@ -65,28 +64,26 @@ scheduler_addctx(pid_t pid, cid_t id, uint8_t p)
parent->contexts = new;
mutex_leave(&proctree_mutex);
- return 0;
+ return new->cid;
}
int
-scheduler_addproc(pid_t pntid, cid_t cid, const char *name)
+scheduler_addproc(struct process *parent, cid_t cid, const char *name)
{
mutex_take(&proctree_mutex);
- struct process *parent = scheduler_findproc(proctree_root, pntid);
if(scheduler_findctx(proctree_root, cid) != NULL) {
mutex_leave(&proctree_mutex);
return -1;
}
if(parent == NULL) parent = proctree_root;
- struct process *new = malloc(sizeof(struct process) + strlen(name));
+ struct process *new = malloc(sizeof(struct process));
new->pid = nprocid++;
new->children = NULL;
- strcpy(new->name, name);
+ new->name = strdup(name);
new->next = parent->children;
parent->children = new;
- mutex_leave(&proctree_mutex);
new->contexts = malloc(sizeof(struct context));
new->contexts->cid = cid;
@@ -100,13 +97,54 @@ scheduler_addproc(pid_t pntid, cid_t cid, const char *name)
node->next = list_tail;
list_tail = node;
- return 0;
+ mutex_leave(&proctree_mutex);
+ return new->pid;
+}
+
+int
+scheduler_detach(struct process *process, struct context *context, const char *name)
+{
+ //Check if context is only one in process
+ int pcc = 0;
+ for(struct context *ctx = process->contexts; ctx; ctx = ctx->next) pcc++;
+ if(pcc == 1) {
+ free(process->name);
+ process->name = strdup(name);
+ return process->pid;
+ }
+ mutex_take(&proctree_mutex);
+ //Remove context from process context list
+ if(process->contexts == context) {
+ process->contexts = context->next;
+ }else {
+ for(struct context *ctx = process->contexts; ctx; ctx = ctx->next) {
+ if(ctx->next == context) {
+ ctx->next = context->next;
+ break;
+ }
+ }
+ }
+ context->next = NULL;
+
+ //Create new process for context
+ struct process *new = malloc(sizeof(struct process));
+ new->pid = nprocid++;
+
+ new->next = process->children;
+ process->children = new;
+
+ new->children = NULL;
+ new->contexts = context;
+ new->name = strdup(name);
+
+ mutex_leave(&proctree_mutex);
+ return new->pid;
}
void
scheduler_loop(void)
{
- settimer(20);
+ settimer(PROC_PRIORITY_MUL);
//swapto(1);
while(1) {
if(list_current == NULL) list_current = list_tail;
@@ -124,13 +162,12 @@ scheduler_loop(void)
void
scheduler_setup(void)
{
- const char *initname = "/bin/init";
- proctree_root = malloc(sizeof(struct process) + strlen(initname));
+ proctree_root = malloc(sizeof(struct process));
proctree_root->pid = nprocid++;
proctree_root->next = NULL;
proctree_root->contexts = NULL;
proctree_root->children = NULL;
- strcpy(proctree_root->name, initname);
+ proctree_root->name = "init";
struct context *initctx = malloc(sizeof(struct context));
initctx = initctx;
diff --git a/app/init/scheduler.h b/app/init/scheduler.h
index d48562b..e46e7d0 100644
--- a/app/init/scheduler.h
+++ b/app/init/scheduler.h
@@ -20,13 +20,12 @@ struct context
};
struct process {
+ char *name;
pid_t pid;
struct process *next;
struct context *contexts;
struct process *children;
-
- char name[];
};
struct clnode { //Round list
@@ -39,8 +38,9 @@ extern struct process *proctree_root;
struct process *scheduler_findproc(struct process *base, pid_t id);
struct context *scheduler_findctx(struct process *base, cid_t id);
-int scheduler_addctx(pid_t pid, cid_t id, uint8_t p);
-int scheduler_addproc(pid_t pntid, cid_t id, const char *name);
+int scheduler_addctx(struct process *parent, cid_t id, uint8_t p);
+int scheduler_addproc(struct process *parent, cid_t id, const char *name);
+int scheduler_detach(struct process *process, struct context *context, const char *name);
/* Assumes init is CID 1 */
void scheduler_setup(void);
diff --git a/app/vfs/main.c b/app/vfs/main.c
index 61a24bf..eb70cc0 100644
--- a/app/vfs/main.c
+++ b/app/vfs/main.c
@@ -1,8 +1,34 @@
#include <stdio.h>
+#include <string.h>
+#include <stddef.h>
+#include "rpc/rpc.h"
+#include "vfs/vfs.h"
+
+struct vfs_file *vfs_root;
+
+intmax_t
+rpc_vfs_mount(struct rpc_args *args)
+{
+ char *path = rpc_getarg(args, char*);
+ struct rpc_vlvpack *pack = rpc_getarg(args, struct rpc_vlvpack*);
+ struct vfs_file *file = (struct vfs_file*)pack->data;
+
+ if(pack->len < sizeof(struct vfs_file)) {
+ printf("ERROR: vfs_file passed to vfs_mount is too small!\n");
+ return -1;
+ }
+
+
+}
int
main(int argc, char **argv)
{
- printf("Hello, World!\n");
- while(1);
+ (void)argc;
+ (void)argv;
+
+ printf("Starting VFS server\n");
+ rpc_export(rpc_define(0, 0, VFS_RPC_MOUNT_ARGS, VFS_RPC_MOUNT_RET), "vfs_mount", rpc_vfs_mount);
+
+ rpc_handle(0);
}
diff --git a/kernel b/kernel
-Subproject 255e2d57b08236051b659323865b6ce2772071f
+Subproject c4f27dbf1d2a257e08087e9a1ce932579f9dc72
diff --git a/lib/c/stdio/vsnprintf.c b/lib/c/stdio/vsnprintf.c
index edc437b..3be4dbb 100644
--- a/lib/c/stdio/vsnprintf.c
+++ b/lib/c/stdio/vsnprintf.c
@@ -7,20 +7,23 @@ static int
__vsnprintf_itoa(char *term, intmax_t val, int base)
{
int size = 0;
- uintmax_t dec = 1;
- bool neg = false;
- if(val < 0) {
- val = 0 - val;
+ uintmax_t d = 1;
+ if(val == 0) {
+ if(term != NULL) *term-- = '0';
+ return 1;
}
- while(dec <= val + 1){
- int digit = (val / dec) % base;
- if(term != NULL){
- *term = digit > 10 ? (digit - 10) + 'a' : digit + '0';
- term--;
+
+ while(d <= val + 1)
+ {
+ int c = (val / d) % base;
+ if(term != NULL) {
+ *term-- = (c > 9 ? ('A' + (c - 10)) : '0' + c);
}
- dec *= base;
+ d *= base;
size++;
}
+
+
return size;
}
@@ -40,7 +43,6 @@ vsnprintf(
va_list ap)
{
size_t wrsize = 0;
- bool truncated = false;
for(const char *c = format; *c && size > 1; c++, size--) {
if(*c != '%') {
str[wrsize++] = *c;
@@ -95,19 +97,28 @@ vsnprintf(
//FALLTHROUGH
case 'i': {
intmax_t val = va_arg(ap, intmax_t);
+ if(val < 0) val = 0 - val;
+ sign = sign | (varsign & (val < 0));
int pwidth = __vsnprintf_itoa(NULL, val, base);
int bufwidth = pwidth > minwidth ? pwidth : minwidth; //Make sure intstr will fit in buffer
- int leftdist = leftadj == false ? bufwidth - 1 : (zero ? bufwidth - 1 : pwidth - 1); //Horrible left-align shenanigans
- if(val < 0 || sign) bufwidth++; //Make room for sign
+ int leftdist = leftadj == false ?
+ bufwidth - 1 :
+ (zero ? bufwidth - 1 : pwidth - 1); //Horrible left-align shenanigans
+ if(sign) bufwidth++; //Make room for sign
char buffer[bufwidth];
memset(buffer, padchr, bufwidth);
- if(val < 0 || sign) //Set sign at top of buffer
+ if(sign) //Set sign at top of buffer
buffer[0] = val > 0 ? '+' : '-';
__vsnprintf_itoa(&buffer[leftdist], val, base); //Write intstr to buffer starting at end
if(upper) strupp(buffer);
wrsize += __vsnprintf_copytill(&str[wrsize], buffer, bufwidth, size); //Copy until reaching either bufwidth or size
size -= bufwidth;
} break;
+ case 'c': {
+ int val = va_arg(ap, int);
+ str[wrsize++] = (char)val;
+ size--;
+ } break;
case 's': {
const char *val = va_arg(ap, const char*);
int vallen = strlen(val) - 1;
diff --git a/lib/c/stdlib/heap.c b/lib/c/stdlib/heap.c
index e1e2ea9..54b8db6 100644
--- a/lib/c/stdlib/heap.c
+++ b/lib/c/stdlib/heap.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "sys/alloc.h"
+#include "sys/mem.h"
#include "sys/lock.h"
#include <stdint.h>
diff --git a/lib/c/string/strdup.c b/lib/c/string/strdup.c
new file mode 100644
index 0000000..9a29022
--- /dev/null
+++ b/lib/c/string/strdup.c
@@ -0,0 +1,10 @@
+#include <string.h>
+#include <stdlib.h>
+
+char*
+strdup(const char *s)
+{
+ char *new = malloc(strlen(s) + 1);
+ strcpy(new, s);
+ return new;
+}
diff --git a/lib/modit/ipc/msg_recv.c b/lib/modit/ipc/msg_recv.c
index 27dcf55..551c2f1 100644
--- a/lib/modit/ipc/msg_recv.c
+++ b/lib/modit/ipc/msg_recv.c
@@ -10,11 +10,12 @@ msg_recv(void)
{
struct syscall_message_data data = { .buffer = NULL };
size_t len = _syscall_message_recv(&data);
- int r = 0;
MESSAGE *msg = malloc(sizeof(MESSAGE) + len);
data.buffer = msg->data;
- r = _syscall_message_recv(&data);
+
+ int r = _syscall_message_recv(&data);
+ if(r != 0) return NULL;
msg->sender = data.tgt;
msg->len = len;
diff --git a/lib/modit/pid/detach.c b/lib/modit/pid/detach.c
new file mode 100644
index 0000000..68fb34e
--- /dev/null
+++ b/lib/modit/pid/detach.c
@@ -0,0 +1,16 @@
+#include <sys/pid.h>
+#include <modit/syscall.h>
+
+DEFN_SYSCALL(detach, SYSCALL_DETACH)
+
+void
+detach_ghost(void)
+{
+ _syscall_detach(NULL);
+}
+
+pid_t
+detach(const char *name)
+{
+ return 0;
+}
diff --git a/lib/rpc/call.c b/lib/rpc/call.c
index a589e1e..5536711 100644
--- a/lib/rpc/call.c
+++ b/lib/rpc/call.c
@@ -2,6 +2,7 @@
#include "rpc/api.h"
#include "sys/ipc.h"
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
int
@@ -13,11 +14,11 @@ marshall(const char *fmt, char *buffer, va_list ap)
intmax_t vallen;
switch(*c) {
case 'b':
- val = va_arg(ap, char);
+ val = va_arg(ap, int);
vallen = 1;
break;
case 'w':
- val = va_arg(ap, short);
+ val = va_arg(ap, int);
vallen = 2;
break;
case 'i':
@@ -36,10 +37,10 @@ marshall(const char *fmt, char *buffer, va_list ap)
size += vallen;
}else if(*c == 'v') {
vallen = va_arg(ap, size_t);
- val = (intmax_t)va_arg(ap, unsigned char*);
+ unsigned char *vlval = va_arg(ap, unsigned char*);
if(buffer != NULL) {
memcpy(&(buffer[size]), &vallen, sizeof(size_t));
- memcpy(&(buffer[size + sizeof(size_t)]), (void*)val, vallen);
+ memcpy(&(buffer[size + sizeof(size_t)]), vlval, vallen);
}
size += vallen + sizeof(size_t);
}else{
diff --git a/lib/rpc/export.c b/lib/rpc/export.c
index 9cd8170..b9bb3a3 100644
--- a/lib/rpc/export.c
+++ b/lib/rpc/export.c
@@ -14,12 +14,13 @@ rpc_export(RPCFUNC *func, const char *name, intmax_t (*handler)(struct rpc_args*
rpc_handles = tmp;
//Add new RPCFUNC to handle
- rpc_handles[rpcc].func = func;
+ rpc_handles[rpcc].func = malloc(sizeof(RPCFUNC) + strlen(func->expects));
+ memcpy(rpc_handles[rpcc].func, func, sizeof(RPCFUNC) + strlen(func->expects));
rpc_handles[rpcc].handler = handler;
func->id = rpcc;
//Call init export RPC
- rpc_call(rpc_init_export, name, sizeof(RPCFUNC), func);
+ rpc_call(rpc_init_export, name, sizeof(RPCFUNC) + strlen(func->expects), func);
rpcc++;
}
@@ -33,7 +34,8 @@ rpc_export_internal(RPCFUNC *func, intmax_t (*handler)(struct rpc_args*))
rpc_handles = tmp;
//Add new RPCFUNC to handle
- rpc_handles[rpcc].func = func;
+ rpc_handles[rpcc].func = malloc(sizeof(RPCFUNC) + strlen(func->expects));
+ memcpy(rpc_handles[rpcc].func, func, sizeof(RPCFUNC) + strlen(func->expects));
rpc_handles[rpcc].handler = handler;
func->id = rpcc++;
}
diff --git a/lib/rpc/getarg.c b/lib/rpc/getarg.c
index 3704e10..e2d663d 100644
--- a/lib/rpc/getarg.c
+++ b/lib/rpc/getarg.c
@@ -6,22 +6,27 @@ uintptr_t
__rpc_getarg(struct rpc_args *args)
{
char type = args->func->expects[args->arg++];
- int typelen = 1;
- void *data = args->data;
-
- switch(type) {
- case 'w': typelen = 2; break;
- case 'i': typelen = 4; break;
- case 'q': typelen = 8; break;
- }
if(type == 's') {
- args->data = (void*)((uintptr_t)args->data + strlen((char*)data));
- return (uintptr_t)data;
- }else if(type == 'v') {
- typelen = *((uintptr_t*)data) + sizeof(size_t);
- args->data = (void*)((uintptr_t)args->data + typelen);
- return (uintptr_t)data;
+ char *ret = (char*)args->data;
+ args->data = (void*)((uintptr_t)ret + strlen(ret));
+ return (uintptr_t)ret;
+ }else
+ if(type == 'v') {
+ struct rpc_vlvpack *ret = (struct rpc_vlvpack*)args->data;
+ size_t len = ret->len + sizeof(size_t);
+ args->data = (void*)((uintptr_t)ret + len);
+ return (uintptr_t)ret;
+ }else {
+ size_t vlen = 0;
+ switch(type) {
+ case 'b': vlen = 1; break;
+ case 's': vlen = 2; break;
+ case 'i': vlen = 4; break;
+ case 'q': vlen = 8; break;
+ }
+ uintptr_t ret = ((uintptr_t*)args->data)[0];
+ args->data = (void*)((uintptr_t)args->data + vlen);
+ return ret;
}
- args->data = (void*)((uintptr_t)args->data + typelen);
- return *((uintptr_t*)data);
+ return NULL;
}
diff --git a/lib/rpc/handle.c b/lib/rpc/handle.c
index d82ca19..9b99ae4 100644
--- a/lib/rpc/handle.c
+++ b/lib/rpc/handle.c
@@ -40,17 +40,15 @@ rpc_handle(bool async)
MESSAGE *msg = msg_recv();
struct rpc_message_packet *pkt = (struct rpc_message_packet*)msg_getdata(msg);
- for(rpcid_t i = 0; i < rpcc; i++) {
- struct rpc_handle *handle = &rpc_handles[i];
- if(handle->func->id == pkt->id) {
- args->func = handle->func;
- args->sender = msg_getsender(msg);
- args->arg = 0;
- args->data = pkt->data;
-
- rpc_handle_return(msg, handle->func, handle->handler(args));
- break;
- }
+ if(pkt->id < rpcc) {
+ struct rpc_handle *handle = &rpc_handles[pkt->id];
+
+ args->func = handle->func;
+ args->sender = msg_getsender(msg);
+ args->arg = 0;
+ args->data = pkt->data;
+
+ rpc_handle_return(msg, handle->func, handle->handler(args));
}
free(msg);
}
diff --git a/root/include/rpc/api.h b/root/include/rpc/api.h
index 21262b9..783d23b 100644
--- a/root/include/rpc/api.h
+++ b/root/include/rpc/api.h
@@ -9,17 +9,17 @@
#define RPC_INIT_REGC 2
#define RPC_IMPORT(name) \
-RPCFUNC *rpc_##name = NULL; \
-intmax_t rpc_func_##name (bool wait, ...) { \
- if(rpc_##name == 0) { \
+RPCFUNC *rpc_ ## name = NULL; \
+intmax_t rpc_func_ ## name (bool wait, ...) { \
+ if(rpc_ ## name == 0) { \
/*Get RPC data from init server*/ \
struct rpc_vlvpack *pack = (struct rpc_vlvpack*)rpc_call(rpc_init_import, #name); \
- rpc_##name = (RPCFUNC*)pack->data; \
+ rpc_ ## name = (RPCFUNC*)pack->data; \
} \
va_list ap; \
va_start(ap, wait); \
/*TODO: Ignore result if wait is false */ \
- intmax_t r = rpc_vcall(rpc_##name, ap); \
+ intmax_t r = rpc_vcall(rpc_ ## name, ap); \
va_end(ap); \
return r; \
}
@@ -29,6 +29,5 @@ intmax_t rpc_func_##name (bool wait, ...) { \
extern RPCFUNC *rpc_init_import;
extern RPCFUNC *rpc_init_export;
-extern RPCFUNC *rpc_init_regc;
#endif
diff --git a/root/include/string.h b/root/include/string.h
index b92d69a..5d00c21 100644
--- a/root/include/string.h
+++ b/root/include/string.h
@@ -8,6 +8,7 @@ size_t strlen(const char *s);
int strcmp(const char *a, const char *b);
char *strcpy(char *restrict dest, const char *src);
+char *strdup(const char *s);
char *strchr(const char *s, char c);
char *strrchr(const char *s, char c);
diff --git a/root/include/sys/pid.h b/root/include/sys/pid.h
new file mode 100644
index 0000000..debe4f9
--- /dev/null
+++ b/root/include/sys/pid.h
@@ -0,0 +1,9 @@
+#ifndef SYS_PID_H
+#define SYS_PID_H 1
+
+typedef int pid_t;
+
+void detach_ghost(void);
+pid_t detach(const char *name);
+
+#endif
diff --git a/root/include/vfs/vfs.h b/root/include/vfs/vfs.h
index 7bb0b18..a21562b 100644
--- a/root/include/vfs/vfs.h
+++ b/root/include/vfs/vfs.h
@@ -20,12 +20,14 @@
#define VFS_RPC_WRITE_ARGS "vi"
#define VFS_RPC_WRITE_RET 'i'
+#define VFS_RPC_MOUNT_ARGS "sv"
+#define VFS_RPC_MOUNT_RET 'i'
+
typedef struct vfs_file
{
struct vfs_file *next;
struct vfs_file *children;
- const char *name;
char type;
char flags;
cid_t driver;
@@ -36,6 +38,7 @@ typedef struct vfs_file
RPCFUNC *write;
int dvri;
+ char name[];
} vfs_file_t;
#endif