all repos — kuro @ 4ed8a026bb214e9ee19387226dbd51d9bc63ad74

multiwindow text editor thing for plan9 with simple client VM and 9p interface

cleanup, fix ctl write
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZbngZgAKCRBohAcXSWbK
8+GdAPsF8KrLmhNLE49dvFXY0kfm82DQNRt68pG0G8rSP1s7GwD+JoxwAiAuZflj
cVItVEM67FNicLztfnyL3SH2izY8rAM=
=W4oM
-----END PGP SIGNATURE-----
commit

4ed8a026bb214e9ee19387226dbd51d9bc63ad74

parent

5040da40fc3dfc7f26527ba52a866e960eb5f83a

8 files changed, 38 insertions(+), 132 deletions(-)

jump to
M 9port.mkfile9port.mkfile

@@ -8,7 +8,6 @@ srv.$O\

client.$O\ util.$O\ node.$O\ - nodetable.$O\ HFILES=dat.h\ fns.h\
M dat.hdat.h

@@ -10,7 +10,9 @@ #include <mouse.h>

#include <keyboard.h> typedef enum { - CTL = 1 + CTL = 0, + CPU = 1, + MEMORY = 2 } FileType; typedef enum {

@@ -87,16 +89,4 @@ Channel* cpu; /* chan(Instruction) */

Handler* handlers; KuroMemory* memory; Channel* status; /* chan(WidowStatus) */ -} Node; - -typedef struct NodeRef NodeRef; - -struct NodeRef { - int fd[2]; - uvlong id; - NodeRef* next; -}; - -typedef struct { - NodeRef* data[256]; -} NodeTable; +} Node;
M fns.hfns.h

@@ -3,14 +3,11 @@ char* strcsw(char* s, char a, char b);

char* uvlong_to_hex(uvlong input, char* buf); int ensure(char* path); -void start_9p(); +void start_9p(Node* n); void kuro9p_set_mtpt(char* mtpt); void kuro9p_write(char* path, char* data, int len); char* kuro9p_read(char* path, char* buf, int len); - -void nodetbl_add(NodeTable* self, NodeRef* node); -void nodetbl_del(NodeTable* self, uvlong id); void node_setup(Node* self, Handler* handlers, KuroMemory* memory); void node_execute(Node* self);
M kuro.ckuro.c

@@ -3,8 +3,9 @@ #include "fns.h"

static char* mtpt; -int threadmaybackground(void) { - return 1; +void srvthread(void* arg) { + Node* vm = (Node*)arg; + start_9p(vm); } void threadmain(int argc, char **argv)

@@ -13,15 +14,14 @@ mtpt = getenv("KURO_MTPT");

if (mtpt == nil) { sysfatal("KURO_MTPT not set"); } - - kuro9p_set_mtpt(mtpt); print("KURO_MTPT=%s\n", mtpt); - ARGBEGIN{ + /* ARGBEGIN{ - }ARGEND + }ARGEND */ - threadcreate(start_9p, nil, 4096); - supervise_node(create_node(argc > 1 ? argv[0] : nil)); + Node* vm = create_node(argc > 0 ? argv[0] : nil); + proccreate(srvthread, (void*)vm, 4096); + supervise_node(vm); threadexitsall(0); }
M mkfilemkfile

@@ -9,7 +9,6 @@ srv.$O\

client.$O\ util.$O\ node.$O\ - nodetable.$O\ HFILES=dat.h\ fns.h\
M node.cnode.c

@@ -37,7 +37,6 @@

Node* create_node(char* filename) { initdraw(nil, nil, "kuro"); - unlockdisplay(display); KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory)); Node* node = (Node*)malloc(sizeof(Node));

@@ -66,7 +65,7 @@ int resize[2];

WindowStatus status; Rune kbd; - if ((mctl = initmouse(nil, screen)) == nil) { + if ((mctl = initmouse(nil, self->memory->img)) == nil) { sysfatal("couldn't initialize mctl"); } if ((kctl = initkeyboard(nil)) == nil) {

@@ -84,20 +83,20 @@

for (;;) { switch (alt(alts)) { case PORT_MOUSE: - print("got a mouse event"); + print("got a mouse event\n"); break; case PORT_RESIZE: /*if (getwindow(display, Refnone) < 0) sysfatal("couldn't resize");*/ - print("got a resize event"); + print("got a resize event\n"); break; case PORT_KBD: - print("got a keypress"); + print("got a keypress\n"); break; case PORT_STATUS: switch(status) { case KURO_QUITS: - print("VM died - let's clean up the data"); + print("VM died - let's clean up the data\n"); goto cleanup; default: break;
D nodetable.c

@@ -1,42 +0,0 @@

-#include "dat.h" -#include "fns.h" - -void nodetbl_add(NodeTable* self, NodeRef* node) { - int i; - NodeRef* n; - if (self && node) { - i = (int)(node->id%256); - n = self->data[i]; - if (n && n->next) { - n = n->next; - } - if (n) { - n->next = node; - } else { - n = node; - } - } -} - -void nodetbl_del(NodeTable* self, uvlong id) { - NodeRef* n; - NodeRef* nprev; - - if (self) { - for(int i = 0; i <= 255; i++) { - n = self->data[i]; - - while (n && n->id != id && n->next) { - nprev = n; - n = n->next; - } - if (n->id == id) { - if (nprev) { - nprev->next = n->next; - } - free(n); - break; - } - } - } -}
M srv.csrv.c

@@ -1,17 +1,7 @@

#include "dat.h" #include "fns.h" -static NodeTable nodes; -static QLock id_lock; - -static uvlong get_next_id(void) { - static uvlong id = 0; - uvlong next; - qlock(&id_lock); - next = ++id; - qunlock(&id_lock); - return next; -} +static Node* node; Aux* create_aux(FileType t) { Aux* self = (Aux*)malloc(sizeof(Aux));

@@ -35,42 +25,13 @@ void kuro_read(Req* r) {

Aux* a = (Aux*)r->fid->file->aux; switch (a->type) { case CTL: + case MEMORY: default: respond(r, nil); break; } } - -void new_window(char* filename, int new) { - int rw_fd[2]; - char client_fd[32] = {0}; - char client_id[32] = {0}; - uvlong id; - NodeRef* noderef; - - pipe(rw_fd); - id = get_next_id(); - - noderef = (NodeRef*)malloc(sizeof(NodeRef)); - noderef->id = id; - noderef->fd[0] = rw_fd[0]; - noderef->fd[1] = rw_fd[1]; - nodetbl_add(&nodes, noderef); - - sprintf(client_fd, "%d", rw_fd[1]); - sprintf(client_id, "%d", id); - - rfork(RFNAMEG); - char* a[] = { "kuro", "-p", client_fd, "-i", client_id, new ? "-n" : filename, new ? filename : 0, 0 }; - exec("./kuro", a); -} - -void newwindowthread(void* arg) { - char* filename = (char*)arg; - new_window(filename, 1); -} - void write_ctl(Req* r) { char cmd[16] = {0}; char* c = r->ifcall.data;

@@ -92,13 +53,11 @@ /* diagnostics for now */

print("cmd: %s\n", cmd); print("arg: %s\n", c); - if (strequ(cmd, "new")) { - threadcreate(newwindowthread, c, 256); - respond(r, nil); - } else { + print("unknown command...\n"); + r->ofcall.count = r->ifcall.count; respond(r, nil); - } + } void kuro_write(Req* r) {

@@ -107,6 +66,7 @@ switch (a->type) {

case CTL: write_ctl(r); break; + case CPU: default: respond(r, nil); break;

@@ -119,21 +79,25 @@ sprintf(buf, "%s/%d", parent, pid);

return buf; } -void start_9p() { +void start_9p(Node* n) { + node = n; char* mtpt_base = getenv("KURO_MTPT"); - if (mtpt_base) { - char mtpt[256] = "TESTING LIKE THIS SHOULD NOT BE NECESSARY; AYEYEYEYEYE"; + + if (mtpt_base && n) { + char mtpt[256] = {0}; + mk_mtpt(mtpt_base, mtpt); - mk_mtpt(mtpt_base, mtpt); - int i = ensure(mtpt); - print("%d result of ensure\n", i); - print("%s\n", mtpt); + if (ensure(mtpt)) { + print("kuro fsys: %s\n", mtpt); + } else { + sysfatal("couldn't create fsys at %s\n", mtpt); + } + Srv srv = { .read = kuro_read, .write = kuro_write }; Tree* tree = alloctree(nil, nil, DMDIR | 0777, fs_destroy_file); srv.tree = tree; - closefile(createfile(tree->root, "ctl", nil, DMAPPEND | 0600, create_aux(CTL))); - closefile(tree->root); - /* TODO: figure out how to kill the server cleanly so we don't need MREPL */ + closefile(createfile(tree->root, "ctl", nil, 0600, create_aux(CTL))); + threadpostmountsrv(&srv, nil, mtpt, MREPL | MCREATE); threadexits(0); }