// SPDX-License-Identifier: MIT #include #include #include #include #include #include #include zn_status_t syscall_handle_clone(struct arch_context* ctx) { zn_handle_t handle = ctx->ARCH_CTX_A0; zn_rights_t cloned_rights = ctx->ARCH_CTX_A1; __user zn_handle_t* cloned = (__user zn_handle_t*)ctx->ARCH_CTX_A2; struct task* current = percpu_get()->sched.current; struct namespace* ns = current->namespace; struct namespace_desc desc; zn_status_t status = namespace_get(ns, handle, &desc); if (status != ZN_OK) return status; zn_handle_t new_handle; status = namespace_clone_desc(ns, &desc, cloned_rights, &new_handle); if (status != ZN_OK) return status; if (!usercopy_write(cloned, &new_handle, sizeof(new_handle))) { namespace_del_desc(ns, new_handle); return ZN_ERR_BAD_BUFFER; } return ZN_OK; } zn_status_t syscall_handle_drop(struct arch_context* ctx) { zn_handle_t handle = ctx->ARCH_CTX_A0; struct task* current = percpu_get()->sched.current; return namespace_del_desc(current->namespace, handle); } zn_status_t syscall_handle_validate(struct arch_context* ctx) { zn_handle_t handle = ctx->ARCH_CTX_A0; struct task* current = percpu_get()->sched.current; struct namespace_desc desc; return namespace_get(current->namespace, handle, &desc); }