summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-09-18 15:46:18 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-09-18 15:46:18 -0400
commit6da70f16c584ee897a4ac4f51d016a615c84042b (patch)
treece5458f9daa9f055340bfafc85d5197ce9aa678a /sys
parent13adbc58eb9f5eb5d6f0e4454bd005e9adbb47c8 (diff)
downloadjove-kernel-6da70f16c584ee897a4ac4f51d016a615c84042b.tar.gz
jove-kernel-6da70f16c584ee897a4ac4f51d016a615c84042b.tar.bz2
jove-kernel-6da70f16c584ee897a4ac4f51d016a615c84042b.zip
cleanup for real hw attempt
Diffstat (limited to 'sys')
-rw-r--r--sys/syscall.c16
-rw-r--r--sys/syscall.h6
-rw-r--r--sys/syscall_pagedir.c81
-rw-r--r--sys/syscall_untyped.c2
4 files changed, 89 insertions, 16 deletions
diff --git a/sys/syscall.c b/sys/syscall.c
index 5670bbb..f41f3f6 100644
--- a/sys/syscall.c
+++ b/sys/syscall.c
@@ -44,8 +44,8 @@ static const syscall_handle_t s_syscall_handles[128] = {
[JOVE_OBJ_OBJDIR] = _syscall_handle_objdir,
[JOVE_OBJ_PAGEDIR] = _syscall_handle_generic,
[JOVE_OBJ_PROCESSOR] = _syscall_handle_generic,
+ [JOVE_OBJ_HWMEMORY] = _syscall_handle_generic,
[JOVE_OBJ_PROCESS] = _syscall_handle_generic,
- [JOVE_OBJ_ACPI_TABLE] = _syscall_handle_generic,
[JOVE_OBJ_INT_HANDLE] = _syscall_handle_generic,
[JOVE_OBJ_INITRD_FILE] = _syscall_handle_generic,
[JOVE_OBJ_FRAMEBUFFER] = _syscall_handle_generic,
@@ -67,19 +67,19 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
jove_owned_obj_t *objdir = pcb_rootdir(pcb);
jove_owned_obj_t *message_obj = objdir_trygetobj(objdir, message_path, message_pathlen);
+ int sysret = 0;
+
if(message_obj == NULL) {
klogf("Process %i tried to call syscall with bad message %P : %s\n",
pcb_pid(pcb), message_path, message_pathlen, errstr(errno));
+ sysret = -errno;
goto release_premsg;
- return errno;
}
- int sysret = 0;
-
if(obj_gettype_linked(message_obj) != JOVE_OBJ_MESSAGE) {
klogf("Process %i tried to call syscall with invalid object %P\n",
pcb_pid(pcb), message_path, message_pathlen);
- sysret = EBADOBJ;
+ sysret = -EBADOBJ;
goto release_return;
}
@@ -91,7 +91,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
if(bytes_needed > messagelen) {
//Target path exceeds message length.
klogf("Process %i tried to call syscall with target path too big for message.\n", pcb_pid(pcb));
- sysret = ETOOSMALL;
+ sysret = -ETOOSMALL;
goto release_return;
}
jove_owned_obj_t *target = objdir_trygetobj(objdir, header->path, header->pathlen);
@@ -99,7 +99,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
//Could not find payload target in pcb rootdir.
klogf("Process %i tried to call syscall with bad target path %P : %s\n",
pcb_pid(pcb), header->path, header->pathlen, errstr(errno));
- sysret = errno;
+ sysret = -errno;
goto release_return;
}
@@ -114,7 +114,7 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
if(call_handle == NULL) {
klogf("Process %i tried to call syscall on object %P which doesn't support syscalls!\n",
pcb_pid(pcb), header->path, header->pathlen);
- sysret = EBADOBJ;
+ sysret = -EBADOBJ;
}else
sysret = call_handle(
pcb_obj, objdir, message_obj, target,
diff --git a/sys/syscall.h b/sys/syscall.h
index 2044069..9f56447 100644
--- a/sys/syscall.h
+++ b/sys/syscall.h
@@ -8,20 +8,20 @@
#define CHECK_TOOSMALL(required, present, fail_msg) \
do { if(present < required) { \
kprintf("%s: %s\n", __func__, fail_msg); \
- return ETOOSMALL; \
+ return -ETOOSMALL; \
} } while(0)
#define CHECK_OBJEXISTS(obj, fail_msg) \
do { if(obj == NULL) { \
kprintf("%s: %s\n", __func__, fail_msg); \
- return EBADOBJ; \
+ return -EBADOBJ; \
} } while(0)
#define CHECK_OBJTYPE(obj, type, fail_msg) \
do { if(obj_gettype(obj) != type) { \
kprintf("%s: %s\n", __func__, fail_msg); \
obj_release(obj); \
- return EBADOBJ; \
+ return -EBADOBJ; \
} } while(0)
#define SYSCALL_FUNCTION_ARGS \
diff --git a/sys/syscall_pagedir.c b/sys/syscall_pagedir.c
index 144a02b..f80da76 100644
--- a/sys/syscall_pagedir.c
+++ b/sys/syscall_pagedir.c
@@ -1,3 +1,4 @@
+#include "api/syscall.h"
#include "hal/memory.h"
#include "jove.h"
#include "lib/printf.h"
@@ -26,10 +27,10 @@ s_syscall_pagedir_map(
"Message too small for untyped path.");
errno = 0;
- jove_owned_obj_t *untyped_obj = objdir_getobj(objdir,
+ jove_owned_obj_t *untyped_obj = objdir_trygetobj(objdir,
payload->untyped_path, payload->untyped_pathlen);
if(errno) {
- kprintf("%s: Untyped path does not point to a valid object.\n", __func__);
+ kprintf("%s: Untyped obj failed for the reason: %s\n", __func__, errstr(errno));
return errno;
}
@@ -53,6 +54,42 @@ s_syscall_pagedir_map(
}
static int
+s_syscall_pagedir_unmap(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data,
+ jove_owned_obj_t **none_ret)
+{
+ size_t bytes_needed = sizeof(struct syscall_pagedir_unmap);
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for payload");
+
+ struct syscall_pagedir_unmap *payload = payload_data;
+ if(payload->virtual_address > 0xFFFF800000000000ULL) {
+ kprintf("%s: Virtual address is above user limit.\n", __func__);
+ return EBADARG;
+ }
+
+ bytes_needed += payload->none_pathlen * 2;
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for none path");
+
+ jove_owned_obj_t *none_obj = objdir_trygetobj(objdir,
+ payload->none_path, payload->none_pathlen);
+ if(errno) {
+ kprintf("%s: None obj retrieval failed for the reason: %s\n",
+ __func__, errstr(errno));
+ return errno;
+ }
+
+ CHECK_OBJTYPE(none_obj, JOVE_OBJ_NONE,
+ "None path does not point to none object.");
+ *none_ret = none_obj;
+ return 0;
+}
+
+static int
s_syscall_pagedir_map_frame(
jove_owned_obj_t *objdir,
jove_owned_obj_t *target_obj,
@@ -66,7 +103,7 @@ s_syscall_pagedir_map_frame(
}
struct syscall_pagedir_map *payload = payload_data;
- sysret = pagedir_map_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
+ sysret = pagedir_map_untyped_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
obj_release(untyped_obj);
return sysret;
}
@@ -85,11 +122,43 @@ s_syscall_pagedir_map_table(
}
struct syscall_pagedir_map *payload = payload_data;
- sysret = pagedir_map_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
+ sysret = pagedir_map_untyped_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
obj_release(untyped_obj);
return sysret;
}
+static int
+s_syscall_pagedir_unmap_frame(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data)
+{
+ jove_owned_obj_t *none_obj;
+ int sysret = s_syscall_pagedir_unmap(objdir, target_obj, payload_bytes, payload_data, &none_obj);
+
+ if(!sysret) return sysret;
+ struct syscall_pagedir_unmap *payload = payload_data;
+
+ return pagedir_unmap_untyped_frame(target_obj, none_obj, payload->virtual_address);
+}
+
+static int
+s_syscall_pagedir_unmap_table(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data)
+{
+ jove_owned_obj_t *none_obj;
+ int sysret = s_syscall_pagedir_unmap(objdir, target_obj, payload_bytes, payload_data, &none_obj);
+
+ if(!sysret) return sysret;
+ struct syscall_pagedir_unmap *payload = payload_data;
+
+ return pagedir_unmap_untyped_table(target_obj, none_obj, payload->virtual_address);
+}
+
int
_syscall_handle_pagedir(
jove_owned_obj_t *pcb_obj,
@@ -105,6 +174,10 @@ _syscall_handle_pagedir(
return s_syscall_pagedir_map_frame(objdir, target_obj, bytes_left, payload);
case SYSCALL_PAGEDIR_MAP_TABLE:
return s_syscall_pagedir_map_table(objdir, target_obj, bytes_left, payload);
+ case SYSCALL_PAGEDIR_UNMAP_FRAME:
+ return s_syscall_pagedir_unmap_frame(objdir, target_obj, bytes_left, payload);
+ case SYSCALL_PAGEDIR_UNMAP_TABLE:
+ return s_syscall_pagedir_unmap_table(objdir, target_obj, bytes_left, payload);
default:
kprintf("syscall_handle_pagedir: Pagedir does not support syscall %i\n", header->callid);
return EBADARG;
diff --git a/sys/syscall_untyped.c b/sys/syscall_untyped.c
index fcdb5f6..975faaa 100644
--- a/sys/syscall_untyped.c
+++ b/sys/syscall_untyped.c
@@ -72,7 +72,7 @@ int _syscall_handle_untyped(
return s_syscall_untyped_merge(objdir, target_obj, payload_bytes, payload);
default:
kprintf("syscall_untyped: Untyped object does not support syscall %i\n", header->callid);
- return EBADARG;
+ return -EBADARG;
}
return 0;
}