From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0866C385842C for ; Thu, 25 May 2023 17:36:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0866C385842C 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-ot1-x332.google.com with SMTP id 46e09a7af769-6af6f309613so860512a34.0 for ; Thu, 25 May 2023 10:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685036207; x=1687628207; h=content-transfer-encoding:in-reply-to:organization:references:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=p4IufDo6+JSvWZz/0xX2AEpcRBpSMEHcEMXllTIrLtg=; b=phhPjS2F48zK2trlGiekMxCIC3xRLPmeSlJlP4+VUE5RBcdorsvYQEjKCWQHW/BEFt qsDVAnGgclpob5A5ZUIJ1VjTnOnlGZe7Y7qUdc81V+QQm+u2kw4LpMWBOvqS823jHqhA rB2fx6/28QWFWYpeTOyVXMfz7koYZ2xXXXVs4+NoY0pipy3UKy01gVbYU6jgoZaeT3nY A19iZ6wQk81pNKH+BGGVzLO7904xFsnSDh+w+7/sWfp4XTn2w+6VIqK0l/E9kddTJYVT gnvn/zQgjl6jwRs/usPu6uNRfKn0qhvd6nWmbTnqmlXSNv5vwtbGqMWGVq5pq1DOxQ0F YR8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685036207; x=1687628207; h=content-transfer-encoding:in-reply-to:organization:references:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p4IufDo6+JSvWZz/0xX2AEpcRBpSMEHcEMXllTIrLtg=; b=P0mu7+mLvXE9X/KMCnauBDRajut2IFYOsGI5e0qLdT7wFZoPjPtv0kipZNBtReEQrg wj1FxjBIz3KIxcY5eleFO7iswW1LrrhAe361O3SMVjb0Q2IeyIpTlSLSOwNEuryaRRgL +WaWpaZTFOjYr9HuIA6GCdUQWny8YIt8qqQQZADQe38LZD+mPpUzWCmoUgBMpmDa9WPF VZDWrD9LHPHjXeblxhjk+4ho65SOy72vL6V6I7ipCS9zltP3p4RQshXO1Wj/dd5W+94z Vb9KE59O6domlIBxcfEcLp6AKR31z3bYws+gyTkV3B8So/BpNswAY1J06qQY1kYvUb27 Kn0Q== X-Gm-Message-State: AC+VfDwLgBYG7lTlsMb+D9cT7E/FuW9L5HiAuFmqXuxu5mA/0DvS2nps Hk6InKgJjmUdFhNVceqp1A7xE8EbPYQdwBIM+MiF4w== X-Google-Smtp-Source: ACHHUZ4SXquiU/detzKOi/UTfsaP1EO9t6MWn9sycRvnlp75V+vnIrRkXBVSuYlM2r25gh3pbeH7IA== X-Received: by 2002:a05:6830:1349:b0:6af:b051:a807 with SMTP id r9-20020a056830134900b006afb051a807mr59951otq.15.1685036207172; Thu, 25 May 2023 10:36:47 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:80c6:51f7:4cf7:20d3? ([2804:1b3:a7c1:4dd5:80c6:51f7:4cf7:20d3]) by smtp.gmail.com with ESMTPSA id g12-20020a056830160c00b006a43519523fsm863936otr.1.2023.05.25.10.36.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 May 2023 10:36:46 -0700 (PDT) Message-ID: Date: Thu, 25 May 2023 14:36:43 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH 5/5] mips: Add the clone3 wrapper Content-Language: en-US From: Adhemerval Zanella Netto To: libc-alpha@sourceware.org References: <20230203171237.1220878-1-adhemerval.zanella@linaro.org> <20230203171237.1220878-6-adhemerval.zanella@linaro.org> Organization: Linaro In-Reply-To: <20230203171237.1220878-6-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: Ping. On 03/02/23 14:12, Adhemerval Zanella wrote: > 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