From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id A502E3857C7A for ; Sat, 22 May 2021 01:39:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A502E3857C7A Received: by mail-ot1-x333.google.com with SMTP id 69-20020a9d0a4b0000b02902ed42f141e1so19716211otg.2 for ; Fri, 21 May 2021 18:39:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/tFiiBZ6dGicKtjhL+oOFYTSwMiJw93gM45vE492jdE=; b=Vt9WDwQ5TaXEq2tFnEz779mmxY+PVnewX5h5DP/OChwiqAG8UPiy+pmYk8NVoiMPQN uPKC52DPZ+hzzcHjoaWuvNXGrZN+0BvbtgGwdKSz7luqntYSVrlCp+wE62ABHch45upM KUdDDdHCxTKqjvu9OxRVaZTfnLVVQfOLVrJpMlUC/ayhnuezBBFo3GSt7gBoBHVkRGqj T0uvzf1S9jO/YGkXp7MsJRIhRLUJl37qX0Xlw/78z6t0H3cPG4tldLrUUAbwqwPhpx79 UT7Edc0UlQKYJOFDjkYj+WKDhzLE50oEiUCLxDVML0N95NWvexMe/DChxOuytwIEAesX Xxtw== X-Gm-Message-State: AOAM532o0v0r1LYAgH5vg0xqreLew/lAkoUDppgkurhi2XqGVr6YBRLm or27lH0VuJs1rRHEwiyWa7sOgegl3P1zeZ1MTyc= X-Google-Smtp-Source: ABdhPJw8EqoEQsnA7LBM7ZRNduRfWFIJKv4E79E2yGOgDbvJTHkL216ecshLguxRTqdHRx39qo+q6S/UtsR7Jl60yFY= X-Received: by 2002:a9d:66d4:: with SMTP id t20mr10944632otm.125.1621647562061; Fri, 21 May 2021 18:39:22 -0700 (PDT) MIME-Version: 1.0 References: <20210515123442.1432385-1-hjl.tools@gmail.com> <20210515123442.1432385-5-hjl.tools@gmail.com> <87y2c9mp83.fsf@oldenburg.str.redhat.com> In-Reply-To: <87y2c9mp83.fsf@oldenburg.str.redhat.com> From: "H.J. Lu" Date: Fri, 21 May 2021 18:38:45 -0700 Message-ID: Subject: Re: [PATCH v5 4/5] x86-64: Add the clone3 wrapper To: Florian Weimer Cc: GNU C Library , Adhemerval Zanella Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3033.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Sat, 22 May 2021 01:39:24 -0000 On Thu, May 20, 2021 at 7:53 AM Florian Weimer wrote: > > * H. J. Lu: > > > extern int clone3 (struct clone_args *__cl_args, > > int (*__func) (void *__arg), void *__arg); > > --- > > sysdeps/unix/sysv/linux/x86_64/clone3.S | 92 +++++++++++++++++++++++++ > > sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 + > > 2 files changed, 94 insertions(+) > > create mode 100644 sysdeps/unix/sysv/linux/x86_64/clone3.S > > > > diff --git a/sysdeps/unix/sysv/linux/x86_64/clone3.S b/sysdeps/unix/sysv/linux/x86_64/clone3.S > > new file mode 100644 > > index 0000000000..f7d4036a6a > > > + .text > > +ENTRY (__clone3) > > + /* Sanity check arguments. */ > > + movq $-EINVAL, %rax > > + testq %rdi, %rdi /* No NULL cl_args pointer. */ > > + jz SYSCALL_ERROR_LABEL > > + testq %rsi, %rsi /* No NULL function pointer. */ > > + jz SYSCALL_ERROR_LABEL > > I think some of these register aren't x32-compatible. Isn't the upper > half undefined? All pointers passed in registers are zero-extended to 64 bits. I changed it to use REG_LP macros to avoid the REX prefix. > > + /* Save the function pointer in R8 which is preserved by the > > + syscall. */ > > + movq %rsi, %r8 > > + > > + /* Put sizeof (struct clone_args) in ESI. */ > > + movl $CLONE_ARGS_SIZE , %esi > > If this is in preparation of the public wrapper, this should actually be > an argument. Sorry didn't realize this was the direction. Fixed. > > +L(thread_start): > > + cfi_startproc > > + /* Clearing frame pointer is insufficient, use CFI. */ > > + cfi_undefined (rip) > > + /* Clear the frame pointer. The ABI suggests this be done, to mark > > + the outermost frame obviously. */ > > + xorl %ebp, %ebp > > + > > + /* Set up arguments for the function call. */ > > + movq %rdx, %rdi /* Argument. */ > > + call *%r8 /* Call function. */ > > + /* Call exit with return value from function call. */ > > + movq %rax, %rdi > > + movl $SYS_ify(exit), %eax > > + syscall > > + cfi_endproc > > + > > + cfi_startproc > > +PSEUDO_END (__clone3) > > If this is a public wrapper, should it round up %rsp to 16 bytes Fixed. > at the point of the caller, to follow the x86-64 calling convention? > > Thanks, > Florian > Thanks. -- H.J.