2019-01-01 00:11:28 +00:00
|
|
|
/* Copyright (C) 2001-2019 Free Software Foundation, Inc.
|
2001-09-19 10:37:31 +00:00
|
|
|
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
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2001-09-19 10:37:31 +00:00
|
|
|
|
|
|
|
#ifndef _LINUX_X86_64_SYSDEP_H
|
|
|
|
#define _LINUX_X86_64_SYSDEP_H 1
|
|
|
|
|
|
|
|
/* There is some commonality. */
|
Add INLINE_SYSCALL_ERROR_RETURN_VALUE
For ia32 PIC, the first thing of many syscalls does is to call
__x86.get_pc_thunk.reg to load PC into reg in case there is an error,
which is required for setting errno. In most cases, there are no
errors. But we still call __x86.get_pc_thunk.reg. This patch adds
INLINE_SYSCALL_ERROR_RETURN_VALUE so that i386 can optimize setting
errno by branching to the internal __syscall_error without PLT.
With i386 INLINE_SYSCALL_ERROR_RETURN_VALUE and i386 syscall inlining
optimization for GCC 5, for sysdeps/unix/sysv/linux/fchmodat.c with
-O2 -march=i686 -mtune=generic, GCC 5.2 now generates:
<fchmodat>:
0: push %ebx
1: mov 0x14(%esp),%eax
5: mov 0x8(%esp),%ebx
9: mov 0xc(%esp),%ecx
d: mov 0x10(%esp),%edx
11: test $0xfffffeff,%eax
16: jne 38 <fchmodat+0x38>
18: test $0x1,%ah
1b: jne 48 <fchmodat+0x48>
1d: mov $0x132,%eax
22: call *%gs:0x10
29: cmp $0xfffff000,%eax
2e: ja 58 <fchmodat+0x58>
30: pop %ebx
31: ret
32: lea 0x0(%esi),%esi
38: pop %ebx
39: mov $0xffffffea,%eax
3e: jmp 3f <fchmodat+0x3f> 3f: R_386_PC32 __syscall_error
43: nop
44: lea 0x0(%esi,%eiz,1),%esi
48: pop %ebx
49: mov $0xffffffa1,%eax
4e: jmp 4f <fchmodat+0x4f> 4f: R_386_PC32 __syscall_error
53: nop
54: lea 0x0(%esi,%eiz,1),%esi
58: pop %ebx
59: jmp 5a <fchmodat+0x5a> 5a: R_386_PC32 __syscall_error
instead of
<fchmodat>:
0: sub $0x8,%esp
3: mov 0x18(%esp),%eax
7: mov %ebx,(%esp)
a: call b <fchmodat+0xb> b: R_386_PC32 __x86.get_pc_thunk.bx
f: add $0x2,%ebx 11: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
15: mov %edi,0x4(%esp)
19: test $0xfffffeff,%eax
1e: jne 70 <fchmodat+0x70>
20: test $0x1,%ah
23: jne 88 <fchmodat+0x88>
25: mov 0x14(%esp),%edx
29: mov 0x10(%esp),%ecx
2d: mov 0xc(%esp),%edi
31: xchg %ebx,%edi
33: mov $0x132,%eax
38: call *%gs:0x10
3f: xchg %edi,%ebx
41: cmp $0xfffff000,%eax
46: ja 58 <fchmodat+0x58>
48: mov (%esp),%ebx
4b: mov 0x4(%esp),%edi
4f: add $0x8,%esp
52: ret
53: nop
54: lea 0x0(%esi,%eiz,1),%esi
58: mov 0x0(%ebx),%edx 5a: R_386_TLS_GOTIE __libc_errno
5e: neg %eax
60: mov %eax,%gs:(%edx)
63: mov $0xffffffff,%eax
68: jmp 48 <fchmodat+0x48>
6a: lea 0x0(%esi),%esi
70: mov 0x0(%ebx),%eax 72: R_386_TLS_GOTIE __libc_errno
76: movl $0x16,%gs:(%eax)
7d: mov $0xffffffff,%eax
82: jmp 48 <fchmodat+0x48>
84: lea 0x0(%esi,%eiz,1),%esi
88: mov 0x0(%ebx),%eax 8a: R_386_TLS_GOTIE __libc_errno
8e: movl $0x5f,%gs:(%eax)
95: mov $0xffffffff,%eax
9a: jmp 48 <fchmodat+0x48>
* sysdeps/unix/sysv/linux/sysdep.h: New file.
* sysdeps/unix/sysv/linux/i386/sysdep.c: Likewise.
* sysdeps/unix/sysv/linux/alpha/sysdep.h: Include
<sysdeps/unix/sysv/linux/sysdep.h>.
* sysdeps/unix/sysv/linux/arm/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/generic/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/hppa/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/ia64/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/m68k/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/microblaze/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/sh/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h: Likewise.
* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) == csu]
(sysdep-dl-routines): Add sysdep.
[$(subdir) == nptl] (libpthread-routines): Likewise.
[$(subdir) == rt] (librt-routines): Likewise.
* sysdeps/unix/sysv/linux/i386/clone.S (__clone): Don't check
PIC when branching to SYSCALL_ERROR_LABEL.
* sysdeps/unix/sysv/linux/i386/sysdep.S: Removed.
* sysdeps/unix/sysv/linux/i386/sysdep.h: Include
<sysdeps/unix/sysv/linux/sysdep.h>.
(SYSCALL_ERROR_LABEL): Changed to __syscall_error.
(SYSCALL_ERROR_ERRNO): Removed.
(SYSCALL_ERROR_HANDLER): Changed to empty.
(SYSCALL_ERROR_HANDLER_TLS_STORE): Likewise.
(__syscall_error): New prototype.
[IS_IN (libc)] (INLINE_SYSCALL): New macro.
(INLINE_SYSCALL_ERROR_RETURN_VALUE): Likewise.
2015-10-13 18:58:53 +00:00
|
|
|
#include <sysdeps/unix/sysv/linux/sysdep.h>
|
2001-09-19 10:37:31 +00:00
|
|
|
#include <sysdeps/unix/x86_64/sysdep.h>
|
2002-10-14 18:10:15 +00:00
|
|
|
#include <tls.h>
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2018-03-18 01:11:56 +00:00
|
|
|
/* Defines RTLD_PRIVATE_ERRNO. */
|
|
|
|
#include <dl-sysdep.h>
|
* sysdeps/generic/bits/libc-tsd.h [USE___THREAD]: Conditional
changed from [USE_TLS && HAVE___THREAD].
* sysdeps/i386/dl-machine.h (elf_machine_type_class, elf_machine_rel):
Disable TLS relocs if [RTLD_BOOTSTRAP && !USE___THREAD].
* sysdeps/x86_64/dl-machine.h
(elf_machine_type_class, elf_machine_rela): Likewise.
* sysdeps/sh/dl-machine.h (elf_machine_type_class, elf_machine_rela):
Likewise.
* include/link.h (struct link_map): Remove member l_tls_tp_initialized.
* elf/rtld.c (_dl_start_final, dl_main): Don't use it.
(_dl_start): Conditionalize PT_TLS check on [USE___THREAD].
* sysdeps/i386/dl-tls.h (__TLS_GET_ADDR): Use ___tls_get_addr_internal
instead of ___tls_get_addr.
(___tls_get_addr_internal): Add attribute_hidden to decl.
* sysdeps/generic/ldsodefs.h (struct rtld_global): New variable
_dl_error_catch_tsd.
* elf/rtld.c (startup_error_tsd): New function.
(dl_main): Point _dl_error_catch_tsd at that.
* elf/dl-error.c: Don't use libc-tsd.h for DL_ERROR,
use new function pointer instead.
* elf/dl-tsd.c: New file.
* elf/Makefile (routines): Add it.
2002-10-07 Roland McGrath <roland@redhat.com>
* elf/dl-misc.c (_dl_debug_vdprintf): Use INTERNAL_SYSCALL macro for
writev if it's available. Otherwise if [RTLD_PRIVATE_ERRNO] then
take _dl_load_lock around calling __writev.
* sysdeps/unix/sysv/linux/i386/sysdep.h (INTERNAL_SYSCALL): New macro.
(INLINE_SYSCALL): Use that.
* sysdeps/generic/dl-sysdep.h: New file.
* sysdeps/mach/hurd/dl-sysdep.h: New file.
* sysdeps/generic/ldsodefs.h: Include <dl-sysdep.h>.
* include/errno.h [IS_IN_rtld]: Include <dl-sysdep.h> to define ...
[RTLD_PRIVATE_ERRNO]: Use a hidden global variable for errno and
access it directly.
* elf/dl-minimal.c (__errno_location): Removed.
* sysdeps/unix/i386/sysdep.S (__syscall_errno) [RTLD_PRIVATE_ERRNO]:
Use GOTOFF access for errno.
* sysdeps/unix/sysv/linux/i386/sysdep.h
[RTLD_PRIVATE_ERRNO] (SYSCALL_ERROR_HANDLER): Likewise.
* sysdeps/unix/x86_64/sysdep.S (__syscall_errno) [RTLD_PRIVATE_ERRNO]:
Use PC-relative access for errno.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h
[RTLD_PRIVATE_ERRNO] (SYSCALL_ERROR_HANDLER): Likewise.
* include/tls.h: New file.
(USE___THREAD): New macro.
Define to 1 under [USE_TLS && HAVE___THREAD] and only when compiling
libc or libpthread.
* sysdeps/unix/sysv/linux/i386/sysdep.h [USE___THREAD]: Conditional
changed from [USE_TLS && HAVE___THREAD].
* sysdeps/unix/sysv/linux/x86_64/sysdep.h: Likewise.
* sysdeps/unix/i386/sysdep.S: Likewise.
* sysdeps/unix/x86_64/sysdep.S: Likewise.
* include/errno.h: Likewise.
* include/netdb.h: Likewise.
* include/resolv.h: Likewise.
* sysdeps/generic/errno.c: New file.
* csu/Makefile (aux): New variable, list errno.
* sysdeps/unix/sysv/linux/i386/sysdep.S (errno, _errno): Remove defns.
* sysdeps/unix/sysv/linux/m68k/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/arm/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/cris/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/hppa/sysdep.c: Likewise.
* sysdeps/unix/sysv/linux/ia64/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/powerpc/sysdep.c: Likewise.
* sysdeps/unix/sysv/linux/sparc/sysdep.S: Likewise.
* sysdeps/unix/sysv/linux/sh/sysdep.S: Likewise.
* sysdeps/unix/alpha/sysdep.S: Likewise.
* sysdeps/generic/start.c: Likewise.
* sysdeps/unix/start.c: Likewise.
* sysdeps/unix/arm/start.c: Likewise.
* sysdeps/unix/bsd/ultrix4/mips/start.S: Likewise.
* sysdeps/unix/sparc/start.c: Likewise.
* sysdeps/unix/sysv/irix4/start.c: Likewise.
* sysdeps/unix/sysv/linux/mips/sysdep.S: File removed.
* manual/search.texi (Tree Search Function, Hash Search Function):
Mention search.h clearly.
2002-10-05 Roland McGrath <roland@redhat.com>
* elf/dl-fxstat64.c: File removed.
* elf/dl-xstat64.c: File removed.
* elf/Makefile (rtld-routines): Remove them.
* sysdeps/unix/sysv/linux/xstat64.c: Remove RTLD_STAT64 conditionals.
Instead, use strong_alias instead of versioned_symbol in the
!SHLIB_COMPAT case.
* sysdeps/unix/sysv/linux/fxstat64.c: Likewise.
* sysdeps/unix/sysv/linux/lxstat64.c: Likewise.
* include/shlib-compat.h
(SHLIB_COMPAT): Require that IS_IN_##lib be defined nonzero.
[! NOT_IN_libc] (IS_IN_libc): Define it.
* cppflags-iterator.mk (CPPFLAGS-$(cpp-src)): Use -Dx=1 not just -Dx.
* elf/Makefile (CPPFLAGS-.os): Likewise.
* sunrpc/rpc_main.c (main): Don't declare with noreturn attribute.
Return the status instead of calling exit.
* Makeconfig (CFLAGS): Prepend -std=gnu99.
* Makerules (+make-deps): Use $(CFLAGS) only for .c sources.
Remove superfluous rm command, whose @ plus make bugs hid
all these commands from the make output.
* include/stubs-prologue.h: New file. Give #error under #ifdef _LIBC.
* Makefile ($(inst_includedir)/gnu/stubs.h): Depend on it.
Use that file's contents instead of literal echo's for the prologue.
* include/features.h: Include <gnu/stubs.h> unconditionally.
* include/gnu/stubs.h: New file.
2002-09-30 Roland McGrath <roland@redhat.com>
* elf/rtld-Rules: New file.
* elf/Makefile ($(objpfx)librtld.map, $(objpfx)librtld.mk,
$(objpfx)rtld-libc.a): New targets.
(generated): Add them.
(reloc-link): Remove -o $@ from the variable.
($(objpfx)dl-allobjs.os): Add -o $@ after $(reloc-link).
(distribute): Add rtld-Rules.
(CPPFLAGS-.os): Define this instead of CFLAGS-.os.
* Makerules ($(+sysdir_pfx)sysd-rules): Emit rules for rtld-% targets.
(common-mostlyclean, common-clean): Clean up rtld-* files.
* sysdeps/unix/make-syscalls.sh: Add rtld-*.os target name to rules.
2002-10-11 10:52:20 +00:00
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
/* For Linux we can use the system call table in the header file
|
|
|
|
/usr/include/asm/unistd.h
|
|
|
|
of the kernel. But these symbols do not follow the SYS_* syntax
|
|
|
|
so we have to redefine the `SYS_ify' macro here. */
|
|
|
|
#undef SYS_ify
|
|
|
|
#define SYS_ify(syscall_name) __NR_##syscall_name
|
|
|
|
|
2002-09-28 04:15:00 +00:00
|
|
|
/* This is a kludge to make syscalls.list find these under the names
|
|
|
|
pread and pwrite, since some kernel headers define those names
|
|
|
|
and some define the *64 names for the same system calls. */
|
|
|
|
#if !defined __NR_pread && defined __NR_pread64
|
|
|
|
# define __NR_pread __NR_pread64
|
|
|
|
#endif
|
|
|
|
#if !defined __NR_pwrite && defined __NR_pwrite64
|
|
|
|
# define __NR_pwrite __NR_pwrite64
|
|
|
|
#endif
|
|
|
|
|
2003-05-05 08:45:16 +00:00
|
|
|
/* This is to help the old kernel headers where __NR_semtimedop is not
|
|
|
|
available. */
|
|
|
|
#ifndef __NR_semtimedop
|
|
|
|
# define __NR_semtimedop 220
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
#ifdef __ASSEMBLER__
|
|
|
|
|
|
|
|
/* Linux uses a negative return value to indicate syscall errors,
|
|
|
|
unlike most Unices, which use the condition codes' carry flag.
|
|
|
|
|
|
|
|
Since version 2.1 the return value of a system call might be
|
|
|
|
negative even if the call succeeded. E.g., the `lseek' system call
|
|
|
|
might return a large offset. Therefore we must not anymore test
|
|
|
|
for < 0, but test for a real error by making sure the value in %eax
|
|
|
|
is a real error number. Linus said he will make sure the no syscall
|
|
|
|
returns a value in -1 .. -4095 as a valid result so we can savely
|
|
|
|
test with -4095. */
|
|
|
|
|
|
|
|
/* We don't want the label for the error handle to be global when we define
|
|
|
|
it here. */
|
2007-08-12 19:03:54 +00:00
|
|
|
# ifdef PIC
|
|
|
|
# define SYSCALL_ERROR_LABEL 0f
|
|
|
|
# else
|
|
|
|
# define SYSCALL_ERROR_LABEL syscall_error
|
|
|
|
# endif
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO
|
|
|
|
# define PSEUDO(name, syscall_name, args) \
|
2001-09-19 10:37:31 +00:00
|
|
|
.text; \
|
|
|
|
ENTRY (name) \
|
* locale/programs/ld-ctype.c (ctype_read): When given a repertoire
name of "", store a null pointer instead.
* configure.in (elf): Set to yes for freebsd*, netbsd*.
* configure: Regenerated.
* locale/xlocale.c [! (USE_TLS && HAVE___THREAD)] (__libc_tsd_LOCALE):
Initialize this instead of __libc_tsd_LOCALE_data.
* sysdeps/unix/grantpt.c (pts_name): Convert ENOTTY return from
ptsname_r to EINVAL.
* sysdeps/generic/ptsname.c (__ptsname_r): Return ENOSYS instead of 0.
* rt/Makefile: Revert last change, it was inappropriate to presume aio
implementations depend on pthreads.
* rt/tst-aio.c (do_test): Exit happy if first failure is ENOSYS.
* rt/tst-aio64.c (do_test): Likewise.
* rt/tst-aio2.c (do_test): Likewise.
* rt/tst-aio3.c (do_test): Likewise.
* rt/tst-aio4.c (do_test): Likewise.
* rt/tst-aio5.c (do_test): Likewise.
* rt/tst-aio6.c (do_test): Likewise.
* rt/tst-aio7.c (do_test): Likewise.
* sysdeps/generic/bits/libc-lock.h (__libc_setspecific): Use a cast to
void so as to avoid compiler warnings.
* libio/oldstdfiles.c [! _IO_MTSAFE_IO] (DEF_STDFILE): Don't define
_IO_wide_data_FD, which is never used here.
* libio/iofread.c
[! _IO_MTSAFE_IO] (fread_unlocked): Add libc_hidden_ver defn.
* libio/iofputs.c [! _IO_MTSAFE_IO] (fputs_unlocked): Likewise.
* libio/iofgets.c [! _IO_MTSAFE_IO] (fgets_unlocked): Likewise.
* include/resolv.h [! _LIBC_REENTRANT] (_res): #undef it before decl.
* include/netdb.h [! _LIBC_REENTRANT] (h_errno): Declare normal extern.
* misc/syslog.c (openlog): Conditionalize locking on [_LIBC_REENTRANT].
(closelog): Likewise.
2002-07-06 Bruno Haible <bruno@clisp.org>
* sysdeps/alpha/fpu/fpu_control.h: Comment fix.
* sysdeps/unix/sysv/linux/alpha/pipe.S: Moved to ...
* sysdeps/unix/alpha/pipe.S: ... here.
* sysdeps/unix/bsd/osf/alpha/pipe.S: File removed.
* sysdeps/unix/i386/brk.S: Rename local label to '.Lhere' in ELF.
* sysdeps/unix/i386/brk.S: Add PSEUDO_END invocation.
* sysdeps/unix/i386/fork.S: Likewise.
* sysdeps/unix/i386/pipe.S: Likewise.
* sysdeps/unix/i386/wait.S: Likewise.
* sysdeps/unix/fork.S: Fix PSEUDO_END argument.
* sysdeps/unix/arm/fork.S: Likewise.
* sysdeps/unix/sysv/linux/arm/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/hppa/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/i386/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/sh/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (PSEUDO): Swap DO_CALL
arguments.
(DO_CALL): Swap argument order.
* sysdeps/i386/sysdep.h (PSEUDO): Fix syntax error.
(L): Define right for ELF.
* sysdeps/unix/sysv/linux/i386/sysdep.h (L): Remove definition.
Now defined in sysdeps/i386/sysdep.h.
* sysdeps/posix/readv.c: Ansify function definition.
* sysdeps/posix/writev.c: Likewise.
* stdio-common/tst-fseek.c (main): Don't assume that off_t and size_t
have the same size. Avoid direct cast from size_t to off_t.
* login/tst-utmp.c (simulate_login): Don't leave garbage after the
nul byte in entry[n].ut_user.
(simulate_logout): Likewise.
* login/programs/utmpdump.c (print_entry): Test _HAVE_UT_TYPE,
_HAVE_UT_PID, _HAVE_UT_ID, _HAVE_UT_HOST, instead of assuming the
existence of corresponding members of 'struct utmp'.
* login/tst-utmp.c: Trivialize the test if testing 'struct utmp' and
!_HAVE_UT_TYPE.
* sysdeps/unix/opendir.c (__opendir): If st_blksize is 0 or too small,
allocate a buffer of at least BUFSIZ bytes, not just of
sizeof (struct dirent).
* sysdeps/generic/glob.c: Include <limits.h>.
(NAME_MAX): Define a fallback.
(glob_in_dir): Allocate enough room for a 'struct dirent64' on the
stack.
* posix/tst-dir.c: Include <stddef.h>, for offsetof.
(main): Allocate enough room for a 'struct dirent64' on the stack.
* posix/tst-gnuglob.c (my_DIR): Allocate enough room for a
'struct dirent'.
* sysdeps/unix/sysv/linux/init-first.c: Don't include
kernel-features.h.
* inet/htontest.c: Include <sys/types.h>.
* sysdeps/generic/sys/sysinfo.h: Surround with __{BEGIN,END}_DECLS.
* include/sys/sysctl.h: Comment fix.
* elf/rtld.c (_rtld_global) [! _LIBC_REENTRANT]: Don't initialize
_dl_load_lock.
* libio/fileno.c (fileno_unlocked): Define regardless of _IO_MTSAFE_IO.
* sysdeps/unix/bsd/bsd4.4/syscalls.list (__sigaltstack): New alias.
* sysdeps/unix/inet/syscalls.list (__connect_internal): New alias.
(__getpeername): New alias.
(__getsockname): New alias.
(__socket): New alias.
* sysdeps/unix/common/syscalls.list (getpgid): Remove.
* sysdeps/unix/syscalls.list (__chown_internal): New alias.
(__fcntl_internal): New alias.
(__profil): New alias.
2002-08-26 11:39:12 +00:00
|
|
|
DO_CALL (syscall_name, args); \
|
2001-09-19 10:37:31 +00:00
|
|
|
cmpq $-4095, %rax; \
|
2012-07-16 14:12:47 +00:00
|
|
|
jae SYSCALL_ERROR_LABEL
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO_END
|
|
|
|
# define PSEUDO_END(name) \
|
2001-09-19 10:37:31 +00:00
|
|
|
SYSCALL_ERROR_HANDLER \
|
|
|
|
END (name)
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO_NOERRNO
|
|
|
|
# define PSEUDO_NOERRNO(name, syscall_name, args) \
|
2003-03-23 19:44:31 +00:00
|
|
|
.text; \
|
|
|
|
ENTRY (name) \
|
|
|
|
DO_CALL (syscall_name, args)
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO_END_NOERRNO
|
|
|
|
# define PSEUDO_END_NOERRNO(name) \
|
2003-03-23 19:44:31 +00:00
|
|
|
END (name)
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# define ret_NOERRNO ret
|
2003-08-16 08:10:06 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO_ERRVAL
|
|
|
|
# define PSEUDO_ERRVAL(name, syscall_name, args) \
|
2003-08-16 06:21:46 +00:00
|
|
|
.text; \
|
|
|
|
ENTRY (name) \
|
|
|
|
DO_CALL (syscall_name, args); \
|
2003-08-16 08:10:06 +00:00
|
|
|
negq %rax
|
2003-08-16 06:21:46 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef PSEUDO_END_ERRVAL
|
|
|
|
# define PSEUDO_END_ERRVAL(name) \
|
2003-08-16 06:21:46 +00:00
|
|
|
END (name)
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# define ret_ERRVAL ret
|
2003-03-23 19:44:31 +00:00
|
|
|
|
2018-03-18 01:11:56 +00:00
|
|
|
# if defined PIC && RTLD_PRIVATE_ERRNO
|
2012-05-21 21:50:21 +00:00
|
|
|
# define SYSCALL_SET_ERRNO \
|
|
|
|
lea rtld_errno(%rip), %RCX_LP; \
|
2012-05-22 12:34:36 +00:00
|
|
|
neg %eax; \
|
|
|
|
movl %eax, (%rcx)
|
2011-09-10 20:50:28 +00:00
|
|
|
# else
|
2014-11-24 09:33:45 +00:00
|
|
|
# if IS_IN (libc)
|
2007-08-12 19:03:54 +00:00
|
|
|
# define SYSCALL_ERROR_ERRNO __libc_errno
|
|
|
|
# else
|
|
|
|
# define SYSCALL_ERROR_ERRNO errno
|
|
|
|
# endif
|
2012-05-21 21:50:21 +00:00
|
|
|
# define SYSCALL_SET_ERRNO \
|
2002-10-16 22:09:55 +00:00
|
|
|
movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\
|
2012-05-22 12:34:36 +00:00
|
|
|
neg %eax; \
|
|
|
|
movl %eax, %fs:(%rcx);
|
2012-05-21 21:50:21 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef PIC
|
|
|
|
# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
|
|
|
|
# else
|
|
|
|
# define SYSCALL_ERROR_HANDLER \
|
|
|
|
0: \
|
|
|
|
SYSCALL_SET_ERRNO; \
|
|
|
|
or $-1, %RAX_LP; \
|
2012-05-23 18:35:38 +00:00
|
|
|
ret;
|
2007-08-12 19:03:54 +00:00
|
|
|
# endif /* PIC */
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2003-03-04 12:33:28 +00:00
|
|
|
/* The Linux/x86-64 kernel expects the system call parameters in
|
|
|
|
registers according to the following table:
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2003-03-04 12:33:28 +00:00
|
|
|
syscall number rax
|
2001-09-19 10:37:31 +00:00
|
|
|
arg 1 rdi
|
|
|
|
arg 2 rsi
|
|
|
|
arg 3 rdx
|
2003-03-04 12:33:28 +00:00
|
|
|
arg 4 r10
|
2001-09-19 10:37:31 +00:00
|
|
|
arg 5 r8
|
|
|
|
arg 6 r9
|
|
|
|
|
2003-03-04 12:33:28 +00:00
|
|
|
The Linux kernel uses and destroys internally these registers:
|
2001-09-19 10:37:31 +00:00
|
|
|
return address from
|
|
|
|
syscall rcx
|
|
|
|
eflags from syscall r11
|
|
|
|
|
2003-03-04 12:33:28 +00:00
|
|
|
Normal function call, including calls to the system call stub
|
|
|
|
functions in the libc, get the first six parameters passed in
|
|
|
|
registers and the seventh parameter and later on the stack. The
|
|
|
|
register use is as follows:
|
|
|
|
|
|
|
|
system call number in the DO_CALL macro
|
|
|
|
arg 1 rdi
|
|
|
|
arg 2 rsi
|
|
|
|
arg 3 rdx
|
|
|
|
arg 4 rcx
|
|
|
|
arg 5 r8
|
|
|
|
arg 6 r9
|
|
|
|
|
|
|
|
We have to take care that the stack is aligned to 16 bytes. When
|
|
|
|
called the stack is not aligned since the return address has just
|
|
|
|
been pushed.
|
|
|
|
|
2003-03-23 19:44:31 +00:00
|
|
|
|
2003-03-04 12:33:28 +00:00
|
|
|
Syscalls of more than 6 arguments are not supported. */
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef DO_CALL
|
|
|
|
# define DO_CALL(syscall_name, args) \
|
2001-09-19 10:37:31 +00:00
|
|
|
DOARGS_##args \
|
2005-03-31 10:02:53 +00:00
|
|
|
movl $SYS_ify (syscall_name), %eax; \
|
2001-09-19 10:37:31 +00:00
|
|
|
syscall;
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# define DOARGS_0 /* nothing */
|
|
|
|
# define DOARGS_1 /* nothing */
|
|
|
|
# define DOARGS_2 /* nothing */
|
|
|
|
# define DOARGS_3 /* nothing */
|
|
|
|
# define DOARGS_4 movq %rcx, %r10;
|
|
|
|
# define DOARGS_5 DOARGS_4
|
|
|
|
# define DOARGS_6 DOARGS_5
|
2001-09-19 10:37:31 +00:00
|
|
|
|
|
|
|
#else /* !__ASSEMBLER__ */
|
|
|
|
/* Define a macro which expands inline into the wrapper code for a system
|
|
|
|
call. */
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef INLINE_SYSCALL
|
|
|
|
# define INLINE_SYSCALL(name, nr, args...) \
|
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
2002-10-24 Roland McGrath <roland@redhat.com>
* libio/bug-wfflush.c: New file.
* libio/Makefile (tests): Add bug-wfflush.
2002-10-24 18:49:00 +00:00
|
|
|
({ \
|
2007-12-14 23:38:23 +00:00
|
|
|
unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
|
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
2002-10-24 Roland McGrath <roland@redhat.com>
* libio/bug-wfflush.c: New file.
* libio/Makefile (tests): Add bug-wfflush.
2002-10-24 18:49:00 +00:00
|
|
|
{ \
|
2003-01-09 04:19:03 +00:00
|
|
|
__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
|
2007-12-14 23:38:23 +00:00
|
|
|
resultvar = (unsigned long int) -1; \
|
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
2002-10-24 Roland McGrath <roland@redhat.com>
* libio/bug-wfflush.c: New file.
* libio/Makefile (tests): Add bug-wfflush.
2002-10-24 18:49:00 +00:00
|
|
|
} \
|
2007-12-14 23:38:23 +00:00
|
|
|
(long int) resultvar; })
|
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
2002-10-24 Roland McGrath <roland@redhat.com>
* libio/bug-wfflush.c: New file.
* libio/Makefile (tests): Add bug-wfflush.
2002-10-24 18:49:00 +00:00
|
|
|
|
2012-05-22 19:42:36 +00:00
|
|
|
/* Define a macro with explicit types for arguments, which expands inline
|
|
|
|
into the wrapper code for a system call. It should be used when size
|
|
|
|
of any argument > size of long int. */
|
|
|
|
# undef INLINE_SYSCALL_TYPES
|
|
|
|
# define INLINE_SYSCALL_TYPES(name, nr, args...) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
|
2012-05-22 19:42:36 +00:00
|
|
|
{ \
|
|
|
|
__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
|
|
|
|
resultvar = (unsigned long int) -1; \
|
|
|
|
} \
|
|
|
|
(long int) resultvar; })
|
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef INTERNAL_SYSCALL_DECL
|
|
|
|
# define INTERNAL_SYSCALL_DECL(err) do { } while (0)
|
2003-01-09 04:19:03 +00:00
|
|
|
|
2015-12-16 13:19:57 +00:00
|
|
|
/* Registers clobbered by syscall. */
|
|
|
|
# define REGISTERS_CLOBBERED_BY_SYSCALL "cc", "r11", "cx"
|
|
|
|
|
2016-07-13 09:50:05 +00:00
|
|
|
/* Create a variable 'name' based on type 'X' to avoid explicit types.
|
|
|
|
This is mainly used set use 64-bits arguments in x32. */
|
|
|
|
#define TYPEFY(X, name) __typeof__ ((X) - (X)) name
|
|
|
|
/* Explicit cast the argument to avoid integer from pointer warning on
|
|
|
|
x32. */
|
|
|
|
#define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
|
|
|
|
|
|
|
|
#undef INTERNAL_SYSCALL
|
|
|
|
#define INTERNAL_SYSCALL(name, err, nr, args...) \
|
|
|
|
internal_syscall##nr (SYS_ify (name), err, args)
|
|
|
|
|
|
|
|
#undef INTERNAL_SYSCALL_NCS
|
|
|
|
#define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
|
|
|
|
internal_syscall##nr (number, err, args)
|
|
|
|
|
|
|
|
#undef internal_syscall0
|
|
|
|
#define internal_syscall0(number, err, dummy...) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall1
|
|
|
|
#define internal_syscall1(number, err, 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" (number), "r" (_a1) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall2
|
|
|
|
#define internal_syscall2(number, err, arg1, arg2) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
TYPEFY (arg2, __arg2) = ARGIFY (arg2); \
|
|
|
|
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
|
|
|
|
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
|
|
|
|
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number), "r" (_a1), "r" (_a2) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall3
|
|
|
|
#define internal_syscall3(number, err, arg1, arg2, arg3) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
TYPEFY (arg3, __arg3) = ARGIFY (arg3); \
|
|
|
|
TYPEFY (arg2, __arg2) = ARGIFY (arg2); \
|
|
|
|
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
|
|
|
|
register TYPEFY (arg3, _a3) asm ("rdx") = __arg3; \
|
|
|
|
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
|
|
|
|
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall4
|
|
|
|
#define internal_syscall4(number, err, arg1, arg2, arg3, arg4) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
TYPEFY (arg4, __arg4) = ARGIFY (arg4); \
|
|
|
|
TYPEFY (arg3, __arg3) = ARGIFY (arg3); \
|
|
|
|
TYPEFY (arg2, __arg2) = ARGIFY (arg2); \
|
|
|
|
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
|
|
|
|
register TYPEFY (arg4, _a4) asm ("r10") = __arg4; \
|
|
|
|
register TYPEFY (arg3, _a3) asm ("rdx") = __arg3; \
|
|
|
|
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
|
|
|
|
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall5
|
|
|
|
#define internal_syscall5(number, err, arg1, arg2, arg3, arg4, arg5) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
TYPEFY (arg5, __arg5) = ARGIFY (arg5); \
|
|
|
|
TYPEFY (arg4, __arg4) = ARGIFY (arg4); \
|
|
|
|
TYPEFY (arg3, __arg3) = ARGIFY (arg3); \
|
|
|
|
TYPEFY (arg2, __arg2) = ARGIFY (arg2); \
|
|
|
|
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
|
|
|
|
register TYPEFY (arg5, _a5) asm ("r8") = __arg5; \
|
|
|
|
register TYPEFY (arg4, _a4) asm ("r10") = __arg4; \
|
|
|
|
register TYPEFY (arg3, _a3) asm ("rdx") = __arg3; \
|
|
|
|
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
|
|
|
|
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
|
|
|
|
"r" (_a5) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#undef internal_syscall6
|
|
|
|
#define internal_syscall6(number, err, arg1, arg2, arg3, arg4, arg5, arg6) \
|
|
|
|
({ \
|
|
|
|
unsigned long int resultvar; \
|
|
|
|
TYPEFY (arg6, __arg6) = ARGIFY (arg6); \
|
|
|
|
TYPEFY (arg5, __arg5) = ARGIFY (arg5); \
|
|
|
|
TYPEFY (arg4, __arg4) = ARGIFY (arg4); \
|
|
|
|
TYPEFY (arg3, __arg3) = ARGIFY (arg3); \
|
|
|
|
TYPEFY (arg2, __arg2) = ARGIFY (arg2); \
|
|
|
|
TYPEFY (arg1, __arg1) = ARGIFY (arg1); \
|
|
|
|
register TYPEFY (arg6, _a6) asm ("r9") = __arg6; \
|
|
|
|
register TYPEFY (arg5, _a5) asm ("r8") = __arg5; \
|
|
|
|
register TYPEFY (arg4, _a4) asm ("r10") = __arg4; \
|
|
|
|
register TYPEFY (arg3, _a3) asm ("rdx") = __arg3; \
|
|
|
|
register TYPEFY (arg2, _a2) asm ("rsi") = __arg2; \
|
|
|
|
register TYPEFY (arg1, _a1) asm ("rdi") = __arg1; \
|
|
|
|
asm volatile ( \
|
|
|
|
"syscall\n\t" \
|
|
|
|
: "=a" (resultvar) \
|
|
|
|
: "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4), \
|
|
|
|
"r" (_a5), "r" (_a6) \
|
|
|
|
: "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
|
|
|
|
(long int) resultvar; \
|
|
|
|
})
|
2012-05-22 19:42:36 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef INTERNAL_SYSCALL_ERROR_P
|
|
|
|
# define INTERNAL_SYSCALL_ERROR_P(val, err) \
|
2007-12-14 23:38:23 +00:00
|
|
|
((unsigned long int) (long int) (val) >= -4095L)
|
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
2002-10-24 Roland McGrath <roland@redhat.com>
* libio/bug-wfflush.c: New file.
* libio/Makefile (tests): Add bug-wfflush.
2002-10-24 18:49:00 +00:00
|
|
|
|
2007-08-12 19:03:54 +00:00
|
|
|
# undef INTERNAL_SYSCALL_ERRNO
|
|
|
|
# define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
|
|
|
|
|
2015-04-17 17:28:03 +00:00
|
|
|
/* List of system calls which are supported as vsyscalls. */
|
|
|
|
# define HAVE_CLOCK_GETTIME_VSYSCALL 1
|
|
|
|
# define HAVE_GETTIMEOFDAY_VSYSCALL 1
|
2015-04-22 17:21:39 +00:00
|
|
|
# define HAVE_GETCPU_VSYSCALL 1
|
2015-04-17 17:28:03 +00:00
|
|
|
|
Linux: Consolidate {RTLD_}SINGLE_THREAD_P definition
Current GLIBC has two ways to implement the single thread optimization
on syscalls to avoid calling the cancellation path: either by using
global variables (__{libc,pthread}_multiple_thread) or by accessing
the TCB field (defined by TLS_MULTIPLE_THREADS_IN_TCB). Both the
variables and the macros to acces its value are defined in the
architecture sysdep-cancel.h header.
This patch consolidates its definition on only one header,
sysdeps/unix/sysv/linux/sysdep-cancel.h, and adds a new define
(SINGLE_THREAD_BY_GLOBAL) which the architecture defines if it prefer
to use the global variables instead of the TCB field. This is an
optimization, so if the architecture does not define it, the TCB
method will be used as default.
Checked on x86_64-linux-gnu and on a build with major touched
ABIs (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
hppa-linux-gnu, i686-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu,
mips-linux-gnu, mips64-linux-gnu, powerpc-linux-gnu,
powerpc64le-linux-gnu, s390-linux-gnu, s390x-linux-gnu, sh4-linux-gnu,
sparcv9-linux-gnu, sparc64-linux-gnu, tilegx-linux-gnu).
* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h: Remove file.
* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
(SINGLE_THREAD_BY_GLOBAL): Define.
* sysdeps/unix/sysv/linux/aarch64/sysdep.h (SINGLE_THREAD_BY_GLOBAL):
Likewise.
* sysdeps/unix/sysv/linux/alpha/sysdep.h (SINGLE_THREAD_BY_GLOBAL):
Likewise.
* sysdeps/unix/sysv/linux/arm/sysdep.h (SINGLE_THREAD_BY_GLOBAL):
Likewise.
* sysdeps/unix/sysv/linux/hppa/sysdep.h (SINGLE_THREAD_BY_GLOBAL):
Likewise.
* sysdeps/unix/sysv/linux/microblaze/sysdep.h
(SINGLE_THREAD_BY_GLOBAL): Likewise.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (SINGLE_THREAD_BY_GLOBAL):
Likewise.
2017-08-03 22:27:27 +00:00
|
|
|
# define SINGLE_THREAD_BY_GLOBAL 1
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
#endif /* __ASSEMBLER__ */
|
|
|
|
|
2005-12-18 06:58:22 +00:00
|
|
|
|
|
|
|
/* Pointer mangling support. */
|
2014-11-20 15:39:43 +00:00
|
|
|
#if IS_IN (rtld)
|
2005-12-18 06:58:22 +00:00
|
|
|
/* We cannot use the thread descriptor because in ld.so we use setjmp
|
|
|
|
earlier than the descriptor is initialized. */
|
2005-12-18 16:59:55 +00:00
|
|
|
# ifdef __ASSEMBLER__
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_MANGLE(reg) xor __pointer_chk_guard_local(%rip), reg; \
|
|
|
|
rol $2*LP_SIZE+1, reg
|
|
|
|
# define PTR_DEMANGLE(reg) ror $2*LP_SIZE+1, reg; \
|
|
|
|
xor __pointer_chk_guard_local(%rip), reg
|
2005-12-18 16:59:55 +00:00
|
|
|
# else
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_MANGLE(reg) asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
|
|
|
|
"rol $2*" LP_SIZE "+1, %0" \
|
2007-02-01 16:14:15 +00:00
|
|
|
: "=r" (reg) : "0" (reg))
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_DEMANGLE(reg) asm ("ror $2*" LP_SIZE "+1, %0\n" \
|
|
|
|
"xor __pointer_chk_guard_local(%%rip), %0" \
|
2005-12-18 21:09:20 +00:00
|
|
|
: "=r" (reg) : "0" (reg))
|
2005-12-18 16:59:55 +00:00
|
|
|
# endif
|
2005-12-18 06:58:22 +00:00
|
|
|
#else
|
2005-12-18 16:59:55 +00:00
|
|
|
# ifdef __ASSEMBLER__
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_MANGLE(reg) xor %fs:POINTER_GUARD, reg; \
|
|
|
|
rol $2*LP_SIZE+1, reg
|
|
|
|
# define PTR_DEMANGLE(reg) ror $2*LP_SIZE+1, reg; \
|
|
|
|
xor %fs:POINTER_GUARD, reg
|
2005-12-18 16:59:55 +00:00
|
|
|
# else
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_MANGLE(var) asm ("xor %%fs:%c2, %0\n" \
|
|
|
|
"rol $2*" LP_SIZE "+1, %0" \
|
2007-02-01 16:14:15 +00:00
|
|
|
: "=r" (var) \
|
|
|
|
: "0" (var), \
|
|
|
|
"i" (offsetof (tcbhead_t, \
|
|
|
|
pointer_guard)))
|
2012-05-14 22:16:27 +00:00
|
|
|
# define PTR_DEMANGLE(var) asm ("ror $2*" LP_SIZE "+1, %0\n" \
|
|
|
|
"xor %%fs:%c2, %0" \
|
2005-12-18 16:59:55 +00:00
|
|
|
: "=r" (var) \
|
|
|
|
: "0" (var), \
|
|
|
|
"i" (offsetof (tcbhead_t, \
|
|
|
|
pointer_guard)))
|
|
|
|
# endif
|
2005-12-18 06:58:22 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-11 22:32:10 +00:00
|
|
|
/* How to pass the off{64}_t argument on p{readv,writev}{64}. */
|
|
|
|
#undef LO_HI_LONG
|
x86-64: Update LO_HI_LONG for p{readv,writev}{64}v2
The kernel interface for p{readv,writev}{64}v is
(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
unsigned long pos_l, unsigned long pos_h)
Except for targets which define __ARCH_WANT_COMPAT_SYS_PREADV64 and
__ARCH_WANT_COMPAT_SYS_PWRITEV64,
(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
off64_t pos)
is used for p{readv,writev}{64}v. X32 is the only such target. The
LO_HI_LONG macro is used to pass offset to the pos_l and pos_h pair.
Since pos_h is ignored when size of offset == sizeof of pos_l, x86-64
has
#define LO_HI_LONG(val) (val)
But the kernel interface for p{readv,writev}{64}v2 is
(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
unsigned long pos_l, unsigned long pos_h, int flags)
Except for targets which define __ARCH_WANT_COMPAT_SYS_PREADV64V2 and
__ARCH_WANT_COMPAT_SYS_PWRITEV64V2,
(unsigned long fd, {const }struct iovec *iov, unsigned long vlen,
off64_t pos, int flags)
is used for p{readv,writev}{64}v2. X32 is the only such target. Update
x86-64 LO_HI_LONG to pass 0 as the high part of the offset argument for
p{readv,writev}{64}v2 and define a different LO_HI_LONG for x32 to only
pass one argument for offset.
Tested on x32 and x86-64.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (LO_HI_LONG): Pass
0 as the high part of offset.
* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (LO_HI_LONG): New.
2017-06-05 14:21:44 +00:00
|
|
|
#define LO_HI_LONG(val) (val), 0
|
2016-07-11 22:32:10 +00:00
|
|
|
|
x86-64/CET: Extend ucontext_t to save shadow stack
This patch adds a field to ucontext_t to save shadow stack:
1. getcontext and swapcontext are updated to save the caller's shadow
stack pointer and return addresses.
2. setcontext and swapcontext are updated to restore shadow stack and
jump to new context directly.
3. makecontext is updated to allocate a new shadow stack and set the
caller's return address to __start_context.
Since makecontext allocates a new shadow stack when making a new
context and kernel allocates a new shadow stack for clone/fork/vfork
syscalls, we track the current shadow stack base. In setcontext and
swapcontext, if the target shadow stack base is the same as the current
shadow stack base, we unwind the shadow stack. Otherwise it is a stack
switch and we look for a restore token.
We enable shadow stack at run-time only if program and all used shared
objects, including dlopened ones, are shadow stack enabled, which means
that they must be compiled with GCC 8 or above and glibc 2.28 or above.
We need to save and restore shadow stack only if shadow stack is enabled.
When caller of getcontext, setcontext, swapcontext and makecontext is
compiled with smaller ucontext_t, shadow stack won't be enabled at
run-time. We check if shadow stack is enabled before accessing the
extended field in ucontext_t.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* sysdeps/unix/sysv/linux/x86/sys/ucontext.h (ucontext_t): Add
__ssp.
* sysdeps/unix/sysv/linux/x86_64/__start_context.S: Include
<asm/prctl.h> and "ucontext_i.h" when shadow stack is enabled.
(__push___start_context): New.
* sysdeps/unix/sysv/linux/x86_64/getcontext.S: Include
<asm/prctl.h>.
(__getcontext): Record the current shadow stack base. Save the
caller's shadow stack pointer and base.
* sysdeps/unix/sysv/linux/x86_64/makecontext.c: Include
<pthread.h>, <libc-pointer-arith.h> and <sys/prctl.h>.
(__push___start_context): New prototype.
(__makecontext): Call __push___start_context to allocate a new
shadow stack, push __start_context onto the new stack as well
as the new shadow stack.
* sysdeps/unix/sysv/linux/x86_64/setcontext.S: Include
<asm/prctl.h>.
(__setcontext): Restore the target shadow stack.
* sysdeps/unix/sysv/linux/x86_64/swapcontext.S: Include
<asm/prctl.h>.
(__swapcontext): Record the current shadow stack base. Save
the caller's shadow stack pointer and base. Restore the target
shadow stack.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h
(STACK_SIZE_TO_SHADOW_STACK_SIZE_SHIFT): New.
* sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym (oSSP): New.
2018-07-25 13:37:14 +00:00
|
|
|
/* Each shadow stack slot takes 8 bytes. Assuming that each stack
|
|
|
|
frame takes 256 bytes, this is used to compute shadow stack size
|
|
|
|
from stack size. */
|
|
|
|
#define STACK_SIZE_TO_SHADOW_STACK_SIZE_SHIFT 5
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
#endif /* linux/x86_64/sysdep.h */
|