From patchwork Fri Feb 3 17:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64263 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 EC24C3858407 for ; Fri, 3 Feb 2023 17:13:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC24C3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675444389; bh=uROL8lIHbdLh0AW8KEzKnHVBlyjiYxT40hqlzO73OrY=; 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=iZqLFuyG6RSDSRkQH8nz3axcp6hv4E6sEkkaxuFvjEorgLQgUhWOI7Y3j+VlKGNYO GUCpPodFvpGxQuTOMnJnjjsuABNsIp4QprjhzhwImmcwUHe6tJDoP0/eRdOUpfEeTp ZRd1o+WxgiJ/7aU84sqvy9OQjviBZuTlk/W03png= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 82F8B3858C52 for ; Fri, 3 Feb 2023 17:12:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82F8B3858C52 Received: by mail-ot1-x32e.google.com with SMTP id r34-20020a05683044a200b0068d4a8a8d2dso1534656otv.12 for ; Fri, 03 Feb 2023 09:12:44 -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=uROL8lIHbdLh0AW8KEzKnHVBlyjiYxT40hqlzO73OrY=; b=Ryb8A2d5+ZE0IPUvyilAMdpeQokwkkySV/s/Y4QSeMRjMRhvGBhKsTMB4oJTlaAPD/ BUhUl5pkCk2TpOhlaqVXj9sOhWB/FxgvKaPc1vZckiJ/tM8kk2PTnknaXCRLMndAIHS3 ZlS30oXXeK5XcaWnbizRE70es+Jt4vsBXtd59YfPImXQgUFe+V0OJpwyb5h+PubJFgck LKnP32oP/93nz4MFu2h8BTtsMQKOTttcKfRtb9P0IybTJpWiu0TVhRfA0wpknGom9tvO dwAZD77h7sgCLu16RWJDQ6+/eWFoEWeyWzs4HGKFKR7Qt3qmuq+b6gY16IJLTq7etUTZ QhiA== X-Gm-Message-State: AO0yUKUQGr1jLQc1Psoe1KQ5Z7hHKNkwf38wa+b3eiokwIkF9/B/G/1U VmBNjaQU8i4L0vJpBtU6Vk3sQxYs79jIoHKvdcU= X-Google-Smtp-Source: AK7set+vbcS4128K8sDMON5OVcwjdVZrYOg69GqIo0h3X4mXofAUsAJvP7OdcZB+zbCiqWHuVbIPfQ== X-Received: by 2002:a9d:6b0d:0:b0:68d:53d5:f7d2 with SMTP id g13-20020a9d6b0d000000b0068d53d5f7d2mr2841015otp.31.1675444363014; Fri, 03 Feb 2023 09:12:43 -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.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:12:42 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 1/5] powerpc64: Add the clone3 wrapper Date: Fri, 3 Feb 2023 14:12:33 -0300 Message-Id: <20230203171237.1220878-2-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.1 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 Netto 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); The powerpc64 ABI requires an initial stackframe so the child can store/restore the TOC. It is create prior calling clone3 by adjusting the stack size (since kernel will compute the stack as stack plus size). Checked on powerpc64-linux-gnu (power8, kernel 6.0) and powerpc64le-linux-gnu (power9, kernel 4.18). Reviewed-by: Paul E. Murphy --- .../sysv/linux/powerpc/powerpc64/clone3.S | 157 ++++++++++++++++++ sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + 2 files changed, 158 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S new file mode 100644 index 0000000000..3c50fe392f --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S @@ -0,0 +1,157 @@ +/* The clone3 syscall wrapper. Linux/powerpc64 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 +#define _ERRNO_H 1 +#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: + r3: cl_args + r4: size + r5: func + r6: arg */ + +#ifdef USE_PPC_SCV +/* This is equivalent to DO_CALL_SCV, but we cannot use the macro here + because it uses CFI directives and we just called cfi_endproc. */ +# define DO_CLONE3_SVC_CALL(jumpfalse) \ + CHECK_SCV_SUPPORT r28 jumpfalse; \ + mflr r9; \ + std r9, FRAME_LR_SAVE(r1); \ + .machine "push"; \ + .machine "power9"; \ + scv 0; \ + .machine "pop"; \ + ld r9, FRAME_LR_SAVE(r1); \ + mtlr r9; \ + /* With scv an, an error is a value -4095 <= x < 0. */ \ + cmpdi cr1, r3, 0; \ + b 1f; +#else +# define DO_CLONE3_SVC_CALL(fail_branch) +#endif + + .text +ENTRY(__clone3) + CALL_MCOUNT 4 + + /* Sanity checks args. */ + cmpdi cr0, r3, 0 + cmpdi cr1, r5, 0 + cror cr0*4+eq, cr1*4+eq, cr0*4+eq + beq cr0,L(badargs) + + /* Save some regs in the "red zone". */ +#ifdef USE_PPC_SCV + std r28, -24(r1) + cfi_offset (r28, -24) +#endif + std r29, -16(r1) + std r30, -8(r1) + cfi_offset (r29, -16) + cfi_offset (r30, -8) + + /* Save func and arg across syscall. */ + mr r30, r5 /* Function in r30. */ + mr r29, r6 /* Argument in r29. */ + + /* End FDE now, because in the child the unwind info will be + wrong. */ + cfi_endproc + + /* Setup a minimum stack frame for child. It needs to first calculate + the effective stack address, write the start empty backchain pointer, + and update the frame size in the input cl_args. */ + ld r7, 40(r3) /* Load stack value. */ + ld r8, 48(r3) /* Load stack_size value. */ + li r10, 0 + add r7, r7, r8 /* Calculate effective stack address. */ + std r10, -FRAME_MIN_SIZE_PARM(r7) + addi r8, r8, -FRAME_MIN_SIZE_PARM + std r8, 48(r3) + + /* Do the system call, the kernel expects: + r0: system call numer + r3: cl_args + r4: size */ + li r0, SYS_ify(clone3) + DO_CLONE3_SVC_CALL (0f) +0: DO_CALL_SC + + /* With sc, error is indicated by cr0.SO. */ + cmpdi cr1, r3, 0 + crandc cr1*4+eq, cr1*4+eq, cr0*4+so + +1: bne- cr1,L(parent) + + /* Child, load the function and arguments. */ + std r2, FRAME_TOC_SAVE(r1) + PPC64_LOAD_FUNCPTR r30 + mr r3, r29 + bctrl + ld r2, FRAME_TOC_SAVE(r1) + + li r0, SYS_ify(exit) + DO_CLONE3_SVC_CALL (2f) +2: DO_CALL_SC + /* We won't ever get here but provide a nop so that the linker + will insert a toc adjusting stub if necessary. */ + nop + +L(badargs): + cfi_startproc + li r3, EINVAL + TAIL_CALL_SYSCALL_ERROR + +L(parent): + /* Check if scv is available. */ + cmpdi cr1, r28, 0 + + /* Parent. Restore registers & return. */ +#ifdef USE_PPC_SCV + cfi_offset (r28, -24) + ld r28, -24(r1) + cfi_restore (r28) +#endif + cfi_offset (r29,-16) + cfi_offset (r30,-8) + ld r29, -16(r1) + ld r30, -8(r1) + cfi_restore (r29) + cfi_restore (r30) + +#ifdef USE_PPC_SCV + beq cr1, 0f + RET_SCV + b 1f +#endif +0: RET_SC +1: TAIL_CALL_SYSCALL_ERROR + +PSEUDO_END (__clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 9859cb8171..96a0edc38f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -214,6 +214,7 @@ #if defined(__PPC64__) || defined(__powerpc64__) #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" From patchwork Fri Feb 3 17:12:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64264 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 D3F81385B520 for ; Fri, 3 Feb 2023 17:13:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3F81385B520 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675444391; bh=GAxnSPpbL6ErEnHSnVRB8HqjSOwNWNelOLHvoVpXugw=; 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=Wxe3+kqaNLTJ7lz2DEZYRxtVqsUEx2sJAFH9VF2zzL7J3qP1NV/FYszhPMHXIIvS3 HbHHfBSlPDgNNxzC9MWkMN5ltEI5hCiXQhFjQOOoygINEQPKUGw8U7LlG1IDIlPPyI 8+z2fZO4XciavNG3ObLyLzkSiIwDO+Bw6Tzv5lhw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 451093858C30 for ; Fri, 3 Feb 2023 17:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 451093858C30 Received: by mail-ot1-x334.google.com with SMTP id x26-20020a056830115a00b0068bbc0ee3eeso1555545otq.0 for ; Fri, 03 Feb 2023 09:12:46 -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=GAxnSPpbL6ErEnHSnVRB8HqjSOwNWNelOLHvoVpXugw=; b=4me1NQHhN5qQPNrN51B/+gTVHQMrrsLl8PNXATR18x19xdL6zon1y0PlenlWasHIV8 E33sI9yJAm0yyfstzvGwZtBDH9MzX9XqNan+e+lyjFrEmKPOwfFF5mmpvLQs6EB7CCXm u0P0eK+gGvQDgn9BbhN+0TjYzRbjvnVvkydSCJdWwjdeVTKh4cWjQyvCp3GFoBnCALuJ pghm/5trXVFLSXIPyRy6mOkn9Y/DSsFXfU1Hebrdmwfj9vjyGPA906RjQ1v8Me+3l7kP z68bT+8PKuJjtHUuZj8r8eKcFI+BPXxQsflwFxPwiQjqE6DRuDWuWjPNy8SP6xz4JjR7 2/Zg== X-Gm-Message-State: AO0yUKUjvH/PxR1fJzrPYVPa+YtQxv6vh2XTJdxzmzeF7LNfNAiNBAHk fswC9Os2OTH79ZMJ1F2OK3SiIefcFqDVjN42g1U= X-Google-Smtp-Source: AK7set8CtrtTrMipyig+Gtc0k/BUl6qfMnO1ISlZov6xUE8kqiuBUlXFjQMKuU2uGXT5NKGJLxnVMw== X-Received: by 2002:a9d:37c2:0:b0:68d:499b:c1a4 with SMTP id x60-20020a9d37c2000000b0068d499bc1a4mr4199569otb.13.1675444364895; Fri, 03 Feb 2023 09:12:44 -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.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:12:44 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 2/5] s390x: Add the clone3 wrapper Date: Fri, 3 Feb 2023 14:12:34 -0300 Message-Id: <20230203171237.1220878-3-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.4 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 Netto 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 s390x-linux-gnu. --- sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + 2 files changed, 82 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S new file mode 100644 index 0000000000..417fdcb785 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S @@ -0,0 +1,81 @@ +/* The clone3 syscall wrapper. Linux/s390x 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 +#define _ERRNO_H 1 +#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: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + stg %r6, 48(%r15) + + /* Sanity check args. */ + ltgr %r2, %r2 + je error + ltgr %r6, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lghi %r1, SYS_ify(clone3) + svc 0 + ltgr %r2,%r2 /* check return code */ + jz thread_start + lg %r6, 48(%r15) + jgm SYSCALL_ERROR_LABEL + br %r14 +error: + lghi %r2,-EINVAL + jg SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 4 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 6, arg in gpr 5. */ + lgr %r2, %r5 + aghi %r15, -160 + xc 0(8,%r15),0(%r15) + basr %r14, %r6 + + DO_CALL (exit, 1) + cfi_endproc + .size thread_start, .-thread_start + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 3bde8ba19c..b099fea9c6 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -72,6 +72,7 @@ #ifdef __s390x__ #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" 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 Netto 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 Netto 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). */ From patchwork Fri Feb 3 17:12:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64267 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 9257A3858408 for ; Fri, 3 Feb 2023 17:14:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9257A3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675444480; bh=mv2z6fIWOVfa+yhLLzdaqnii16YNEJSofdmi2xHXMIs=; 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=iSJmhLIHdMyPt5lnG0g/QHjh0KUJLhaLvWyhQUI7cRw+yMeQ8g4mE4hkg9l63c5eg zM4mJXZuUjIPrQIvlaPa7pXxZwhrhiph5EYr2j6uNwQ5Fh5aIMcLm1H+sO60mO8Ejb VS8E+WdMkbgkiM6yGhIT6DLA1m5GKNgBKNJThn4U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 1FD053858426 for ; Fri, 3 Feb 2023 17:12:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FD053858426 Received: by mail-ot1-x335.google.com with SMTP id g21-20020a9d6495000000b0068bb336141dso1537616otl.11 for ; Fri, 03 Feb 2023 09:12:50 -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=mv2z6fIWOVfa+yhLLzdaqnii16YNEJSofdmi2xHXMIs=; b=TtbhjNqh18NKYyE1d17uqdThgc1wrYysqPKeRoUjcTlq1LOpWFKMbGqTS+QnChrHQw inSTGWHdXCVEeYzwGpZDCbJ4lWLluSsE98hH9Mr165anFyWdmfiBXBZvLDQSifAL67Vd VIX2sakHccQHwRwSuKk+ut/ssquoYqWxUFWdgCRnA/8HrTD0C54L6I8q2DtVN9NxwpzC OrBhAwYdU4lCiKWmEEqH0qs4s9kOD/EwJLbUuoBjV6eD3HWf9HPrLOnrBRcCu72F5Dyv TqaDt4VgLpY83ip5igGzDUQlP1txstvF2+lPj/IQZnGh9502RuH47+2dHKIjud7QwRIM UQfw== X-Gm-Message-State: AO0yUKX8zP9aZulhay9FG04Gm38pzYNI4I5IEoPz/haZD3ynNzZsE+7k rJxitQPQlm3u/w3I0tW+FYRFTLIKyJF08PWgaqU= X-Google-Smtp-Source: AK7set8uwDpCgcfMacYX/3EbRw/7PTjS5SWS6oLDW26ds3UZ2kbtQ/w67arrtNWVoF8TMfc5HOB4LQ== X-Received: by 2002:a05:6830:309b:b0:68b:bf5e:492c with SMTP id g27-20020a056830309b00b0068bbf5e492cmr5426892ots.28.1675444368852; Fri, 03 Feb 2023 09:12:48 -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.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:12:48 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 4/5] arm: Add the clone3 wrapper Date: Fri, 3 Feb 2023 14:12:36 -0300 Message-Id: <20230203171237.1220878-5-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=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, 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 Netto 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 arm-linux-gnueabihf. --- sysdeps/unix/sysv/linux/arm/clone3.S | 80 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/arm/sysdep.h | 1 + 2 files changed, 81 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S diff --git a/sysdeps/unix/sysv/linux/arm/clone3.S b/sysdeps/unix/sysv/linux/arm/clone3.S new file mode 100644 index 0000000000..f236d18390 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arm/clone3.S @@ -0,0 +1,80 @@ +/* The clone3 syscall wrapper. Linux/arm 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 +#define _ERRNO_H 1 +#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: + r0: cl_args + r1: size + r2: func + r3: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + cmp r0, #0 + ite ne + cmpne r1, #0 + moveq r0, #-EINVAL + beq PLTJMP(syscall_error) + + /* Do the syscall, the kernel expects: + r7: system call number: + r0: cl_args + r1: size */ + push { r7 } + cfi_adjust_cfa_offset (4) + cfi_rel_offset (r7, 0) + ldr r7, =SYS_ify(clone3) + swi 0x0 + cfi_endproc + + cmp r0, #0 + beq 1f + pop {r7} + blt PLTJMP(C_SYMBOL_NAME(__syscall_error)) + RETINSTR(, lr) + + cfi_startproc +PSEUDO_END (__clone3) + +1: + .fnstart + .cantunwind + mov r0, r3 + mov ip, r2 + BLX (ip) + + /* And we are done, passing the return value through r0. */ + ldr r7, =SYS_ify(exit) + swi 0x0 + + .fnend + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 2f321881c8..57fc5f16bd 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -362,6 +362,7 @@ __local_syscall_error: \ #define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime64" #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +#define HAVE_CLONE3_WRAPPER 1 #define LOAD_ARGS_0() #define ASM_ARGS_0 From patchwork Fri Feb 3 17:12:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 64266 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 6DD10384F00E for ; Fri, 3 Feb 2023 17:13:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DD10384F00E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675444435; bh=ft3dP+E7AeZFHjqEN0x7NHRiQBFFsU+6Dda3hOgFDo0=; 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=Z/QpNNXIUP52yWE8a6NobmIDJ4DHUHoMpooSr/LaHVHum44jVWSpRv+pI8bHW80zj lb7N5XD1T+9UaNTWSekcr8umoLdyoLsu87RhDe9RIwiP7N0/SDo/++dbRjnn0Asv82 LB2L4TmMP1KakRlGM7qOw8h8wIT9jyjUHEYnTuvU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 2108D3858408 for ; Fri, 3 Feb 2023 17:12:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2108D3858408 Received: by mail-ot1-x32a.google.com with SMTP id 14-20020a9d010e000000b0068bdddfa263so1546313otu.2 for ; Fri, 03 Feb 2023 09:12:52 -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=ft3dP+E7AeZFHjqEN0x7NHRiQBFFsU+6Dda3hOgFDo0=; b=2ZrricEVDlYjgfkGzkX+sOaRTagu5joa9IZ8JAzpr8Y1VTD16Hcvg71gVpxyLUNQ2q vstglzUI/kYmqcUw8rWEk61RcJZ7YJ90kb2f3p5i3WnBFi2rY46lB7lsordwaTSngY5M lHqvT0//+LFKNL0G//rNiXfeK4UbPWxavDYWJ50Ic2Uuq3JQTtoak2XwozxvFEronK/h V/9tpDFuHIPuSLxA7ojnqee5bYpjb+psfe6rWElEUq64SVU2kKQy86z/dcXp0DpZ4nlB flwAapnGe4r1e8VpLzSvnQuJbt0Nzclndymz2trOPQcZrNW3mhJBF1kdF35VxOd6pLHM AVEg== X-Gm-Message-State: AO0yUKUatmuCnlh/85tpo7Zhcfj2Pri08E72h4JxnOM4J8Df7RCy+c5R OLoFdmFG50iKCpyzJQQm72MK+iU8NtxxuIKrxk4= X-Google-Smtp-Source: AK7set8Wu95HKuk4+y80MWV6lXhzrplvfgm/4Qg3WV8L6ZkMcQILe1l2AjSvhCAe2KXccJY3gBkfMQ== X-Received: by 2002:a9d:6749:0:b0:684:c723:539c with SMTP id w9-20020a9d6749000000b00684c723539cmr5257323otm.35.1675444370752; Fri, 03 Feb 2023 09:12:50 -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.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:12:49 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 5/5] mips: Add the clone3 wrapper Date: Fri, 3 Feb 2023 14:12:37 -0300 Message-Id: <20230203171237.1220878-6-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.6 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 Netto 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 mips64el-linux-gnueabihf and mipsel-linux-gnu. --- sysdeps/unix/sysv/linux/mips/clone3.S | 139 ++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/mips/sysdep.h | 2 + 2 files changed, 141 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S diff --git a/sysdeps/unix/sysv/linux/mips/clone3.S b/sysdeps/unix/sysv/linux/mips/clone3.S new file mode 100644 index 0000000000..492d6d8b77 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/clone3.S @@ -0,0 +1,139 @@ +/* The clone3 syscall wrapper. Linux/mips 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 +#define _ERRNO_H 1 +#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/$4: cl_args + a1/$5: size + a2/$6: func + a3/$7: arg */ + + .text + .set nomips16 +#if _MIPS_SIM == _ABIO32 +# define EXTRA_LOCALS 1 +#else +# define EXTRA_LOCALS 0 +#endif +#define FRAMESZ ((NARGSAVE*SZREG)+ALSZ)&ALMASK +GPOFF= FRAMESZ-(1*SZREG) +NESTED(__clone3, SZREG, sp) +#ifdef __PIC__ + SETUP_GP +#endif +#if FRAMESZ + PTR_SUBU sp, FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK (GPOFF, __clone) +#ifdef __PIC__ + SAVE_GP (GPOFF) +#endif +#ifdef PROF + .set noat + move $1,ra + jal _mcount + .set at +#endif + + /* Sanity check args. */ + li v0, EINVAL + beqz a0, L(error) /* No NULL cl_args pointer. */ + beqz a2, L(error) /* No NULL function pointer. */ + + move $8, a3 /* a3 is set to 0/1 for syscall success/error + while a4/$8 is returned unmodified. */ + + /* Do the system call, the kernel expects: + v0: system call number + a0: cl_args + a1: size */ + li v0, __NR_clone3 + cfi_endproc + syscall + + bnez a3, L(error) + beqz v0, L(thread_start_clone3) + + /* Successful return from the parent */ + cfi_startproc +#if FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK_CFI (GPOFF) + cfi_remember_state + RESTORE_GP64_STACK +#if FRAMESZ + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) +#endif + ret + +L(error): + cfi_restore_state +#ifdef __PIC__ + PTR_LA t9,__syscall_error + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + jr t9 +#else + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + j __syscall_error +#endif +END (__clone3) + +/* Load up the arguments to the function. Put this block of code in + its own function so that we can terminate the stack trace with our + debug info. */ + +ENTRY(__thread_start_clone3) +L(thread_start_clone3): + cfi_undefined ($31) + /* cp is already loaded. */ + SAVE_GP (GPOFF) + /* The stackframe has been created on entry of clone3. */ + + /* Restore the arg for user's function. */ + move t9, a2 /* Function pointer. */ + move a0, $8 /* Argument pointer. */ + + /* Call the user's function. */ + jal t9 + + move a0, v0 + li v0, __NR_exit + syscall +END(__thread_start_clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h index ff84a91b31..673aa08b57 100644 --- a/sysdeps/unix/sysv/linux/mips/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -28,3 +28,5 @@ #endif #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" #define HAVE_CLOCK_GETRES_VSYSCALL "__vdso_clock_getres" + +#define HAVE_CLONE3_WRAPPER 1