summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-11-28 18:55:19 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-11-28 18:55:19 -0500
commitc4f27dbf1d2a257e08087e9a1ce932579f9dc72f (patch)
tree702a525bab082d85050be5550b3660b081cc928e
parent255e2d57b08236051b659323865b6ce2772071f6 (diff)
downloadmodit-kernel-c4f27dbf1d2a257e08087e9a1ce932579f9dc72f.tar.gz
modit-kernel-c4f27dbf1d2a257e08087e9a1ce932579f9dc72f.tar.bz2
modit-kernel-c4f27dbf1d2a257e08087e9a1ce932579f9dc72f.zip
removed excess mutex; add detach syscall
-rw-r--r--include/arch_x86/common/ipc.h2
-rw-r--r--src/arch_x86/64/task/context.c1
-rw-r--r--src/arch_x86/64/task/message.c8
-rw-r--r--src/arch_x86/64/task/port.c36
-rw-r--r--src/arch_x86/common/syscall/syscall.c10
5 files changed, 10 insertions, 47 deletions
diff --git a/include/arch_x86/common/ipc.h b/include/arch_x86/common/ipc.h
index f451e18..c8ed004 100644
--- a/include/arch_x86/common/ipc.h
+++ b/include/arch_x86/common/ipc.h
@@ -48,6 +48,6 @@ int port_read(portid_t id, uint8_t *buffer, size_t n);
int port_write(portid_t id, uint8_t *buffer, size_t n);
int message_send(size_t tgt, uint8_t *data, size_t len);
-int message_recv(uint8_t *buffer, size_t *sender);
+int message_recv(uint8_t *buffer, intmax_t *sender);
#endif
diff --git a/src/arch_x86/64/task/context.c b/src/arch_x86/64/task/context.c
index 27f6e55..5f84223 100644
--- a/src/arch_x86/64/task/context.c
+++ b/src/arch_x86/64/task/context.c
@@ -29,7 +29,6 @@ excontext_timer_handler(struct intregs *regs)
apic_write(0xB0, 0);
return;
}
-
in_timer = true;
excontext_switch(timer_context);
}
diff --git a/src/arch_x86/64/task/message.c b/src/arch_x86/64/task/message.c
index 64649ae..28244d0 100644
--- a/src/arch_x86/64/task/message.c
+++ b/src/arch_x86/64/task/message.c
@@ -13,7 +13,7 @@ message_send(size_t tgt, uint8_t *data, size_t len)
struct mailbox *mbx = &ctx->mailbox;
//Lock until mailbox has space
- while(mbx->messagec > IPC_MESSAGE_MAX);
+ while(mbx->messagec > IPC_MESSAGE_MAX) asm("hlt");
mbx->messagec++;
mutex_lock(&mbx->lock);
@@ -38,20 +38,20 @@ message_send(size_t tgt, uint8_t *data, size_t len)
}
int
-message_recv(uint8_t *buffer, size_t *sender)
+message_recv(uint8_t *buffer, intmax_t *sender)
{
struct mailbox *mbx = &current_excontext->mailbox;
//Lock until mailbox has messages
- while(mbx->messagec == 0);
+ while(mbx->messagec == 0) asm("hlt");
mbx->messagec--;
mutex_lock(&mbx->lock);
struct message *msg = mbx->messages_tail;
if(buffer == NULL) {
- mutex_unlock(&mbx->lock);
mbx->messagec++;
+ mutex_unlock(&mbx->lock);
return msg->datalen;
}
diff --git a/src/arch_x86/64/task/port.c b/src/arch_x86/64/task/port.c
index bda3658..601c12c 100644
--- a/src/arch_x86/64/task/port.c
+++ b/src/arch_x86/64/task/port.c
@@ -48,7 +48,6 @@ portid_t
port_open(size_t a, size_t b)
{
//Find if exists
- LOCK(ipc_ports)
for(intmax_t i = 0; i < portc; i++) {
if((ports[i].parties[0] == a && ports[i].parties[1] == b) ||
(ports[i].parties[1] == a && ports[i].parties[0] == b)) {
@@ -56,18 +55,15 @@ port_open(size_t a, size_t b)
return i;
}
}
- UNLOCK(ipc_ports)
portid_t id = 0;
struct port *port = port_findopen(&id);
if(port == NULL) return -1;
- mutex_lock(&port->lock);
port->parties[0] = a;
port->parties[1] = b;
port->datalen = 0;
- mutex_unlock(&port->lock);
return id;
}
@@ -77,23 +73,16 @@ port_close(portid_t id)
{
struct port *port = port_get(id);
if(port == NULL) return -1;
- LOCK(ipc_ports)
- mutex_lock(&port->lock);
//Make sure the closer owns the port
if(port->parties[0] != current_excontext->id &&
port->parties[1] != current_excontext->id) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return -2;
}
//Clear ownership from the port
port->parties[0] = 0;
port->parties[1] = 0;
-
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return 0;
}
@@ -101,21 +90,14 @@ int port_clear(portid_t id)
{
struct port *port = port_get(id);
if(port == NULL) return -1;
- LOCK(ipc_ports)
- mutex_lock(&port->lock);
//Make sure the closer owns the port
if(port->parties[0] != current_excontext->id &&
port->parties[1] != current_excontext->id) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return -2;
}
port->datalen = 0;
-
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return 0;
}
@@ -124,28 +106,19 @@ port_read(portid_t id, uint8_t *buffer, size_t n)
{
struct port *port = port_get(id);
if(port == NULL) return -1;
- LOCK(ipc_ports)
- mutex_lock(&port->lock);
//Make sure the closer owns the port
if(port->parties[0] != current_excontext->id &&
port->parties[1] != current_excontext->id) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return -2;
}
if(buffer == NULL) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return port->datalen;
}
if(n > port->datalen) n = port->datalen;
memcpy(buffer, port->data, n);
-
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return n;
}
@@ -154,29 +127,20 @@ port_write(portid_t id, uint8_t *buffer, size_t n)
{
struct port *port = port_get(id);
if(port == NULL) return -1;
- LOCK(ipc_ports)
- mutex_lock(&port->lock);
//Make sure the closer owns the port
if(port->parties[0] != current_excontext->id &&
port->parties[1] != current_excontext->id) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return -2;
}
if(buffer == NULL) {
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return 0;
}
if(n > IPC_PORT_DATA_MAX) n = IPC_PORT_DATA_MAX;
memcpy(port->data, buffer, n);
if(port->datalen < n) port->datalen = n;
-
- mutex_unlock(&port->lock);
- UNLOCK(ipc_ports)
return n;
}
diff --git a/src/arch_x86/common/syscall/syscall.c b/src/arch_x86/common/syscall/syscall.c
index 50bb49b..824b7ee 100644
--- a/src/arch_x86/common/syscall/syscall.c
+++ b/src/arch_x86/common/syscall/syscall.c
@@ -24,7 +24,7 @@ syscall_print(struct syscall_print_data *data)
POINTER_CHECK(data)
POINTER_CHECK(data->msg)
PRIV_CHECK(SYSCALL_PRIV_PRINT)
- return printk(KERNEL_INFO, "%s", data->msg);
+ return printf("%i %s", current_excontext->id, data->msg);
}
int
@@ -166,7 +166,8 @@ syscall_message_recv(struct syscall_message_data *data)
if(data->buffer != NULL) {
POINTER_CHECK(data->buffer)
}
- return message_recv(data->buffer, &data->tgt);
+ int len = message_recv(data->buffer, &(data->tgt));
+ return len;
}
int
@@ -189,12 +190,11 @@ int
syscall_detach(void *unused)
{
(void)unused;
- uintptr_t cr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "cr3");
+ uintptr_t cr3 = current_excontext->vcr3;
uintptr_t pcr3 = tlb_clonecr3();
+ if(pcr3 == 0) return 0;
vmm_mappg(pcr3, cr3, 0, 3);
- current_excontext->vcr3 = cr3;
-
excontext_switch(current_excontext);
return 0;
}