diff options
author | Alexis211 <alexis211@gmail.com> | 2010-04-07 11:37:21 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2010-04-07 11:37:21 +0200 |
commit | ee348973b0cb0f6481e4fd6e7494c63167c9759c (patch) | |
tree | a9f1cd82703aaeeefbf4cf449203881cfcafc0a5 /src/library | |
parent | ca4f5906f284e60a7a59ca7450e3e09c4f9356e5 (diff) | |
download | TCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.tar.gz TCE-ee348973b0cb0f6481e4fd6e7494c63167c9759c.zip |
More work on manager
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/Makefile | 3 | ||||
-rw-r--r-- | src/library/gc/server.c | 25 | ||||
-rw-r--r-- | src/library/gc/shm.c | 4 | ||||
-rw-r--r-- | src/library/gm/call.c | 34 | ||||
-rw-r--r-- | src/library/gm/call/manager.c | 44 | ||||
-rw-r--r-- | src/library/std/stdio.c | 51 | ||||
-rw-r--r-- | src/library/std/string.c | 40 |
7 files changed, 189 insertions, 12 deletions
diff --git a/src/library/Makefile b/src/library/Makefile index 1451c26..3d55354 100644 --- a/src/library/Makefile +++ b/src/library/Makefile @@ -8,8 +8,9 @@ LDFLAGS = -r Library = grapes.o Objects = gc/syscall.o gc/server.o \ + gm/call.o gm/call/manager.o \ gc/mem.o gc/shm.o \ - std/mutex.o std/string.o \ + std/mutex.o std/string.o std/stdio.o \ start.o all: $(Library) diff --git a/src/library/gc/server.c b/src/library/gc/server.c index 9fd1616..96c3180 100644 --- a/src/library/gc/server.c +++ b/src/library/gc/server.c @@ -47,25 +47,27 @@ void srv_handle(Server *o, int act) { 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].val.i = rq.params[i]; + 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].val.p = p; + 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].val.p = (void*)rq.params[i]; + md.parameters[i].p = (void*)rq.params[i]; } break; } @@ -77,10 +79,15 @@ void srv_handle(Server *o, int act) { 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].val.p); + shm_freeDel(md.parameters[i].p); } } } @@ -156,7 +163,7 @@ method_handler getHandler(Server *o, uint32_t m) { } struct method_ret checkIfHandles(struct method_data *d) { - if (getHandler(d->obj, d->parameters[0].val.i) == 0) { + if (getHandler(d->obj, d->parameters[0].i) == 0) { return mr_long(0); } return mr_long(1); @@ -165,9 +172,9 @@ struct method_ret checkIfHandles(struct method_data *d) { 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].val.p, i; + uint32_t *data = d->parameters[0].p, i; if (data == 0) return mr_long(0); - for (i = 0; i < d->parameters[1].val.i; i++) { + for (i = 0; i < d->parameters[1].i; i++) { if (getHandler(d->obj, data[i]) == 0) return mr_long(0); } return mr_long(1); @@ -185,8 +192,8 @@ struct method_ret mr_llong(int64_t val) { return r; } -struct method_ret mr_obj(Object* obj) { - struct method_ret r; r.status = 0; r.type = PT_OBJDESC; r.i = obj->id; +struct method_ret mr_obj(Object obj) { + struct method_ret r; r.status = 0; r.type = PT_OBJDESC; r.i = obj; return r; } diff --git a/src/library/gc/shm.c b/src/library/gc/shm.c index 8077352..7f8609a 100644 --- a/src/library/gc/shm.c +++ b/src/library/gc/shm.c @@ -28,7 +28,7 @@ void* shm_alloc(size_t size) { //go through all blocks, get the one with the closest size struct shm_block *i = blocks, *block = 0; while (i) { - if (i->size >= size && i->is_hole == 1 && i->size < block->size) block = i; + if (i->size >= size && i->is_hole == 1 && (block == 0 || i->size < block->size)) block = i; i = i->next; } if (block == 0) { @@ -57,7 +57,7 @@ static void unify (struct shm_block *b) { if (b->next == 0 || b->is_hole == 0 || b->next->is_hole == 0) return; struct shm_block *n = b->next; b->size += n->size; - n->next->prev = b; + if (n->next != 0) n->next->prev = b; b->next = n->next; free(n); } diff --git a/src/library/gm/call.c b/src/library/gm/call.c new file mode 100644 index 0000000..553fbaf --- /dev/null +++ b/src/library/gm/call.c @@ -0,0 +1,34 @@ +#include <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 new file mode 100644 index 0000000..4b296f7 --- /dev/null +++ b/src/library/gm/call/manager.c @@ -0,0 +1,44 @@ +#include <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/std/stdio.c b/src/library/std/stdio.c new file mode 100644 index 0000000..3b24da1 --- /dev/null +++ b/src/library/std/stdio.c @@ -0,0 +1,51 @@ +#include <stdlib.h> + +void printk_int(int number) { + if (number == 0) { + printk("0"); + return; + } + int negative = 0; + if (number < 0) { + negative = 1; + number = 0 - number; + } + int order = 0, temp = number, i; + char numbers[] = "0123456789"; + while (temp > 0) { + order++; + temp /= 10; + } + + char *s, *r; + s = malloc(order + (negative ? 2 : 1)); + if (negative) { + s[0] = '-'; + r = s + 1; + } else { + r = s; + } + + for (i = order; i > 0; i--) { + r[i - 1] = numbers[number % 10]; + number /= 10; + } + r[order] = 0; + printk(s); + free(s); +} + +void printk_hex(unsigned v) { + char s[11] = {'0', 'x', 0}; + + int i; + + char hexdigits[] = "0123456789ABCDEF"; + + for (i = 0; i < 8; i++) { + s[i + 2] = (hexdigits[v >> 28]); + v = v << 4; + } + s[11] = 0; + printk(s); +} diff --git a/src/library/std/string.c b/src/library/std/string.c index 869256a..4c374ad 100644 --- a/src/library/std/string.c +++ b/src/library/std/string.c @@ -6,6 +6,46 @@ int strlen(const char *str) { return i; } +char *strchr(const char *str, char c) { + while (*str) { + if (*str == c) return (char*)str; + str++; + } + return NULL; +} + +char *strcpy(char *dest, const char *src) { + memcpy(dest, src, strlen(src) + 1); + return (char*)src; +} + +char *strdup(const char *src) { + char* ret = malloc(strlen(src) + 1); + if (ret == NULL) return ret; + strcpy(ret, src); + return ret; +} + +char *strcat(char *dest, const char *src) { + char *dest2 = dest; + dest2 += strlen(dest) - 1; + while (*src) { + *dest2 = *src; + src++; + dest2++; + } + *dest2 = 0; + return dest; +} + +int strcmp(const char *s1, const char *s2) { + while ((*s1) && (*s1 == *s2)) { + s1++; + s2++; + } + return (* (unsigned char*)s1 - *(unsigned char*)s2); +} + void *memcpy(void *vd, const void *vs, int count) { uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs; uint32_t f = count % 4, n = count / 4, i; |