]> git.corax.cc Git - corax/commitdiff
kernel/core: Use IPC mailboxes in process and cxipc implementation
authorMatthias Kruk <m@m10k.eu>
Sat, 14 Mar 2020 09:03:39 +0000 (18:03 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 14 Mar 2020 09:03:39 +0000 (18:03 +0900)
kernel/Makefile
kernel/core/cxipc.c
kernel/core/process.c
kernel/include/process.h

index e14ae2c2aa431469a26f35644ac2582573d47d11..b96b61f779a9be952c55a46ec863f3eb84ac52c9 100644 (file)
@@ -2,7 +2,8 @@ OBJECTS = arch/arch.o core/core.o vga/vga.o kbd/kbd.o sched/sched.o
 OBJECTS += klibc/klibc.a # klibc needs to be last
 DEPS = arch core vga kbd klibc sched
 LDFLAGS = --oformat=elf32-i386 -b elf32-i386 -m elf_i386
-CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding
+CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding -nostdinc \
+        -fno-builtin -fno-builtin-memcpy
 LIBGCC = /usr/lib/gcc/i686-linux-gnu/8/libgcc.a
 PHONY = $(DEPS) clean
 OUTPUT = corax
index 50de0d97ba9d2f599ae94dc78437c6ab947f24a5..32d06c13076fb12d395f9e5a971bad4eeb73e873 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * This file is part of the Corax operating system.
+ * Copyright (C) 2016-2020 Matthias Kruk
+ *
+ * Corax is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Corax is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Corax.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <config.h>
 #include <corax/types.h>
 #include <corax/errno.h>
@@ -48,23 +66,14 @@ int sys_cxsend(pid_t to, struct cxmsg *msg)
                                kmsg->cm_len = CONFIG_IPC_MSGSIZE;
                        }
 
-                       /* place the message somewhere the destination process can find it */
+                       /* deliver the message to the destination process */
                        ret_val = process_inbox_put(dproc, kmsg);
 
                        if(ret_val < 0) {
-                               kfree(kmsg);
-                       } else {
-                               /* wait for destination process to pick up the message */
-
-#if FEATURE(DEBUG_IPC)
-                               dbg_printf("[%u] waiting for pid %u\n", process_get_id(sproc), to);
-#endif /* FEATURE(DEBUG_IPC) */
+                               dbg_printf("[%u] Failed to deliver message to pid %u\n",
+                                          process_get_id(sproc), to);
 
-                               process_wait(to);
-
-#if FEATURE(DEBUG_IPC)
-                               dbg_printf("[%u] returned from process_wait()\n", process_get_id(sproc));
-#endif /* FEATURE(DEBUG_IPC) */
+                               kfree(kmsg);
                        }
                }
        }
@@ -75,34 +84,25 @@ int sys_cxsend(pid_t to, struct cxmsg *msg)
 int sys_cxrecv(pid_t from, struct cxmsg *msg)
 {
        process_t *cproc;
+       struct cxmsg *kmsg;
        int ret_val;
 
-#if FEATURE(DEBUG_IPC)
-       dbg_printf("sys_cxrecv(0x%08x, %p)\n", from, msg);
-#endif /* FEATURE(DEBUG_IPC) */
-
-       ret_val = -EFAULT;
        cproc = process_get_current();
 
-       if(cproc) {
-               struct cxmsg *kmsg;
-
 #if FEATURE(DEBUG_IPC)
-               dbg_printf("[%u] waiting for message\n", process_get_id(cproc));
+       dbg_printf("sys_cxrecv(0x%08x, %p)\n", from, msg);
+       dbg_printf("[%u] waiting for message\n", process_get_id(cproc));
 #endif /* FEATURE(DEBUG_IPC) */
 
-               /* process_inbox_get() always returns a valid message (or waits forever) */
-               kmsg = process_inbox_get(from);
+       ret_val = process_inbox_get(cproc, &kmsg);
 
+       if(!ret_val) {
 #if FEATURE(DEBUG_IPC)
                dbg_printf("[%u] got a message\n", process_get_id(cproc));
 #endif /* FEATURE(DEBUG_IPC) */
 
                process_memcpy_ktop(cproc, msg, kmsg, sizeof(*msg));
 
-               /* signal source that their message was picked up */
-               process_signal(kmsg->cm_src);
-
                /* we don't need the kernel-space buffer anymore */
                kfree(kmsg);
 
index 72ac3e98e65772b18b643c6e1369cee276a62a8a..828819a49b51cadad47c5a890fbf011205b1d944 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * This file is part of the Corax operating system.
+ * Copyright (C) 2016-2020 Matthias Kruk
+ *
+ * Corax is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Corax is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Corax.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <config.h>
 #include <corax/types.h>
 #include <corax/errno.h>
 #include <unistd.h>
 #include "fd.h"
 #include "sched.h"
+#include "mailbox.h"
 
+/*
+ * FIXME: Use a semaphore to count process references
+ */
 enum procstate {
        PROC_STATE_INIT = 0,
        PROC_STATE_READY,
@@ -29,11 +51,7 @@ struct process {
        gid_t          p_gid;
 
        spinlock_t     p_lock;
-
-       struct {
-               struct cxmsg *msg;
-               pid_t        sender;
-       } p_inbox[32];
+       struct mailbox p_mbox;
 
        enum procstate p_state;
        int            p_status;
@@ -518,56 +536,26 @@ int process_memcpy_ptop(process_t *dproc, void *dst, process_t *sproc, void *src
 
 int process_inbox_put(process_t *proc, struct cxmsg *msg)
 {
-       process_t *cproc;
        int ret_val;
-       int i;
-
-       cproc = process_get_current();
 
-       for(ret_val = -ENOMEM, i = 0; i < 32; i++) {
-               if(!(proc->p_inbox[i].sender)) {
-                       proc->p_inbox[i].sender = cproc->p_id;
-                       proc->p_inbox[i].msg = msg;
+       ret_val = -EINVAL;
 
-                       process_signal(proc->p_id);
-                       ret_val = 0;
-                       break;
-               }
+       if(proc) {
+               ret_val = mailbox_put(&(proc->p_mbox), msg);
        }
 
        return(ret_val);
 }
 
-struct cxmsg* process_inbox_get(pid_t from)
+int process_inbox_get(process_t *proc, struct cxmsg **msg)
 {
-       process_t *proc;
-       void *ret_val;
-
-       proc = process_get_current();
-
-       do {
-               int i;
-
-               for(ret_val = NULL, i = 0; i < 32; i++) {
-                       /* skip empty entries */
-                       if(!proc->p_inbox[i].sender) {
-                               continue;
-                       }
-
-                       if(proc->p_inbox[i].sender == from || from == PID_ANY) {
-                               ret_val = proc->p_inbox[i].msg;
-                               proc->p_inbox[i].msg = NULL;
-                               proc->p_inbox[i].sender = 0;
+       int ret_val;
 
-                               break;
-                       }
-               }
+       if(!proc) {
+               proc = process_get_current();
+       }
 
-               if(!ret_val) {
-                       dbg_printf("[%u] waiting for pid 0x%x\n", process_get_id(proc), from);
-                       process_wait(from);
-               }
-       } while(!ret_val);
+       ret_val = mailbox_get(&(proc->p_mbox), (void**)msg);
 
        return(ret_val);
 }
index 4d9eef95d56a87410260e7ae33e65a39f16eaf54..e2fda64ba73f6362e01d7f839e90f894e9e54781 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of the Corax operating system.
- * Copyright (C) 2016-2019 Matthias Kruk
+ * Copyright (C) 2016-2020 Matthias Kruk
  *
  * Corax is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@ int process_memcpy_ktop(process_t*, void*, void*, u32_t);
 int process_memcpy_ptop(process_t*, void*, process_t*, void*, u32_t);
 
 int           process_inbox_put(process_t*, struct cxmsg*);
-struct cxmsg* process_inbox_get(pid_t);
+int           process_inbox_get(process_t*, struct cxmsg**);
 
 int           process_wait(pid_t);
 int           process_signal(pid_t);