Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2526195rdg; Mon, 14 Aug 2023 05:35:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFrvOcQXLulsH6lQSufCCMB8sICL6dSJM5kCkKI7Cn1VMoDwlJgYiNV5Ne4VxiN5DT4jcGx X-Received: by 2002:a05:651c:217:b0:2b6:e78e:1e58 with SMTP id y23-20020a05651c021700b002b6e78e1e58mr6565684ljn.5.1692016519707; Mon, 14 Aug 2023 05:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692016519; cv=none; d=google.com; s=arc-20160816; b=CTMaoefA5yTtCC4Y6I6/etJoiKrE865Tu/ggvexUPvVX6ub/RSjb4Aiwt3UUVk9t2u CMFo9x3Ru2YAHjQLYGJO6E649lO2/yLNCwvmUeGJxMaVRN+uARxx53OF5MdJ8u5t2Ccd o9dE/hDA4GP5A9D2Xp8yJ2XoJFXmo4Sd0YsZyxzvKKUlU3SGILNg1V9eSTYIF7HL2X8p ksYfEqSS4jAcoxM388TbWt89a5g4P6bKQBnfrXfd9Gqqdqd36dBCmZmo3iZd0xhVoY0+ ZMAsOqAVFblcF1JCoZlR/tBj6kQflYdX8e6kY1aVZfN/f2XSxOm/yLegWaUrBBK1US3V D0Nw== 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=rjERJfxhVyvpIinYWjsz/B8kxtL8M/Iz2qsrYK1nX90=; fh=lmlr0Gbzm2gQ2YJMNaZBB6x9h83u4wS0T623cr3uDXk=; b=a3yBYaFS/9LzgTstYr+5RzRAMaVUlJ4WhyTGFDqSfLP8TpsMcZfcX1J9UD3VMlqnuK sVYTuwf+1RgaRQ8UnrDfg5i4r3maW7SMnKKCpF3TY0XjllCM1zb8P00ZKl0fNx7a9Fwk LPHeHcCDefUiE8LfqehtP3pv0Ru3oRwwes8gr03P3GLEvP/1QOpFcZighWHJt4+aCvU2 dj+/33e8p6E8NsAAXpZuEtjAEjCPBwmuAinjnaaIvVDF1WkhKKqsPw2fhWk0D8sy6zFm ywJLtaKBtuGgLpVxiNydk4esvUEr1iAW4w3CbxoNU/trL2h+dPoHIC+evnTkdmjaZwUC sNXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kq15-20020a170906abcf00b0098291c57810si7758920ejb.704.2023.08.14.05.34.54; Mon, 14 Aug 2023 05:35:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233310AbjHNLQ0 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Aug 2023 07:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbjHNLQI (ORCPT ); Mon, 14 Aug 2023 07:16:08 -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 ESMTPS id 35552FA for ; Mon, 14 Aug 2023 04:16:05 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-129-2x1Vd_nCORSXjSBBMiHBAA-1; Mon, 14 Aug 2023 12:16:03 +0100 X-MC-Unique: 2x1Vd_nCORSXjSBBMiHBAA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 14 Aug 2023 12:15:51 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 14 Aug 2023 12:15:51 +0100 From: David Laight To: 'Zhangjin Wu' , "w@1wt.eu" CC: "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "thomas@t-8ch.de" Subject: RE: [PATCH v5] tools/nolibc: fix up size inflate regression Thread-Topic: [PATCH v5] tools/nolibc: fix up size inflate regression Thread-Index: AQHZzpwIMKbqPe7hTkqs7/1zyBEHW6/pnUhg Date: Mon, 14 Aug 2023 11:15:51 +0000 Message-ID: <6fef903020954515abdcee7261918903@AcuMS.aculab.com> References: <20230814082224.GA16761@1wt.eu> <20230814104226.7094-1-falcon@tinylab.org> In-Reply-To: <20230814104226.7094-1-falcon@tinylab.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 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,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham 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: Zhangjin Wu > Sent: 14 August 2023 11:42 ... > [...] > > > > Sure it's not pretty, and I'd rather just go back to SET_ERRNO() to be > > > > honest, because we're there just because of the temptation to remove > > > > lines that were not causing any difficulties :-/ > > > > > > > > I think we can do something in-between and deal only with signed returns, > > > > and explicitly place the test for MAX_ERRNO on the two unsigned ones > > > > (brk and mmap). It should look approximately like this: > > > > > > > > #define __sysret(arg) \ > > > > ({ \ > > > > __typeof__(arg) __sysret_arg = (arg); \ > > > > (__sysret_arg < 0) ? ({ /* error ? */ \ > > > > SET_ERRNO(-__sysret_arg); /* yes: errno != -ret */ \ > > > > ((__typeof__(arg)) -1); /* return -1 */ \ I'm pretty sure you don't need the explicit cast. (It would be needed for a pointer type.) Can you use __arg < ? SET_ERRNO(-__arg), -1 : __arg Thinking, maybe it should be: #define __sysret(syscall_fn_args) ({ __typeof__(syscall_fn_args) __rval = syscall_fn_args; __rval >= 0 ? __rval : SET_ERRNO(-__rval), -1; }) Since, IIRC, the usage is return __sysret(sycall_fn(args)); I'm not sure how public SET_ERRO() is. But it could include the negate have the value of -1 cast to its argument type? I think: error = -(int)(long)(arg + 0u); will avoid any sign extension - the (int) might not even be needed. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)