[RFC] Linux system call builtins

2024-04-10 Thread Matheus Afonso Martins Moreira via Gcc
> Yes, for regular function calls, > but at least in the case of NetBSD, > not for syscalls. Those are the registers Linux uses for system calls on MIPS. They are documented as such here: https://www.man7.org/linux/man-pages/man2/syscall.2.html > The second table shows the registers used > to pa

[RFC] Linux system call builtins

2024-04-10 Thread Matheus Afonso Martins Moreira via Gcc
> because the portable c api layer and syscall abi layer > has a large enough gap that applications can break > libc internals by doing raw syscalls. I think that problem cannot really be fixed. System call users just have to be aware of it. It's true that using certain system calls can clobber l

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> note: some syscalls / features don't work without asm > (posix thread cancellation, vfork, signal return,..) That's true. On the other hand, POSIX compliance is not always a goal or a requirement. > and using raw syscalls outside of the single runtime the > application is using is problematic (

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> I see systems making it more difficult for code to make syscalls, > not easier. That's true. I think it's because other systems can afford to keep that ABI unstable. Since Linux is an independently developed kernel, it _must_ be possible to target the kernel directly with no user space compone

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> 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

[RFC] Linux system call builtins

2024-04-09 Thread Matheus Afonso Martins Moreira via Gcc
> As noted by J. Wakely, you don't need to have one variant > for each number of arguments. Yes, he is right about that. I have already deleted all the variants from my code since the variadic builtin will be able to generate optimal code, unlike a variadic C function. > I assume you're talking a

Re: Re: [RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
> There is quite a bit of variance in how the kernel is entered. I assume you mean the vDSO. It is also documented and stable. https://www.kernel.org/doc/html/latest/admin-guide/abi-stable.html#vdso > Unless otherwise noted, the set of symbols with any given version > and the ABI of those symbol

Re: Re: [RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
> What's the advantage of the _1, _2 etc. forms? Now that you mention it... I don't believe there are any. > The compiler knows how many arguments you're passing, > why can't there just be one built-in handling all cases? You're right about that. When I started working on this I just mirrored t

[RFC] Linux system call builtins

2024-04-08 Thread Matheus Afonso Martins Moreira via Gcc
Hello! I'm a beginner when it comes to GCC development. I want to learn how it works and start contributing. Decided to start by implementing something relatively simple but which would still be very useful for me: Linux builtins. I sought help in the OFTC IRC channel and it was suggested that I di