diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gc/mem.h | 9 | ||||
-rw-r--r-- | src/include/gc/obj.h | 14 | ||||
-rw-r--r-- | src/include/gc/server.h | 79 | ||||
-rw-r--r-- | src/include/gc/syscall.h | 4 | ||||
-rw-r--r-- | src/include/gm/method.h | 22 |
5 files changed, 127 insertions, 1 deletions
diff --git a/src/include/gc/mem.h b/src/include/gc/mem.h new file mode 100644 index 0000000..2557289 --- /dev/null +++ b/src/include/gc/mem.h @@ -0,0 +1,9 @@ +#ifndef DEF_HEAP_H +#define DEF_HEAP_H + +#include "gc/syscall.h" + +void* malloc(size_t size); +void free(void* p); + +#endif diff --git a/src/include/gc/obj.h b/src/include/gc/obj.h new file mode 100644 index 0000000..10651f5 --- /dev/null +++ b/src/include/gc/obj.h @@ -0,0 +1,14 @@ +#ifndef DEF_OBJ_H +#define DEF_OBJ_H + +// generic method error codes +#define ME_UNHANDLED -32767 +#define ME_INTERRUPTED -32766 + +struct object_cli { + int id; +}; + +typedef struct object_cli Object; + +#endif diff --git a/src/include/gc/server.h b/src/include/gc/server.h new file mode 100644 index 0000000..b98b4fb --- /dev/null +++ b/src/include/gc/server.h @@ -0,0 +1,79 @@ +#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; + } val; + int type; + int keepShm; //for messages : keep shared memory segment after return or unmap ? (default : 0 = unmap) + } parameters[3]; + uint32_t func; + 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); + +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); +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 5287d85..f731e10 100644 --- a/src/include/gc/syscall.h +++ b/src/include/gc/syscall.h @@ -21,6 +21,7 @@ struct user_sendrequest { uint32_t func, a, b, c; uint32_t answeri; int64_t answerll; + int errcode; }; void thread_exit(); @@ -38,9 +39,10 @@ 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, int answer1, int answer2); +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/method.h b/src/include/gm/method.h new file mode 100644 index 0000000..ac6ab0e --- /dev/null +++ b/src/include/gm/method.h @@ -0,0 +1,22 @@ +#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. */ + +#endif |