summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/untyped-retype.c38
-rw-r--r--lib/untyped.c16
2 files changed, 51 insertions, 3 deletions
diff --git a/lib/untyped-retype.c b/lib/untyped-retype.c
index 70fb4d2..526f19e 100644
--- a/lib/untyped-retype.c
+++ b/lib/untyped-retype.c
@@ -1,11 +1,43 @@
-#include <object.h>
-#include <memory.h>
+#include "object.h"
+#include "memory.h"
#include <stddef.h>
-#include <error.h>
+#include "error.h"
+#include "string.h"
int
ko_untyped_retype_objdir(objdir_entry_t *target)
{
size_t *untyped = ko_entry_data(target);
if(*untyped != 0x1000) return -KE_BADSIZE;
+
+ objdir_t *objdir = (objdir_t*)untyped;
+ memset(objdir, 0, 0x1000);
+
+ objdir->self = (objdir_entry_t) {
+ .type = KO_OBJECT_DIRECTORY,
+ .data = target->data
+ };
+ *target = (objdir_entry_t) {
+ .type = KO_OBJECT_DIRECTORY,
+ .lock = 0,
+ .extra = 0,
+ .data = objdir->self.data
+ };
+ return 0;
+}
+
+int
+ko_untyped_retype_message(objdir_entry_t *target, uintptr_t vptr)
+{
+ size_t *untyped = ko_entry_data(target);
+ if(*untyped != 0x1000) return -KE_BADSIZE;
+
+ memset(untyped, 0, KO_MESSAGE_BYTES);
+ *target = (objdir_entry_t) {
+ .type = KO_OBJECT_DIRECTORY,
+ .lock = 0,
+ .extra = 0,
+ .data = target->data
+ };
+ return 0;
}
diff --git a/lib/untyped.c b/lib/untyped.c
new file mode 100644
index 0000000..8a20f63
--- /dev/null
+++ b/lib/untyped.c
@@ -0,0 +1,16 @@
+#include "include/object.h"
+#include "error.h"
+
+int
+ko_untyped_split(objdir_entry_t *target, objdir_entry_t *dest, size_t bytes)
+{
+ size_t *untyped = ko_entry_data(target);
+ if(*untyped <= bytes) return KE_TOOSMALL;
+
+ *untyped -= bytes;
+ dest->data = target->data + *untyped;
+ *(size_t*)ko_entry_data(dest) = bytes;
+ dest->type = KO_MEMORY_UNTYPED;
+
+ return 0;
+}