public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Will Newton <will.newton@linaro.org>
To: Andrew Pinski <apinski@cavium.com>
Cc: libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 17/29] [AARCH64] Syscalls for ILP32 are passed always via 64bit values.
Date: Tue, 18 Nov 2014 12:50:00 -0000	[thread overview]
Message-ID: <CANu=Dmj_MHGVPgkQfOkvj3wXCVGEPdU7V3=jBPjnkoRL2B4LRA@mail.gmail.com> (raw)
In-Reply-To: <1414396793-9005-18-git-send-email-apinski@cavium.com>

On 27 October 2014 07:59, Andrew Pinski <apinski@cavium.com> wrote:
> This patch adds support for ILP32 syscalls, sign and zero extending
> where needed.  Unlike LP64, pointers are 32bit and need to be zero
> extended rather than the standard sign extend that the code would do.
> We take advatage of ssize_t being long rather than int for ILP32,
> to get this correct.
>
> * sysdeps/unix/sysv/linux/aarch64/sysdep.h
> (INLINE_VSYSCALL): Use long long instead of long.
> (INTERNAL_VSYSCALL): Likewise.
> (INLINE_SYSCALL): Likewise.
> (INTERNAL_SYSCALL_RAW): Likewise.
> (ARGIFY): New macro.
> (LOAD_ARGS_0): Use long long instead of long.
> (LOAD_ARGS_1): Use long long instead of long
> and use ARGIFY.
> (LOAD_ARGS_2): Likewise.
> (LOAD_ARGS_3): Likewise.
> (LOAD_ARGS_4): Likewise.
> (LOAD_ARGS_5): Likewise.
> (LOAD_ARGS_6): Likewise.
> (LOAD_ARGS_7): Likewise.
> ---
>  sysdeps/unix/sysv/linux/aarch64/sysdep.h |   52 ++++++++++++++++++-----------
>  1 files changed, 32 insertions(+), 20 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> index fc31661..0d9fa8a 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
> @@ -156,7 +156,7 @@
>    ({                                                                         \
>      __label__ out;                                                           \
>      __label__ iserr;                                                         \
> -    long sc_ret;                                                             \
> +    long long sc_ret;                                                        \
>      INTERNAL_SYSCALL_DECL (sc_err);                                          \
>                                                                               \
>      if (__vdso_##name != NULL)                                               \
> @@ -187,7 +187,7 @@
>  #  define INTERNAL_VSYSCALL(name, err, nr, args...)                          \
>    ({                                                                         \
>      __label__ out;                                                           \
> -    long v_ret;                                                                      \
> +    long long v_ret;                                                                 \
>                                                                               \
>      if (__vdso_##name != NULL)                                               \
>        {                                                                              \
> @@ -224,11 +224,11 @@
>     call.  */
>  # undef INLINE_SYSCALL
>  # define INLINE_SYSCALL(name, nr, args...)                             \
> -  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);  \
> +  ({ unsigned long long _sys_result = INTERNAL_SYSCALL (name, , nr, args);     \
>       if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
>         {                                                               \
>          __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));          \
> -        _sys_result = (unsigned long) -1;                              \
> +        _sys_result = (unsigned long long) -1;                         \
>         }                                                               \
>       (long) _sys_result; })
>
> @@ -237,10 +237,10 @@
>
>  # undef INTERNAL_SYSCALL_RAW
>  # define INTERNAL_SYSCALL_RAW(name, err, nr, args...)          \
> -  ({ long _sys_result;                                         \
> +  ({ long long _sys_result;                                            \
>       {                                                         \
>         LOAD_ARGS_##nr (args)                                   \
> -       register long _x8 asm ("x8") = (name);                  \
> +       register long long _x8 asm ("x8") = (name);             \
>         asm volatile ("svc      0       // syscall " # name     \
>                      : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \
>         _sys_result = _x0;                                      \
> @@ -262,36 +262,48 @@
>  # undef INTERNAL_SYSCALL_ERRNO
>  # define INTERNAL_SYSCALL_ERRNO(val, err)      (-(val))
>
> +/* Convert X to a long long, without losing any bits if it is one
> +   already or warning if it is a 32-bit pointer.  This zero extends
> +   32-bit pointers and sign extends other signed types.  Note this only
> +   works because ssize_t is long and short-short is promoted to int.   */
> +#define ARGIFY(X)                                                                                      \
> +       ((unsigned long long)                                                                           \
> +         __builtin_choose_expr(__builtin_types_compatible_p(__typeof__(X), __typeof__((X) - (X))),     \
> +                               (X),                                                                    \
> +           __builtin_choose_expr(__builtin_types_compatible_p(int, __typeof__((X) - (X))),             \
> +                                 (X),                                                                  \
> +                                 (unsigned long)(X))))
> +

This could do with spaces before parentheses and the line wrapping
could be made more readable, but otherwise this looks ok.

>  # define LOAD_ARGS_0()                         \
> -  register long _x0 asm ("x0");
> +  register long long _x0 asm ("x0");
>  # define LOAD_ARGS_1(x0)                       \
> -  long _x0tmp = (long) (x0);                   \
> +  long long _x0tmp = ARGIFY (x0);              \
>    LOAD_ARGS_0 ()                               \
>    _x0 = _x0tmp;
>  # define LOAD_ARGS_2(x0, x1)                   \
> -  long _x1tmp = (long) (x1);                   \
> +  long long _x1tmp = ARGIFY (x1);              \
>    LOAD_ARGS_1 (x0)                             \
> -  register long _x1 asm ("x1") = _x1tmp;
> +  register long long _x1 asm ("x1") = _x1tmp;
>  # define LOAD_ARGS_3(x0, x1, x2)               \
> -  long _x2tmp = (long) (x2);                   \
> +  long long _x2tmp = ARGIFY (x2);              \
>    LOAD_ARGS_2 (x0, x1)                         \
> -  register long _x2 asm ("x2") = _x2tmp;
> +  register long long _x2 asm ("x2") = _x2tmp;
>  # define LOAD_ARGS_4(x0, x1, x2, x3)           \
> -  long _x3tmp = (long) (x3);                   \
> +  long long _x3tmp = ARGIFY (x3);              \
>    LOAD_ARGS_3 (x0, x1, x2)                     \
> -  register long _x3 asm ("x3") = _x3tmp;
> +  register long long _x3 asm ("x3") = _x3tmp;
>  # define LOAD_ARGS_5(x0, x1, x2, x3, x4)       \
> -  long _x4tmp = (long) (x4);                   \
> +  long long _x4tmp = ARGIFY (x4);              \
>    LOAD_ARGS_4 (x0, x1, x2, x3)                 \
> -  register long _x4 asm ("x4") = _x4tmp;
> +  register long long _x4 asm ("x4") = _x4tmp;
>  # define LOAD_ARGS_6(x0, x1, x2, x3, x4, x5)   \
> -  long _x5tmp = (long) (x5);                   \
> +  long long _x5tmp = ARGIFY (x5);              \
>    LOAD_ARGS_5 (x0, x1, x2, x3, x4)             \
> -  register long _x5 asm ("x5") = _x5tmp;
> +  register long long _x5 asm ("x5") = _x5tmp;
>  # define LOAD_ARGS_7(x0, x1, x2, x3, x4, x5, x6)\
> -  long _x6tmp = (long) (x6);                   \
> +  long long _x6tmp = ARGIFY (x6);              \
>    LOAD_ARGS_6 (x0, x1, x2, x3, x4, x5)         \
> -  register long _x6 asm ("x6") = _x6tmp;
> +  register long long _x6 asm ("x6") = _x6tmp;
>
>  # define ASM_ARGS_0
>  # define ASM_ARGS_1    , "r" (_x0)
> --
> 1.7.2.5
>



-- 
Will Newton
Toolchain Working Group, Linaro

  reply	other threads:[~2014-11-18 12:50 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27  8:00 [PATCH 00/29] Add Support for AARCH64:ILP32 Andrew Pinski
2014-10-27  8:00 ` [PATCH 02/29] Allow sigset be an array of a different type Andrew Pinski
2014-10-27 20:32   ` Roland McGrath
2014-10-27  8:00 ` [PATCH 12/29] [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S Andrew Pinski
2014-11-18 12:23   ` Will Newton
2014-10-27  8:00 ` [PATCH 24/29] [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found Andrew Pinski
2014-11-18 14:31   ` Will Newton
2014-10-27  8:00 ` [PATCH 27/29] [AARCH64] Fix up ucontext for ILP32 Andrew Pinski
2014-10-28 20:10   ` Mike Frysinger
2014-11-18 14:54   ` Will Newton
2014-10-27  8:00 ` [PATCH 11/29] [AARCH64] Use PTR_REG in crti.S Andrew Pinski
2014-11-18 12:09   ` Will Newton
2014-10-27  8:00 ` [PATCH 08/29] [AARCH64] Add header guards to sysdep.h headers Andrew Pinski
2014-10-27 16:32   ` Chris Metcalf
2014-10-27  8:00 ` [PATCH 07/29] Allow generic stat and statfs not have padding for 32bit targets Andrew Pinski
2014-10-27 16:32   ` Chris Metcalf
2014-10-27  8:00 ` [PATCH 01/29] [AARCH64] Fix utmp struct for compatibility reasons Andrew Pinski
2014-10-27 17:57   ` Joseph S. Myers
2014-10-27 21:18     ` Andreas Schwab
2014-10-27  8:00 ` [PATCH 06/29] Allow some fields of siginfo to be different from the generic one Andrew Pinski
2014-11-18 11:31   ` Will Newton
2014-10-27  8:00 ` [PATCH 05/29] Allow fd_mask type not be an array of long Andrew Pinski
2014-10-27 16:32   ` Chris Metcalf
2014-11-18 11:24     ` Will Newton
2014-10-27  8:00 ` [PATCH 03/29] Add ability for the IPC structures (msqid_ds, semid_ds, shmid_ds, etc.) to have time_t being 64bit Andrew Pinski
2014-10-27 16:32   ` Chris Metcalf
2014-11-18 10:57   ` Will Newton
2014-10-27  8:00 ` [PATCH 18/29] [AARCH64] Reformat inline-asm in elf_machine_load_address Andrew Pinski
2014-11-18 13:51   ` Will Newton
2014-10-27  8:00 ` [PATCH 04/29] Allow rusage work on a big-endian 32bit-on-64bit target Andrew Pinski
2014-10-28 20:05   ` Mike Frysinger
2014-10-27  8:00 ` [PATCH 15/29] [AARCH64] Use PTR_REG in getcontext.S Andrew Pinski
2014-11-18 12:37   ` Will Newton
2014-10-27  8:00 ` [PATCH 19/29] [AARCH64] Add ILP32 support to elf_machine_load_address Andrew Pinski
2014-11-18 13:56   ` Will Newton
2014-10-27  8:00 ` [PATCH 13/29] [AARCH64] Use PTR_* macros in dl-trampoline.S Andrew Pinski
2014-11-18 12:33   ` Will Newton
2014-10-27  8:00 ` [PATCH 10/29] [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE. Use it in LDST_PCREL and LDST_GLOBAL Andrew Pinski
2014-11-18 12:04   ` Will Newton
2014-10-27  8:00 ` [PATCH 09/29] Add dynamic ILP32 AARCH64 relocations to elf.h Andrew Pinski
2014-10-27 20:36   ` Roland McGrath
2014-10-27  8:00 ` [PATCH 25/29] [AARCH64] Add kernel_sigaction.h for AARCH64 ILP32 Andrew Pinski
2014-11-18 14:42   ` Will Newton
2014-10-27  8:03 ` [PATCH 22/29] [AARCH64] Add support to ldconfig for ILP32 and libilp32 Andrew Pinski
2014-11-18 14:20   ` Will Newton
2014-10-27  8:03 ` [PATCH 26/29] [AARCH64] Add sigstack.h header for ILP32 reasons Andrew Pinski
2014-11-18 14:49   ` Will Newton
2014-10-27  8:03 ` [PATCH 16/29] [AARCH64] Detect ILP32 in configure scripts Andrew Pinski
2014-10-27 18:05   ` Joseph S. Myers
2014-10-28 20:16   ` Mike Frysinger
2014-10-28 20:18     ` Andrew Pinski
2014-10-27  8:03 ` [PATCH 20/29] [AARCH64] Set up wordsize for ILP32 Andrew Pinski
2014-11-18 13:58   ` Will Newton
2014-10-27  8:03 ` [PATCH 17/29] [AARCH64] Syscalls for ILP32 are passed always via 64bit values Andrew Pinski
2014-11-18 12:50   ` Will Newton [this message]
2014-10-27  8:03 ` [PATCH 28/29] [AARCH64] Add typesizes.h for ILP32 Andrew Pinski
2014-10-27 16:32   ` Chris Metcalf
2014-10-28 20:06   ` Mike Frysinger
2014-10-27  8:03 ` [PATCH 21/29] [AARCH64] Add ILP32 to makefiles Andrew Pinski
2014-10-28 20:14   ` Mike Frysinger
2014-10-28 22:46     ` Joseph S. Myers
2014-10-27  8:03 ` [PATCH 23/29] [AARCH64] Add ILP32 ld.so to the known interpreter names Andrew Pinski
2014-11-18 14:26   ` Will Newton
2014-10-27  8:03 ` [PATCH 29/29] [AARCH64] Make lp64 and ilp32 directories Andrew Pinski
2014-10-27 18:07   ` Joseph S. Myers
2014-10-27  8:03 ` [PATCH 14/29] [AARCH64] Use PTR_* in start.S Andrew Pinski
2014-11-18 12:35   ` Will Newton
2014-10-28  9:15 ` [PATCH 00/29] Add Support for AARCH64:ILP32 Marcus Shawcroft
2015-05-26 13:37 ` Andreas Schwab
2015-05-26 14:13   ` Pinski, Andrew
2015-05-26 14:39     ` Andreas Schwab
2015-05-26 15:10       ` Pinski, Andrew
2015-05-26 15:16         ` Andreas Schwab

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='CANu=Dmj_MHGVPgkQfOkvj3wXCVGEPdU7V3=jBPjnkoRL2B4LRA@mail.gmail.com' \
    --to=will.newton@linaro.org \
    --cc=apinski@cavium.com \
    --cc=libc-alpha@sourceware.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).