From 76dd27b8398d58b928f14ecbd45ecacc538648ee Mon Sep 17 00:00:00 2001 From: Michalis Pappas Date: Thu, 3 Apr 2025 15:04:25 +0200 Subject: [PATCH] lib/posix-process/signal: Add stub for CLONE_SIGHAND Provide stub for CLONE_SIGHAND when LIBPOSIX_PROCESS_SIGNAL is not selected. This prevents clone() from returning -ENOTSUP when signals are not selected. Signed-off-by: Michalis Pappas Approved-by: Andrei Tatar Reviewed-by: Sergiu Moga GitHub-Closes: #1628 --- lib/posix-process/Makefile.uk | 5 +-- lib/posix-process/signal/clone.c | 52 +++++++++++++++++--------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/posix-process/Makefile.uk b/lib/posix-process/Makefile.uk index 86ca80b5f..9e61777e7 100644 --- a/lib/posix-process/Makefile.uk +++ b/lib/posix-process/Makefile.uk @@ -38,10 +38,7 @@ LIBPOSIX_PROCESS_SRCS-y += $(LIBPOSIX_PROCESS_BASE)/signal/kill.c LIBPOSIX_PROCESS_SRCS-y += $(LIBPOSIX_PROCESS_BASE)/signal/tgkill.c LIBPOSIX_PROCESS_SRCS-y += $(LIBPOSIX_PROCESS_BASE)/signal/tkill.c -ifeq ($(CONFIG_LIBPOSIX_PROCESS_CLONE), y) -LIBPOSIX_PROCESS_SRCS-$(CONFIG_LIBPOSIX_PROCESS_SIGNAL) += $(LIBPOSIX_PROCESS_BASE)/signal/clone.c|signal -endif - +LIBPOSIX_PROCESS_SRCS-$(CONFIG_LIBPOSIX_PROCESS_CLONE) += $(LIBPOSIX_PROCESS_BASE)/signal/clone.c|signal LIBPOSIX_PROCESS_SRCS-$(CONFIG_LIBPOSIX_PROCESS_CLONE) += $(LIBPOSIX_PROCESS_BASE)/clone.c LIBPOSIX_PROCESS_SRCS-$(CONFIG_LIBPOSIX_PROCESS_CLONE) += $(LIBPOSIX_PROCESS_BASE)/arch/$(CONFIG_UK_ARCH)/clone.S|arch LIBPOSIX_PROCESS_SRCS-$(CONFIG_LIBPOSIX_PROCESS_CLONE) += $(LIBPOSIX_PROCESS_BASE)/clonetab.ld diff --git a/lib/posix-process/signal/clone.c b/lib/posix-process/signal/clone.c index e3ad9b33e..b6a2bb351 100644 --- a/lib/posix-process/signal/clone.c +++ b/lib/posix-process/signal/clone.c @@ -3,31 +3,8 @@ * Copyright (c) 2022, NEC Laboratories Europe GmbH, NEC Corporation. * All rights reserved. * Copyright (c) 2024, Unikraft GmbH and The Unikraft Authors. - * - * 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 copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. + * Licensed under the BSD-3-Clause License (the "License"). + * You may not use this file except in compliance with the License. */ #include @@ -37,6 +14,8 @@ #include #include +#if CONFIG_LIBPOSIX_PROCESS_SIGNAL + #include "signal.h" static int uk_posix_clone_sighand(const struct clone_args *cl_args, @@ -163,6 +142,29 @@ fail_tdesc_alloc: return rc; } +#else /* !CONFIG_LIBPOSIX_PROCESS_SIGNAL */ +static int uk_posix_clone_sighand(const struct clone_args *cl_args, + size_t cl_args_len __unused, + struct uk_thread *child __unused, + struct uk_thread *parent __unused) +{ + /* CLONE_SIGHAND and CLONE_CLEAR_SIGHAND should not be together */ + if (unlikely((cl_args->flags & (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND)) == + (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND))) + return -EINVAL; + /* CLONE_SIGHAND requires CLONE_VM */ + if (unlikely((cl_args->flags & CLONE_SIGHAND) && + !(cl_args->flags & CLONE_VM))) + return -EINVAL; + /* CLONE_THREAD requires CLONE_SIGHAND */ + if (unlikely((cl_args->flags & CLONE_THREAD) && + !(cl_args->flags & CLONE_SIGHAND))) + return -EINVAL; + + UK_WARN_STUBBED(); + return 0; +} +#endif /* !CONFIG_LIBPOSIX_PROCESS_SIGNAL */ UK_POSIX_CLONE_HANDLER(CLONE_SIGHAND | CLONE_CLEAR_SIGHAND, false, uk_posix_clone_sighand, 0x0); -- 2.39.5