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
+/*
+ * 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>
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);
}
}
}
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);
+/*
+ * 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,
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;
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);
}
/*
* 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
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);