[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9edb16b4-0d3f-4355-a7b1-684a28f9b4cb@t-8ch.de>
Date: Thu, 8 Jun 2023 18:06:16 +0200
From: Thomas Weißschuh <thomas@...ch.de>
To: David Laight <David.Laight@...lab.com>
Cc: 'Zhangjin Wu' <falcon@...ylab.org>, "w@....eu" <w@....eu>,
"arnd@...db.de" <arnd@...db.de>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
"linux-riscv@...ts.infradead.org" <linux-riscv@...ts.infradead.org>
Subject: Re: [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and
__sysret() helpers
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
Powered by blists - more mailing lists