summaryrefslogtreecommitdiff
path: root/kernel/ipc.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/ipc.c')
-rw-r--r--kernel/ipc.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/kernel/ipc.c b/kernel/ipc.c
index e29b169..d051ea1 100644
--- a/kernel/ipc.c
+++ b/kernel/ipc.c
@@ -13,28 +13,33 @@ struct IpcEndpoint {
struct IpcEndpoint ipc_endpoints[100];
bool ipc_register_endpoint(u32 endpoint) {
- if (endpoint >= 100)
+ if (endpoint >= 100) {
return false;
- if (ipc_endpoints[endpoint].in_use)
+ }
+ if (ipc_endpoints[endpoint].in_use) {
return false;
+ }
ipc_endpoints[endpoint].in_use = 1;
ipc_endpoints[endpoint].pid = get_current_task()->pid;
return true;
}
bool ipc_endpoint_to_pid(u32 endpoint, u32 *pid) {
- if (endpoint >= 100)
+ if (endpoint >= 100) {
return false;
- if (!ipc_endpoints[endpoint].in_use)
+ }
+ if (!ipc_endpoints[endpoint].in_use) {
return false;
+ }
*pid = ipc_endpoints[endpoint].pid;
return true;
}
int ipc_get_mailbox(u32 id, struct IpcMailbox **out) {
process_t *p;
- if (!get_task_from_pid(id, &p))
+ if (!get_task_from_pid(id, &p)) {
return 0;
+ }
*out = &p->ipc_mailbox;
return 1;
}
@@ -43,27 +48,36 @@ int ipc_read(u8 *buffer, u32 length, u32 *sender_pid) {
struct IpcMailbox *handler = &get_current_task()->ipc_mailbox;
u32 read_ptr = handler->read_ptr;
- struct IpcMessage *ipc_message = NULL;
+ struct IpcMessage *ipc_message = &handler->data[read_ptr];
for (;;) {
- ipc_message = &handler->data[read_ptr];
if (!ipc_message->is_used) {
- return 0;
+ if (get_current_task()->is_interrupted) {
+ get_current_task()->is_interrupted = 0;
+ get_current_task()->is_halted = 0;
+ return 0;
+ }
+ get_current_task()->is_halted = 1;
+ asm("sti");
+ continue;
}
- kprintf("breaking out\n");
break;
}
+ get_current_task()->is_halted = 0;
+ asm("cli");
ipc_message->is_used = 0;
// TODO: Verify sender_pid is a valid address
- if (sender_pid)
+ if (sender_pid) {
*sender_pid = ipc_message->sender_pid;
+ }
u32 len = min(length, ipc_message->size);
memcpy(buffer, ipc_message->buffer, len);
// Update read_ptr
read_ptr++;
- if (read_ptr >= IPC_NUM_DATA)
+ if (read_ptr >= IPC_NUM_DATA) {
read_ptr = 0;
+ }
handler->read_ptr = read_ptr;
return len;
}
@@ -82,8 +96,9 @@ int ipc_write_to_process(int pid, u8 *buffer, u32 length) {
// Update write_ptr
write_ptr++;
- if (write_ptr >= IPC_NUM_DATA)
+ if (write_ptr >= IPC_NUM_DATA) {
write_ptr = 0;
+ }
handler->write_ptr = write_ptr;
return len;
}