public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] x32: Properly pass long to syscall [BZ #25810]
@ 2020-04-13 14:25 H.J. Lu
  2020-04-13 14:25 ` [PATCH 1/3] Add SYSCALL_ULONG_ARG_[12] to " H.J. Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: H.J. Lu @ 2020-04-13 14:25 UTC (permalink / raw)
  To: libc-alpha

X32 has 32-bit long and pointer with 64-bit off_t.  Since x32 psABI
requires that pointers passed in registers must be zero-extended to
64bit, x32 can share many syscall interfaces with LP64.  When a LP64
syscall with long and unsigned long arguments is used for x32, these
arguments must be properly extended to 64-bit.  Otherwise if the upper
32 bits of the register have undefined value, such a syscall will be
rejected by kernel.

For syscalls implemented in assembly codes, 'U' is added to syscall
signature key letters for unsigned long.  SYSCALL_ULONG_ARG_1 and
SYSCALL_ULONG_ARG_2 are passed to syscall-template.S for the first
and the second unsigned long arguments if PSEUDOS_HAVE_4_ARGS is
defined.  They are used by x32 to zero-extend 32-bit arguments to
64 bits.

For x32 INLINE_SYSCALLs, cast

1. pointer to unsigned long (32 bit).
2. 32-bit unsigned integer to unsigned long long (64 bit).
3. 32-bit integer to long long (64 bit).

For

       void *mmap(void *addr, size_t length, int prot, int flags,
                  int fd, off_t offset);

we now generate

   0:	41 f7 c1 ff 0f 00 00 	test   $0xfff,%r9d
   7:	75 1f                	jne    28 <__mmap64+0x28>
   9:	48 63 d2             	movslq %edx,%rdx
   c:	89 f6                	mov    %esi,%esi
   e:	4d 63 c0             	movslq %r8d,%r8
  11:	4c 63 d1             	movslq %ecx,%r10
  14:	b8 09 00 00 40       	mov    $0x40000009,%eax
  19:	0f 05                	syscall

That is

1. addr is unchanged.
2. length is zero-extend to 64 bits.
3. prot is sign-extend to 64 bits.
4. flags is sign-extend to 64 bits.
5. fd is sign-extend to 64 bits.
6. offset is unchanged.

For int arguments, since kernel uses only the lower 32 bits and ignores
the upper 32 bits in 64-bit registers, these work correctly.

Tested on i386, x86-64 and x32 as well as with build-many-glibcs.py.

H.J. Lu (3):
  Add SYSCALL_ULONG_ARG_[12] to pass long to syscall [BZ #25810]
  x32: Properly pass long to syscall [BZ #25810]
  Add a syscall test for [BZ #25810]

 misc/Makefile                               |   2 +-
 misc/tst-syscalls.c                         | 146 ++++++++++++++++++++
 sysdeps/unix/make-syscalls.sh               |  88 ++++++++++++
 sysdeps/unix/syscall-template.S             |  43 +++++-
 sysdeps/unix/syscalls.list                  |   6 +-
 sysdeps/unix/sysv/linux/syscalls.list       |  14 +-
 sysdeps/unix/sysv/linux/x86_64/sysdep.h     |  80 ++++++++---
 sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h |  38 +++++
 8 files changed, 385 insertions(+), 32 deletions(-)
 create mode 100644 misc/tst-syscalls.c

-- 
2.25.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-04-13 21:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13 14:25 [PATCH 0/3] x32: Properly pass long to syscall [BZ #25810] H.J. Lu
2020-04-13 14:25 ` [PATCH 1/3] Add SYSCALL_ULONG_ARG_[12] to " H.J. Lu
2020-04-13 14:25 ` [PATCH 2/3] x32: Properly " H.J. Lu
2020-04-13 14:43   ` Florian Weimer
2020-04-13 15:03     ` H.J. Lu
2020-04-13 15:17       ` Florian Weimer
2020-04-13 16:33         ` V2 " H.J. Lu
2020-04-13 17:00           ` Florian Weimer
2020-04-13 18:34           ` Adhemerval Zanella
2020-04-13 20:43             ` H.J. Lu
2020-04-13 21:13               ` Florian Weimer
2020-04-13 21:19                 ` H.J. Lu
2020-04-13 14:25 ` [PATCH 3/3] Add a syscall test for " H.J. Lu

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