klange/toaruos — pull request #36 by Jimx- (2013-06-26 13:44:15+00:00)
Title: Microkernel: IPC and some ideas

Hi! I'm very interested in your os:)

I just wrote two new syscalls: ```send_msg(pid_t dest, message_t * message)``` and ```receive_msg(pid_t src, message_t * message)```, which are used for sending/receiving message.

```message_t``` is a struct that contains some information.
```C
/* Message struct */
typedef struct message {
int	retval;
} message_t;
```

This is a very first step, but when we put syscalls into some daemon programs(VFS, MM, device drivers), this will be useful. In a microkernel system, user programs call syscalls by sending request messages, read() for example,
```C
/* User program */
message_t msg;
msg.TYPE = READ;
msg.FD = fd;
msg.BUF = buf;
msg.CNT = count;
send_msg(VFS, &msg);
```
After sending the message, the user program will be blocked. Then VFS(as a daemon process) will receive this message and handle it:
```C
/* VFS */
message_t msg;
receive_msg(PROC_ANY, &msg);
msg.retval = read_fs(msg.FD, msg.BUF, msg.CNT);
send_msg(msg.SRC, &msg);
```
In this way, the result is sent back to the user program.
```C
/* User program */
...
receive_msg(VFS, &msg);
retval = msg.retval;
```
So the read() syscall should be:
```C
int read(fd, buf, count) {
message_t msg;
msg.TYPE = READ;
msg.FD = fd;
msg.BUF = buf;
msg.CNT = count;
send_msg(VFS, &msg);
receive_msg(VFS, &msg);
return msg.retval;
}
```
These are my simple ideas on the microkernel structure...haven't tested it and since I'm still trying to get familiar with toaruos, if I did something wrong, please tell me...