[PATCH 1/5] x86_64: Extend 32-bit syscall arguments to the full register (BZ 34917)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Nov 6 11:15:32 GMT 2026
On 06/11/26 06:36, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> +/* Some ABI (x86_64, aarch64) leave the upper 32 bits of a register holding
>> + a 32-bit argument unspecified. Linux declares some arguments that glibc
>> + takes as int or unsigned int as long or unsigned long, and rejects stray
>> + upper bits. So the wrapper must extend them. */
>> +
>> +#define DIRTY(v) \
>> + ((uint64_t) (unsigned int) (v) | UINT64_C (0xdeadbeef00000000))
>
> This needs a compiler barrier. I'm sure some compiler will optimize out
> the upper bits if only the lower 32 bits are used.
I have tested with gcc-16 on both aarch64 and x86_64 and the added tests
does stress the issues. But I will add a compiler barrier to avoid the
optimization.
>
>> +#include <support/test-driver.c>
>> diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
>> index 104acff3a36..af5c9c5f8fe 100644
>> --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
>> +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
>> @@ -220,12 +220,13 @@
>> /* Registers clobbered by syscall. */
>> # define REGISTERS_CLOBBERED_BY_SYSCALL "cc", "r11", "cx"
>>
>> -/* NB: This also works when X is an array. For an array X, type of
>> - (X) - (X) is ptrdiff_t, which is signed, since size of ptrdiff_t
>> - == size of pointer, cast is a NOP. */
>> -#define TYPEFY1(X) __typeof__ ((X) - (X))
>> -/* Explicit cast the argument. */
>> -#define ARGIFY(X) ((TYPEFY1 (X)) (X))
>> +/* The psABI leaves the upper 32 bits of a register holding a 32-bit argument
>> + unspecified, but the kernel reads the whole register for arguments it
>> + declares as long or unsigned longi. Some of those are int in the C
>
> Typo: unsigned long[]
>
Ack.
> Thanks,
> Florian
More information about the Libc-alpha
mailing list