public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Add SYSCALL_LONG/SYSCALL_ULONG to pass long to syscall [BZ #25810]
Date: Mon, 13 Apr 2020 04:54:42 -0700	[thread overview]
Message-ID: <CAMe9rOqP5Z8kk2PCF9dde2L4ONmjGGqEJqmag+HiLgCz_wTrdQ@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOqmRyamraYL=VnKO0bSEkNA3AvqCXhTBnoX0DhJpKT-kw@mail.gmail.com>

On Mon, Apr 13, 2020 at 4:44 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Apr 13, 2020 at 1:23 AM Florian Weimer <fw@deneb.enyo.de> wrote:
> >
> > * H. J. Lu:
> >
> > > On Sun, Apr 12, 2020 at 1:44 PM Florian Weimer <fw@deneb.enyo.de> wrote:
> > >>
> > >> * H. J. Lu:
> > >>
> > >> > nohup: ignoring input and appending output to 'nohup.out'
> > >> > gnu-tools-1:pts/5[130]> m nohup.out
> > >> > In file included from ../sysdeps/x86_64/nptl/tls.h:28,
> > >> >                  from ../include/errno.h:25,
> > >> >                  from ../sysdeps/unix/sysv/linux/fexecve.c:18:
> > >> > ../sysdeps/unix/sysv/linux/fexecve.c: In function ‘fexecve’:
> > >> > ../sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h:56:6: error: cast from pointer to
> > >> >  integer of different size [-Werror=pointer-to-int-cast]
> > >> >    56 |    : (long long int) (X))
> > >> >       |      ^
> > >>
> > >> Please try something like this:
> > >>
> > >> #define ARGIFY(X)                                                       \
> > >>   ({                                                                    \
> > >>     _Pragma ("GCC diagnostic push");                                    \
> > >>     _Pragma ("GCC diagnostic ignored \"-Wpointer-to-int-cast\"");       \
> > >>     (sizeof (X) <= 4 && (__typeof__ (X)) 0 < (__typeof__ (X)) -1)       \
> > >>       ? (long long int) (unsigned long int) (X)                         \
> > >>       : (long int long) (X);                                            \
> > >>     _Pragma ("GCC diagnostic pop");                                     \
> > >>   })
> > >>
> > >> (__builtin_choose_expr does not work because it only suppresses
> > >> errors, not warnings.)
> > >>
> > >> It may not work in some cases because (__typeof__ (X)) 0 is not valid
> > >> if X is an array.
> > >
> > > It compiles, but doesn't work.  We need to cast the input of
> > >
> > > #define TYPEFY(X, name) __typeof__ ((X) - (X)) name
> > > #define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
> > >
> > > to unsigned long long.
> >
> > Why does it fail?  Are there any arguments besides pointers which must
> > not be sign-extended to 64 bits?  According to syscall(2), I don't
> > think, so I still think we can make this work if we just avoid
> > sign-extending pointers.
>
> Here is a simple testcase:
>
> ---
> #define TYPEFY(X, name) __typeof__ ((X) - (X)) name
> #define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
>
> int
> foo (unsigned int arg1)
> {
>   unsigned long int resultvar;
>   TYPEFY (arg1, __arg1) = ARGIFY (arg1);
>   register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;
>   asm volatile ("syscall\n\t"
> : "=a" (resultvar)
> : "0" (0xff), "r" (_a1)
> : "memory");
>   return resultvar;
> }
> ---
>
> When compiled with -O2 -mx32, we need "movl %edi, %edi" before
> syscall
>

I may have found a solution.

-- 
H.J.

  reply	other threads:[~2020-04-13 11:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10 21:22 H.J. Lu
2020-04-11 10:01 ` Florian Weimer
2020-04-11 13:26   ` H.J. Lu
2020-04-11 14:45     ` Florian Weimer
2020-04-11 15:04       ` H.J. Lu
2020-04-11 15:10         ` Florian Weimer
2020-04-11 15:23           ` H.J. Lu
2020-04-11 15:31             ` Florian Weimer
2020-04-11 20:25               ` H.J. Lu
2020-04-11 20:47                 ` Florian Weimer
2020-04-11 21:58                   ` H.J. Lu
2020-04-12 20:44                     ` Florian Weimer
2020-04-12 22:42                       ` H.J. Lu
2020-04-13  8:23                         ` Florian Weimer
2020-04-13 11:44                           ` H.J. Lu
2020-04-13 11:54                             ` H.J. Lu [this message]
2020-04-13 14:26                               ` H.J. Lu

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=CAMe9rOqP5Z8kk2PCF9dde2L4ONmjGGqEJqmag+HiLgCz_wTrdQ@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=fw@deneb.enyo.de \
    --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).