From patchwork Wed Dec 16 15:01:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 10035 Received: (qmail 79665 invoked by alias); 16 Dec 2015 15:01:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 79649 invoked by uid 89); 16 Dec 2015 15:01:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pf0-f179.google.com X-Received: by 10.98.16.70 with SMTP id y67mr5947377pfi.77.1450278101248; Wed, 16 Dec 2015 07:01:41 -0800 (PST) Date: Wed, 16 Dec 2015 07:01:39 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] [BZ #19371] Properly handle x32 syscall Message-ID: <20151216150139.GA24629@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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. Before the patch: Dump of assembler code for function syscall: 0x000dab20 <+0>: mov %rdi,%rax 0x000dab23 <+3>: mov %rsi,%rdi 0x000dab26 <+6>: mov %rdx,%rsi 0x000dab29 <+9>: mov %rcx,%rdx 0x000dab2c <+12>: mov %r8,%r10 0x000dab2f <+15>: mov %r9,%r8 0x000dab32 <+18>: mov 0x8(%rsp),%r9 0x000dab37 <+23>: syscall 0x000dab39 <+25>: cmp $0xfffffffffffff001,%rax 0x000dab3f <+31>: jae 0xdab42 0x000dab41 <+33>: retq 0x000dab42 <+34>: mov 0x2b3367(%rip),%rcx # 0x38deb0 0x000dab49 <+41>: neg %eax 0x000dab4b <+43>: mov %eax,%fs:(%rcx) 0x000dab4e <+46>: or $0xffffffff,%eax ^^^^^^^^^^^^^^^^^^ This is 32-bit error return. 0x000dab51 <+49>: retq End of assembler dump. After the patch: Dump of assembler code for function syscall: 0x000daaf0 <+0>: mov %rdi,%rax 0x000daaf3 <+3>: mov %rsi,%rdi 0x000daaf6 <+6>: mov %rdx,%rsi 0x000daaf9 <+9>: mov %rcx,%rdx 0x000daafc <+12>: mov %r8,%r10 0x000daaff <+15>: mov %r9,%r8 0x000dab02 <+18>: mov 0x8(%rsp),%r9 0x000dab07 <+23>: syscall 0x000dab09 <+25>: cmp $0xfffffffffffff001,%rax 0x000dab0f <+31>: jae 0xdab12 0x000dab11 <+33>: retq 0x000dab12 <+34>: mov 0x2b3397(%rip),%rcx # 0x38deb0 0x000dab19 <+41>: neg %eax 0x000dab1b <+43>: mov %eax,%fs:(%rcx) 0x000dab1e <+46>: or $0xffffffffffffffff,%rax 0x000dab22 <+50>: retq End of assembler dump. OK for master? H.J. --- [BZ #19371] * posix/unistd.h (syscall): Use __syscall_slong_t for return type. * sysdeps/unix/sysv/linux/x86_64/x32/syscall.S: New file. --- posix/unistd.h | 2 +- sysdeps/unix/sysv/linux/x86_64/x32/syscall.S | 33 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/syscall.S diff --git a/posix/unistd.h b/posix/unistd.h index 1b52930..bb61ad7 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -1058,7 +1058,7 @@ extern void *sbrk (intptr_t __delta) __THROW; In Mach, all system calls take normal arguments and always return an error code (zero for success). */ -extern long int syscall (long int __sysno, ...) __THROW; +extern __syscall_slong_t syscall (long int __sysno, ...) __THROW; #endif /* Use misc. */ diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscall.S b/sysdeps/unix/sysv/linux/x86_64/x32/syscall.S new file mode 100644 index 0000000..cc5255f --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscall.S @@ -0,0 +1,33 @@ +/* The syscall system call. Linux/x32 version. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* 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