From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by sourceware.org (Postfix) with ESMTPS id ED07A3858C2D for ; Wed, 28 Sep 2022 20:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED07A3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-131b7bb5077so2174309fac.2 for ; Wed, 28 Sep 2022 13:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=SXvfJ94gN0ZLg0RX29DGDVMF5SKDborn2olvvCKpTnc=; b=zezniznSRKWzlDwDMjpcbmBhNzFPK9d29/Yc1WzYOqgVo/2KPqkwVd4hjAjXj09HUm CodwtClmkU4NBai3gGWZ7ZmTYaBi6bO99WqtfAhj9Kn2S7dtC1fTDRspZT6B2EIxkKtr AXYkvEtYpNAyCHb2hs6SL+MAZ6dmygM+QkEVBVmsWi2J1xXkDfY453aV/it9SP9Vs3mJ 8htbKb1wru1R0z4BehKm6COWua3OHzq2r5NJ2xyUzCvtQVKykyde8jd4KPB2D6567qiw 1TitAtLkUB7ofjvPckRT3M1+ddm4PmUqsEzXQD0tRvlfjhmKlc6zPLJlicWgwTZBazfF Vs5A== 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; bh=SXvfJ94gN0ZLg0RX29DGDVMF5SKDborn2olvvCKpTnc=; b=e6EnDxucOqozuOR1FRhHUcZ8tApSlspBSnS6a7TvTtsDnFBV5MWhxP8zGaNbIp3O4m Wgat253HEU0Ta2Srd9oE73+d2YmamiONx5uE1yidzOZNEM5jtv4O/toN063tnmYPm3d4 k3vwQjNlem1Mrtu3Cc7hCDW/1i0LHt286NFh5ftzavhpMZusrrCqvB5amzPxi+KlPjBS 32GrWVZ7euOdkDlos8V4OSXRyRJdkkQjNTb91hvVFe/j5IKF+F88Tn3AeXKRtuf+6Azx lIRbMOshqiPk03Ey8idCfLRBTkDUfX0iPyvmDdvVBRJK4N07a+JHfF+RGDEKRSqOMdqw gYFw== X-Gm-Message-State: ACrzQf2b1mbcUFoyYUkIX5VPc0OBuPZSHmtYSWLaWpeAu7cooTt6bLQv V/yQ4WMFzx1HD7EhAcJaHOL8458aSozmQnye X-Google-Smtp-Source: AMsMyM5YitNSJmxA3+ACzwKz77NozWti+3QdKDrm3aJbY9FyL8kNRmz589fT6AXIIqMy5NPkhXyICg== X-Received: by 2002:a05:6870:f60e:b0:131:b7cc:f994 with SMTP id ek14-20020a056870f60e00b00131b7ccf994mr1693854oab.113.1664398002079; Wed, 28 Sep 2022 13:46:42 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:3736:3f57:3c77:8813:789c]) by smtp.gmail.com with ESMTPSA id x4-20020a056870434400b0011bde9f5745sm3219345oah.23.2022.09.28.13.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 13:46:41 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Christian Brauner Subject: [PATCH 3/7] powerpc64le: Add the clone3 wrapper Date: Wed, 28 Sep 2022 17:46:30 -0300 Message-Id: <20220928204634.3036650-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928204634.3036650-1-adhemerval.zanella@linaro.org> References: <20220928204634.3036650-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); And x86_64 semantics to return EINVAL if either cl_args or func is NULL. The stack is 16-byte aligned prior executing func. Checked on powerpc64le-linux-gnu. --- .../sysv/linux/powerpc/powerpc64/clone3.S | 145 ++++++++++++++++++ sysdeps/unix/sysv/linux/powerpc/sysdep.h | 1 + 2 files changed, 146 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..a7461a3a42 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone3.S @@ -0,0 +1,145 @@ +/* The clone3 syscall wrapper. Linux/powerpc64 version. + Copyright (C) 2022 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 */ + + .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 fn and args across syscall. */ + mr r30, r5 /* Function. */ + mr r29, r6 /* Arguments. */ + + /* End FDE now, because in the child the unwind info will be + wrong. */ + cfi_endproc + + /* Do the system call, the kernel expects: + r0: system call numer + r3: cl_args + r4: size */ + li r0, SYS_ify(clone3) +#ifdef USE_PPC_SCV + CHECK_SCV_SUPPORT r28 0f + /* 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. */ + mflr r9 + std r9, FRAME_LR_SAVE(r1) + .machine "push" + .machine "power9" + scv 0 + .machine "pop" + ld r9, FRAME_LR_SAVE(r1) + mtlr r9 + + /* When using scv, error is indicated by negative r3. */ + cmpdi cr1, r3, 0 + b 1f +#endif +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. */ + + /* Align stack. */ + rldicr r1, r1, 0, 59 + + 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_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 svc 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 4fb135aa8d..b86951207d 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -246,6 +246,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" -- 2.34.1