[PATCH] [BZ #19371] Properly handle x32 syscall

Dmitry V. Levin ldv@altlinux.org
Wed Dec 16 17:17:00 GMT 2015


On Wed, Dec 16, 2015 at 08:52:34AM -0800, H.J. Lu wrote:
> On Wed, Dec 16, 2015 at 8:48 AM, Dmitry V. Levin <ldv@altlinux.org> wrote:
> > On Wed, Dec 16, 2015 at 07:01:39AM -0800, H.J. Lu wrote:
> >> X32 syscall() may return 64-bit integer as lseek, time and times.  Its
> >> return type should be __syscall_slong_t instead of long int.  We need
> >> to properly return 64-bit error value.
> > [...]
> >> +#include <sysdep.h>
> >> +
> >> +/* Return -1LL in a full 64 bits.  */
> >> +#undef SYSCALL_ERROR_HANDLER
> >> +#define SYSCALL_ERROR_HANDLER        \
> >> +0:                           \
> >> +     SYSCALL_SET_ERRNO;      \
> >> +     orq $-1, %rax;          \
> >> +     ret;
> >> +
> >> +/* Always use our own error handler.  */
> >> +#undef SYSCALL_ERROR_LABEL
> >> +#define SYSCALL_ERROR_LABEL 0f
> >> +
> >> +#include <sysdeps/unix/sysv/linux/x86_64/syscall.S>
> >
> > While this looks technically OK, I don't understand why RAX_LP is used
> > at all in default SYSCALL_ERROR_HANDLER in place for rax.  Everything
> > would be simpler if glibc finally admitted that return code of any
> > x32 linux syscall is stored in %rax and not in %eax.
> 
> Only 3 system calls return 64-bit value.

What do you mean by saying that?
Every bit of %rax is initialized on return from any syscall.

> %eax is one-byte shorter.

In your proposed fix for times syscall wrapper, the new __times is 2 bytes
shorter than the old one.  Could it happen that other syscall wrappers
will also win after switching from %eax to %rax?


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20151216/a26321cf/attachment.sig>


More information about the Libc-alpha mailing list