summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--api/obj.h2
-rw-r--r--api/syscall.h74
-rw-r--r--arch/x86_64/hal/obj.c29
-rw-r--r--arch/x86_64/hal/obj.h2
-rw-r--r--arch/x86_64/hal/paging.c74
-rw-r--r--arch/x86_64/hal/paging.h5
-rw-r--r--config.h2
-rw-r--r--hal/memory.h10
-rw-r--r--hal/untyped.c6
-rw-r--r--jove.h5
-rw-r--r--sys/syscall.c41
-rw-r--r--sys/syscall.h4
-rw-r--r--sys/syscall_objdir.c24
-rw-r--r--sys/syscall_pagedir.c112
-rw-r--r--sys/syscall_untyped.c17
16 files changed, 367 insertions, 41 deletions
diff --git a/Makefile b/Makefile
index 3f6b900..a584ec9 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,6 @@ SFILES += $(foreach dir, $(CDIRS), $(wildcard arch/$(TARGET_MACHINE)/$(dir)/*.s)
OBJFILES := $(patsubst %.c,%.o,$(CFILES))
OBJFILES += $(patsubst %.s,%.o,$(SFILES))
-OBJFILES += uacpi.a
DEPFILES := $(patsubst %.c,%.d,$(CFILES))
CLEAN_DEPENDS =
diff --git a/api/obj.h b/api/obj.h
index a9614b8..64171a2 100644
--- a/api/obj.h
+++ b/api/obj.h
@@ -19,6 +19,8 @@ enum
JOVE_OBJ_LINK,
};
+#define OBJDIR_NUM_ENTRIES (0x1000 / sizeof(uintmax_t))
+
typedef uint16_t objpath_part_t;
#endif
diff --git a/api/syscall.h b/api/syscall.h
index bdd9972..8c35270 100644
--- a/api/syscall.h
+++ b/api/syscall.h
@@ -6,6 +6,14 @@
#include "obj.h"
+/* General syscall behavior:
+ * If the message passed is not a JOVE_OBJ_MESSAGE type, the kernel will return EBADOBJ.
+ * If the message is too small to hold the target path, the kernel will return ETOOSMALL.
+ * If the target path does not target a real object, the kernel will return EBADPATH.
+ * If the target does not support the callid, the kernel will return EBADARG.
+ * Otherwise, behavior depends on the syscall specified in callid.
+ * */
+
struct syscall_header
{
uint16_t callid;
@@ -13,28 +21,51 @@ struct syscall_header
objpath_part_t path[];
};
+/* If the message is too small for data, the kernel will return ETOOSMALL.
+ * */
struct syscall_generic_write
{
size_t len;
char data[];
};
+/* If the message is too small for path, the kernel will return ETOOSMALL.
+ * If the path does not point to an object, the kernel will return EBADPATH.
+ * */
struct syscall_generic_objpath
{
uint16_t pathlen;
objpath_part_t path[];
};
-#define SYSCALL_UNTYPED_SIZE 0
-#define SYSCALL_UNTYPED_ALIGN 1
+/* The kernel will return the physical memory address of this untyped object. */
+#define SYSCALL_UNTYPED_ADDRESS 0
+/* The kernel will return the size of this untyped object. */
+#define SYSCALL_UNTYPED_SIZE 1
+/* If newtype is not a valid JOVE object, the kernel will return EBADARG.
+ * If the untyped object is too small for this object, the kernel will return ETOOSMALL.
+ * If the untyped object is too big for this object, the kernel will return ETOOBIG.
+ * New objects will be initialized with default values.
+ * */
#define SYSCALL_UNTYPED_RETYPE 2
struct syscall_untyped_retype
{
uint16_t newtype;
};
+/* Splits the tail of the untyped object into another untyped object with [bytes] length.
+ * If bytes is less than JOVE_UNTYPED_MINSIZE, the kernel will return ETOOSMALL.
+ * If the syscall message is too small for dest_path, the kernel will return ETOOSMALL.
+ * If dest_path does not target a JOVE_OBJ_NONE object, the kernel will return EBADOBJ.
+ * Destination path will be occupied by the untyped object created by the split.
+ * */
#define SYSCALL_UNTYPED_SPLIT 3
+/* Follows rules declared above syscall_generic_objpath.
+ * If dest_path does not target a JOVE_OBJ_UNTYPED object, the kernel will return EBADPATH.
+ * If the dest untyped object is not adjacent to the target object, the kernel will return EBADOBJ.
+ * Destination path will be set to JOVE_OBJ_NONE and target untyped will grow to include the object.
+ * */
#define SYSCALL_UNTYPED_MERGE 4
struct syscall_untyped_split
{
@@ -43,8 +74,47 @@ struct syscall_untyped_split
objpath_part_t dest_path[];
};
+/* Follows rules declared above syscall_generic_objpath.
+ * Returns the object type at path.
+ * */
#define SYSCALL_OBJDIR_OBJTYPE 0
+/*
+ * If virtual_address does not have a page table, the kernel will return ENOMAP.
+ * If virtual_address already has a mapping, the kernel will return EEXIST.
+ * Follows the rules defined above syscall_pagedir_map.
+ * Maps the untyped page frame to the page table at virtual_address with the passed flags bits.
+ * */
+#define SYSCALL_PAGEDIR_MAP_FRAME 0
+
+/* If virtual_address already has a page table, the kernel will return EHASMAP.
+ * Follows the rules defined above syscall_pagedir_map.
+ * Creates a page table using the untyped object for memory allocation at virtual_address.
+ * Flags bits are always set to writeable and executable.
+ * */
+#define SYSCALL_PAGEDIR_MAP_TABLE 1
+
+/* If virtual_address is above the JOVE_USER_MEMORY_LIMIT, the kernel will return EBADARG.
+ * If the message is too small for untyped_path, the kernel will return ETOOSMALL.
+ * If untyped_path does not point to a valid JOVE_OBJ_UNTYPED, the kernel will return EBADOBJ.
+ * If the untyped object is not aligned to 0x1000, the kernel will return EALIGN.
+ * If the untyped object is not sized to 0x1000, the kernel will return EBADSIZE.
+ *
+ * */
+struct syscall_pagedir_flags
+{
+ uint8_t writeable : 1;
+ uint8_t executable : 1;
+ uint8_t flg_unused : 6;
+};
+struct syscall_pagedir_map
+{
+ struct syscall_pagedir_flags flags;
+ uintptr_t virtual_address;
+ uint16_t untyped_pathlen;
+ objpath_part_t untyped_path[];
+};
+
#define SYSCALL_VTT_WRITE 0
#endif
diff --git a/arch/x86_64/hal/obj.c b/arch/x86_64/hal/obj.c
index c5d5c69..b8924a6 100644
--- a/arch/x86_64/hal/obj.c
+++ b/arch/x86_64/hal/obj.c
@@ -37,6 +37,12 @@ obj_gettype(jove_owned_obj_t *obj)
return obj->locked.type;
}
+uint8_t
+obj_peektype(jove_obj_t obj)
+{
+ return obj.type;
+}
+
void
obj_settype(jove_owned_obj_t *obj, uint8_t type)
{
@@ -55,6 +61,24 @@ obj_setvalue(jove_owned_obj_t *obj, uintmax_t value)
obj->locked.value = value & 0x00007FFFFFFFFFFFULL;
}
+jove_obj_t
+objdir_peeklocal(
+ jove_owned_obj_t *objdir_obj,
+ uint16_t entry)
+{
+ if(obj_gettype_linked(objdir_obj) != JOVE_OBJ_OBJDIR) {
+ errno = EBADOBJ;
+ return (jove_obj_t) { 0 };
+ }
+ if(entry >= JOVE_OBJDIR_ENTRIES) {
+ errno = EBADPATH;
+ return (jove_obj_t) { 0 };
+ }
+
+ jove_objdir_t *objtab = obj_deref_linked(objdir_obj);
+ return objtab->entries[entry];
+}
+
jove_owned_obj_t*
objdir_getlocal(
jove_owned_obj_t *objdir_obj,
@@ -64,7 +88,7 @@ objdir_getlocal(
reterr(EBADOBJ);
}
if(entry >= JOVE_OBJDIR_ENTRIES) {
- reterr(EOOB);
+ reterr(EBADPATH);
}
jove_objdir_t *objtab = obj_deref_linked(objdir_obj);
@@ -81,9 +105,10 @@ objdir_getobj(
return objdir_obj;
}
{
+ errno = 0;
jove_owned_obj_t *child_objdir = objdir_getlocal(objdir_obj, path[0]);
if(child_objdir == 0) {
- return 0;
+ reterr(EBADPATH);
}
jove_owned_obj_t *target_obj = objdir_getobj(child_objdir, path + 1, path_len - 1);
diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h
index 51f2d6a..d28d81b 100644
--- a/arch/x86_64/hal/obj.h
+++ b/arch/x86_64/hal/obj.h
@@ -49,6 +49,7 @@ void *obj_deref(jove_owned_obj_t *obj);
/*Getters and setters for accessing the type field of the kernel object. */
uint8_t obj_gettype(jove_owned_obj_t *obj);
+uint8_t obj_peektype(jove_obj_t obj);
void obj_settype(jove_owned_obj_t *obj, uint8_t type);
/*Getters and setters for accessing the value field of the kernel object. */
@@ -59,6 +60,7 @@ void obj_setvalue(jove_owned_obj_t *obj, uintmax_t value);
* If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ.
* If the passed entry index is out of bounds, returns NULL and sets errno to EOOB.*/
jove_owned_obj_t *objdir_getlocal(jove_owned_obj_t *objdir_obj, uint16_t entry);
+jove_obj_t objdir_peeklocal(jove_owned_obj_t *objdir_obj, uint16_t entry);
/*Recursively seeks through an object directory for an object following the passed
* path variable.
diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c
index fb6dea7..507dfce 100644
--- a/arch/x86_64/hal/paging.c
+++ b/arch/x86_64/hal/paging.c
@@ -3,12 +3,12 @@
#include "jove.h"
#include "init.h"
#include "config.h"
-#include "smp.h"
#include "hal/obj.h"
#include "lib/string.h"
#include "lib/printf.h"
#include "lib/panic.h"
#include "idt.h"
+#include "api/syscall.h"
PAGEALIGN page_t _kernel_pml4[512];
PAGEALIGN page_t _kernel_pml3[512];
@@ -73,6 +73,78 @@ s_int_handle_pf_early(struct int_stackframe *frame)
hcf();
}
+int pagedir_map_frame(
+ jove_owned_obj_t *tgt, jove_owned_obj_t *untyped_obj,
+ uintptr_t vptr, struct syscall_pagedir_flags flg)
+{
+ page_t *pml4 = obj_deref(tgt);
+ uintptr_t frame = obj_getvalue(untyped_obj);
+
+ size_t pml4i = PML4I(vptr);
+ if(!pml4[pml4i].p) return ENOMAP;
+
+ page_t *pml3 = (page_t*)(((uintptr_t)pml4[pml4i].paddr << 12) | IDENT_VIRT_BASE);
+ size_t pml3i = PML3I(vptr);
+ if(!pml3[pml3i].p) return ENOMAP;
+
+ page_t *pml2 = (page_t*)(((uintptr_t)pml3[pml3i].paddr << 12) | IDENT_VIRT_BASE);
+ size_t pml2i = PML2I(vptr);
+ if(!pml2[pml2i].p) return ENOMAP;
+
+ page_t *pml1 = (page_t*)(((uintptr_t)pml2[pml2i].paddr << 12) | IDENT_VIRT_BASE);
+ size_t pml1i = PML1I(vptr);
+ if(pml1[pml1i].p) return EEXIST;
+
+ pml1[pml1i].value = frame |
+ PAGE_PRESENT |
+ PAGE_USER |
+ (flg.writeable ? PAGE_WRITETHROUGH : 0) |
+ (flg.executable ? 0 : PAGE_XD);
+ return 0;
+}
+
+int pagedir_map_table(
+ jove_owned_obj_t *tgt, jove_owned_obj_t *untyped_obj,
+ uintptr_t vptr, struct syscall_pagedir_flags flg)
+{
+ page_t *target_table = NULL;
+ page_t *pml4 = obj_deref(tgt);
+ uintptr_t frame = obj_getvalue(untyped_obj);
+
+ void *frame_ident = obj_deref(untyped_obj);
+ memset(frame_ident, 0, 0x1000);
+
+ size_t pml4i = PML4I(vptr);
+ if(!pml4[pml4i].p) {
+ target_table = &pml4[pml4i];
+ goto map_table;
+ }
+
+ page_t *pml3 = (page_t*)(((uintptr_t)pml4[pml4i].paddr << 12) | IDENT_VIRT_BASE);
+ size_t pml3i = PML3I(vptr);
+ if(!pml3[pml3i].p) {
+ target_table = &pml3[pml3i];
+ goto map_table;
+ }
+
+ page_t *pml2 = (page_t*)(((uintptr_t)pml3[pml3i].paddr << 12) | IDENT_VIRT_BASE);
+ size_t pml2i = PML2I(vptr);
+ if(!pml2[pml2i].p) {
+ target_table = &pml2[pml2i];
+ goto map_table;
+ }
+ return EHASMAP;
+
+map_table:
+ target_table->value = frame |
+ PAGE_PRESENT |
+ PAGE_USER |
+ (flg.writeable ? PAGE_WRITETHROUGH : 0) |
+ (flg.executable ? 0 : PAGE_XD);
+ return 0;
+}
+
+
void
paging_pml4_init(void)
{
diff --git a/arch/x86_64/hal/paging.h b/arch/x86_64/hal/paging.h
index 5736326..754ac99 100644
--- a/arch/x86_64/hal/paging.h
+++ b/arch/x86_64/hal/paging.h
@@ -42,6 +42,11 @@ extern void *_kernel_physptr;
#define PMLI_SHL(l) (12 + (l * 9))
#define PMLI_MASK(l) (~0xFFFFULL << PMLI_SHL(l))
+#define PML4I(v) (((v) >> 39) & 0x1FF)
+#define PML3I(v) (((v) >> 30) & 0x1FF)
+#define PML2I(v) (((v) >> 21) & 0x1FF)
+#define PML1I(v) (((v) >> 12) & 0x1FF)
+
#define IDENT_VIRT_BASE 0xFFFF800000000000ULL
#define KERNEL_VIRT_BASE 0xFFFFFFFF80000000ULL
#define KPTR_TOPHYS(v) (((uintptr_t)v) - KERNEL_VIRT_BASE + (uintptr_t)_kernel_physptr)
diff --git a/config.h b/config.h
index 7b08924..4b099a3 100644
--- a/config.h
+++ b/config.h
@@ -10,6 +10,6 @@
#define FRAMEBUFFER_MAX_HEIGHT 1080
#define INIT_PROGRAM_PAGES_MAX 32
-#define INIT_STACK_PAGES 1
+#define INIT_STACK_PAGES 2
#endif
diff --git a/hal/memory.h b/hal/memory.h
index 659263c..ca021ef 100644
--- a/hal/memory.h
+++ b/hal/memory.h
@@ -2,6 +2,7 @@
#define _JOVE_HAL_MEMORY_H 1
#include "obj.h"
+#include "api/syscall.h"
typedef struct jove_obj_untyped
{
@@ -14,11 +15,18 @@ void mem_setup_untyped(void);
void *phys_tovirt(uintptr_t phys);
+uintptr_t untyped_address(jove_owned_obj_t *tgt);
size_t untyped_size(jove_owned_obj_t *tgt);
-size_t untyped_align(jove_owned_obj_t *tgt);
int untyped_split(jove_owned_obj_t *tgt, jove_owned_obj_t *dst, size_t bytes);
int untyped_merge(jove_owned_obj_t *a, jove_owned_obj_t *b);
int untyped_retype(jove_owned_obj_t *tgt, uint8_t newtype);
+int pagedir_map_frame(
+ jove_owned_obj_t *tgt, jove_owned_obj_t *untyped_obj,
+ uintptr_t vptr, struct syscall_pagedir_flags flg);
+int pagedir_map_table(
+ jove_owned_obj_t *tgt, jove_owned_obj_t *untyped_obj,
+ uintptr_t vptr, struct syscall_pagedir_flags flg);
+
#endif
diff --git a/hal/untyped.c b/hal/untyped.c
index 243f3ec..e76dd0e 100644
--- a/hal/untyped.c
+++ b/hal/untyped.c
@@ -8,10 +8,10 @@ untyped_size(jove_owned_obj_t *tgt)
return ((jove_untyped_t*)obj_deref(tgt))->limit;
}
-size_t
-untyped_align(jove_owned_obj_t *tgt)
+uintptr_t
+untyped_address(jove_owned_obj_t *tgt)
{
- return (uintptr_t)obj_deref(tgt) & 0xFFF;
+ return (uintptr_t)obj_deref(tgt);
}
int
diff --git a/jove.h b/jove.h
index 0c0b181..28e3388 100644
--- a/jove.h
+++ b/jove.h
@@ -20,5 +20,10 @@ extern int errno;
#define EBADARG -4
#define ETOOSMALL -5
#define ETOOBIG -6
+#define EBADSIZE -7
+#define ENOMAP -8
+#define EHASMAP -9
+#define EALIGN -10
+#define EEXIST -11
#endif
diff --git a/sys/syscall.c b/sys/syscall.c
index 9a98030..eb2874d 100644
--- a/sys/syscall.c
+++ b/sys/syscall.c
@@ -7,6 +7,22 @@
#include "sys/link.h"
#include "sys/message.h"
+int __syscall_generic_objpath(jove_owned_obj_t *objdir, size_t payload_bytes, void *payload_data, jove_owned_obj_t **retobj)
+{
+ size_t bytes_needed = sizeof(struct syscall_generic_objpath);
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for payload.");
+ struct syscall_generic_objpath *payload = payload_data;
+
+ bytes_needed += payload->pathlen << 1;
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for object path.");
+
+ errno = 0;
+ *retobj = objdir_getobj(objdir, payload->path, payload->pathlen);
+ return errno;
+}
+
int
_syscall_handle_generic(
jove_owned_obj_t *pcb_obj,
@@ -47,17 +63,15 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
jove_owned_obj_t *pcb_obj = process_current();
pcb_t *pcb = obj_deref(pcb_obj);
-
jove_owned_obj_t *objdir = pcb_rootdir(pcb);
-
jove_owned_obj_t *message_obj = objdir_getobj(objdir, message_path, message_pathlen);
+
+ int sysret = 0;
if(message_obj == 0) {
- obj_release(objdir);
- obj_release(pcb_obj);
- return errno;
+ sysret = errno;
+ goto release_premsg;
}
- int sysret = 0;
if(obj_gettype_linked(message_obj) != JOVE_OBJ_MESSAGE) {
kprintf("syscall: Process %i tried to call syscall with invalid object: %P\n", pcb_pid(pcb), message_path, message_pathlen);
sysret = EBADOBJ;
@@ -68,12 +82,11 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
void *messagedata = message_data(message_obj);
struct syscall_header *header = messagedata;
- size_t header_bytes = sizeof(struct syscall_header) + header->pathlen * 2;
- int bytes_left = messagelen - header_bytes;
- if(bytes_left < 0) {
+ size_t bytes_needed = sizeof(struct syscall_header) + header->pathlen * 2;
+ if(bytes_needed > messagelen) {
//Target path exceeds message length.
- kprintf("syscall: Process %i tried to call syscall with OOB target path.\n", pcb_pid(pcb));
- sysret = EBADPATH;
+ kprintf("syscall: Process %i tried to call syscall with target path too big for message.\n", pcb_pid(pcb));
+ sysret = ETOOSMALL;
goto release_return;
}
jove_owned_obj_t *target = objdir_getobj(objdir, header->path, header->pathlen);
@@ -86,10 +99,11 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
}
uint8_t target_type = obj_gettype(target);
+ size_t bytes_left = messagelen - bytes_needed;
if(target_type > 0x7F) {
sysret = _syscall_handle_arch(
pcb_obj, objdir, message_obj, target,
- header, bytes_left, messagedata + header_bytes);
+ header, bytes_left, messagedata + bytes_needed);
}else{
syscall_handle_t call_handle = s_syscall_handles[obj_gettype(target)];
if(call_handle == NULL) {
@@ -99,11 +113,12 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen)
}else
sysret = call_handle(
pcb_obj, objdir, message_obj, target,
- header, bytes_left, messagedata + header_bytes);
+ header, bytes_left, messagedata + bytes_needed);
}
obj_release(target);
release_return:
obj_release(message_obj);
+release_premsg:
obj_release(objdir);
obj_release(pcb_obj);
return sysret;
diff --git a/sys/syscall.h b/sys/syscall.h
index ea75152..2044069 100644
--- a/sys/syscall.h
+++ b/sys/syscall.h
@@ -20,6 +20,7 @@ do { if(obj == NULL) { \
#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; \
} } while(0)
@@ -34,11 +35,14 @@ do { if(obj == NULL) { \
typedef int (*syscall_handle_t)(SYSCALL_FUNCTION_ARGS);
+int __syscall_generic_objpath(jove_owned_obj_t *objdir, size_t bytes_left, void *payload_data, jove_owned_obj_t **retobj);
+
int _syscall_handle_generic(SYSCALL_FUNCTION_ARGS);
int _syscall_handle_arch(SYSCALL_FUNCTION_ARGS);
int _syscall_handle_vtt(SYSCALL_FUNCTION_ARGS);
int _syscall_handle_objdir(SYSCALL_FUNCTION_ARGS);
int _syscall_handle_untyped(SYSCALL_FUNCTION_ARGS);
+int _syscall_handle_pagedir(SYSCALL_FUNCTION_ARGS);
#endif
diff --git a/sys/syscall_objdir.c b/sys/syscall_objdir.c
index 5e49fd4..277639f 100644
--- a/sys/syscall_objdir.c
+++ b/sys/syscall_objdir.c
@@ -1,3 +1,4 @@
+#include "arch/x86_64/hal/obj.h"
#include "hal/process.h"
#include "jove.h"
#include "lib/printf.h"
@@ -10,20 +11,17 @@ s_syscall_objdir_objtype(
size_t payload_size,
void *payload_data)
{
- int bytes_needed = sizeof(struct syscall_generic_objpath);
- CHECK_TOOSMALL(bytes_needed, payload_size, "Message is too small for this payload!");
-
- struct syscall_generic_objpath *payload = payload_data;
- bytes_needed += payload->pathlen * 2;
- CHECK_TOOSMALL(bytes_needed, payload_size, "Message is too small for second target path!");
+ size_t bytes_needed = 2;
+ CHECK_TOOSMALL(bytes_needed, payload_size, "Message is too small for payload.");
- int retval = 0;
- jove_owned_obj_t *second_obj = objdir_getobj(objdir, payload->path, payload->pathlen);
- CHECK_OBJEXISTS(second_obj, "Second target does not exist!");
+ uint16_t local_idx = *((uint16_t*)payload_data);
+ if(local_idx > JOVE_OBJDIR_ENTRIES) {
+ kprintf("%s: Object index is out of bounds (>= 512)\n", __func__);
+ return EOOB;
+ }
- retval = obj_gettype(second_obj);
- obj_release(second_obj);
- return retval;
+ jove_obj_t local_obj = objdir_peeklocal(target_dir, local_idx);
+ return obj_peektype(local_obj);
}
int
@@ -41,6 +39,6 @@ _syscall_handle_objdir(
return s_syscall_objdir_objtype(objdir, target_obj, bytes_left, payload);
default:
kprintf("syscall_handle_objdir: Objdir does not support syscall %i\n", header->callid);
- return EOOB;
+ return EBADARG;
}
}
diff --git a/sys/syscall_pagedir.c b/sys/syscall_pagedir.c
new file mode 100644
index 0000000..144a02b
--- /dev/null
+++ b/sys/syscall_pagedir.c
@@ -0,0 +1,112 @@
+#include "hal/memory.h"
+#include "jove.h"
+#include "lib/printf.h"
+#include "syscall.h"
+
+static int
+s_syscall_pagedir_map(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data,
+ jove_owned_obj_t **untyped_ret)
+{
+ size_t bytes_needed = sizeof(struct syscall_pagedir_map);
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for payload.");
+
+ struct syscall_pagedir_map *payload = payload_data;
+ if(payload->virtual_address > 0xFFFF800000000000ULL) {
+ kprintf("%s: Virtual address is above user limit.\n", __func__);
+ return EBADARG;
+ }
+
+ bytes_needed += payload->untyped_pathlen << 1;
+ CHECK_TOOSMALL(bytes_needed, payload_bytes,
+ "Message too small for untyped path.");
+
+ errno = 0;
+ jove_owned_obj_t *untyped_obj = objdir_getobj(objdir,
+ payload->untyped_path, payload->untyped_pathlen);
+ if(errno) {
+ kprintf("%s: Untyped path does not point to a valid object.\n", __func__);
+ return errno;
+ }
+
+ CHECK_OBJTYPE(untyped_obj, JOVE_OBJ_UNTYPED,
+ "Untyped path does not point to an untyped object.");
+ jove_untyped_t *untyped_data = obj_deref(untyped_obj);
+
+ if((uintptr_t)untyped_data & 0xFFF) {
+ kprintf("%s: Untyped object is not page aligned.\n", __func__);
+ obj_release(untyped_obj);
+ return EALIGN;
+ }
+ if(untyped_data->limit != 0x1000) {
+ kprintf("%s: Untyped object is not page sized.\n", __func__);
+ obj_release(untyped_obj);
+ return EBADSIZE;
+ }
+
+ *untyped_ret = untyped_obj;
+ return 0;
+}
+
+static int
+s_syscall_pagedir_map_frame(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data)
+{
+ jove_owned_obj_t *untyped_obj = NULL;
+ int sysret = s_syscall_pagedir_map(objdir, target_obj, payload_bytes, payload_data, &untyped_obj);
+ if(sysret != 0) {
+ return sysret;
+ }
+
+ struct syscall_pagedir_map *payload = payload_data;
+ sysret = pagedir_map_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
+ obj_release(untyped_obj);
+ return sysret;
+}
+
+static int
+s_syscall_pagedir_map_table(
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *target_obj,
+ size_t payload_bytes,
+ void *payload_data)
+{
+ jove_owned_obj_t *untyped_obj = NULL;
+ int sysret = s_syscall_pagedir_map(objdir, target_obj, payload_bytes, payload_data, &untyped_obj);
+ if(sysret != 0) {
+ return sysret;
+ }
+
+ struct syscall_pagedir_map *payload = payload_data;
+ sysret = pagedir_map_frame(target_obj, untyped_obj, payload->virtual_address, payload->flags);
+ obj_release(untyped_obj);
+ return sysret;
+}
+
+int
+_syscall_handle_pagedir(
+ jove_owned_obj_t *pcb_obj,
+ jove_owned_obj_t *objdir,
+ jove_owned_obj_t *message_obj,
+ jove_owned_obj_t *target_obj,
+ struct syscall_header *header,
+ size_t bytes_left,
+ void *payload)
+{
+ switch(header->callid) {
+ case SYSCALL_PAGEDIR_MAP_FRAME:
+ 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);
+ 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 3467830..fcdb5f6 100644
--- a/sys/syscall_untyped.c
+++ b/sys/syscall_untyped.c
@@ -20,7 +20,7 @@ s_syscall_untyped_split(
jove_owned_obj_t *dst_obj = objdir_getobj(objdir, payload->dest_path, payload->dest_pathlen);
CHECK_OBJTYPE(dst_obj, JOVE_OBJ_NONE, "Destination path is occupied!");
-
+
return untyped_split(target_obj, dst_obj, payload->bytes);
}
@@ -41,7 +41,14 @@ s_syscall_untyped_merge(
jove_owned_obj_t *snd_obj = objdir_getobj(objdir, payload->path, payload->pathlen);
CHECK_OBJTYPE(snd_obj, JOVE_OBJ_UNTYPED, "Second object is not an untyped!");
- return untyped_merge(target_obj, snd_obj);
+ int sysret = untyped_merge(target_obj, snd_obj);
+ if(obj_gettype(snd_obj) == JOVE_OBJ_UNTYPED) {
+ //Untyped merged into second object. We need to switch objects.
+ obj_settype(target_obj, JOVE_OBJ_UNTYPED);
+ obj_setvalue(target_obj, obj_getvalue(snd_obj));
+ obj_settype(snd_obj, JOVE_OBJ_NONE);
+ }
+ return sysret;
}
@@ -55,12 +62,14 @@ int _syscall_handle_untyped(
void* payload)
{
switch(header->callid) {
+ case SYSCALL_UNTYPED_ADDRESS:
+ return untyped_address(target_obj);
case SYSCALL_UNTYPED_SIZE:
return untyped_size(target_obj);
- case SYSCALL_UNTYPED_ALIGN:
- return untyped_align(target_obj);
case SYSCALL_UNTYPED_SPLIT:
return s_syscall_untyped_split(objdir, target_obj, payload_bytes, payload);
+ case SYSCALL_UNTYPED_MERGE:
+ 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;