public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
To: gcc@gcc.gnu.org
Subject: [RFC] Linux system call builtins
Date: Tue, 09 Apr 2024 22:48:37 -0300	[thread overview]
Message-ID: <ad3f3e743fba028670681b4c8883d202@gmail.com> (raw)
In-Reply-To: <CA+=Sn1nZadvbmZEQU0vZHPL=kGT2KSSEN=_TN6SSOxsh4vV6zw@mail.gmail.com>

> Now the question comes is the argument long or some other type?

I believe so. Every library I've seen and the kernel itself uses long.
Other types just get typecasted to long. I think it's just supposed to
mean "register type" since all the arguments must be in registers.

> E.g. for some 32bit ABIs built on top of 64bit ISA might always
> just pass 32bits or they might allow passing the full 64bits.
> (x32 might fall under this and MIPS n32).

The registers used are documented here:

https://www.man7.org/linux/man-pages/man2/syscall.2.html

x32 uses the exact same registers as x86_64, all 64 bit:

> x86-64    rdi rsi rdx r10 r8 r9
> x32       rdi rsi rdx r10 r8 r9

MIPS calling conventions work like this:

> mips/n32,64 a0 a1 a2 a3 a4 a5
> mips/o32    a0 a1 a2 a3 ...
> mips/o32    args5-8 are passed on the stack

> Maybe you should warn/error out
> if not passed the correct sized argument.

Yes. It should be an error if the inputs are not register sized.
As far as I know all system call inputs are either register sized
values or pointers to C strings, buffers or much larger structures.

> Also do you sign or zero extend a 32bit argument for LP64 targets?

I'm not sure. System call stubs just declare these register values as
signed long so whatever happens in that case seems to be appropriate.

  parent reply	other threads:[~2024-04-10  1:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  9:19 Matheus Afonso Martins Moreira
2024-04-08  9:58 ` Jonathan Wakely
2024-04-08 11:59   ` Matheus Afonso Martins Moreira
2024-04-08 14:00     ` Jonathan Wakely
2024-04-08 11:24 ` Florian Weimer
2024-04-08 11:44   ` Alexander Monakov
2024-04-08 11:50     ` Florian Weimer
2024-04-08 13:01       ` Alexander Monakov
2024-04-08 13:37   ` Matheus Afonso Martins Moreira
2024-04-08 18:18 ` Paul Iannetta
2024-04-08 18:26   ` Andrew Pinski
2024-04-08 20:01     ` Paul Iannetta
2024-04-08 20:20       ` Paul Koning
2024-04-10  1:48     ` Matheus Afonso Martins Moreira [this message]
2024-04-10 13:15       ` Paul Koning
2024-04-10 14:10         ` Matheus Afonso Martins Moreira
2024-04-10  1:26   ` Matheus Afonso Martins Moreira
2024-04-08 20:24 ` Paul Floyd
2024-04-10  2:19   ` Matheus Afonso Martins Moreira
2024-04-09 11:45 ` Szabolcs Nagy
2024-04-10  2:59   ` Matheus Afonso Martins Moreira
2024-04-10 11:04     ` Szabolcs Nagy
2024-04-10 14:00       ` Matheus Afonso Martins Moreira

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=ad3f3e743fba028670681b4c8883d202@gmail.com \
    --to=matheus.a.m.moreira@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /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).