From 50152369119ffc92d7790ddcfd26f32613366ede Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 26 Mar 2010 16:04:01 +0100 Subject: IPC documented, still not tested. --- doc/syscalls.txt | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ src/kernel/ipc/object.c | 2 +- src/kernel/ipc/request.c | 22 ++++++++++---- src/modules/test/main.c | 18 ++++++------ 4 files changed, 101 insertions(+), 16 deletions(-) diff --git a/doc/syscalls.txt b/doc/syscalls.txt index 2972b97..6846fb9 100644 --- a/doc/syscalls.txt +++ b/doc/syscalls.txt @@ -33,3 +33,78 @@ id=eax Name Parameters Description 18 send_msg same as above Send a nonblocking request to object, same as above If a processes wishes to exit with an error code, it HAS to use process_exit. thread_exit will do nothing. + +====== SYSCALL DESCRIPTION ====== + += object_create (10) +Parameters: none +Returns: descriptor to created object, 0 if failure (should not happen) +Creates an object belonging to current proces. + += object_owned (11) +Parameters: an object descriptor +Returns: +- 1 if object belongs to current process +- 0 if object does not belong to current process +- -10 if descriptor does not exist + += object_close (12) +Parameters: an object descriptor +Returns: nothing +Closes a given descriptor to an object. If descriptor does not exist, call is ignored. + += request_get (13) +Parameters: an object descriptor, a pointer to a location to write request, a boolean : wait for a request? +Returns: +- -10 if descriptor does not exist +- -2 if object is not possesed by current process +- -3 if a blocking request is currently being processed +- -1 if no request is pending and [wait] is not set +- 0 if a request was written to location (call successful) +Fetches a waiting request or message on object, and deletes it or acknowledge it. + += request_has (14) +Parameters: an object descriptor +Returns: +- -10 if descriptor does not exist +- -2 if object is not possesed by current process +- 0 if no request is pending +- 1 if a waiting request is there +- 2 if a request is being processed + += request_answer (15) +Parameters: an object descriptor, two ints forming a long long if necessary +Returns: nothing +Answers a request marked as currently being processed, ignoring cases where : +- descriptor does not exist +- object does not belong to process +- no request was being processed + += request_mapShm (16) +Parameters: [id] object descriptor, [pos] pointer to a location, [number] int +Returns: +- -9 if [number] < 0 or [number] > 2 +- -10 if descriptor does not exist +- -2 if object is not possesed by current process +- -3 if no request is being processed +- -4 if there is usually no shared memory in parameter [number] +- -7 if sender process is receiver process, in which case memory is already mapped somewhere +- -5 if no shared memory was sent by this parameter +- 0 if shared memory in parameter [number] of currently processed request of object [id] was mapped at [pos] + += request (17) +Parameters: [id] object descriptor, [pos] pointer to request data +Returns: +- -1 if an unknown error happened (should not happen) +- -10 if descriptor does not exist +- -11 if objet cannot handle requests +- -2 if request was interrupted +- 0 if request was handled and result written in [pos]->answer + += send_msg (18) +Parameters: [id] object descriptor, [pos] pointer to request data +Returns: +- -1 if an unknown error happened (should not happen) +- -10 if descriptor does not exist +- -11 if object cannot handle requests +- 0 if nonblocking message was sent diff --git a/src/kernel/ipc/object.c b/src/kernel/ipc/object.c index ea59d28..e381c89 100644 --- a/src/kernel/ipc/object.c +++ b/src/kernel/ipc/object.c @@ -107,7 +107,7 @@ int object_create() { int object_owned(int id) { struct object *obj = objdesc_read(current_thread->process, id); - if (obj == 0) return -1; + if (obj == 0) return -10; if (obj->owner == current_thread->process) return 1; return 0; } diff --git a/src/kernel/ipc/request.c b/src/kernel/ipc/request.c index 25c778a..9e42d6a 100644 --- a/src/kernel/ipc/request.c +++ b/src/kernel/ipc/request.c @@ -14,7 +14,7 @@ int request_get(int id, uint32_t ptr, int wait) { //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) return -1; + if (wait == 0 && obj->request == 0) return -1; while (obj->busyMutex != MUTEX_LOCKED && (obj->request == 0 || obj->request->acknowledged != RS_PENDING)) thread_sleep(1); obj->request->acknowledged = RS_PROCESSED; //when request pending (wait finished), write it to ptr @@ -95,7 +95,7 @@ int request_mapShm(int id, uint32_t pos, int number) { 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 || obj->request->requester == 0) 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; @@ -117,16 +117,20 @@ int request_mapShm(int id, uint32_t pos, int number) { } static struct request *mkrequest(int id, struct thread *requester, - uint32_t func, uint32_t a, uint32_t b, uint32_t c) { + 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) return 0; + 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 : @@ -176,10 +180,13 @@ static struct request *mkrequest(int id, struct thread *requester, } 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); + 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(); @@ -199,10 +206,13 @@ int request(int obj, uint32_t rq_ptr) { } 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); + 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; return 0; } diff --git a/src/modules/test/main.c b/src/modules/test/main.c index d2a4692..df8b2ef 100644 --- a/src/modules/test/main.c +++ b/src/modules/test/main.c @@ -5,33 +5,33 @@ int obj = -1; void thread2(void* d) { - printk("[module:test:2] Creating new object...\n"); + printk("[test:2] Creating new object...\n"); obj = object_create(); struct user_request rq; while (1) { - printk("[module:test:2] Waiting for a request...\n"); + printk("[test:2] Waiting for a request...\n"); request_get(obj, &rq, 1); if (rq.isBlocking) { - printk("[module:test:2] Got request. Answering...\n"); + printk("[test:2] Got request. Answering...\n"); request_answer(obj, 42, 0); } else { - printk("[module:test:2] Got message. Ignoring it.\n"); + printk("[test:2] Got message. Ignoring it.\n"); } } } int main() { - printk("[module:test:1] Hi world !\n"); - printk("[module:test:1] Creating new thread...\n"); + printk("[test:1] Hi world !\n"); + printk("[test:1] Creating new thread...\n"); thread_new(thread2, 0); while (obj == -1); - printk("[module:test:1] Object was created. Sending request...\n"); + printk("[test:1] Object was created. Sending request...\n"); struct user_sendrequest sr; sr.func = 0x80000001; request(obj, &sr); - printk("[module:test:1] Got answer. Sending message...\n"); + printk("[test:1] Got answer. Sending message...\n"); send_msg(obj, &sr); - printk("[module:test:1] HAHA !!! Death in 10 seconds!\n"); + printk("[test:1] HAHA !!! Death in 10 seconds!\n"); thread_sleep(10000); return 0; } -- cgit v1.2.3