summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-09-10 19:35:31 +0200
committerAlexis211 <alexis211@gmail.com>2010-09-10 19:35:31 +0200
commita8da6dba7ddc5e3d31a1914597e7b38fbc2d197c (patch)
treefbef80d474e5b9c891e0eb353cfa602acf67fdae /src/library
parentaba6ed4b91aff5d914be11704e34de75bfd4d003 (diff)
downloadTCE-a8da6dba7ddc5e3d31a1914597e7b38fbc2d197c.tar.gz
TCE-a8da6dba7ddc5e3d31a1914597e7b38fbc2d197c.zip
Removed all old object/request/... stuff (that was crap)
Diffstat (limited to 'src/library')
-rw-r--r--src/library/Makefile3
-rw-r--r--src/library/gc/server.c213
-rw-r--r--src/library/gc/syscall.c48
-rw-r--r--src/library/gm/call.c34
-rw-r--r--src/library/gm/call/manager.c44
-rw-r--r--src/library/start.c1
6 files changed, 7 insertions, 336 deletions
diff --git a/src/library/Makefile b/src/library/Makefile
index ac585f5..6e51efd 100644
--- a/src/library/Makefile
+++ b/src/library/Makefile
@@ -1,6 +1,5 @@
Out = grapes.o
-Obj = gc/syscall.o gc/server.o \
- gm/call.o gm/call/manager.o \
+Obj = gc/syscall.o \
gc/mem.o gc/shm.o \
std/mutex.o std/string.o std/stdio.o \
start.o
diff --git a/src/library/gc/server.c b/src/library/gc/server.c
deleted file mode 100644
index 96c3180..0000000
--- a/src/library/gc/server.c
+++ /dev/null
@@ -1,213 +0,0 @@
-#include <gc/server.h>
-#include <gm/method.h>
-#include <gc/mem.h>
-#include <gc/shm.h>
-
-Server procServer;
-static Server* servers = 0;
-
-static method_handler getHandler(Server *o, uint32_t m);
-static struct method_ret checkIfHandles(struct method_data *d);
-static struct method_ret checkIfHandlesMany(struct method_data *d);
-
-void objsrv_init() {
- procServer.id = 0;
- procServer.methods = 0;
- procServer.next = 0;
- procServer.data = 0;
- servers = &procServer;
- srv_addHandler(&procServer, M_HANDLECHECK_BIVV, checkIfHandles);
- srv_addHandler(&procServer, M_HANDLECHECK_BMIV, checkIfHandlesMany);
-}
-
-void srv_handleAll() {
- Server *i = servers;
- while (i) {
- srv_handle(i, HA_ONCE);
- i = i->next;
- }
-}
-
-void srv_handle(Server *o, int act) {
- int i;
-
- if (act == HA_LOOP) {
- while (1) srv_handle(o, HA_WAIT);
- } else {
- struct user_request rq;
- int v = request_get(o->id, &rq, (act == HA_WAIT));
- if (v == 0) {
- method_handler m = getHandler(o, rq.func);
- if (m == 0) {
- if (rq.isBlocking) {
- request_answer(o->id, 0, 0, ME_UNHANDLED);
- }
- } else {
- struct method_data md;
- md.func = rq.func;
- md.blocking = rq.isBlocking;
- md.obj = o;
- md.pid = rq.pid;
- //get parameters
- for (i = 0; i < 3; i++) {
- md.parameters[i].type = (rq.func >> (28 - (2 * i))) & 3;
- switch (md.parameters[i].type) {
- case PT_LONG:
- case PT_OBJDESC:
- md.parameters[i].i = rq.params[i];
- break;
- case PT_SHM: //all the fuss about keepShm only applies to messages.
- md.parameters[i].keepShm = 1; //if local memory or if nothing, do not unmap it
- md.parameters[i].shmsize = rq.shmsize[i];
- if (rq.params[i] == 0) { //TODO : map shm (shm manager) !!!
- void* p = shm_alloc(rq.shmsize[i]);
- md.parameters[i].p = p;
- if (p != 0) {
- request_mapShm(o->id, (size_t)p, i);
- md.parameters[i].keepShm = 0; //we had to map it, so mark it to be unmapped
- }
- } else {
- md.parameters[i].p = (void*)rq.params[i];
- }
- break;
- }
- }
-
- struct method_ret ret = m(&md); //Call method
- if (rq.isBlocking) {
- uint32_t a = 0, b = 0;
- if (ret.type == PT_OBJDESC || ret.type == PT_LONG) a = ret.i;
- if (ret.type == PT_LONGLONG) a = (uint32_t)ret.l, b = (uint32_t)((uint64_t)ret.l >> 32);
- request_answer(o->id, a, b, ret.status);
- for (i = 0; i < 3; i++) {
- if (md.parameters[i].type == PT_SHM && md.parameters[i].p != 0) {
- shm_free(md.parameters[i].p);
- }
- }
- } else {
- for (i = 0; i < 3; i++) {
- if (md.parameters[i].type == PT_SHM && md.parameters[i].keepShm == 0) {
- shm_freeDel(md.parameters[i].p);
- }
- }
- }
- }
- }
- }
-}
-
-void srv_addHandler(Server* o, uint32_t method, method_handler h) {
- struct method_srv *s = malloc(sizeof(struct method_srv));
- s->id = method;
- s->h = h;
- s->next = o->methods;
- o->methods = s;
-}
-
-Server *srv_create() {
- Server *s = malloc(sizeof(Server));
- s->id = object_create();
- s->methods = 0;
- s->data = 0;
- s->next = servers;
- srv_addHandler(s, M_HANDLECHECK_BIVV, checkIfHandles);
- srv_addHandler(s, M_HANDLECHECK_BMIV, checkIfHandlesMany);
- servers = s;
- return s;
-}
-
-Server *srv_get(int descriptor) {
- Server *s = servers;
- while (s) {
- if (s->id == descriptor) return s;
- s = s->next;
- }
- return 0;
-}
-
-void srv_delete(Server* s) {
- //remove s from servers
- if (servers == s) {
- servers = s->next;
- } else {
- Server *i = servers;
- while (i->next != 0) {
- if (i->next == s) {
- i->next = s->next;
- break;
- }
- i = i->next;
- }
- }
- //close s
- object_close(s->id);
- //free methods for s
- while (s->methods != 0) {
- struct method_srv *m = s->methods->next;
- free(s->methods);
- s->methods = m;
- }
- //free s
- free(s);
-}
-
-// internal use
-
-method_handler getHandler(Server *o, uint32_t m) {
- struct method_srv *i = o->methods;
- while (i) {
- if (i->id == m) return i->h;
- i = i->next;
- }
- return 0;
-}
-
-struct method_ret checkIfHandles(struct method_data *d) {
- if (getHandler(d->obj, d->parameters[0].i) == 0) {
- return mr_long(0);
- }
- return mr_long(1);
-}
-
-struct method_ret checkIfHandlesMany(struct method_data *d) {
- if (d->parameters[0].type != PT_SHM) return mr_err(-1);
- if (d->parameters[1].type != PT_LONG) return mr_err(-1);
- uint32_t *data = d->parameters[0].p, i;
- if (data == 0) return mr_long(0);
- for (i = 0; i < d->parameters[1].i; i++) {
- if (getHandler(d->obj, data[i]) == 0) return mr_long(0);
- }
- return mr_long(1);
-}
-
-// ***************************** HELPER FUNCTIONS FOR RETRUN VALUES
-
-struct method_ret mr_long(int val) {
- struct method_ret r; r.status = 0; r.type = PT_LONG; r.i = val;
- return r;
-}
-
-struct method_ret mr_llong(int64_t val) {
- struct method_ret r; r.status = 0; r.type = PT_LONGLONG; r.l = val;
- return r;
-}
-
-struct method_ret mr_obj(Object obj) {
- struct method_ret r; r.status = 0; r.type = PT_OBJDESC; r.i = obj;
- return r;
-}
-
-struct method_ret mr_srv(Server* obj) {
- struct method_ret r; r.status = 0; r.type = PT_OBJDESC; r.i = obj->id;
- return r;
-}
-
-struct method_ret mr_void() {
- struct method_ret r; r.status = 0; r.type = PT_VOID;
- return r;
-}
-
-struct method_ret mr_err(int error) {
- struct method_ret r; r.status = error; r.type = PT_VOID; r.l = 0;
- return r;
-}
diff --git a/src/library/gc/syscall.c b/src/library/gc/syscall.c
index b16881e..3100dd7 100644
--- a/src/library/gc/syscall.c
+++ b/src/library/gc/syscall.c
@@ -55,50 +55,14 @@ int proc_priv() {
return call(7, 0, 0, 0, 0, 0);
}
-int shm_create(size_t offset, size_t length) {
- return call(8, offset, length, 0, 0, 0);
-}
-
-int shm_delete(size_t offset) {
- return call(9, offset, 0, 0, 0, 0);
-}
-
-int object_create() {
- return call(10, 0, 0, 0, 0, 0);
-}
-
-int object_owned(int descriptor) {
- return call(11, descriptor, 0, 0, 0, 0);
-}
-
-void object_close(int descriptor) {
- call(12, descriptor, 0, 0, 0, 0);
-}
-
-int request_get(int descriptor, struct user_request *rq, int wait) {
- return call(13, descriptor, (size_t)rq, wait, 0, 0);
-}
-
-int request_has(int descriptor) {
- return call(14, descriptor, 0, 0, 0, 0);
-}
-
-void request_answer(int descriptor, uint32_t answer1, uint32_t answer2, int errcode) {
- call(15, descriptor, answer1, answer2, errcode, 0);
-}
-
-int request_mapShm(int descriptor, size_t offset, int number) {
- return call(16, descriptor, offset, number, 0, 0);
-}
-
-int request(int descriptor, struct user_sendrequest *rq) {
- return call(17, descriptor, (size_t)rq, 0, 0, 0);
+int proc_setheap(size_t start, size_t end) {
+ return call(8, start, end, 0, 0, 0);
}
-int send_msg(int descriptor, struct user_sendrequest *rq) {
- return call(18, descriptor, (size_t)rq, 0, 0, 0);
+int shm_create(size_t offset, size_t length) {
+ return call(9, offset, length, 0, 0, 0);
}
-int proc_setheap(size_t start, size_t end) {
- return call(19, start, end, 0, 0, 0);
+int shm_delete(size_t offset) {
+ return call(10, offset, 0, 0, 0, 0);
}
diff --git a/src/library/gm/call.c b/src/library/gm/call.c
deleted file mode 100644
index c897415..0000000
--- a/src/library/gm/call.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <gc/syscall.h>
-#include <gm/call.h>
-#include <gm/method.h>
-#include <gc/shm.h>
-#include <string.h>
-
-int c_handleCheck(_CHP, int method) {
- struct user_sendrequest sr;
- sr.func = M_HANDLECHECK_BIVV;
- sr.a = method;
- _CHC;
- if (sr.errcode) return 0;
- return sr.answeri;
-}
-
-int c_handleCheckA(_CHP, int* methods, int number) {
- struct user_sendrequest sr;
- sr.func = M_HANDLECHECK_BMIV;
- void* ptr = shm_allocNew(sizeof(int) * number);
- memcpy(ptr, methods, sizeof(int) * number);
- sr.a = (uint32_t)methods;
- sr.b = number;
- _CHC;
- shm_freeDel(ptr);
- if (sr.errcode) return 0;
- return sr.answeri;
-}
-
-int c_nothing(_CHP) {
- struct user_sendrequest sr;
- sr.func = M_NOTHING_VVVV;
- _CHC;
- return sr.errcode;
-}
diff --git a/src/library/gm/call/manager.c b/src/library/gm/call/manager.c
deleted file mode 100644
index f4cef90..0000000
--- a/src/library/gm/call/manager.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <gc/syscall.h>
-#include <gm/call/manager.h>
-#include <gm/method.h>
-#include <gc/shm.h>
-#include <string.h>
-
-Object c_open(_CHP, char *c) {
- struct user_sendrequest sr;
- sr.func = M_OPEN_OMVV;
- void* ptr = shm_allocNew(strlen(c) + 1);
- strcpy(ptr, c);
- sr.a = (uint32_t)ptr;
- _CHC;
- shm_freeDel(ptr);
- if (sr.errcode) return -1;
- return sr.answeri;
-}
-
-Object open(char *c) {
- return c_open(1, 1, c);
-}
-
-void c_registerSvc(char *name) {
- struct user_sendrequest sr;
- sr.func = M_REGISTERSVC_VMOV;
- void* ptr = shm_allocNew(strlen(name) + 1);
- strcpy(ptr, name);
- sr.a = (uint32_t)ptr;
- sr.b = 0;
- send_msg(1, &sr);
- shm_freeDel(ptr);
-}
-
-void c_logSvc(char *log, int level) {
- struct user_sendrequest sr;
- sr.func = M_LOGSVC_VMIV;
- void* ptr = shm_allocNew(strlen(log) + 1);
- if (ptr == 0) return;
- strcpy(ptr, log);
- sr.a = (uint32_t)ptr;
- sr.b = level;
- request(1, &sr);
- shm_freeDel(ptr);
-}
diff --git a/src/library/start.c b/src/library/start.c
index c9a7acc..b3c5541 100644
--- a/src/library/start.c
+++ b/src/library/start.c
@@ -3,7 +3,6 @@
extern int main();
void start() {
- objsrv_init();
int ret = main();
process_exit(ret);
}