aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2020-08-22 19:44:49 +0200
committerMarvin Borner2020-08-22 19:44:49 +0200
commit8bb7b5cceaaf96a5dd6321d35aae28748896d87b (patch)
tree9a4103fb1da636fdf0c5ec8f04425c0c388f527d /kernel/features
parent424dc57424ee17de77d689443f95d2e1bed72f4a (diff)
Added *very* basic polling ipc
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/proc.c36
-rw-r--r--kernel/features/syscall.c15
2 files changed, 50 insertions, 1 deletions
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index b968032..4d4a9f3 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -99,6 +99,30 @@ struct proc *proc_current()
return NULL;
}
+void proc_send(struct proc *src, struct proc *dest, enum message_type type, void *data)
+{
+ assert(src && dest);
+ struct proc_message *msg = malloc(sizeof(*msg));
+ msg->src = src;
+ msg->dest = dest;
+ msg->msg = malloc(sizeof(struct message));
+ msg->msg->src = src->pid;
+ msg->msg->type = type;
+ msg->msg->data = data;
+ list_add(dest->messages, msg);
+}
+
+struct proc_message *proc_receive(struct proc *proc)
+{
+ if (proc->messages && proc->messages->head) {
+ struct proc_message *msg = proc->messages->head->data;
+ list_remove(proc->messages, proc->messages->head);
+ return msg;
+ } else {
+ return NULL;
+ }
+}
+
void proc_resolve(struct proc *proc)
{
proc->state = PROC_RESOLVED;
@@ -107,6 +131,17 @@ void proc_resolve(struct proc *proc)
hlt();
}
+struct proc *proc_from_pid(u32 pid)
+{
+ struct node *iterator = proc_list->head;
+ do {
+ if (((struct proc *)iterator->data)->pid == pid) {
+ return iterator->data;
+ }
+ } while ((iterator = iterator->next) != NULL);
+ return NULL;
+}
+
void proc_exit(struct proc *proc, int status)
{
assert(proc);
@@ -130,6 +165,7 @@ struct proc *proc_make()
struct proc *proc = malloc(sizeof(*proc));
proc->pid = pid++;
proc->events = list_new();
+ proc->messages = list_new();
proc->state = PROC_DEFAULT;
if (current)
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index c8da824..9bd5e9b 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -16,7 +16,9 @@ void syscall_handler(struct regs *r)
{
enum sys num = r->eax;
r->eax = 0;
- printf("[SYSCALL] %d: ", num);
+
+ if (num != SYS_RECEIVE)
+ printf("[SYSCALL] %d: ", num);
switch (num) {
case SYS_LOOP: {
@@ -87,6 +89,17 @@ void syscall_handler(struct regs *r)
proc_resolve(proc_current());
break;
}
+ case SYS_SEND: {
+ printf("send\n");
+ proc_send(proc_current(), proc_from_pid(r->ebx), r->ecx, (void *)r->edx);
+ break;
+ }
+ case SYS_RECEIVE: {
+ /* printf("receive\n"); */
+ struct proc_message *msg = proc_receive(proc_current());
+ r->eax = (u32)(msg ? msg->msg : NULL);
+ break;
+ }
default: {
printf("unknown\n");
loop();