From 10ae2e6ebc7e9776b9f124c9fc530c79f5e84460 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 2 Dec 2022 21:12:11 +0200 Subject: initial shared memory working --- common/uapi/mem.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'common/uapi/mem.c') diff --git a/common/uapi/mem.c b/common/uapi/mem.c index 374bcbe..099028e 100644 --- a/common/uapi/mem.c +++ b/common/uapi/mem.c @@ -107,23 +107,33 @@ SYSCALL_DEFINE3(req_pmem)(struct tcb *t, sys_arg_t paddr, sys_arg_t size, * Request shared memory syscall handler. * * @param t Current tcb. + * @param tid Thread to share memory with. * @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. + * @param sflags Flags of allocation for \p t. + * @param cflags Flags of allocation for \p tid. + * @return \ref OK and start of \p t allocation and start of \p tid allocation, + * in that order, \ref ERR_OOMEM otherwise. * * @todo should we also take the thread who should get the other end of the * memory? */ -SYSCALL_DEFINE2(req_sharedmem)(struct tcb *t, sys_arg_t size, sys_arg_t flags) +SYSCALL_DEFINE4(req_sharedmem)(struct tcb *t, sys_arg_t tid, + sys_arg_t size, sys_arg_t sflags, + sys_arg_t cflags) { - /** \todo check that requester is server */ - struct tcb *r = get_cproc(t); - vm_t start = 0; - if (!(start = alloc_shared_uvmem(r, size, flags))) + /** @todo check capability for shared memory */ + struct tcb *u = get_tcb(tid); + if (!u) + return_args(t, SYS_RET1(ERR_INVAL)); + + struct tcb *s = get_cproc(t); + struct tcb *c = get_rproc(u); + + vm_t sstart, cstart; + if (alloc_shared_uvmem(s, c, size, sflags, cflags, &sstart, &cstart)) return_args(t, SYS_RET1(ERR_OOMEM)); - return_args(t, SYS_RET2(OK, start)); + return_args(t, SYS_RET3(OK, sstart, cstart)); } /** \todo add some way to specify who gets to access the shared memory? */ -- cgit v1.3