Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2303599pxp; Mon, 21 Mar 2022 16:22:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsramsNH1RvgZawtNKPNG9iUSk6T5sTfKik0s3ggBK+qG9dYHqGwpl22AjYjr/IBMx/Xb7 X-Received: by 2002:a65:6942:0:b0:378:9365:5963 with SMTP id w2-20020a656942000000b0037893655963mr19676576pgq.142.1647904968591; Mon, 21 Mar 2022 16:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647904968; cv=none; d=google.com; s=arc-20160816; b=0g6jJX8S1LkCzgEjntMvhqTbrAP6lET+222TPqPl1TTldOUvHQXtLuFn24yYRr1ISe jaiXqZPiT+5zSzOx7Nj3lVfMD0xW4s0XksyUsm+AZZFVmXMun/g9wZ6scspqWxByPob6 QQBy1pn4mTcWUpm/Gp5QmH4Gu1BHTD6GIO1e0+7fvQMGqjuwOKPG/70CKBr36PVvNcE+ 600O/6/816OE3Kbdcpdq48kdfutZ6zrXZhF7TDsFx2S/aI5uON/dTMwSrn/0n4xx+c/G 0Sr/Fp3QuetPBNfkfdbL/tnJiOJymL7BB2BBKybjDnZyH8NlzJSxr9lgIlnro37jtoBz jl1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=lJK+ClcwaHkW7GFq6nvOv7+7yMPT0lk32e/avGJs9ag=; b=EfvBZeZWYEvCMr1cobhrfFHBOZ8A7ecFJulpumbLrxCaXvs5PJCPKN817O7SVGGyX5 loQKxd9m4MA07j0GPlDlwuFtJla/QEVptXAxV63tPfGBBjc1xjc4zfSmj3GjPYGh2jLL gDZQgRAkiaF8QbNbmmyuIZhb7id55qnxl3pVf3rARV9sVA9oPI+jA4YVjF9X8HFGtweS m64P3MncASvoKEIB3bVOAszOQMR6dLRmzR+x05tkfaPhoRvRkwASApLH/TBtAb45dJ/B F7t3iVMCHHyF0H7HDRCE0jeiz1+zn5w1Hf3zj8SenWVkTQr/fxTumE5F8F9k+68DOSrX f2NQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 17-20020a17090a191100b001bef4ea053esi529784pjg.62.2022.03.21.16.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:22:48 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C6F70393957; Mon, 21 Mar 2022 15:23:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245119AbiCTNMB convert rfc822-to-8bit (ORCPT + 99 others); Sun, 20 Mar 2022 09:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235848AbiCTNL7 (ORCPT ); Sun, 20 Mar 2022 09:11:59 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 756F51F614 for ; Sun, 20 Mar 2022 06:10:36 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-319-oFCxxHf5MgGGf8WvpDCCEg-1; Sun, 20 Mar 2022 13:10:33 +0000 X-MC-Unique: oFCxxHf5MgGGf8WvpDCCEg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sun, 20 Mar 2022 13:10:33 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Sun, 20 Mar 2022 13:10:33 +0000 From: David Laight To: 'Ammar Faizi' , Willy Tarreau CC: "Paul E. McKenney" , Alviro Iskandar Setiawan , Nugraha , "Linux Kernel Mailing List" , GNU/Weeb Mailing List , "x86@kernel.org" , "llvm@lists.linux.dev" Subject: RE: [RFC PATCH v1 3/6] tools/nolibc: i386: Implement syscall with 6 arguments Thread-Topic: [RFC PATCH v1 3/6] tools/nolibc: i386: Implement syscall with 6 arguments Thread-Index: AQHYPD5aHmXDAqFOcUemVcZ8MoFj5azIOuNw Date: Sun, 20 Mar 2022 13:10:33 +0000 Message-ID: <2e335ac54db44f1d8496583d97f9dab0@AcuMS.aculab.com> References: <20220320093750.159991-1-ammarfaizi2@gnuweeb.org> <20220320093750.159991-4-ammarfaizi2@gnuweeb.org> In-Reply-To: <20220320093750.159991-4-ammarfaizi2@gnuweeb.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 From: Ammar Faizi > Sent: 20 March 2022 09:38 > > 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). i386 doesn't have a redzone. If you get a signal it will trash -4(%sp) > 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. > > 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. How is that going to work for an inlined functon? And using xchg is slow - it is always locked. One possibility might be to do: push arg6 push %ebp mov %ebp, 4(%sp) int 0x80 pop %ebp add %esp,4 Although I'm not sure you really want to allocate 4k pages for every malloc() call. Probably better to write a mini 'libc' that uses sbrk() and a best fit scan of a linear free list. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)