Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp932372rwd; Thu, 8 Jun 2023 09:34:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LUSHE2W/krhycoAUJ75Qonj844UMKSHGpwbSkK3YCOY10oEv024VDQ1Y+7G6f+N+OY6Cx X-Received: by 2002:a17:902:c103:b0:1b1:1168:6571 with SMTP id 3-20020a170902c10300b001b111686571mr8093653pli.36.1686242077184; Thu, 08 Jun 2023 09:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686242077; cv=none; d=google.com; s=arc-20160816; b=ZdD8Z3hKLaETkZ9+fmSsfAkhT2XIJOygMgT2Q2Dhsp/ZFdKOnp27xX/KqojIPJpmNS 4QrYVDS2DlwEsX29BMVKuo8rw4FNaRez9VrdSFR3jFHL4boSquxZKgjIfqaSpYLL0IPy Rs1VfKY1SaDzVwfzVe1lt+cmK18ql9QP4FK1tte23+h7JdLcdoVS9PmB9zl4T1LibsJn xyzpoL07zzIVn997SGguBj0dnGfKvXGuXQZjhVcSuz0vYZAgOdeOs09DPAJkFJy9nEdT P8Co3+wRTs63glZvAHQD7dcIrbmNIj21h5VEbuKFglqgKm9jQsuQwcZw6jeEog1r5K3O cZ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=WgdF8ysDUtZL21h8Ku6acqpkKyw3i8LKex11kuDYUZo=; b=HomV2kbZnt+OhHdaai4pTlnZvvV2aEtPDQ9n6ydBmdmYRftmnwPVkws6TeLJ8k5Plh p7gTMMMwfgD5dDWdA7VZQknNlUzEZq4XllIkfia/662W6M1TpSDZGR7+pe17Jkuj7Gv2 xPNnfNb1kjLAt2mYoc5uTiPMha+w4+E7/16R1ifKmifVz+d5E51ZQDH0w581dh68ApSb g0+yFhZ07b08TdmiqKlGl4OmZXmcwdnhwRiklxAyPuf6ELX1WxRF7k+Iy10bNMLn8fPE WIh1qQUUm5sgNIMbrF26rxNdqs3XvoQUu+efQtE8oPS7Nt4qFuEYHRDLBJszS28NM/BW B7Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=LgZCtK5C; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a170902dac500b001afd4fceea5si1269003plx.617.2023.06.08.09.34.25; Thu, 08 Jun 2023 09:34:37 -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; dkim=pass header.i=@t-8ch.de header.s=mail header.b=LgZCtK5C; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231661AbjFHQGX (ORCPT + 99 others); Thu, 8 Jun 2023 12:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbjFHQGW (ORCPT ); Thu, 8 Jun 2023 12:06:22 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A94134; Thu, 8 Jun 2023 09:06:18 -0700 (PDT) Date: Thu, 8 Jun 2023 18:06:16 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1686240377; bh=PLbGY4orS7r/OO9ChDGkyjxNSJlc51OFBzDXVDH4Ii4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LgZCtK5CqJi7+kGUwNDw+NV2XHBX6YW+VlVYYRIh7g472vEfThJkLzBg7zz6OQz9q 1REcTFqGgqztBtkaxjzSA+u+UUQNllwVj0yL2elkwYkZ0Gndk6DuLrBtvjfdIHkOsO FRLX/2O510m2f9t3t7X2D97I+/nQi4JqlRJ0y4SM= From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: David Laight Cc: 'Zhangjin Wu' , "w@1wt.eu" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "linux-riscv@lists.infradead.org" Subject: Re: [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers Message-ID: <9edb16b4-0d3f-4355-a7b1-684a28f9b4cb@t-8ch.de> References: <94dd5170929f454fbc0a10a2eb3b108d@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <94dd5170929f454fbc0a10a2eb3b108d@AcuMS.aculab.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hi David, On 2023-06-08 14:35:49+0000, David Laight wrote: > From: Zhangjin Wu > > Sent: 06 June 2023 09:10 > > > > most of the library routines share the same code model, let's add two > > helpers to simplify the coding and shrink the code lines too. > > > ... > > +/* Syscall return helper, set errno as -ret when ret < 0 */ > > +static inline __attribute__((always_inline)) long __sysret(long ret) > > +{ > > + if (ret < 0) { > > + SET_ERRNO(-ret); > > + ret = -1; > > + } > > + return ret; > > +} > > If that right? > I thought that that only the first few (1024?) negative values > got used as errno values. > > Do all Linux architectures even use negatives for error? > I thought at least some used the carry flag. > (It is the historic method of indicating a system call failure.) I guess you are thinking about the architectures native systemcall ABI. In nolibc these are abstracted away in the architecture-specific assembly wrappers: my_syscall0 to my_syscall6. (A good example would be arch-mips.h) These normalize the architecture systemcall ABI to negative errornumbers which then are returned from the sys_* wrapper functions. The sys_* wrapper functions in turn are used by the libc function which translate the negative error number to the libc-style "return -1 and set errno" mechanism. At this point the new __sysret function is used. Returning negative error numbers in between has the advantage that it can be used without having to set up a global/threadlocal errno variable. In hope this helped, Thomas