From 62fc51338d7259c2ea39f38bd8c7d9552e9b2002 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 12 Jun 2022 16:18:47 +0300 Subject: doxygen shows no warnings + Does not mean documentation is done, but it's a nice little achievement nonetheless. --- common/uapi/mem.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 10 deletions(-) (limited to 'common/uapi/mem.c') diff --git a/common/uapi/mem.c b/common/uapi/mem.c index 374e722..71686d6 100644 --- a/common/uapi/mem.c +++ b/common/uapi/mem.c @@ -4,6 +4,7 @@ /** * @file mem.c * Memory handling syscall implementations. + * \todo Should we return more error information? */ #include @@ -11,33 +12,76 @@ #include #include +/** + * Memory request syscall handler. + * + * @param size Minimum size of allocation. + * @param flags Flags of allocation. + * @return \ref OK and start of allocation when succesful, + * \ref ERR_OOMEM and \c NULL otherwise. + */ SYSCALL_DEFINE2(req_mem)(sys_arg_t size, sys_arg_t flags) { /* get current effective process */ struct tcb *r = cur_proc(); - return (struct sys_ret){ OK, alloc_uvmem(r, size, flags) }; + vm_t start = 0; + if ((start = alloc_uvmem(r, size, flags))) + return (struct sys_ret){ ERR_OOMEM, NULL }; + + return (struct sys_ret){ OK, start }; } +/** + * Fixed memory request syscall handler. + * + * @param start Address which should be included in allocation. + * @param size Minimum size of allocation after \c start. + * @param flags Flags of allocation. + * @return \ref OK and start of allocation when succesful, + * \ref ERR_OOMEM and \c NULL otherwise. + */ SYSCALL_DEFINE3(req_fixmem)(sys_arg_t start, sys_arg_t size, sys_arg_t flags) { struct tcb *r = cur_proc(); - /* should probably check if the allocation succeeded...? \todo */ - return (struct sys_ret){ OK, alloc_fixed_uvmem(r, start, size, flags) }; + vm_t start = 0; + if ((start = alloc_fixed_uvmem(r, start, size, flags))) + return (sys_ret){ ERR_OOMEM, NULL }; + + return (struct sys_ret){ OK, start }; } +/** + * Free memory syscall handler. + * + * @param start Start of allocation to free. + * @return \ref OK and \c 0 when succesful, \ref ERR_NF and \c 0 otherwise. + */ SYSCALL_DEFINE1(free_mem)(sys_arg_t start) { struct tcb *r = cur_proc(); vm_t vm_start = (vm_t)start; + stat_t status = OK; if (vm_start > __pre_top && vm_start < __post_base) - free_uvmem(r, vm_start); + status = free_uvmem(r, vm_start); else - free_devmem(r, vm_start); + status = free_devmem(r, vm_start); + + if (status) + return (struct sys_ret){ ERR_NF, 0 }; return (struct sys_ret){ OK, 0 }; } +/** + * Request physical memory syscall handler. + * + * @param paddr Physical address to map. + * @param size Minimum size of allocation. + * @param flags Flags of allocation. + * @return \ref OK and start of allocation when succesful, + * \ref ERR_OOMEM and \c NULL otherwise. + */ SYSCALL_DEFINE3(req_pmem)(sys_arg_t paddr, sys_arg_t size, sys_arg_t flags) { /* this will require some pondering, but essentially this syscall should @@ -46,29 +90,48 @@ SYSCALL_DEFINE3(req_pmem)(sys_arg_t paddr, sys_arg_t size, sys_arg_t flags) * that keeps track of used regions outside of RAM. We'll see. */ struct tcb *r = cur_proc(); - return (struct sys_ret){ OK, alloc_devmem(r, paddr, size, flags) }; + vm_t start = 0; + if ((start = alloc_devmem(r, paddr, size, flags))) + return (struct sys_ret){ ERR_OOMEM, NULL }; + + return (struct sys_ret){ OK, start }; } +/** + * Request shared memory syscall handler. + * + * @param size Minimum size of allocation. + * @param flags Flags of allocation. + * @return \ref OK and start of allocation when succesful, + * \ref ERR_OOMEM and \c NULL otherwise. + */ SYSCALL_DEFINE2(req_sharedmem)(sys_arg_t size, sys_arg_t flags) { /** \todo check that requester is server */ struct tcb *t = cur_proc(); vm_t start = 0; if ((start = alloc_shared_uvmem(t, size, flags))) - return (struct sys_ret){ ERR_OOMEM, 0 }; + return (struct sys_ret){ ERR_OOMEM, NULL }; return (struct sys_ret){ OK, start }; } -/* add a syscall like ref_sharedmem that adds a reference to an existing shared - * memory region to a new tid? */ +/** + * Reference shared memory syscall handler. + * + * @param tid Thread ID of shared memory owner. + * @param va Start of shared memory in \c tid. + * @param flags Flags of reference. + * @return \ref OK and start of reference when succesful, + * \ref ERR_OOMEM and \c NULL otherwise. + */ SYSCALL_DEFINE3(ref_sharedmem)(sys_arg_t tid, sys_arg_t va, sys_arg_t flags) { struct tcb *t1 = cur_tcb(); struct tcb *t2 = get_tcb(tid); vm_t start = 0; if ((start = ref_shared_uvmem(t1, t2, va, flags))) - return (struct sys_ret){ ERR_OOMEM, 0 }; + return (struct sys_ret){ ERR_OOMEM, NULL }; return (struct sys_ret){ OK, start }; } -- cgit v1.3