summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xcopy_fdd.sh1
-rw-r--r--doc/manager.txt17
-rw-r--r--doc/messaging.txt48
-rw-r--r--doc/method.txt1
-rw-r--r--doc/objects-requests.txt25
-rw-r--r--doc/roadmap.txt4
-rw-r--r--doc/syscalls.txt121
-rw-r--r--menu_fdd.cfg1
-rw-r--r--src/include/gc/obj.h10
-rw-r--r--src/include/gc/server.h90
-rw-r--r--src/include/gc/syscall.h12
-rw-r--r--src/include/gm/call.h18
-rw-r--r--src/include/gm/call/manager.h14
-rw-r--r--src/include/gm/method.h27
-rw-r--r--src/include/gm/method/manager.h20
-rw-r--r--src/kernel/Makefile2
-rw-r--r--src/kernel/ipc/object.c118
-rw-r--r--src/kernel/ipc/object.h40
-rw-r--r--src/kernel/ipc/request.c253
-rw-r--r--src/kernel/ipc/request.h54
-rw-r--r--src/kernel/task/syscall.c24
-rw-r--r--src/kernel/task/task.c11
-rw-r--r--src/kernel/task/task.h3
-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
-rw-r--r--src/modules/manager/Makefile9
-rw-r--r--src/modules/manager/main.c109
-rw-r--r--src/modules/test/main.c61
33 files changed, 115 insertions, 1323 deletions
diff --git a/Makefile b/Makefile
index 192c867..c83979c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.PHONY: clean, mrproper, Init.rfs, floppy, commit
-Projects = kernel library modules/manager modules/test
+Projects = kernel library modules/test
Floppy = Grapes.fl.img
diff --git a/copy_fdd.sh b/copy_fdd.sh
index 4a6b239..d154abb 100755
--- a/copy_fdd.sh
+++ b/copy_fdd.sh
@@ -9,7 +9,6 @@ cp menu_fdd.cfg mnt/boot/menu.cfg
# copy kernel
cp src/kernel/kernel.elf mnt
cp src/modules/test/test.elf mnt
-cp src/modules/manager/manager.elf mnt
#echo "*** Launching a BASH shell, if you want to do any maintenance ***"
#bash || exit 0
diff --git a/doc/manager.txt b/doc/manager.txt
deleted file mode 100644
index 5603ee5..0000000
--- a/doc/manager.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-The manager is a service whose role is to manage all other services. By default, all loaded modules
-get a descriptor to the manager service (descriptor 1).
-
-Each service has a set of ressources that can get a descriptor by openning them. These ressources
-are identified by a string, such as :
-kbd:readtext
-file:root/System/
-console:myuser/main
-
-To open these objects, a process would call the open() method on the manager object. The manager would
-then call the open() method on the corresponding process with the string after the first semicolon
-(for example: open("file:root/System") would call file.open("root/System")).
-
-If the string is just a service name (like open("kbd")), the manager would return a descriptor to the
-root object for that service.
-
-The manager is also the one that handle log entries for services, for the moment by printing them on the screen.
diff --git a/doc/messaging.txt b/doc/messaging.txt
new file mode 100644
index 0000000..804bb5d
--- /dev/null
+++ b/doc/messaging.txt
@@ -0,0 +1,48 @@
+Message passing is the technique used by processes for communicating with each other.
+It is based on a few basic functions :
+
+= msg_register =
+Registers the current process as the owner of a system channel.
+System channels are aliases for PIDs (negative PIDs resolve to corresponding real PID).
+They range from -1 to -255. They are allocated as follows :
+ from -1 to -19 : drivers
+ -1 = keyboard
+ -2 = mouse
+ from -20 to -29 : network services
+ -20 = networking subsystem (may be in several parts)
+ from -30 to -39 : system services
+ -30 = virtual file system
+ -31 = logger
+ -32 = user server
+ from -40 to -49 : UI services
+ -40 = graphic server (includes VESA driver for now)
+ -41 = sound server
+Modules for HDD drivers, network cards, sound cards, ... do not register as devices but instead
+notify of their presence to the corresponding service.
+
+= msg_send =
+Sends a message to a process. Arguments:
+- Receiver PID or system channel id
+- Message data (up to 64k bytes, minimum 4 bytes)
+The first 4 bytes of the message data always designate the message code (function).
+The kernel may intercept some special messages (as "kill process" or stuff like that).
+
+= msg_info =
+Gets first message in the queue for current process.
+Function can block waiting for a message if asked by caller and if no other function already does it.
+When it is there, return the following:
+- If a message has come
+- The sender PID
+- The message code (first 4 bytes of data)
+- The length of the data
+
+= msg_get =
+Reads the data of the first message in the queue for current process.
+Is passed a pointer where the data will be written. It is supposed that enougth memory is already allocated.
+
+From a kernel point of view, message passing is asynchronious,
+but there also are userland functions for making them look synchronious by waiting for an answer.
+Usually, message codes | 0x80000000 are answers to a message.
+
+Most processes, most of the time, will be in a loop waiting for messages to come.
+The drivers are the principal exception to that, they instead wait for an interrupt or another hardware signal.
diff --git a/doc/method.txt b/doc/method.txt
deleted file mode 100644
index 066e0ae..0000000
--- a/doc/method.txt
+++ /dev/null
@@ -1 +0,0 @@
-All methods are defined in src/include/gm/method.h and src/include/gm/m/*
diff --git a/doc/objects-requests.txt b/doc/objects-requests.txt
deleted file mode 100644
index e53c343..0000000
--- a/doc/objects-requests.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-The requests can be of two types :
-- Blocking, IE the sender waits for an answer
-- Nonblocking, the request is a simple message.
-
-Requests are identified by a 32bit function number, composed as follows :
- (8 bit) parameter and return type ; (24bit) function number
-
-the first 8 bits are :
- 2bit answer type ; 2bit parameter a type ; 2bit parameter b type ; 2bit parameter c type
-
-each two bit couple can be one of the following :
-- 00 : void
-- 01 : object descriptor number (will be copied with a new number to reciever)
-- 10 : long
-- 11 : long long (replies), or shared memory offset in sender's space (requests and messages)
-
-When shared memory segments are sent as request parameters from a process to the same process, the pointer
-to the memory is kept and sent to the handler function. If handler is in another process, receiver will
-have to call request_mapShm specifying a pointer. Shared memory is automatically unmapped when requests
-yields an answer, and is kept when the request is nonblocking (message).
-
-When objects are sent as request parameters, the receiver process will get an immediately usable object
-descriptor. The descriptor is closed in blocking requests after the request yields an answer (except if the
-request is handled in the same process than the sender, OR if the receiver already had a descriptor to
-this object). The descriptor is kept when sent by a nonblocking request (message).
diff --git a/doc/roadmap.txt b/doc/roadmap.txt
index 14003c0..cf14395 100644
--- a/doc/roadmap.txt
+++ b/doc/roadmap.txt
@@ -7,5 +7,5 @@
** 0.0.5 'Truth is better cold' **
- Review privilege system
- Driver processes can ask to map physical memory in their address space
-- Describe interfaces for server (any service's main object), reader and writer.
-- Keyboard driver, userland display driver, virtual terminal driver
+- Redo all messaging stuff, simpler.
+- Keyboard driver, veryveryvery simple shell module using kbd driver and printk
diff --git a/doc/syscalls.txt b/doc/syscalls.txt
index 8053b38..28eb636 100644
--- a/doc/syscalls.txt
+++ b/doc/syscalls.txt
@@ -14,100 +14,39 @@ id=eax Name Parameters Description
edx: stack pointer
6 irq_wait ebx: irq number Waits for an IRQ (requires privilege PL_DRIVER)
7 proc_priv none Returns current process privilege level
- 8 shm_create ebx: offset Create a shared memory segment at offset (ret = errcode)
+ 8 proc_setheap
+ 9 shm_create ebx: offset Create a shared memory segment at offset (ret = errcode)
ecx: length
- 9 shm_delete ebx: offset Delete a shared memory segment at offset (ret = errcode)
- 10 object_create none Creates an object for current process (returns a descriptor to it)
- 11 object_owned ebx: object descriptor True (1) if object with this descriptor is ours, false(0) elsewhere
- 12 object_close ebx: object descriptor Closes descriptor to an object (deleting it if necessary)
- 13 request_get ebx: object descriptor Gets a request pending on object (only if we own it)
- ecx: pointer to write request
- edx: wait for a request ?
- 14 request_has ebx: object descriptor Is there a request waiting on this object ?
- 15 request_answer ebx: object descriptor
- ecx, edx: answer Answer a request on object
- 16 request_mapShm ebx: object descriptor Map shared memory sent with request to receiver's address space
- ecx: offset
- edx: parameter number (0, 1 or 2)
- 17 request ebx: object descriptor Send a blocking request to object
- ecx: pointer to user_sendrequest struct with information
- 18 send_msg same as above Send a nonblocking request to object, same as above
- 19 proc_setheap ebx: start address Creates/resizes/moves the heap segment allocated to this process (one per process)
- ecx: end address
+ 10 shm_delete ebx: offset Delete a shared memory segment at offset (ret = errcode)
+ 11 msg_register ebx: service id Registers current process as owner of a system channel (ret = errcode)
+ 12 msg_send ebx: receiver pid Sends a message to pid or owner of system channel
+ ecx: message data ptr
+ edx: message length
+ 13 msg_info ebx: answer struct ptr Get info on the first message of the queue for this process
+ ecx: wait?
+ 14 msg_get ebx: pointer to data Gets the data for first message on the queue; deletes message from queue
+
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, an int which is the return status (error code) of the function
-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
+= msg_register (10)
+Parameters: requested system channel id (int)
+Returns: errorcode or 0 on success
+Registers current process as owner of given system channel.
+
+= msg_send (11)
+Parameters: receiver pid (signed! int), data ptr (void*), data len (unsigned)
+Returns: errorcode or 0 on success
+Sends a message to given PID or owner of given system channel.
+
+= msg_info (12)
+Parameters: pointer to answer struct (msg_info_answer*), wait for request? (bool)
+Returns: nothing (all is in answer struct)
+Gets info on waiting messages for current process.
+
+= msg_get (13)
+Parameters: pointer to data struct (void*)
+Returns: errorcode or 0 on failure
+Gets the data for a message that is in the queue.
diff --git a/menu_fdd.cfg b/menu_fdd.cfg
index 551c1e8..d9654f7 100644
--- a/menu_fdd.cfg
+++ b/menu_fdd.cfg
@@ -2,5 +2,4 @@ timeout 1
title Grapes
kernel /kernel.elf
-module /manager.elf
module /test.elf
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 <gc/obj.h>
-
-#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 <gm/call.h>
-#include <gc/obj.h>
-
-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_<method_name>_<ret><param1><param2><param3>
- * 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 <lib/mutex.h>
-#include <mem/mem.h>
-
-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 <task/task.h>
-
-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 <lib/mutex.h>
-#include <mem/seg.h>
-#include <mem/mem.h>
-
-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 <mem/mem.h>
#include <mem/seg.h>
#include <mem/gdt.h>
-#include <ipc/object.h>
#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 <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);
}
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 <gc/syscall.h>
-#include <gc/mem.h>
-#include <gc/server.h>
-#include <gm/method.h>
-#include <gm/call/manager.h>
-#include <string.h>
-
-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 <gc/syscall.h>
#include <gc/mem.h>
-#include <gc/server.h>
-#include <gm/method.h>
-#include <gm/call.h>
-#include <gm/call/manager.h>
#include <stdlib.h>
-#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;
}