From: Rich Felker <dalias@libc.org>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Askar Safin <safinaskar@zohomail.com>,
libc-alpha@sourceware.org, carlos@redhat.com
Subject: Re: [PATCH, RFC] Add public function syscall_no_errno
Date: Thu, 1 Feb 2024 13:18:35 -0500 [thread overview]
Message-ID: <20240201181835.GC22081@brightrain.aerifal.cx> (raw)
In-Reply-To: <380959fd-3414-4fc6-ae3f-85abdee2a9a0@linaro.org>
On Thu, Feb 01, 2024 at 02:53:44PM -0300, Adhemerval Zanella Netto wrote:
>
>
> On 28/01/24 13:39, Askar Safin wrote:
> > Hi! I want glibc to have function "syscall_no_errno" on Linux.
> > It should do the same "syscall" does, but it should not interpret
> > return value and set errno. This is useful for calling syscalls
> > such as getuid. I. e. now the user can call directly all syscalls
> > including getuid and similar.
> >
> > I add example patch. It is quick-and-dirty. I was unable to figure out
> > how to add function to headers. So, please, don't apply it as-is.
> >
> > I just want to know do you agree with my proposal. If yes, I will try
> > to write better patch.
> >
> > I will repeat: currently glibc is simply incomplete, because it
> > does not provide a way to call directly syscalls, such as getuid.
> > So the user have to craft assembly, which is very difficult.
>
> Indeed there some old syscalls where trying to issue them directly with
> syscall is problematic (like 'time' and 'brk' for some ABIs), but getuid
> is not one of them. Also, recent Linux kABI is trying to avoid such
> problematic interfaces to return the value as the return code and make
> the invalid value similar to all cases. So these are not very compeling
> reason to add a non-standard symbol to issue syscalls.
>
> CCing Rich, maybe he has a different view about this.
That would be my view too. In general, it's rarely useful to make a
raw syscall() to begin with. For the majority of syscalls that are
ingredients in implementing standard or almost-standard functions
provided by libc, going around libc to call it directly risks creating
inconsistent state (brk), having inconsistent types (stat, etc.),
missing fallback cases (direct use of time64 syscalls), etc. and
really should not be encouraged by making unneeded new ways to do it.
Indeed the only syscalls I'm aware of for which there's ambiguity
about the result are of this sort.
I don't even think brk is an affected one; values >=4095UL are not
valid brk boundaries. Similarly, I don't think Linux supports setting
system clock to before the epoch (and doing so would not be accurate
anyway), so time is arguably not affected either. Even if it were,
it's superseded by clock_gettime or gettimeofday, which don't have the
problem, and might not even be available on future archs.
There is also fcntl with F_GETOWN, which was not mentioned above, but
it is superseded by F_GETOWN_EX, which the libc fcntl function
automatically uses when available instead of using F_GETOWN directly.
So I don't think it has modern relevance either.
In any case, back to my original point, the use case for syscall()
should be seen as calling newly-added extensions that don't yet have,
or that aren't suitable to have, libc functions for them. Use of it as
a means to "poke behind libc" should not be encouraged, as that tends
to break things. If someone really wants to write code that's
independent of libc -- like to run in a vforked child or CLONE_VM
context or something without a valid thread pointer/TLS state/etc. --
it can't be using libc at all, and that includes the libc syscall()
function (which not only may write errno, but might inspect TLS to
determine how to make the syscall). For this level of "raw" syscall
access, you need to write your own asm.
Rich
next prev parent reply other threads:[~2024-02-01 18:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 16:39 Askar Safin
2024-02-01 17:53 ` Adhemerval Zanella Netto
2024-02-01 18:18 ` Rich Felker [this message]
2024-02-01 19:32 ` Askar Safin
2024-02-01 20:16 ` dalias
2024-02-01 20:57 ` Adhemerval Zanella Netto
2024-02-08 15:02 ` [PATCH v2] " Askar Safin
2024-02-08 17:48 ` Szabolcs Nagy
2024-02-12 14:24 ` Florian Weimer
2024-02-12 14:44 ` Rich Felker
2024-02-12 16:16 ` Askar Safin
2024-02-12 17:25 ` Zack Weinberg
2024-02-12 17:43 ` Andreas Schwab
2024-02-12 18:22 ` Zack Weinberg
2024-02-13 9:10 ` Andreas Schwab
2024-02-13 11:57 ` Adhemerval Zanella Netto
2024-02-12 17:55 ` Adhemerval Zanella Netto
2024-02-12 18:34 ` Askar Safin
2024-02-07 0:59 ` [PATCH, RFC] " Askar Safin
2024-02-07 20:59 ` dalias
2024-02-08 17:08 ` Askar Safin
2024-02-07 1:57 ` Mike Frysinger
2024-02-07 12:55 ` Askar Safin
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=20240201181835.GC22081@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=adhemerval.zanella@linaro.org \
--cc=carlos@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=safinaskar@zohomail.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).