From patchwork Fri Feb 3 17:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 64265 X-Patchwork-Delegate: palmer@dabbelt.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 342CD38515F1 for ; Fri, 3 Feb 2023 17:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 342CD38515F1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675444433; bh=+QwjkBwJmId3RItwB9d3VcsAkNxNu00znx68YyERodU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ErnadUTLDNSYeJfjCiGNEWaKWPLAkQBMP4XQ4r/+Y6kPybCopQ0DCRZyeDcnuixcy WCdJlho/hNTwEeMDCyrXjoCSyM7LamAToa3CBxzMGD0TQFk5XFh4h/G+g47NjmUuDp tMPG3yw7+HLJXHiGHkY+wDJ3I1MRlq5+eUfJ+fYE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 710A43858004 for ; Fri, 3 Feb 2023 17:12:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 710A43858004 Received: by mail-ot1-x332.google.com with SMTP id e12-20020a0568301e4c00b0068bc93e7e34so1546408otj.4 for ; Fri, 03 Feb 2023 09:12:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+QwjkBwJmId3RItwB9d3VcsAkNxNu00znx68YyERodU=; b=E2wjoaShuOB2Kj24kwfPde7o1g7b29lNTwb6HrjdbR1Gcf6y3hbBzhdygjIQaeDMhX Sux37alcr5hFRxSV+YocPJP72CmY6mTa+VI3WYQDglMR4tVFsLIuvYUxM9W1mkEXdw99 oo3p9wuU9eXdxQuK6Qz0qGo+nwn9hxeoDTAJqyw7Mxx61bQe6AdHe4LPAUUI5N9xyS8X Vjc5tpE0OTxBf+62Z66sWZMFl/XrM7T+28vEQwI1pkueMLRtNowrN0IiPGQGWqediGWq jdNrijQebknGaR3XvgicjapQKtlk8bSJSnQg/CiPIcbwP63UD49/7tQTMY4/H1rzH2EL kYRw== X-Gm-Message-State: AO0yUKX0dftOv5oYuLvxVvPMTX9tHuQR4z/HsKzvAIlQDohDcs8e3ZCw 7PyAOIeDdEhWWk1ZC01OLATm8WxOTk/kc/8B2WA= X-Google-Smtp-Source: AK7set+S8wzLfeIWnRThKSZdA62/CQwHCSk3Sf+cRFkUQuARoXke3s+HUGNRJDqGdIbf4dO6Fbc6wg== X-Received: by 2002:a05:6830:1e57:b0:68b:b721:8f1c with SMTP id e23-20020a0568301e5700b0068bb7218f1cmr6355456otj.27.1675444367024; Fri, 03 Feb 2023 09:12:47 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:38a0:ca4:680a:31ed]) by smtp.gmail.com with ESMTPSA id cp23-20020a056830661700b0068bdd78f763sm1346672otb.29.2023.02.03.09.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:12:46 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 3/5] riscv: Add the clone3 wrapper Date: Fri, 3 Feb 2023 14:12:35 -0300 Message-Id: <20230203171237.1220878-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203171237.1220878-1-adhemerval.zanella@linaro.org> References: <20230203171237.1220878-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on riscv64-linux-gnu-rv64imafdc-lp64d. Reviewed-by: Palmer Dabbelt --- sysdeps/unix/sysv/linux/riscv/clone3.S | 80 ++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/riscv/sysdep.h | 1 + 2 files changed, 81 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/riscv/clone3.S diff --git a/sysdeps/unix/sysv/linux/riscv/clone3.S b/sysdeps/unix/sysv/linux/riscv/clone3.S new file mode 100644 index 0000000000..ee5780ee2f --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/clone3.S @@ -0,0 +1,80 @@ +/* The clone3 syscall wrapper. Linux/RISC-V version. + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + a0: cl_args + a1: size + a2: func + a3: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + beqz a0, L(invalid) /* No NULL cl_args pointer. */ + beqz a2, L(invalid) /* No NULL function pointer. */ + + /* Do the system call, the kernel expects: + a7: system call number + a0: cl_args + a1: size */ + li a7, __NR_clone3 + scall + + bltz a0, L(error) + beqz a0, L(thread_start) + + ret + +L(invalid): + li a0, -EINVAL +L(error): + tail __syscall_error +END (__clone3) + +ENTRY(__thread_start_clone3) +L(thread_start): + /* Terminate call stack by noting ra is undefined. Use a dummy + .cfi_label to force starting the FDE. */ + .cfi_label .Ldummy + cfi_undefined (ra) + + /* Restore the arg for user's function and call the user's + function. */ + mv a1, a2 /* Function pointer. */ + mv a0, a3 /* Argument pointer. */ + jalr a1 + + /* Call exit with the function's return value. */ + li a7, __NR_exit + scall +END(__thread_start_clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h index 4af5fe5dbc..e96a930409 100644 --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h @@ -151,6 +151,7 @@ /* RV32 does not support the gettime VDSO syscalls. */ # endif +# define HAVE_CLONE3_WRAPPER 1 /* List of system calls which are supported as vsyscalls (for RV32 and RV64). */