summaryrefslogtreecommitdiffstats
path: root/syscall
diff options
context:
space:
mode:
Diffstat (limited to 'syscall')
-rw-r--r--syscall/handler.c8
-rw-r--r--syscall/invoke-untyped.c19
-rw-r--r--syscall/invoke_objdir.c40
3 files changed, 57 insertions, 10 deletions
diff --git a/syscall/handler.c b/syscall/handler.c
index 6ac71da..b3eea99 100644
--- a/syscall/handler.c
+++ b/syscall/handler.c
@@ -31,6 +31,12 @@ s_syscall_handle_invoke(objdir_t *root_dir, uint8_t *payload)
objdir_entry_t *target_entry;
SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, target_pathw, target_entry);
+#ifdef DBG_SYSCALL
+ klogf("Calling invoke on obj %p [%i:%i] type %i\n",
+ target_entry, target_pathw,
+ payload[payload_at - 1], target_entry->type);
+#endif
+
switch(target_entry->type) {
case KO_NONE:
return -KE_BADOBJ;
@@ -38,8 +44,6 @@ s_syscall_handle_invoke(objdir_t *root_dir, uint8_t *payload)
return s_invoke_release(root_dir, target_entry, payload, payload_at, syscall_handle_invoke_objdir);
case KO_MEMORY_UNTYPED:
return s_invoke_release(root_dir, target_entry, payload, payload_at, syscall_handle_invoke_untyped);
- case KO_MEMORY_MAPPING:
- return s_invoke_release(root_dir, target_entry, payload, payload_at, syscall_handle_invoke_mapping);
default:
return _syscall_handler_arch(root_dir, target_entry, payload, payload_at);
}
diff --git a/syscall/invoke-untyped.c b/syscall/invoke-untyped.c
index 6b9199f..fe34ce9 100644
--- a/syscall/invoke-untyped.c
+++ b/syscall/invoke-untyped.c
@@ -56,20 +56,27 @@ s_handle_invoke_untyped_split(
SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, dest_pathw, dest_entry);
if(dest_entry->type != KO_NONE) return -KE_BADOBJ;
- size_t *untyped = (size_t*)target->data;
+ uintptr_t untyped_phys = target->data;
+ size_t *untyped = ko_entry_data(target);
size_t untyped_size = *untyped;
SYSCALL_PAYLOAD_TAKEL(payload, payload_at, dest_bytes, size_t);
if(untyped_size - sizeof(size_t) <= dest_bytes) return -KE_TOOSMALL;
- size_t *split = (size_t*)(((uintptr_t)untyped) + untyped_size - dest_bytes);
- *untyped -= dest_bytes;
- *split = dest_bytes;
-
*dest_entry = (objdir_entry_t) {
.type = KO_MEMORY_UNTYPED,
- .data = (uintptr_t)split
+ .data = untyped_phys + untyped_size - dest_bytes
};
+
+ size_t *split = ko_entry_data(dest_entry);
+ *untyped -= dest_bytes;
+ *split = dest_bytes;
+
+#ifdef DBG_SYSCALL
+ klogf("split %p[%p:%i] into %p[%p:%i]\n",
+ target, target->data, untyped_size,
+ dest_entry, dest_entry->data, dest_bytes);
+#endif
return 0;
}
diff --git a/syscall/invoke_objdir.c b/syscall/invoke_objdir.c
index 97dd126..0cc5a44 100644
--- a/syscall/invoke_objdir.c
+++ b/syscall/invoke_objdir.c
@@ -2,6 +2,7 @@
#include "syscall.h"
#include "error.h"
#include "lock.h"
+#include "string.h"
#include "print.h"
static int
@@ -40,15 +41,50 @@ s_handle_invoke_objdir_lastmemb(
uint8_t lastfull = 0;
for(int i = 1; i < 256; i++) {
if(target_dir->entries[i].type != KO_NONE) lastfull = i;
- }
+}
+#ifdef DBG_SYSCALL
+ klogf("%i\n", lastfull);
+#endif
*dest = lastfull;
return 0;
}
+static int
+s_handle_invoke_objdir_move(
+ objdir_t *root_dir,
+ objdir_t *target_dir,
+ uint8_t *payload,
+ size_t payload_at
+ )
+{
+ uint8_t target_memb;
+ size_t dest_pathw;
+ objdir_entry_t *dest_entry;
+
+ SYSCALL_PAYLOAD_TAKEL(payload, payload_at, target_memb, uint8_t);
+ SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, dest_pathw, dest_entry);
+
+ if(target_memb == 0) return KE_OOB;
+ if(dest_entry->type != KO_NONE) return KE_FULL;
+
+ objdir_entry_t *move_entry = &target_dir->entries[target_memb];
+ if(move_entry->type == KO_NONE) return KE_BADOBJ;
+
+#ifdef DBG_SYSCALL
+ klogf("move %p -> %p\n", move_entry, dest_entry);
+#endif
+
+ memcpy(dest_entry, move_entry, sizeof(objdir_entry_t));
+ memset(move_entry, 0, sizeof(objdir_entry_t));
+
+ return KE_OK;
+}
+
static int (*s_invoke_handles[])(objdir_t*, objdir_t*, uint8_t*, size_t) = {
[INVOKE_OBJDIR_GETMEMB] = s_handle_invoke_objdir_getmemb,
- [INVOKE_OBJDIR_LASTMEMB] = s_handle_invoke_objdir_lastmemb
+ [INVOKE_OBJDIR_LASTMEMB] = s_handle_invoke_objdir_lastmemb,
+ [INVOKE_OBJDIR_MOVE] = s_handle_invoke_objdir_move,
};
static size_t s_invoke_handles_count = sizeof(s_invoke_handles) / sizeof(void*);