From afeab489696bb50fdcc36bc50f0c67961c66ae85 Mon Sep 17 00:00:00 2001 From: Philippe Aubertin <39178965+phaubertin@users.noreply.github.com> Date: Sun, 26 Jan 2025 18:31:49 -0500 Subject: [PATCH] Remove MCLONE system call (#118) Remove unused MCLONE system call. This system call used to be used by the userspace loader but isn't anymore. --- doc/syscalls/README.md | 4 +- doc/syscalls/mclone.md | 87 ------------------ include/jinue/jinue.h | 9 -- include/jinue/shared/asm/syscalls.h | 3 - include/jinue/shared/types.h | 7 -- include/kernel/application/syscalls.h | 2 - kernel/Makefile | 1 - kernel/application/syscalls/mclone.c | 125 -------------------------- kernel/interface/syscalls.c | 56 ------------ userspace/lib/jinue/syscalls.c | 25 ------ 10 files changed, 2 insertions(+), 317 deletions(-) delete mode 100644 doc/syscalls/mclone.md delete mode 100644 kernel/application/syscalls/mclone.c diff --git a/doc/syscalls/README.md b/doc/syscalls/README.md index 7ef69bdb..2bbdcbd6 100644 --- a/doc/syscalls/README.md +++ b/doc/syscalls/README.md @@ -21,7 +21,7 @@ | 12 | [EXIT_THREAD](exit-thread.md) | Terminate the current thread | | 13 | [MMAP](mmap.md) | Map memory | | 14 | [CREATE_PROCESS](create-process.md) | Create a process | -| 15 | [MCLONE](mclone.md) | Clone a memory mapping | +| 15 | - | Reserved | | 16 | [DUP](dup.md) | Duplicate a descriptor | | 17 | [CLOSE](close.md) | Close a descriptor | | 18 | [DESTROY](destroy.md) | Destroy a kernel object | @@ -30,7 +30,7 @@ | 21 | [AWAIT_THREAD](await-thread.md) | Wait for a thread to exit | | 22 | [REPLY_ERROR](reply-error.md) | Reply to message with an error | | 23-4095 | - | Reserved | -| 4096+ | [SEND](send.md) | Send a message | +| 4096+ | [SEND](send.md) | Send a message | #### Reserved Function Numbers diff --git a/doc/syscalls/mclone.md b/doc/syscalls/mclone.md deleted file mode 100644 index b9d49766..00000000 --- a/doc/syscalls/mclone.md +++ /dev/null @@ -1,87 +0,0 @@ -# MCLONE - Clone a Memory Mapping - -## Description - -Clone a contiguous memory mapping from one process to another. - -For this operation to succeed, the destination process descriptor must have the -[JINUE_PERM_MAP](../../include/jinue/shared/asm/permissions.h) permission. - -## Arguments - -Function number (`arg0`) is 15. - -The descriptor number for the source process is set in `arg1`. - -The descriptor number for the destination process is set in `arg2`. - -A pointer to a [jinue_mclone_args_t structure](../../include/jinue/shared/types.h) -(i.e. the mclone arguments structure) that contains the rest of the arguments is -set in `arg3`. - -``` - +----------------------------------------------------------------+ - | function = 15 | arg0 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | src | arg1 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | dest | arg2 - +----------------------------------------------------------------+ - 31 0 - - +----------------------------------------------------------------+ - | pointer to mclone arguments structure | arg3 - +----------------------------------------------------------------+ - 31 0 -``` - -The mclone arguments structure contains the following fields: - -* `src_addr` the virtual address (i.e. pointer) of the start of the mapping in -the source address space. -* `dest_addr` the virtual address (i.e. pointer) of the start of the mapping in -the destination address space. -* `length` the length of the mapping, in bytes. -* `prot` the protection flags (see below). - -`src_addr`, `dest_addr` and `length` must all be aligned on a page boundary. - -`prot` must be set to either `JINUE_PROT_NONE` or to the bitwise or of -`JINUE_PROT_READ`, `JINUE_PROT_WRITE` and/or `JINUE_PROT_EXEC` as described in -the following table: - -| Value | Name | Description | -|-------|------------------|-----------------------| -| 0 | JINUE_PROT_NONE | No access | -| 1 | JINUE_PROT_READ | Mapping is readable | -| 2 | JINUE_PROT_WRITE | Mapping is writeable | -| 4 | JINUE_PROT_EXEC | Mapping is executable | - -If this function fails with a `JINUE_ENOMEM` error, the mapping may have been -partially cloned. - -## Return Value - -On success, this function returns 0 (in `arg0`). On failure, this function -returns -1 and an error number is set (in `arg1`). - -## Errors - -* JINUE_EINVAL if `src_addr`, `dest_addr` and/or `length` are not aligned to a -page boundary. -* JINUE_EINVAL if any part of the mclone arguments structure as specified by `arg3` -belongs to the kernel. -* JINUE_EINVAL if `prot` is not `JINUE_PROT_NONE` or a bitwise or combination of -`JINUE_PROT_READ`, `JINUE_PROT_WRITE` and/or `JINUE_PROT_EXEC`. -* JINUE_EBADF if one of the specified descriptors is invalid, or does not refer -to a process, or is closed. -* JINUE_EIO if either process no longer exists. -* JINUE_ENOMEM if not enough memory is available to allocate needed page tables. -* JINUE_EPERM if the destination process descriptor does not have the -permission to map memory into the process. diff --git a/include/jinue/jinue.h b/include/jinue/jinue.h index da98a711..2416c741 100644 --- a/include/jinue/jinue.h +++ b/include/jinue/jinue.h @@ -90,15 +90,6 @@ int jinue_create_endpoint(int fd, int *perrno); int jinue_create_process(int fd, int *perrno); -int jinue_mclone( - int src, - int dest, - void *src_addr, - void *dest_addr, - size_t length, - int prot, - int *perrno); - int jinue_dup(int process, int src, int dest, int *perrno); int jinue_close(int fd, int *perrno); diff --git a/include/jinue/shared/asm/syscalls.h b/include/jinue/shared/asm/syscalls.h index 87601269..95aa1f7a 100644 --- a/include/jinue/shared/asm/syscalls.h +++ b/include/jinue/shared/asm/syscalls.h @@ -68,9 +68,6 @@ /** create a new process */ #define JINUE_SYS_CREATE_PROCESS 14 -/** clone a memory mapping from the current process to another */ -#define JINUE_SYS_MCLONE 15 - /** duplicate a descriptor from the current process to another */ #define JINUE_SYS_DUP 16 diff --git a/include/jinue/shared/types.h b/include/jinue/shared/types.h index 88c352d4..50eb46a2 100644 --- a/include/jinue/shared/types.h +++ b/include/jinue/shared/types.h @@ -99,13 +99,6 @@ typedef struct { uint64_t paddr; } jinue_mmap_args_t; -typedef struct { - void *src_addr; - void *dest_addr; - size_t length; - int prot; -} jinue_mclone_args_t; - typedef struct { int process; int fd; diff --git a/include/kernel/application/syscalls.h b/include/kernel/application/syscalls.h index 2c62d899..6e9dfc9f 100644 --- a/include/kernel/application/syscalls.h +++ b/include/kernel/application/syscalls.h @@ -54,8 +54,6 @@ void *get_thread_local(void); int get_address_map(const jinue_buffer_t *buffer); -int mclone(int src, int dest, const jinue_mclone_args_t *args); - int mint(int owner, const jinue_mint_args_t *args); int mmap(int process_fd, const jinue_mmap_args_t *args); diff --git a/kernel/Makefile b/kernel/Makefile index 5632ad33..69a3c45b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -74,7 +74,6 @@ sources.kernel.c = \ application/syscalls/await_thread.c \ application/syscalls/mint.c \ application/syscalls/mmap.c \ - application/syscalls/mclone.c \ application/syscalls/puts.c \ application/syscalls/reboot.c \ application/syscalls/receive.c \ diff --git a/kernel/application/syscalls/mclone.c b/kernel/application/syscalls/mclone.c deleted file mode 100644 index 706c4991..00000000 --- a/kernel/application/syscalls/mclone.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2024 Philippe Aubertin. - * All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -static int with_destination( - process_t *current, - process_t *src_process, - descriptor_t *dest_desc, - const jinue_mclone_args_t *args) { - - process_t *dest_process = descriptor_get_process(dest_desc); - - if(dest_process == NULL) { - return -JINUE_EBADF; - } - - if(!descriptor_has_permissions(dest_desc, JINUE_PERM_MAP)) { - return -JINUE_EPERM; - } - - bool success = machine_clone_userspace_mapping( - dest_process, - args->dest_addr, - src_process, - args->src_addr, - args->length, - args->prot - ); - - if(!success) { - return -JINUE_ENOMEM; - } - - return 0; -} - -static int with_source( - process_t *current, - descriptor_t *src_desc, - int dest, - const jinue_mclone_args_t *args) { - - process_t *src_process = descriptor_get_process(src_desc); - - if(src_process == NULL) { - return -JINUE_EBADF; - } - - /* TODO what permissions do we need on the source for this? Should the - * source just implicitly be the current process? */ - - descriptor_t dest_desc; - int status = descriptor_access_object(&dest_desc, current, dest); - - if(status < 0) { - return status; - } - - status = with_destination(current, src_process, &dest_desc, args); - - descriptor_unreference_object(&dest_desc); - - return status; -} - -/** - * Implementation for the MCLONE system call - * - * Clone memory mappings from one process to another. - * - * @param src source process descriptor number - * @param dest destination process descriptor number - * @param args MCLONE system call arguments structure - * @return zero on success, negated error code on failure - */ -int mclone(int src, int dest, const jinue_mclone_args_t *args) { - process_t *current = get_current_process(); - - descriptor_t src_desc; - int status = descriptor_access_object(&src_desc, current, src); - - if(status < 0) { - return status; - } - - status = with_source(current, &src_desc, dest, args); - - descriptor_unreference_object(&src_desc); - - return status; -} diff --git a/kernel/interface/syscalls.c b/kernel/interface/syscalls.c index 2148bf4e..9ea17dcd 100644 --- a/kernel/interface/syscalls.c +++ b/kernel/interface/syscalls.c @@ -375,59 +375,6 @@ static void sys_create_process(jinue_syscall_args_t *args) { set_return_value_or_error(args, retval); } -static void sys_mclone(jinue_syscall_args_t *args) { - const jinue_mclone_args_t *userspace_mclone_args; - - int src = get_descriptor(args->arg1); - int dest = get_descriptor(args->arg2); - userspace_mclone_args = (void *)args->arg3; - - if(src < 0) { - set_return_value_or_error(args, src); - return; - } - - if(dest < 0) { - set_return_value_or_error(args, dest); - return; - } - - if(! check_userspace_buffer(userspace_mclone_args, sizeof(jinue_mclone_args_t))) { - set_error(args, JINUE_EINVAL); - return; - } - - jinue_mclone_args_t mclone_args = *userspace_mclone_args; - - if(OFFSET_OF_PTR(mclone_args.src_addr, PAGE_SIZE) != 0) { - set_error(args, JINUE_EINVAL); - return; - } - - if(OFFSET_OF_PTR(mclone_args.dest_addr, PAGE_SIZE) != 0) { - set_error(args, JINUE_EINVAL); - return; - } - - if((mclone_args.length & (PAGE_SIZE -1)) != 0) { - set_error(args, JINUE_EINVAL); - return; - } - - if((mclone_args.prot & ~ALL_PROT_FLAGS) != 0) { - set_error(args, JINUE_EINVAL); - return; - } - - if((mclone_args.prot & WRITE_EXEC) == WRITE_EXEC) { - set_error(args, JINUE_ENOTSUP); - return; - } - - int retval = mclone(src, dest, &mclone_args); - set_return_value_or_error(args, retval); -} - static void sys_dup(jinue_syscall_args_t *args) { int process_fd = get_descriptor(args->arg1); int src = get_descriptor(args->arg2); @@ -607,9 +554,6 @@ void handle_syscall(jinue_syscall_args_t *args) { case JINUE_SYS_CREATE_PROCESS: sys_create_process(args); break; - case JINUE_SYS_MCLONE: - sys_mclone(args); - break; case JINUE_SYS_DUP: sys_dup(args); break; diff --git a/userspace/lib/jinue/syscalls.c b/userspace/lib/jinue/syscalls.c index c9e6c9dd..e38a2166 100644 --- a/userspace/lib/jinue/syscalls.c +++ b/userspace/lib/jinue/syscalls.c @@ -222,31 +222,6 @@ int jinue_create_process(int fd, int *perrno) { return call_with_usual_convention(&args, perrno); } -int jinue_mclone( - int src, - int dest, - void *src_addr, - void *dest_addr, - size_t length, - int prot, - int *perrno) { - - jinue_syscall_args_t args; - jinue_mclone_args_t mclone_args; - - mclone_args.src_addr = src_addr; - mclone_args.dest_addr = dest_addr; - mclone_args.length = length; - mclone_args.prot = prot; - - args.arg0 = JINUE_SYS_MCLONE; - args.arg1 = src; - args.arg2 = dest; - args.arg3 = (uintptr_t)&mclone_args; - - return call_with_usual_convention(&args, perrno); -} - int jinue_dup(int process, int src, int dest, int *perrno) { jinue_syscall_args_t args;