From 772717dc22e04b4d168d0f77bee6b6357118768c Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Tue, 19 Aug 2025 15:03:42 -0400 Subject: refactor KO_MEMORY_MAPPING invoke --- arch/x86_64/device/processor.c | 135 ++++++++++++++++++++++++++++++++ arch/x86_64/ivt.s | 2 +- arch/x86_64/page-mapping.c | 15 ++++ arch/x86_64/page_directory.c | 2 +- arch/x86_64/processor.c | 135 -------------------------------- arch/x86_64/syscall-invoke-mapping.c | 148 ----------------------------------- arch/x86_64/syscall.c | 55 ------------- arch/x86_64/syscall/invoke-mapping.c | 146 ++++++++++++++++++++++++++++++++++ arch/x86_64/syscall/syscall.c | 55 +++++++++++++ arch/x86_64/syscall/wrappers.h | 14 ++++ 10 files changed, 367 insertions(+), 340 deletions(-) create mode 100644 arch/x86_64/device/processor.c create mode 100644 arch/x86_64/page-mapping.c delete mode 100644 arch/x86_64/processor.c delete mode 100644 arch/x86_64/syscall-invoke-mapping.c delete mode 100644 arch/x86_64/syscall.c create mode 100644 arch/x86_64/syscall/invoke-mapping.c create mode 100644 arch/x86_64/syscall/syscall.c create mode 100644 arch/x86_64/syscall/wrappers.h (limited to 'arch') diff --git a/arch/x86_64/device/processor.c b/arch/x86_64/device/processor.c new file mode 100644 index 0000000..f7e5cac --- /dev/null +++ b/arch/x86_64/device/processor.c @@ -0,0 +1,135 @@ +#include "device/processor.h" +#include "arch/x86_64/tables.h" +#include "include/arch/x86_64/idt.h" +#include "include/arch/x86_64/object.h" +#include "jove.h" + +processor_t s_bsp = { + .odir = &_initDirectory +}; + +struct jove_ObjectDirectory s_processor_dir = { + .entries = { + [0] = { + .type = KO_OBJECT_DIRECTORY, + .data = 2 + }, + [1] = { + .type = KO_DEV_PROCESSOR, + .data = (uintptr_t)&s_bsp + } + } +}; + +char s_initial_response_buffer[256] = { 0 }; + +typedef union msr_efer +{ + struct { + uint8_t sce : 1; + uint8_t resv : 7; + uint8_t lme : 1; + uint8_t unk0 : 1; + uint8_t lma : 1; + uint8_t nxe : 1; + uint8_t svme : 1; + uint8_t lmsle : 1; + uint8_t ffxsr : 1; + uint8_t tce : 1; + }; + uint32_t v[2]; +} msr_efer_t; + +typedef union msr_star +{ + struct { + uint32_t eip; + uint16_t kcs; + uint16_t ucs; + }; + uint32_t v[2]; +} msr_star_t; + +typedef union msr_lstar +{ + uint32_t v[2]; + uintptr_t ip; +} msr_lstar_t; + +static void +s_enable_sce(void) +{ + msr_efer_t feat; + rdmsr(MSR_EFER, &feat.v[0], &feat.v[1]); + + feat.sce = 1; + wrmsr(MSR_EFER, feat.v[0], feat.v[1]); + + msr_star_t star; + star.kcs = GDT_OFFSET_KERNEL_CODE; + star.ucs = GDT_OFFSET_USER_CODE; + wrmsr(MSR_STAR, star.v[0], star.v[1]); + + extern void _syscall_entry(void); + msr_lstar_t lstar; + lstar.ip = (uintptr_t)_syscall_entry; + wrmsr(MSR_LSTAR, lstar.v[0], lstar.v[1]); +} + +void +processor_setup(void *_processor) +{ + processor_t *processor = (processor_t*)_processor; + gdt_setup(processor); + idt_setup(processor); + + wrmsr(MSR_GS_BASE, + (uint32_t)((uintptr_t)_processor & 0xFFFFFFFF), + (uint32_t)((uintptr_t)_processor >> 32)); +} + +void enable_fpu(void); +void enable_sse(void); +void enable_avx(void); + +void +bsp_setup(void) +{ +#ifdef ENABLE_SSE + enable_fpu(); + enable_sse(); +#endif +#ifdef ENABLE_AVX + enable_avx(); +#endif + + _initDirectory.entries[INIT_OBJECT_PROCESSOR_DIR] = (objdir_entry_t) { + .type = KO_OBJECT_DIRECTORY, + .data = (uintptr_t)(&s_processor_dir) + }; + + ivt_setup(); + s_enable_sce(); + + processor_setup(&s_bsp); +} + +void +rdmsr(uint32_t msr, uint32_t *lo, uint32_t *hi) +{ + __asm__ volatile("rdmsr": "=a"(*lo), "=d"(*hi): "c"(msr)); +} + +void +wrmsr(uint32_t msr, uint32_t lo, uint32_t hi) +{ + __asm__ volatile("wrmsr":: "a"(lo), "d"(hi), "c"(msr)); +} + +void* +processor_current(void) +{ + uint64_t r = 0; + rdmsr(MSR_GS_BASE, (uint32_t*)&r, ((uint32_t*)&r) + 1); + return (void*)r; +} diff --git a/arch/x86_64/ivt.s b/arch/x86_64/ivt.s index 0005686..a64f6b7 100644 --- a/arch/x86_64/ivt.s +++ b/arch/x86_64/ivt.s @@ -13,9 +13,9 @@ idt_load: .type __isr_head @function __isr_head: pushall - movq %rsp, %rdi cld + movq %rsp, %rdi call isr_handle popall diff --git a/arch/x86_64/page-mapping.c b/arch/x86_64/page-mapping.c new file mode 100644 index 0000000..0de5bfa --- /dev/null +++ b/arch/x86_64/page-mapping.c @@ -0,0 +1,15 @@ +#include "arch/x86_64/page-mapping.h" +#include "arch/x86_64/page.h" +#include + +pmle_t* +page_mapping_traverse(pmle_t *pml4, uint8_t depth, uint16_t *path) +{ + uint16_t pathi = path[0]; + + pmle_t *pmle = &pml4[pathi]; + pmle_t *pmle_table = vmem_phys_tovirt(pmle->paddr << 12); + if(depth == 0) return pmle; + if(!pmle->p) return NULL; + return page_mapping_traverse(pmle_table, depth - 1, path + 1); +} diff --git a/arch/x86_64/page_directory.c b/arch/x86_64/page_directory.c index 494cab5..7030b05 100644 --- a/arch/x86_64/page_directory.c +++ b/arch/x86_64/page_directory.c @@ -114,6 +114,6 @@ vmem_setup(void) //Add page mapping object to init directory. _initDirectory.entries[INIT_OBJECT_PAGEMAP] = (objdir_entry_t) { .type = KO_MEMORY_MAPPING, - .data = kernel_pml4_base | 3 + .data = kernel_pml4_base }; } diff --git a/arch/x86_64/processor.c b/arch/x86_64/processor.c deleted file mode 100644 index f7e5cac..0000000 --- a/arch/x86_64/processor.c +++ /dev/null @@ -1,135 +0,0 @@ -#include "device/processor.h" -#include "arch/x86_64/tables.h" -#include "include/arch/x86_64/idt.h" -#include "include/arch/x86_64/object.h" -#include "jove.h" - -processor_t s_bsp = { - .odir = &_initDirectory -}; - -struct jove_ObjectDirectory s_processor_dir = { - .entries = { - [0] = { - .type = KO_OBJECT_DIRECTORY, - .data = 2 - }, - [1] = { - .type = KO_DEV_PROCESSOR, - .data = (uintptr_t)&s_bsp - } - } -}; - -char s_initial_response_buffer[256] = { 0 }; - -typedef union msr_efer -{ - struct { - uint8_t sce : 1; - uint8_t resv : 7; - uint8_t lme : 1; - uint8_t unk0 : 1; - uint8_t lma : 1; - uint8_t nxe : 1; - uint8_t svme : 1; - uint8_t lmsle : 1; - uint8_t ffxsr : 1; - uint8_t tce : 1; - }; - uint32_t v[2]; -} msr_efer_t; - -typedef union msr_star -{ - struct { - uint32_t eip; - uint16_t kcs; - uint16_t ucs; - }; - uint32_t v[2]; -} msr_star_t; - -typedef union msr_lstar -{ - uint32_t v[2]; - uintptr_t ip; -} msr_lstar_t; - -static void -s_enable_sce(void) -{ - msr_efer_t feat; - rdmsr(MSR_EFER, &feat.v[0], &feat.v[1]); - - feat.sce = 1; - wrmsr(MSR_EFER, feat.v[0], feat.v[1]); - - msr_star_t star; - star.kcs = GDT_OFFSET_KERNEL_CODE; - star.ucs = GDT_OFFSET_USER_CODE; - wrmsr(MSR_STAR, star.v[0], star.v[1]); - - extern void _syscall_entry(void); - msr_lstar_t lstar; - lstar.ip = (uintptr_t)_syscall_entry; - wrmsr(MSR_LSTAR, lstar.v[0], lstar.v[1]); -} - -void -processor_setup(void *_processor) -{ - processor_t *processor = (processor_t*)_processor; - gdt_setup(processor); - idt_setup(processor); - - wrmsr(MSR_GS_BASE, - (uint32_t)((uintptr_t)_processor & 0xFFFFFFFF), - (uint32_t)((uintptr_t)_processor >> 32)); -} - -void enable_fpu(void); -void enable_sse(void); -void enable_avx(void); - -void -bsp_setup(void) -{ -#ifdef ENABLE_SSE - enable_fpu(); - enable_sse(); -#endif -#ifdef ENABLE_AVX - enable_avx(); -#endif - - _initDirectory.entries[INIT_OBJECT_PROCESSOR_DIR] = (objdir_entry_t) { - .type = KO_OBJECT_DIRECTORY, - .data = (uintptr_t)(&s_processor_dir) - }; - - ivt_setup(); - s_enable_sce(); - - processor_setup(&s_bsp); -} - -void -rdmsr(uint32_t msr, uint32_t *lo, uint32_t *hi) -{ - __asm__ volatile("rdmsr": "=a"(*lo), "=d"(*hi): "c"(msr)); -} - -void -wrmsr(uint32_t msr, uint32_t lo, uint32_t hi) -{ - __asm__ volatile("wrmsr":: "a"(lo), "d"(hi), "c"(msr)); -} - -void* -processor_current(void) -{ - uint64_t r = 0; - rdmsr(MSR_GS_BASE, (uint32_t*)&r, ((uint32_t*)&r) + 1); - return (void*)r; -} diff --git a/arch/x86_64/syscall-invoke-mapping.c b/arch/x86_64/syscall-invoke-mapping.c deleted file mode 100644 index 5b79239..0000000 --- a/arch/x86_64/syscall-invoke-mapping.c +++ /dev/null @@ -1,148 +0,0 @@ -#include "syscall/handles.h" -#include "arch/x86_64/syscall.h" -#include "arch/x86_64/page.h" -#include -#include "error.h" -#include "lock.h" -#include "string.h" -#include "memory.h" -#include "print.h" - -static int -s_handle_invoke_mapping_release( - objdir_t *root_dir, - objdir_entry_t *target_entry, - uint8_t *payload, - size_t payload_at - ) -{ -#ifdef DBG_SYSCALL - klogf("release mapping %p\n", target_entry); -#endif - target_entry->data = 0; - target_entry->type = KO_NONE; - return 0; -} - -static int -s_handle_invoke_mapping_get( - objdir_t *root_dir, - objdir_entry_t *target_entry, - uint8_t *payload, - size_t payload_at - ) -{ - pmli_t pmli; - SYSCALL_PAYLOAD_TAKEL(payload, payload_at, pmli, pmli_t); - - if(pmli > 511) return KE_OOB; - - uint8_t level = target_entry->data & 3; - pmle_t *target_pml = (pmle_t*)vmem_phys_tovirt(target_entry->data & ~3ULL); - if(level == 3 && pmli > 255) return KE_OOB; - if(level < 0) return KE_BADOBJ; - - size_t dest_pathw; - objdir_entry_t *dest_entry; - SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, dest_pathw, dest_entry); - - if(dest_entry->type != KO_NONE) return KE_FULL; - - pmle_t pmle = target_pml[pmli]; - if(!pmle.p) return KE_DNE; - - *dest_entry = (objdir_entry_t) { - .type = KO_MEMORY_MAPPING, - .data = (((uintptr_t)target_pml[pmli].paddr) << 12ULL) | (level - 1) - }; -#ifdef DBG_SYSCALL - klogf("Get pml%i %p[%i] -> %p\n", level, target_pml, pmli, dest_entry->data & ~3ULL); -#endif - return 0; -} - -static int -s_handle_invoke_mapping_map( - objdir_t *root_dir, - objdir_entry_t *target_entry, - uint8_t *payload, - size_t payload_at - ) -{ - uint8_t level = target_entry->data & 3; - pmle_t *target_pml = (pmle_t*)vmem_phys_tovirt(target_entry->data & ~3ULL); - - pmli_t pmli; - SYSCALL_PAYLOAD_TAKEL(payload, payload_at, pmli, pmli_t); - - if(pmli > 511) return KE_OOB; - if(level == 3 && pmli > 255) return KE_OOB; - if(level < 0) return KE_BADOBJ; - - size_t untyped_pathw; - objdir_entry_t *untyped_entry; - SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, untyped_pathw, untyped_entry); - - if(untyped_entry->type != KO_MEMORY_UNTYPED) return KE_BADOBJ; - mtx_acquire(&untyped_entry->lock); - - if((untyped_entry->data & 0xFFF) != 0) { - mtx_release(&untyped_entry->lock); - return KE_ALIGN; - } - - uintptr_t untyped_phys = untyped_entry->data; - size_t *untyped = ko_entry_data(untyped_entry); - size_t untyped_size = *untyped; - if(untyped_size != 0x1000) { - mtx_release(&untyped_entry->lock); - return KE_BADSIZE; - } - - pmle_t pmle = target_pml[pmli]; - if(pmle.p) { - mtx_release(&untyped_entry->lock); - return KE_OCCUPIED; - } - - target_pml[pmli].value = untyped_phys | PAGE_RW | PAGE_US | PAGE_PRESENT; - if(level != 0) { - memset(untyped, 0, 0x1000); - } - untyped_entry->type = KO_MEMORY_MAPPING; - untyped_entry->data |= level - 1; - -#ifdef DBG_SYSCALL - klogf("map %p[%p] to pml%i %p[%i]\n", untyped_entry, untyped_phys, level, target_pml, pmli); -#endif - - mtx_release(&untyped_entry->lock); - return 0; -} - -static int (*s_invoke_handles[])(objdir_t*, objdir_entry_t*, uint8_t*, size_t) = { - [INVOKE_MAPPING_RELEASE] = s_handle_invoke_mapping_release, - [INVOKE_MAPPING_GET] = s_handle_invoke_mapping_get, - [INVOKE_MAPPING_MAP] = s_handle_invoke_mapping_map, -}; - -static size_t s_invoke_handles_count = sizeof(s_invoke_handles) / sizeof(void*); - -int -syscall_handle_invoke_mapping( - objdir_t *root_dir, - objdir_entry_t *target, - uint8_t *payload, - size_t payload_at - ) -{ - uint8_t funcid; - SYSCALL_PAYLOAD_TAKEL(payload, payload_at, funcid, uint8_t); - - if(funcid >= s_invoke_handles_count) return KE_BADFUNC; - int r = s_invoke_handles[funcid](root_dir, target, payload, payload_at); -#ifdef DBG_SYSCALL - klogf("Call returns %i\n", r); -#endif - return r; -} diff --git a/arch/x86_64/syscall.c b/arch/x86_64/syscall.c deleted file mode 100644 index 5582336..0000000 --- a/arch/x86_64/syscall.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "arch/x86_64/processor.h" -#include "syscall/handles.h" -#include "print.h" -#include "lock.h" -#include "error.h" -#include - -static inline int -s_invoke_release( - objdir_t *root_dir, - objdir_entry_t *target, - uint8_t *payload, - size_t payload_at, - int (*invoke)(objdir_t*, objdir_entry_t*, uint8_t*, size_t)) -{ - int e = invoke(root_dir, target, payload, payload_at); - mtx_release(&target->lock); - return e; -} - -int -_syscall_handler_arch(objdir_t *root_dir, objdir_entry_t *target, uint8_t *payload, size_t payload_at) -{ - switch(target->type) { - case KO_MEMORY_MAPPING: - return s_invoke_release(root_dir, target, payload, payload_at, syscall_handle_invoke_mapping); - default: - klogf("Missing implementation of invoke for type %i\n", target->type); - mtx_release(&target->lock); - return -KE_BADTYPE; - } -} - -__attribute__((naked)) -void _syscall_entry(void) -{ - __asm__ volatile(" \ - pushq %%r11; \ - pushq %%rcx; \ - swapgs; \ - movq %%gs:%c[tcb], %%rax; \ - movq %%rsp, %c[sp](%%rax); \ - movq %c[ksp](%%rax), %%rsp; \ - pushq %c[sp](%%rax); \ - callq _syscall_handler; \ - swapgs; \ - popq %%rsp; \ - popq %%rcx; \ - popq %%r11; \ - sysretq;" - :: - [tcb] "i"(offsetof(processor_t, tcb)), - [sp] "i"(offsetof(tcb_t, sp)), - [ksp] "i"(offsetof(tcb_t, ksp))); -} diff --git a/arch/x86_64/syscall/invoke-mapping.c b/arch/x86_64/syscall/invoke-mapping.c new file mode 100644 index 0000000..be401d6 --- /dev/null +++ b/arch/x86_64/syscall/invoke-mapping.c @@ -0,0 +1,146 @@ +#include "arch/x86_64/syscall/wrappers.h" +#include "arch/x86_64/syscall.h" +#include "arch/x86_64/page.h" +#include +#include "error.h" +#include "lock.h" +#include "string.h" +#include "memory.h" +#include "print.h" + +static int +s_handle_invoke_mapping_exists( + objdir_t *root_dir, + objdir_entry_t *target_entry, + uint8_t *payload, + size_t payload_at + ) +{ + pmle_t *pml4 = (pmle_t*)vmem_phys_tovirt(target_entry->data); + pmle_t *target_pml; + uint8_t target_depth; + SYSCALL_PAYLOAD_TAKEPML(payload, payload_at, pml4, target_depth, target_pml); + if(target_pml == NULL || !target_pml->p) return KE_DNE; + +#ifdef DBG_SYSCALL + klogf("pml d%i %p from %p exists\n", target_depth, target_pml, pml4); +#endif + return 0; +} + +static int +s_handle_invoke_mapping_map( + objdir_t *root_dir, + objdir_entry_t *target_entry, + uint8_t *payload, + size_t payload_at + ) +{ + pmle_t *pml4 = (pmle_t*)vmem_phys_tovirt(target_entry->data); + pmle_t *target_pml; + uint8_t target_depth; + SYSCALL_PAYLOAD_TAKEPML(payload, payload_at, pml4, target_depth, target_pml); + if(target_pml == NULL) return KE_DNE; + + size_t untyped_pathw; + objdir_entry_t *untyped_entry; + SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, untyped_pathw, untyped_entry); + + if(untyped_entry->type != KO_MEMORY_UNTYPED) return KE_BADOBJ; + mtx_acquire(&untyped_entry->lock); + + if((untyped_entry->data & 0xFFF) != 0) { + mtx_release(&untyped_entry->lock); + return KE_ALIGN; + } + + uintptr_t untyped_phys = untyped_entry->data; + size_t *untyped = ko_entry_data(untyped_entry); + size_t untyped_size = *untyped; + if(untyped_size != 0x1000) { + mtx_release(&untyped_entry->lock); + return KE_BADSIZE; + } + + target_pml->value = untyped_phys | PAGE_RW | PAGE_US | PAGE_PRESENT; + __asm__ volatile("invlpg (%0)":: "r"(untyped): "memory"); + + if(target_depth != 3) { + memset(untyped, 0, 0x1000); + } + untyped_entry->type = KO_NONE; +#ifdef DBG_SYSCALL + klogf("map %p[%i] to %p[%i]\n", untyped_phys, target_depth, target_pml, ((uintptr_t)target_pml & 0xFFF) / 8); +#endif + + mtx_release(&untyped_entry->lock); + return 0; +} + +static int +s_handle_invoke_mapping_unmap( + objdir_t *root_dir, + objdir_entry_t *target_entry, + uint8_t *payload, + size_t payload_at + ) +{ + pmle_t *pml4 = (pmle_t*)vmem_phys_tovirt(target_entry->data); + pmle_t *target_pml; + uint8_t target_depth; + SYSCALL_PAYLOAD_TAKEPML(payload, payload_at, pml4, target_depth, target_pml); + if(target_pml == NULL || !target_pml->p) return KE_DNE; + + if(target_depth != 3) { + for(pmli_t i = 0; i < 512; i++) { + if(target_pml[i].p) return KE_FULL; + } + } + + target_pml->p = false; + + objdir_entry_t *dest_entry; + size_t dest_pathw; + SYSCALL_PAYLOAD_TAKEOBJ(payload, payload_at, dest_pathw, dest_entry); + + if(dest_entry->type != KO_NONE) return KE_FULL; + uintptr_t pmle_addr = target_pml->paddr << 12; + size_t *untyped = vmem_phys_tovirt(pmle_addr); + __asm__ volatile("invlpg (%0)":: "r"(untyped): "memory"); + + *untyped = 0x1000; + dest_entry->type = KO_MEMORY_UNTYPED; + dest_entry->data = pmle_addr; + +#ifdef DBG_SYSCALL + klogf("unmap %p[%i] to untyped %p\n", target_pml, 3 - target_depth, pmle_addr); +#endif + return 0; +} + +static int (*s_invoke_handles[])(objdir_t*, objdir_entry_t*, uint8_t*, size_t) = { + [INVOKE_MAPPING_EXISTS] = s_handle_invoke_mapping_exists, + [INVOKE_MAPPING_MAP] = s_handle_invoke_mapping_map, + [INVOKE_MAPPING_UNMAP] = s_handle_invoke_mapping_unmap +}; + +static size_t s_invoke_handles_count = sizeof(s_invoke_handles) / sizeof(void*); + +int +syscall_handle_invoke_mapping( + objdir_t *root_dir, + objdir_entry_t *target, + uint8_t *payload, + size_t payload_at + ) +{ + uint8_t funcid; + SYSCALL_PAYLOAD_TAKEL(payload, payload_at, funcid, uint8_t); + + if(funcid >= s_invoke_handles_count) return KE_BADFUNC; + int r = s_invoke_handles[funcid](root_dir, target, payload, payload_at); +#ifdef DBG_SYSCALL + klogf("Call returns %i\n", r); +#endif + return r; +} diff --git a/arch/x86_64/syscall/syscall.c b/arch/x86_64/syscall/syscall.c new file mode 100644 index 0000000..5582336 --- /dev/null +++ b/arch/x86_64/syscall/syscall.c @@ -0,0 +1,55 @@ +#include "arch/x86_64/processor.h" +#include "syscall/handles.h" +#include "print.h" +#include "lock.h" +#include "error.h" +#include + +static inline int +s_invoke_release( + objdir_t *root_dir, + objdir_entry_t *target, + uint8_t *payload, + size_t payload_at, + int (*invoke)(objdir_t*, objdir_entry_t*, uint8_t*, size_t)) +{ + int e = invoke(root_dir, target, payload, payload_at); + mtx_release(&target->lock); + return e; +} + +int +_syscall_handler_arch(objdir_t *root_dir, objdir_entry_t *target, uint8_t *payload, size_t payload_at) +{ + switch(target->type) { + case KO_MEMORY_MAPPING: + return s_invoke_release(root_dir, target, payload, payload_at, syscall_handle_invoke_mapping); + default: + klogf("Missing implementation of invoke for type %i\n", target->type); + mtx_release(&target->lock); + return -KE_BADTYPE; + } +} + +__attribute__((naked)) +void _syscall_entry(void) +{ + __asm__ volatile(" \ + pushq %%r11; \ + pushq %%rcx; \ + swapgs; \ + movq %%gs:%c[tcb], %%rax; \ + movq %%rsp, %c[sp](%%rax); \ + movq %c[ksp](%%rax), %%rsp; \ + pushq %c[sp](%%rax); \ + callq _syscall_handler; \ + swapgs; \ + popq %%rsp; \ + popq %%rcx; \ + popq %%r11; \ + sysretq;" + :: + [tcb] "i"(offsetof(processor_t, tcb)), + [sp] "i"(offsetof(tcb_t, sp)), + [ksp] "i"(offsetof(tcb_t, ksp))); +} diff --git a/arch/x86_64/syscall/wrappers.h b/arch/x86_64/syscall/wrappers.h new file mode 100644 index 0000000..a6fdf88 --- /dev/null +++ b/arch/x86_64/syscall/wrappers.h @@ -0,0 +1,14 @@ +#ifndef _JOVE_ARCH_x86_64_SYSCALL_WRAPPERS_H +#define _JOVE_ARCH_x86_64_SYSCALL_WRAPPERS_H 1 + +#include "arch/x86_64/page-mapping.h" +#include "syscall/handles.h" + +#define SYSCALL_PAYLOAD_TAKEPML(payload, at, pml4, depth, pml) \ + SYSCALL_PAYLOAD_TAKEL(payload, at, depth, uint8_t); \ + if(((depth + 1) * sizeof(uint16_t)) + at >= KO_MESSAGE_BYTES) return KE_BADMSG; \ + if(depth == 0 && *(uint16_t*)&payload[at] > 255) return KE_OOB; \ + pml = page_mapping_traverse(pml4, depth, (uint16_t*)&payload[at]); \ + at += (depth + 1) * sizeof(uint16_t) + +#endif -- cgit v1.2.1