mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: David Laight <David.Laight@aculab.com>
Cc: 'Zhangjin Wu' <falcon@tinylab.org>, "w@1wt.eu" <w@1wt.eu>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>
Subject: Re: [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers
Date: Thu, 8 Jun 2023 18:06:16 +0200	[thread overview]
Message-ID: <9edb16b4-0d3f-4355-a7b1-684a28f9b4cb@t-8ch.de> (raw)
In-Reply-To: <94dd5170929f454fbc0a10a2eb3b108d@AcuMS.aculab.com>

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

  reply	other threads:[~2023-06-08 16:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06  8:08 [PATCH v2 0/4] tools/nolibc: add two new syscall helpers Zhangjin Wu
2023-06-06  8:09 ` [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers Zhangjin Wu
2023-06-06 10:33   ` Zhangjin Wu
2023-06-08 14:35   ` David Laight
2023-06-08 16:06     ` Thomas Weißschuh [this message]
2023-06-09  4:42       ` Zhangjin Wu
2023-06-09  9:15         ` David Laight
2023-06-06  8:11 ` [PATCH v2 2/4] tools/nolibc: unistd.h: apply __sysret() helper Zhangjin Wu
2023-06-06  8:16 ` [PATCH v2 3/4] tools/nolibc: sys.h: " Zhangjin Wu
2023-06-06  8:17 ` [PATCH v2 4/4] tools/nolibc: sys.h: apply __syscall() helper Zhangjin Wu
2023-06-06 18:36   ` Thomas Weißschuh
2023-06-07  0:34     ` Zhangjin Wu
2023-06-07  4:05       ` Willy Tarreau
2023-06-07  5:39         ` Zhangjin Wu
2023-06-07  6:05           ` Thomas Weißschuh
2023-06-07  6:38             ` Zhangjin Wu
2023-06-10 16:34           ` David Laight
2023-06-10 16:58             ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9edb16b4-0d3f-4355-a7b1-684a28f9b4cb@t-8ch.de \
    --to=thomas@t-8ch.de \
    --cc=David.Laight@aculab.com \
    --cc=arnd@arndb.de \
    --cc=falcon@tinylab.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®