Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2278403pxp; Mon, 21 Mar 2022 15:42:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCF4E3BD3TfcZgYb3YYPvh2uZ7FXqsYStpVww79Fk7N4QDprGaY2hBwMSqAeGeRk9aw1LS X-Received: by 2002:a17:902:d504:b0:154:172:3677 with SMTP id b4-20020a170902d50400b0015401723677mr15300400plg.147.1647902539639; Mon, 21 Mar 2022 15:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647902539; cv=none; d=google.com; s=arc-20160816; b=t0jbpFLK9eAOAYL3cCTGE82BZOqzmxaxyJQzJtEyOfHn6nL/qohmPNIntfJi/2DEI1 h32/l3iInIMDOyJ28Kafi1vRYDoNL2zcFtgR5AiDtek81PNRYvojMX6EEzb3UuZ5dWAw aQvYJvsBHWm7ow2qDOA+/n9LbEc/7kyKK+WSGGFdkEaBYEHLClKoDWG3BBHst4c5h1nE TdqDlaK7l8FT3MbJbnKztqrL5zCbEsefvmoEqrigdWT985WzAj7X0AW0YC4P9Nw0k9HE 9tETMy7NHF+9bzgPwkMCOc/0uyvKzYaGeg5OxH4trEXaroIWWpIyRKln/EcyhC5s+tAn G/oA== 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=/kKiAvk6+atYvXT1CjpLpXmRh57upnvdN147c82TIzE=; b=awJGQ0YGnsxUIx1VvCb4iRc1GXIUiL4Y+z3/wEpGBaZUbgfOZgBAKkt0S52m+qsaFX wDol3YrdBoIcvjuX2C+S8i0+1pTmCN5lFTzqG7St7asaVnzOFGuE8Atu3GjcH1rVOium Nzy8j4WZlh6KNUws9C/rqb0l3szqLqlwwjCS61wlFQDCLzc0FnqWZuMMO0sSoIkV3rgS llUEgSOKH1b1pESbkUIOZX+0vwYrfWNyXl7rM9LzPw001t856yMWn6VZH6ZP5Ds7Ujf+ Zkh7xI08DcNegqzyZdwxCCdJqj3GDfci3SeK7Ez2aIwjBiRPTui+MEkPvuaUwuBE5J4K LW2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=BQVnZb1w; 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 u7-20020a170902e80700b00153b2d164fesi13610995plg.262.2022.03.21.15.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:42:19 -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=BQVnZb1w; 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 6A8922D4D67; Mon, 21 Mar 2022 14:55:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239722AbiCTKfB (ORCPT + 99 others); Sun, 20 Mar 2022 06:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235555AbiCTKfA (ORCPT ); Sun, 20 Mar 2022 06:35:00 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5768C2DD4D for ; Sun, 20 Mar 2022 03:33:37 -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 6CDB47E324 for ; Sun, 20 Mar 2022 10:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1647772416; bh=QhuOmEY/VCeKijDg6b0RqGpMGFruSC64r7vq9XAIaXI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BQVnZb1w9D5dwRtB8M9TO2yLt7M523VaFfJlntG020Xalbco6fhUJmzqoGH89yD2D yM/V/Dx6gXZ7CTzQRAu+jrfPWQuY9AUMQy7gbBjkz0K9ShwtkDZ2W4hRJ/yCbuZI0p iVfsTl3dYRyrSffFgX7sgYukQCqaVgPTma/TjcEStRK6JlL6w+qUYVvQadauXrkBkF Fu225SKpr8AJp7aejyf8UsDLEozo/Y2sZeaNAZfO1DTp0WGywMcCkriJ0cIgWCAIqO /lBFws3jnIdz+3/n6iTuWJZnVDhYfRles4YHHy1DS9yR/ChZHMJXNZr+ljuCXY+QVX Ffn6UjRkhnt+w== Received: by mail-lj1-f169.google.com with SMTP id c15so16503559ljr.9 for ; Sun, 20 Mar 2022 03:33:36 -0700 (PDT) X-Gm-Message-State: AOAM532YeIrxiWbnPyrDVDxnvBX2TpX+xQBAsF/EFmrzDc4nUzP3Curk HWjArvG2SMUDRSp5c6+JNzvS16Ek+pVOR99y5l8= X-Received: by 2002:a2e:2d11:0:b0:246:3c3e:d544 with SMTP id t17-20020a2e2d11000000b002463c3ed544mr11789581ljt.518.1647772414468; Sun, 20 Mar 2022 03:33:34 -0700 (PDT) MIME-Version: 1.0 References: <20220320093750.159991-1-ammarfaizi2@gnuweeb.org> <20220320093750.159991-4-ammarfaizi2@gnuweeb.org> In-Reply-To: <20220320093750.159991-4-ammarfaizi2@gnuweeb.org> From: Alviro Iskandar Setiawan Date: Sun, 20 Mar 2022 17:33:23 +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 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. -- Viro