From a8da6dba7ddc5e3d31a1914597e7b38fbc2d197c Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 10 Sep 2010 19:35:31 +0200 Subject: Removed all old object/request/... stuff (that was crap) --- src/include/gc/obj.h | 10 -- src/include/gc/server.h | 90 -------------- src/include/gc/syscall.h | 12 +- src/include/gm/call.h | 18 --- src/include/gm/call/manager.h | 14 --- src/include/gm/method.h | 27 ----- src/include/gm/method/manager.h | 20 ---- src/kernel/Makefile | 2 +- src/kernel/ipc/object.c | 118 ------------------- src/kernel/ipc/object.h | 40 ------- src/kernel/ipc/request.c | 253 ---------------------------------------- src/kernel/ipc/request.h | 54 --------- src/kernel/task/syscall.c | 24 +--- src/kernel/task/task.c | 11 -- src/kernel/task/task.h | 3 - src/library/Makefile | 3 +- src/library/gc/server.c | 213 --------------------------------- src/library/gc/syscall.c | 48 +------- src/library/gm/call.c | 34 ------ src/library/gm/call/manager.c | 44 ------- src/library/start.c | 1 - src/modules/manager/Makefile | 9 -- src/modules/manager/main.c | 109 ----------------- src/modules/test/main.c | 61 ++++------ 24 files changed, 34 insertions(+), 1184 deletions(-) delete mode 100644 src/include/gc/obj.h delete mode 100644 src/include/gc/server.h delete mode 100644 src/include/gm/call.h delete mode 100644 src/include/gm/call/manager.h delete mode 100644 src/include/gm/method.h delete mode 100644 src/include/gm/method/manager.h delete mode 100644 src/kernel/ipc/object.c delete mode 100644 src/kernel/ipc/object.h delete mode 100644 src/kernel/ipc/request.c delete mode 100644 src/kernel/ipc/request.h delete mode 100644 src/library/gc/server.c delete mode 100644 src/library/gm/call.c delete mode 100644 src/library/gm/call/manager.c delete mode 100644 src/modules/manager/Makefile delete mode 100644 src/modules/manager/main.c (limited to 'src') diff --git a/src/include/gc/obj.h b/src/include/gc/obj.h deleted file mode 100644 index fcb60cd..0000000 --- a/src/include/gc/obj.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DEF_OBJ_H -#define DEF_OBJ_H - -// generic method error codes -#define ME_UNHANDLED -32767 -#define ME_INTERRUPTED -32766 - -typedef int Object; - -#endif diff --git a/src/include/gc/server.h b/src/include/gc/server.h deleted file mode 100644 index 3612a1d..0000000 --- a/src/include/gc/server.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef DEF_SERVER_H -#define DEF_SERVER_H - -#include "syscall.h" -#include "obj.h" - -//parameter/return values types -#define PT_VOID 0 -#define PT_OBJDESC 1 -#define PT_LONG 2 -#define PT_LONGLONG 3 //for return values -#define PT_SHM 3 - -struct method_data { - struct { - union { - int i; - void* p; - }; - int type; - int keepShm; //for messages : keep shared memory segment after return or unmap ? (default : 0 = unmap) - size_t shmsize; - } parameters[3]; - uint32_t func; - int pid; - int blocking; //1 : blocking request, 0 : message - struct object_srv *obj; -}; - -struct method_ret { - union { - int i; - int64_t l; - }; - int type; - int status; //= error code if any -}; - -//helper function for creating return values -struct method_ret mr_long(int val); -struct method_ret mr_llong(int64_t val); -struct method_ret mr_obj(Object obj); -struct method_ret mr_srv(struct object_srv* obj); -struct method_ret mr_void(); -struct method_ret mr_err(int error); - -// for checking if a string passed in shared memory is valid -#define CHKSSTR(md, n) { size_t _i, _ok = 0; if (md->parameters[n].p == 0) return mr_err(-1); \ - for (_i = 0; _i < md->parameters[n].shmsize; _i++) { \ - if (*((char*)md->parameters[n].p + _i) == 0) { \ - _ok = 1; break; \ - } } \ - if (!_ok && md->parameters[n].shmsize != 0) return mr_err(-1); } - -typedef struct method_ret (*method_handler)(struct method_data*); - -struct method_srv { - uint32_t id; - method_handler h; - - struct method_srv *next; -}; - -struct object_srv { - int id; //descriptor - struct method_srv *methods; - - void *data; - - struct object_srv *next; -}; - -typedef struct object_srv Server; - -extern Server procServer; //corresponds to descriptor 0. - -//possible actions for srv_handle -#define HA_ONCE 1 //check if requests are waiting, if so handle them -#define HA_WAIT 2 //check if requests are waiting, if so handle them, else wait for one to come and handle it -#define HA_LOOP 3 //wait for requests to come, handling them in an infinite loop - -void srv_handleAll(); //check all objects once -void srv_handle(Server* o, int act); - -Server *srv_create(); -void srv_delete(Server *o); -Server *srv_get(int descriptor); -void srv_addHandler(Server* o, uint32_t method, method_handler h); - -#endif diff --git a/src/include/gc/syscall.h b/src/include/gc/syscall.h index e6005c1..a8928e3 100644 --- a/src/include/gc/syscall.h +++ b/src/include/gc/syscall.h @@ -35,17 +35,9 @@ void printk(char* str); void thread_new(void (*entry)(void*), void *data); void irq_wait(int number); int proc_priv(); + +int proc_setheap(size_t start, size_t end); int shm_create(size_t offset, size_t length); int shm_delete(size_t offset); -int object_create(); -int object_owned(int descriptor); -void object_close(int descriptor); -int request_get(int descriptor, struct user_request *rq, int wait); -int request_has(int descriptor); -void request_answer(int descriptor, uint32_t answer1, uint32_t answer2, int errcode); -int request_mapShm(int descriptor, size_t offset, int number); -int request(int descriptor, struct user_sendrequest *rq); -int send_msg(int descriptor, struct user_sendrequest *rq); -int proc_setheap(size_t start, size_t end); #endif diff --git a/src/include/gm/call.h b/src/include/gm/call.h deleted file mode 100644 index 5c3849d..0000000 --- a/src/include/gm/call.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef DEF_CALL_H -#define DEF_CALL_H - -/* - * This file and all files in include/call/ define prototypes to helper functions for calling methods on objects. - */ - -#include - -#define _CHP Object o, int block -#define _CHC if (block) request(o, &sr); else send_msg(o, &sr); - -int c_handleCheck(_CHP, int method); -int c_handleCheckA(_CHP, int* methods, int number); - -int c_nothing(_CHP); - -#endif diff --git a/src/include/gm/call/manager.h b/src/include/gm/call/manager.h deleted file mode 100644 index 49aafe7..0000000 --- a/src/include/gm/call/manager.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef DEF_CALL_MANAGER_H -#define DEF_CALL_MANAGER_H - -#include -#include - -Object c_open(_CHP, char *c); -Object open(char *c); //calls c_open with object 1 - -void c_registerSvc(char *name); //automatically calls with objecct id 0 - -void c_logSvc(char *log, int level); - -#endif diff --git a/src/include/gm/method.h b/src/include/gm/method.h deleted file mode 100644 index 13d3f16..0000000 --- a/src/include/gm/method.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef DEF_METHOD_H -#define DEF_METHOD_H - -#define MP(r, a, b, c) (((r << 6) | (a << 4) | (b << 2) | c) << 24) - -/* ****** FORMAT FOR #define NAMES : ****** - * M__ - * where ret, param1, param2 and param3 are one of the following : - * - V (0) : nothing (void) - * - O (1) : object descriptor - * - I (2) : int - * - B (2) : int used as a boolean (0 = no, 1 = yes) - * - M (3) : shared memory, only for parameters - * - L (3) : int64 (long long), only for return values - */ - -#define M_HANDLECHECK_BIVV (1 | MP(2, 2, 0, 0)) -#define M_HANDLECHECK_BMIV (1 | MP(2, 3, 2, 0)) -/* Checks if object handles that method. In case BIVV, only one method is checked for. - * In case BMIV, the [b] methods in shared memory [a] are checked, first one not found returns false. */ - -#define M_NOTHING_VVVV (2) -/* This method does nothing, it just checks message transmission to an object. */ - -#include "method/manager.h" - -#endif diff --git a/src/include/gm/method/manager.h b/src/include/gm/method/manager.h deleted file mode 100644 index 2066093..0000000 --- a/src/include/gm/method/manager.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef DEF_METHOD_H - -#define M_OPEN_OMVV (10 | MP(1, 3, 0, 0)) -/* This function opens a distant ressource. Example : open("file:Root/Public/test.txt"); */ - -#define M_REGISTERSVC_VMOV (11 | MP(0, 3, 1, 0)) -/* This function registers a service. - * parameter 1 : service name; - * parameter 2 : service root object. */ - -#define M_LOGSVC_VMIV (12 | MP(0, 3, 2, 0)) -/* This parameters logs an entry for service with corresponding PID. Parameter 2 is : */ -#define LL_CRITICAL 0 -#define LL_ERROR 1 -#define LL_WARNING 2 -#define LL_NOTICE 3 -#define LL_STATUS 4 -#define LL_DEBUG 5 - -#endif diff --git a/src/kernel/Makefile b/src/kernel/Makefile index 757349f..5d46325 100644 --- a/src/kernel/Makefile +++ b/src/kernel/Makefile @@ -4,7 +4,7 @@ Obj = core/loader_.o core/kmain.o core/sys.o core/test.o \ task/idt.o task/idt_.o task/task.o task/task_.o task/syscall.o task/sched.o \ lib/stdlib.o lib/bitset.o lib/mutex.o \ mem/mem.o mem/paging.o mem/gdt.o mem/heap.o mem/seg.o \ - ipc/shm.o ipc/object.o ipc/request.o \ + ipc/shm.o \ linker/elf.o include ../common.make diff --git a/src/kernel/ipc/object.c b/src/kernel/ipc/object.c deleted file mode 100644 index cfb9652..0000000 --- a/src/kernel/ipc/object.c +++ /dev/null @@ -1,118 +0,0 @@ -#include "object.h" -#include -#include - -struct object* obj_new(struct process* owner) { - struct object* ret = kmalloc(sizeof(struct object)); - ret->owner = owner; - ret->descriptors = 0; - ret->busyMutex = MUTEX_UNLOCKED; - ret->request = 0; - ret->wakeupOnRq = 0; - return ret; -} - -void obj_delete(struct object* obj) { - if (obj->descriptors > 0) return; - if (obj->busyMutex != MUTEX_UNLOCKED) return; - if (obj->request != 0) return; - kfree(obj); -} - -int obj_createP(struct process* p) { - return objdesc_add(p, obj_new(p)); -} - -void obj_closeP(struct process* p, int id) { - struct object* obj = objdesc_read(p, id); - if (obj == 0) return; - objdesc_rm(p, id); - if (obj->owner == p) { - if (obj->descriptors > 0) { //TODO !!! - obj->owner = 0; // set object to be invalid - //if a request was being handled, set it to interrupted (acknowledged = 3) and wake up receiver thread or if nonblocking delete it - //unlock objects busymutex - } else { - obj_delete(obj); - } - } else { - if (obj->descriptors == 0 && obj->owner == 0) { - obj_delete(obj); - } else if (obj->descriptors == 1 && obj->owner != 0) { - //future : send message becuz object closed for everyone - } - } -} - -void obj_closeall(struct process* p) { - while (p->objects != 0) obj_closeP(p, p->objects->id); -} - -// DESCRIPTORS - -int objdesc_add(struct process* proc, struct object* obj) { - int tmp = objdesc_get(proc, obj); - if (tmp != -1) { return -1; } //signal that a descriptor already exists - struct obj_descriptor *ret = kmalloc(sizeof(struct obj_descriptor)); - ret->obj = obj; - ret->id = proc->next_objdesc; - ret->next = proc->objects; - proc->objects = ret; - obj->descriptors++; - proc->next_objdesc++; - return ret->id; -} - -int objdesc_get(struct process* proc, struct object* obj) { - struct obj_descriptor *it = proc->objects; - while (it != 0) { - if (it->obj == obj) return it->id; - it = it->next; - } - return -1; -} - -struct object* objdesc_read(struct process* proc, int id) { - struct obj_descriptor *it = proc->objects; - while (it != 0) { - if (it->id == id) return it->obj; - it = it->next; - } - return 0; -} - -void objdesc_rm(struct process* proc, int id) { - struct obj_descriptor *e = proc->objects; - if (e != 0 && e->id == id) { - proc->objects = e->next; - e->obj->descriptors--; - kfree(e); - return; - } - while (e->next != 0) { - if (e->next->id == id) { - e->next = e->next->next; - e->next->obj->descriptors--; - kfree(e->next); - return; - } - e = e->next; - } -} - -// SYSCALLS - -int object_create() { - return obj_createP(current_thread->process); -} - -int object_owned(int id) { - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return -10; - if (obj->owner == current_thread->process) return 1; - return 0; -} - -void object_close(int id) { - obj_closeP(current_thread->process, id); -} diff --git a/src/kernel/ipc/object.h b/src/kernel/ipc/object.h deleted file mode 100644 index 4577615..0000000 --- a/src/kernel/ipc/object.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef DEF_OBJECT_H -#define DEF_OBJECT_H - -#include - -struct object { - struct process *owner; //when 0, object is invalid and cannot handle requests - int descriptors; - uint32_t busyMutex; //if busy, either a blocking request is being processed, or a sent message is waiting for being recieved - struct request *request; - struct thread *wakeupOnRq; -}; - -struct obj_descriptor { - struct object *obj; - int id; - struct obj_descriptor *next; -}; - -//Objects -struct object* obj_new(struct process *owner); -void obj_delete(struct object* obj); - -int obj_createP(struct process* p); -void obj_closeP(struct process* p, int id); -void obj_closeall(struct process* p); - -//Object descriptors -int objdesc_add(struct process* proc, struct object* obj); // add a descriptor -int objdesc_get(struct process* proc, struct object* obj); // look in descriptors for the one corresponding to the object -struct object* objdesc_read(struct process* proc, int id); // get the object correspoinding to the id -void objdesc_rm(struct process* proc, int id); // remove descriptor for an object - -//Syscalls -int object_create(); -int object_owned(int id); //does current process own object ? 1=yes 0=no -void object_close(int id); //closes descriptor to specified object. if we are the owner, make all requests to object fail. - -#endif - diff --git a/src/kernel/ipc/request.c b/src/kernel/ipc/request.c deleted file mode 100644 index 7fe8f2b..0000000 --- a/src/kernel/ipc/request.c +++ /dev/null @@ -1,253 +0,0 @@ -#include "request.h" -#include "shm.h" -#include "object.h" -#include -#include -#include - -int request_get(int id, uint32_t ptr, int wait) { - int i; - //check if we own the object, if not return -2 (-10 if descriptor does not exist) - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return -10; - if (obj->owner != current_thread->process) return -2; - //check if a request is pending. if request is being processed (acknowledged), return -3 - if (obj->request != 0 && obj->request->acknowledged != RS_PENDING) return -3; - //if not (busymutex unlocked and request==0) && wait, then wait, else return -1 - if (wait == 0 && obj->request == 0) return -1; - while (obj->busyMutex != MUTEX_LOCKED && (obj->request == 0 || obj->request->acknowledged != RS_PENDING)) { - //set thread to be waked up on request - obj->wakeupOnRq = current_thread; - //go to sleep - thread_goInactive(); - } - obj->request->acknowledged = RS_PROCESSED; - //when request pending (wait finished), write it to ptr - struct user_request *p = (struct user_request*)ptr; - p->func = obj->request->func; - for (i = 0; i < 3; i++) { - p->params[i] = obj->request->params[i]; - p->shmsize[i] = obj->request->shmsize[i]; - } - p->isBlocking = (obj->request->requester != 0); - p->pid = obj->request->pid; - //if request is nonblocking and no shm is to be mapped, delete request and unlock objects busymutex, else set it to acknowledged - if (p->isBlocking) return 0; - for (i = 0; i < 3; i++) { - if (obj->request->shm_sndr[i] != 0) return 0; - } - kfree(obj->request); - obj->request = 0; - mutex_unlock(&obj->busyMutex); - return 0; -} - -int request_has(int id) { - //check if we own the object, if not return -2 (-10 if descriptor does not exist) - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return -10; - if (obj->owner != current_thread->process) return -2; - //check if a request is pending. - // if none (busymutex unlocked or request==0), return 0 - if (obj->request == 0 || obj->busyMutex == MUTEX_UNLOCKED) return 0; - // if waiting for ack (not acknowledged), return 1 - if (obj->request->acknowledged == RS_PENDING) return 1; - // if being processed (acknowledged), return 2 - return 2; -} - -void request_answer(int id, uint32_t answer, uint32_t answer2, int errcode) { - int i; - //check if we own the object, if not return (also return if descriptor does not exist) - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return; - if (obj->owner != current_thread->process) return; - //if no blocking request is being processed (including non-acknowledged waiting requests), return - if (obj->request == 0 || obj->request->acknowledged == RS_PENDING || obj->request->requester == 0) return; - //unmap shared memory segments from shm_rcv, close descriptors to objects from obj_close - for (i = 0; i < 3; i++) { - if (obj->request->shm_rcv[i] != 0) seg_unmap(obj->request->shm_rcv[i]); - if (obj->request->obj_close[i] != 0) obj_closeP(obj->owner, obj->request->obj_close[i]); - } - //set blocking request to finished (acknowledged = 2), and set its answer - obj->request->acknowledged = RS_FINISHED; - switch (obj->request->func >> 30) { - case PT_OBJDESC: - if ((int)answer < 0) { - obj->request->answer.n = answer; - } else { - if (obj->owner == obj->request->requester->process) { - obj->request->answer.n = answer; - } else { - struct object *o = objdesc_read(obj->owner, answer); - int n = -1; - if (o != 0) { - n = objdesc_get(obj->request->requester->process, o); - if (n == -1) { - n = objdesc_add(obj->request->requester->process, o); - } - } - obj->request->answer.n = n; - } - } - break; - case PT_LONG: - obj->request->answer.n = answer; - break; - case PT_LONGLONG: - obj->request->answer.ll = (uint64_t)((uint64_t)answer2 << 32) | answer; - } - obj->request->errcode = errcode; - //wake up receiver thread (thread_wakeUp) - thread_wakeUp(obj->request->requester); - //dereference request from object, unlock objects busymutex - obj->request = 0; - mutex_unlock(&obj->busyMutex); -} - -int request_mapShm(int id, uint32_t pos, int number) { - int i; - if (number > 2 || number < 0) return -9; - //check if we own the object, if not return -2 (-10 if descriptor does not exist) - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return -10; - if (obj->owner != current_thread->process) return -2; - //if no request is being processes (including non-acknowledged waiting requests), return -3 - if (obj->request == 0 || obj->request->acknowledged == RS_PENDING) return -3; - //check if the requests should have shm in parameter [number], if not return -4 - int n = (obj->request->func >> (28 - (2 * number))) & 3; - if (n != PT_SHM) return -4; - //check if sender process is different from receiver process, if not return -7 - if (obj->request->requester != 0 && obj->owner == obj->request->requester->process) return -7; - //check if sender sent a shm seg in parameter [number], if not return -5 - if (obj->request->shm_sndr[number] == 0) return -5; - //map shm to position - obj->request->shm_rcv[number] = seg_map(obj->request->shm_sndr[number]->seg, obj->owner->pagedir, pos); - obj->request->shm_sndr[number]->seg->mappings--; - //if request is nonblocking and no more shm is to be mapped, delete request and free object busymutex - if (obj->request->requester != 0) return 0; - for (i = 0; i < 3; i++) { - if (obj->request->shm_sndr[i] != 0 && obj->request->shm_rcv[i] == 0) return 0; - } - kfree(obj->request); - obj->request = 0; - mutex_unlock(&obj->busyMutex); - return 0; -} - -static struct request *mkrequest(int id, struct thread *requester, - uint32_t func, uint32_t a, uint32_t b, uint32_t c, uint32_t *err) { - int i; - // get object from descriptor id, if none return 0 - struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) { - *err = -10; - return 0; - } - // waitlock object's busy mutex - mutex_lock(&obj->busyMutex); - // if object cannot answer (owner == 0) return 0 - if (obj->owner == 0) { - mutex_unlock(&obj->busyMutex); - *err = -11; - return 0; - } - // create request, fill it up : - struct request *rq = kmalloc(sizeof(struct request)); - rq->obj = obj; - rq->requester = requester; - rq->func = func; - for (i = 0; i < 3; i++) { rq->params[i] = 0; rq->obj_close[i] = 0; rq->shm_sndr[i] = 0; rq->shm_rcv[i] = 0; } - rq->acknowledged = RS_PENDING; - rq->pid = current_thread->process->pid; - // integers: use as is - // objects: open a new descriptor in receiver process (if same process, keep number), put that number as an int - // if receiver already had descriptor to this object, use it and set obj_close to 0, else set obj_close to new number - // shm: if same process, put ptr as int, else put 0 as int and get segment_map to shm_sndr - // objects and shm: 0 means sender didn't want to share anything, that should stay 0. - for (i = 0; i < 3; i++) { - int n = (rq->func >> (28 - (2 * i))) & 3; - uint32_t v = (i == 0 ? a : (i == 1 ? b : c)); - switch (n) { - case PT_OBJDESC: - if ((int)v < 0) { - rq->params[i] = v; - } else { - if (obj->owner == current_thread->process) { - rq->params[i] = v; - } else { - int d = objdesc_get(obj->owner, objdesc_read(current_thread->process, v)); - if (d == -1) { - d = objdesc_add(obj->owner, objdesc_read(current_thread->process, v)); - rq->obj_close[i] = d; - } - rq->params[i] = d; - } - } - break; - case PT_LONG: - rq->params[i] = v; - break; - case PT_SHM: - rq->shmsize[i] = 0; - if (obj->owner == current_thread->process) { - rq->params[i] = v; - struct segment_map *t = shmseg_getByOff(current_thread->process, v); - if (t != 0) rq->shmsize[i] = t->len; - } else { - rq->shm_sndr[i] = shmseg_getByOff(current_thread->process, v); - rq->shm_sndr[i]->seg->mappings++; - if (rq->shm_sndr[i] != 0) rq->shmsize[i] = rq->shm_sndr[i]->len; - } - break; - } - } - // reference request from object - obj->request = rq; - if (obj->wakeupOnRq != 0) { - thread_wakeUp(obj->wakeupOnRq); - obj->wakeupOnRq = 0; - } - // return request - return rq; -} - -int request(int obj, uint32_t rq_ptr) { - uint32_t e = 0; - - struct user_sendrequest *urq = (void*)rq_ptr; - //call mkrequest with parameters (requester thread = current thread) - struct request *rq = mkrequest(obj, current_thread, urq->func, urq->a, urq->b, urq->c, &e); - //if returned value is 0 (could not create request), return -1 - if (e != 0) return e; - if (rq == 0) return -1; - //sleep until request is handled - thread_goInactive(); - //if request has been interrupted because process closed communication (acknowledged == 3), return -2 - if (rq->acknowledged == 3) return -2; - //write answer to urq, delete request, return 0 - switch (urq->func >> 30) { - case PT_OBJDESC: - case PT_LONG: - urq->answeri = rq->answer.n; - break; - case PT_LONGLONG: - urq->answerll = rq->answer.ll; - } - urq->errcode = rq->errcode; - kfree(rq); - return 0; -} - -int send_msg(int obj, uint32_t rq_ptr) { - uint32_t e = 0; - - struct user_sendrequest *urq = (void*)rq_ptr; - //call mkrequest with parameters (requester thread = 0) - struct request *rq = mkrequest(obj, 0, urq->func, urq->a, urq->b, urq->c, &e); - //if returned value is 0, return -1 else return 0 - if (e != 0) return e; - if (rq == 0) return -1; - urq->errcode = 0; - return 0; -} diff --git a/src/kernel/ipc/request.h b/src/kernel/ipc/request.h deleted file mode 100644 index 760a159..0000000 --- a/src/kernel/ipc/request.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef DEF_REQUEST_H -#define DEF_REQUEST_H - -#include "object.h" - -#define RS_PENDING 0 -#define RS_PROCESSED 1 -#define RS_FINISHED 2 -#define RS_INTERRUPTED 3 - -#define PT_VOID 0 -#define PT_OBJDESC 1 -#define PT_LONG 2 -#define PT_LONGLONG 3 //for return values -#define PT_SHM 3 //for parameters - -struct request { - struct object *obj; - struct thread *requester; //0 if nonblocking message - uint32_t func, params[3], obj_close[3], shmsize[3]; //obj_close : object descriptors to close when requests yields an answer - struct segment_map *shm_sndr[3], *shm_rcv[3]; - int acknowledged; // (only for blocking requests) 0 : request is pending, 1 : request is being processes, 2 : finished, 3 : interrupted - union { - int64_t ll; - uint32_t n; - } answer; - int errcode; //returned when function has finished - int pid; //pid of caller -}; - -struct user_request { - uint32_t func, params[3], shmsize[3]; - int isBlocking; // 1 : blocking request, 0 : nonblocking request (message) - int pid; //pid of caller process -}; - -struct user_sendrequest { - uint32_t func, a, b, c; - uint32_t answeri; - int64_t answerll; - int errcode; -}; - -//syscalls -int request_get(int obj, uint32_t ptr, int wait); -int request_has(int obj); -void request_answer(int obj, uint32_t answer, uint32_t answer2, int errcode); //answer2 used for long long. -int request_mapShm(int obj, uint32_t pos, int number); - -int request(int obj, uint32_t rq_ptr); -int send_msg(int obj, uint32_t rq_ptr); - -#endif - diff --git a/src/kernel/task/syscall.c b/src/kernel/task/syscall.c index b490987..46ccff6 100644 --- a/src/kernel/task/syscall.c +++ b/src/kernel/task/syscall.c @@ -21,18 +21,9 @@ CALL1V(process_exit, process_exit_sc); CALL1(monitor_write, printk_sc); CALL1V(idt_waitIrq, irq_wait_sc); CALL0(proc_priv, proc_priv_sc); +CALL2(process_setheapseg, proc_setheap_sc); CALL2(shm_create, shm_create_sc); CALL1(shm_delete, shm_delete_sc); -CALL0(object_create, object_create_sc); -CALL1(object_owned, object_owned_sc); -CALL1V(object_close, object_close_sc); -CALL3(request_get, request_get_sc); -CALL1(request_has, request_has_sc); -CALL4V(request_answer, request_answer_sc); -CALL3(request_mapShm, request_mapShm_sc); -CALL2(request, request_sc); -CALL2(send_msg, send_msg_sc); -CALL2(process_setheapseg, proc_setheap_sc); static void thread_new_sc(struct registers* r) { thread_new(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); @@ -47,16 +38,7 @@ int_callback syscalls[NUMBER_OF_SYSCALLS] = { thread_new_sc, //5 irq_wait_sc, proc_priv_sc, - shm_create_sc, - shm_delete_sc, - object_create_sc, //10 - object_owned_sc, - object_close_sc, - request_get_sc, - request_has_sc, - request_answer_sc, //15 - request_mapShm_sc, - request_sc, - send_msg_sc, proc_setheap_sc, + shm_create_sc, + shm_delete_sc, //10 0 }; diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index b8a72ce..f074c77 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -5,13 +5,10 @@ #include #include #include -#include #include "timer.h" #define KSTACKSIZE 0x8000 -static struct object *manager_object = 0; - //Static routines for handling threads exiting and all cleanup static void thread_exit_stackJmp(uint32_t reason); static void thread_exit2(uint32_t reason); @@ -294,13 +291,6 @@ struct process *process_new(struct process* parent, uint32_t uid, uint32_t privi p->stack = stacksBottom + USER_STACK_SIZE - 4; } - p->next_objdesc = 0; - p->objects = 0; - struct object* o = obj_new(p); - if (manager_object == 0) manager_object = o; - objdesc_add(p, o); //create process' root object and add descriptor 0 to it - objdesc_add(p, manager_object); - processes = p; return p; } @@ -332,7 +322,6 @@ static void process_delete(struct process *pr) { thread_delete(it); it = it->next; } - obj_closeall(pr); if (processes == pr) { processes = pr->next; } else { diff --git a/src/kernel/task/task.h b/src/kernel/task/task.h index 171a9fd..fdffa11 100644 --- a/src/kernel/task/task.h +++ b/src/kernel/task/task.h @@ -28,9 +28,6 @@ struct process { struct page_directory *pagedir; size_t stack; - struct obj_descriptor *objects; - uint32_t next_objdesc; - struct segment_map *heapseg; struct process *next; //Forms a linked list 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 -#include -#include -#include - -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 -#include -#include -#include -#include - -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 -#include -#include -#include -#include - -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); } diff --git a/src/modules/manager/Makefile b/src/modules/manager/Makefile deleted file mode 100644 index abce5cb..0000000 --- a/src/modules/manager/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -Obj = main.o -Out = manager.elf - -include ../../common.make - -CFLAGS += -I ../../include - -LDFLAGS += -T ../../library/link.ld -L ../../library -Map manager.map - diff --git a/src/modules/manager/main.c b/src/modules/manager/main.c deleted file mode 100644 index 58d9232..0000000 --- a/src/modules/manager/main.c +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include -#include - -char *loglevels[] = {"Critical", "Error", "Warning", "Notice", "Status", "Debug"}; -int loglevel = LL_DEBUG; - -struct service { - char* name; - int pid; - Object obj; - struct service *next; -}; - -struct service *services = 0; - -//************************ FUNCTIONS THAT DO STUFF ******************** -void logsvc(int pid, char* log, int level) { - if (level > loglevel || level < 0) return; - struct service *svc = services; - while (svc) { - if (svc->pid == pid) break; - svc = svc->next; - } - if (svc == 0) { - printk("[log:??] "); - } else { - printk("[log:"); printk(svc->name); printk("] "); - } - printk(loglevels[level]); printk(": "); - printk(log); printk("\n"); -} - -void registersvc(int pid, char* name, Object descriptor) { - struct service *svc = malloc(sizeof(struct service)); - svc->name = strdup(name); - svc->pid = pid; - svc->obj = descriptor; - svc->next = services; - services = svc; - char msg[100] = "Service registered: "; - strcat(msg, svc->name); - logsvc(1, msg, LL_NOTICE); -} - -//****************************** HANDLING METHODS ON MAIN OBJECT ***************** -struct method_ret handle_nothing(struct method_data *d) { - if (d->blocking) logsvc(1, "Received a {nothing} request.", LL_DEBUG); - else logsvc(1, "Received a {nothing} message.", LL_DEBUG); - return mr_void(); -} - -struct method_ret handle_open(struct method_data *d) { - CHKSSTR(d, 0); - char *svc = d->parameters[0].p; - char *sep, *res; - sep = strchr(svc, ':'); - if (sep != 0) *sep = '0'; - struct service *s = services; - while (s) { - if (strcmp(s->name, svc) == 0) break; - s = s->next; - } - if (s == 0) return mr_err(-2); - if (sep == 0) { - return mr_obj(s->obj); - } else { - *sep = ':'; - res = sep + 1; - // open service svc, ressource res - Object r = c_open(s->obj, 1, res); - if (r == -1) return mr_err(-3); - return mr_obj(r); - } -} - -struct method_ret handle_registersvc(struct method_data *d) { - CHKSSTR(d, 0); - if (d->parameters[1].i == 0) return mr_err(-1); - registersvc(d->pid, d->parameters[0].p, d->parameters[1].i); - return mr_void(); -} - -struct method_ret handle_logsvc(struct method_data *d) { - CHKSSTR(d, 0); - logsvc(d->pid, d->parameters[0].p, d->parameters[1].i); - return mr_void(); -} - -int main() { - logsvc(1, "Manager module configuring...", LL_NOTICE); - registersvc(1, "manager", 0); - - Server *mgr = srv_get(0); - srv_addHandler(mgr, M_NOTHING_VVVV, handle_nothing); - - srv_addHandler(mgr, M_OPEN_OMVV, handle_open); - srv_addHandler(mgr, M_REGISTERSVC_VMOV, handle_registersvc); - srv_addHandler(mgr, M_LOGSVC_VMIV, handle_logsvc); - - logsvc(1, "Manager module configured : starting request handling.", LL_STATUS); - srv_handle(mgr, HA_LOOP); - - printk("[manager] Manager EPIC FAIL.\n"); - return 0; -} diff --git a/src/modules/test/main.c b/src/modules/test/main.c index 493867e..8085007 100644 --- a/src/modules/test/main.c +++ b/src/modules/test/main.c @@ -1,53 +1,34 @@ #include #include -#include -#include -#include -#include #include -#define FACTOR 4 - -struct method_ret nulhandle(struct method_data *d) { - if (d->blocking) c_logSvc("Handling a nothing request.", LL_STATUS); - else c_logSvc("Handling a nothing message.", LL_STATUS); - return mr_void(); -} - -struct method_ret openhandle(struct method_data *d) { - CHKSSTR(d, 0); - printk("test.open: "); printk(d->parameters[0].p); printk("\n"); - return mr_err(-1); -} - -void thread2(void* d) { - Server *s = srv_get(0); - srv_addHandler(s, M_NOTHING_VVVV, nulhandle); - srv_addHandler(s, M_OPEN_OMVV, openhandle); - while (1) { - c_logSvc("{2} Waiting for a request on main object...", LL_STATUS); - srv_handle(s, HA_WAIT); - } -} - void thread_cascade(void* d) { - c_logSvc("{#} Thread cascade element started. Continuing.", LL_STATUS); - thread_new(thread_cascade, (void*)((int)d - 1)); - c_logSvc("{#} Thread cascade element finished.", LL_STATUS); + int n = (int)d; + + if (d == 0) { + printk("{#} 0 cascade element started => end\n"); + } else { + if (n < 0) { + printk("{#} - cascade element started\n"); + n = 0 - n; + } else { + printk("{#} + cascade element started\n"); + } + printk("{#} FORK + ...\n"); + thread_new(thread_cascade, (void*)(n - 1)); + printk("{#} FORK - ...\n"); + thread_new(thread_cascade, (void*)(1 - n)); + printk("{#} Thread cascade element finished.\n"); + } } int main() { - c_logSvc("Hi world from unregistered test module !", LL_NOTICE); - c_registerSvc("test"); - c_logSvc("Creating new thread...", LL_STATUS); - thread_new(thread2, 0); - c_logSvc("{1} Sending a test message to manager", LL_STATUS); - c_nothing(1, 0); + printk("Hi world from unregistered test module !\n"); - c_logSvc("{1} Creating thread cascade len:3", LL_STATUS); - thread_new(thread_cascade, (void*)3); + printk("{1} Creating thread cascade len:1\n"); + thread_new(thread_cascade, (void*)1); - c_logSvc("{1} Thread now sleeping...", LL_WARNING); + printk("{1} Thread now sleeping...\n"); while (1) thread_sleep(1000); return 0; } -- cgit v1.2.3