Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2284183pxp; Mon, 21 Mar 2022 15:52:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLePrHB6eNF6FkTj8CCquwR84f1CDKFU2jlTl4TivEEEonwGuvvQfQArmx3Lv5mCLxoJfA X-Received: by 2002:a17:903:22c6:b0:154:4156:f397 with SMTP id y6-20020a17090322c600b001544156f397mr11107416plg.29.1647903129572; Mon, 21 Mar 2022 15:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647903129; cv=none; d=google.com; s=arc-20160816; b=X2FXAvxmFOVwGLI/ISUw1ep0THWAz75h0McJDt70VqFrZbCFERuZ1+0aZ3JLmss++i /VsgVwOVtoMM7VgWrHlQ/BKriASgJe2zWy5PUZNTSBJHi62pcuweOYNAuEIWiLtRdJEn GyE64t0e5EJJT/a2jIloJcHlrCwdicZsorltOgTtggMppujoXqFqtNFhT/YvXGEqUCgi q2NY7UG6dFZwnxW69P7WvOigBXiblAQN63lr4736igX9lUyIFvpOB/AVucoxbVuIJvZp OAYCnzjS79VbDN4wIvb8TtiNAqbyLByecfADEYg4le70sQFPU4O4zxTJaKInZpvpuQ78 VxYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BEqin7BgqbZKYzKSm5rSrMyzFoYf3cfmYy66h4c8k+8=; b=u+e0GbmBnoJMHn1jKmHEjUPAf2jIBU/FJqmylk6jbr/gfA4+pM8/NYRIZWGPa+h4Rn 9/7iy8h7Wq5k9NAl307713QPCHXJTUjM8GCByG1CMwLdVweyB2fCLfuUvsODCAFULIet uXYWIzIJVCJoq4cD62698VhgsaxTxcIwd6f3dyDSkYsB92GaWxD2vkiiouAtB4IFCjgO ietIo2FuHE0rORGTN5H284qFg0u+ZMJ+WRl4SxUqRSnBdklVBzKCLBFZaleY2SL4J4rv ILYeTukxaG4/a6vdZSxPNPa/UIliIsk6iE81X/QA8Nlav8YwX0Cg00hD+F1SD37XXDzR HZDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=bFDGdfBQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b18-20020a170902ed1200b00153b2d165f0si9461841pld.504.2022.03.21.15.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=bFDGdfBQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E99633E2698; Mon, 21 Mar 2022 14:59:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244067AbiCTKoJ (ORCPT + 99 others); Sun, 20 Mar 2022 06:44:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235555AbiCTKoH (ORCPT ); Sun, 20 Mar 2022 06:44:07 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 220144B85A for ; Sun, 20 Mar 2022 03:42:45 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by gnuweeb.org (Postfix) with ESMTPSA id 482587E331 for ; Sun, 20 Mar 2022 10:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1647772964; bh=cslQqgZ7BRLt7KwLkN6alHsy0RvZ6fR/hvzrpU/IQcw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bFDGdfBQ3owjAm/4oBfunZS+DrEyK0awO7Qz5oGktEcPCnImR0wZgBv+LNd7aIC1i fGyvC6p4/FN/DDQPq228Zj2yJixTbwoCcoKkpJ0/AzFbX0uMA43D+mh2L252TLLN5B /ncMD+AGOhrx61gIsxzAKanZnCRzwtqnmuL1M091E9UV2Aeznl/4I3VTVCcEfGwE/I C1+DL4Si5HQ6+QxLauMO6t+W60QB8B0vo+6an6k8Y4FJUMgbHM+dG2rH91/RIHUJxJ 9Bch068lVennn7YcAryshledQyBPUmKNHe1fzSmjiEwXmFaZsJpbiDozN9PbcIA1fW fKf+RyhIyrJhA== Received: by mail-lj1-f169.google.com with SMTP id 17so16566831lji.1 for ; Sun, 20 Mar 2022 03:42:44 -0700 (PDT) X-Gm-Message-State: AOAM531ErKTrPcPJFFILQU7YYrjOvs6pCzF61wlPDqp7nlHCX+oQ4GqE 0BEZ1fsnm/8F29FccehLrBypY7ynozxSBjJiZEY= X-Received: by 2002:a2e:7d05:0:b0:247:ed41:690d with SMTP id y5-20020a2e7d05000000b00247ed41690dmr12102096ljc.92.1647772962093; Sun, 20 Mar 2022 03:42:42 -0700 (PDT) MIME-Version: 1.0 References: <20220320093750.159991-1-ammarfaizi2@gnuweeb.org> <20220320093750.159991-4-ammarfaizi2@gnuweeb.org> In-Reply-To: From: Alviro Iskandar Setiawan Date: Sun, 20 Mar 2022 17:42:30 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v1 3/6] tools/nolibc: i386: Implement syscall with 6 arguments To: Ammar Faizi Cc: Willy Tarreau , "Paul E. McKenney" , Nugraha , Linux Kernel Mailing List , "GNU/Weeb Mailing List" , x86@kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 20, 2022 at 5:33 PM Alviro Iskandar Setiawan wrote: > On Sun, Mar 20, 2022 at 4:37 PM Ammar Faizi wrote: > > In i386, the 6th argument of syscall goes in %ebp. However, both Clang > > and GCC cannot use %ebp in the clobber list and in the "r" constraint > > without using -fomit-frame-pointer. To make it always available for any > > kind of compilation, the below workaround is implemented. > > > > For clang (the Assembly statement can't clobber %ebp): > > 1) Save the %ebp value to the redzone area -4(%esp). > > 2) Load the 6-th argument from memory to %ebp. > > 3) Subtract the %esp by 4. > > 4) Do the syscall (int $0x80). > > 5) Pop %ebp. > > I don't think you can safely use redzone from inline Assembly. The > compiler may also use redzone for a leaf function. In case the syscall > is done at the same time, your %ebp saving will clobber the redzone > that the compiler uses. > > > For GCC, fortunately it has a #pragma that can force a specific function > > to be compiled with -fomit-frame-pointer, so it can always use "r"(var) > > where `var` is a variable bound to %ebp. > > > > Cc: x86@kernel.org > > Cc: llvm@lists.linux.dev > > Signed-off-by: Ammar Faizi > [...] > > +#if defined(__clang__) > > +static inline long ____do_syscall6(long eax, long ebx, long ecx, long edx, > > + long esi, long edi, long ebp) > > +{ > > + __asm__ volatile ( > > + "movl %%ebp, -4(%%esp)\n\t" > > + "movl %[arg6], %%ebp\n\t" > > + "subl $4, %%esp\n\t" > > + "int $0x80\n\t" > > + "popl %%ebp\n\t" > > + : "=a"(eax) > > + : "a"(eax), "b"(ebx), "c"(ecx), "d"(edx), "S"(esi), "D"(edi), > > + [arg6]"m"(ebp) > > + : "memory", "cc" > > + ); > > + return eax; > > +} > > + > > -4(%esp) may be used by the compiler on a leaf call, you can't clobber that. Using xchgl to preserve %ebp in the same place where the arg6 is stored in memory is a better solution and doesn't clobber anything. xchgl %ebp, %[arg6] int $0x80 xchgl %ebp, %[arg6] -- Viro