[PATCH 1/5] x86_64: Extend 32-bit syscall arguments to the full register (BZ 34917)

Florian Weimer fweimer@redhat.com
Fri Nov 6 09:36:54 GMT 2026


* 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.

> +#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[]

Thanks,
Florian



More information about the Libc-alpha mailing list