hjl / source-git / glibc

Forked from source-git/glibc 4 years ago
Clone

Blame sysdeps/unix/sysv/linux/aarch64/sysdep.h

Packit 6c4009
/* Copyright (C) 2005-2018 Free Software Foundation, Inc.
Packit 6c4009
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public License as
Packit 6c4009
   published by the Free Software Foundation; either version 2.1 of the
Packit 6c4009
   License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _LINUX_AARCH64_SYSDEP_H
Packit 6c4009
#define _LINUX_AARCH64_SYSDEP_H 1
Packit 6c4009
Packit 6c4009
#include <sysdeps/unix/sysdep.h>
Packit 6c4009
#include <sysdeps/aarch64/sysdep.h>
Packit 6c4009
#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
Packit 6c4009
Packit 6c4009
/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO.  */
Packit 6c4009
#include <dl-sysdep.h>
Packit 6c4009
Packit 6c4009
#include <tls.h>
Packit 6c4009
Packit 6c4009
/* In order to get __set_errno() definition in INLINE_SYSCALL.  */
Packit 6c4009
#ifndef __ASSEMBLER__
Packit 6c4009
#include <errno.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* For Linux we can use the system call table in the header file
Packit 6c4009
	/usr/include/asm/unistd.h
Packit 6c4009
   of the kernel.  But these symbols do not follow the SYS_* syntax
Packit 6c4009
   so we have to redefine the `SYS_ify' macro here.  */
Packit 6c4009
#undef SYS_ify
Packit 6c4009
#define SYS_ify(syscall_name)	(__NR_##syscall_name)
Packit 6c4009
Packit 6c4009
#ifdef __ASSEMBLER__
Packit 6c4009
Packit 6c4009
/* Linux uses a negative return value to indicate syscall errors,
Packit 6c4009
   unlike most Unices, which use the condition codes' carry flag.
Packit 6c4009
Packit 6c4009
   Since version 2.1 the return value of a system call might be
Packit 6c4009
   negative even if the call succeeded.  E.g., the `lseek' system call
Packit 6c4009
   might return a large offset.  Therefore we must not anymore test
Packit 6c4009
   for < 0, but test for a real error by making sure the value in R0
Packit 6c4009
   is a real error number.  Linus said he will make sure the no syscall
Packit 6c4009
   returns a value in -1 .. -4095 as a valid result so we can safely
Packit 6c4009
   test with -4095.  */
Packit 6c4009
Packit 6c4009
# undef	PSEUDO
Packit 6c4009
# define PSEUDO(name, syscall_name, args)				      \
Packit 6c4009
  .text;								      \
Packit 6c4009
  ENTRY (name);								      \
Packit 6c4009
    DO_CALL (syscall_name, args);					      \
Packit 6c4009
    cmn x0, #4095;							      \
Packit 6c4009
    b.cs .Lsyscall_error;
Packit 6c4009
Packit 6c4009
# undef	PSEUDO_END
Packit 6c4009
# define PSEUDO_END(name)						      \
Packit 6c4009
  SYSCALL_ERROR_HANDLER							      \
Packit 6c4009
  END (name)
Packit 6c4009
Packit 6c4009
# undef	PSEUDO_NOERRNO
Packit 6c4009
# define PSEUDO_NOERRNO(name, syscall_name, args)			      \
Packit 6c4009
  .text;								      \
Packit 6c4009
  ENTRY (name);								      \
Packit 6c4009
    DO_CALL (syscall_name, args);
Packit 6c4009
Packit 6c4009
# undef	PSEUDO_END_NOERRNO
Packit 6c4009
# define PSEUDO_END_NOERRNO(name)					      \
Packit 6c4009
  END (name)
Packit 6c4009
Packit 6c4009
# define ret_NOERRNO ret
Packit 6c4009
Packit 6c4009
/* The function has to return the error code.  */
Packit 6c4009
# undef	PSEUDO_ERRVAL
Packit 6c4009
# define PSEUDO_ERRVAL(name, syscall_name, args) \
Packit 6c4009
  .text;								      \
Packit 6c4009
  ENTRY (name)								      \
Packit 6c4009
    DO_CALL (syscall_name, args);					      \
Packit 6c4009
    neg x0, x0
Packit 6c4009
Packit 6c4009
# undef	PSEUDO_END_ERRVAL
Packit 6c4009
# define PSEUDO_END_ERRVAL(name) \
Packit 6c4009
  END (name)
Packit 6c4009
Packit 6c4009
# define ret_ERRVAL ret
Packit 6c4009
Packit 6c4009
# if !IS_IN (libc)
Packit 6c4009
#  define SYSCALL_ERROR  .Lsyscall_error
Packit 6c4009
#  if RTLD_PRIVATE_ERRNO
Packit 6c4009
#   define SYSCALL_ERROR_HANDLER				\
Packit 6c4009
.Lsyscall_error:						\
Packit 6c4009
	adrp	x1, C_SYMBOL_NAME(rtld_errno);			\
Packit 6c4009
	neg     w0, w0;						\
Packit 6c4009
	str     w0, [x1, :lo12:C_SYMBOL_NAME(rtld_errno)];	\
Packit 6c4009
	mov	x0, -1;						\
Packit 6c4009
	RET;
Packit 6c4009
#  else
Packit 6c4009
Packit 6c4009
#   define SYSCALL_ERROR_HANDLER				\
Packit 6c4009
.Lsyscall_error:						\
Packit 6c4009
	adrp	x1, :gottprel:errno;				\
Packit 6c4009
	neg	w2, w0;						\
Packit 6c4009
	ldr	PTR_REG(1), [x1, :gottprel_lo12:errno];		\
Packit 6c4009
	mrs	x3, tpidr_el0;					\
Packit 6c4009
	mov	x0, -1;						\
Packit 6c4009
	str	w2, [x1, x3];					\
Packit 6c4009
	RET;
Packit 6c4009
#  endif
Packit 6c4009
# else
Packit 6c4009
#  define SYSCALL_ERROR __syscall_error
Packit 6c4009
#  define SYSCALL_ERROR_HANDLER                                 \
Packit 6c4009
.Lsyscall_error:                                                \
Packit 6c4009
	b	__syscall_error;
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
/* Linux takes system call args in registers:
Packit 6c4009
	syscall number	x8
Packit 6c4009
	arg 1		x0
Packit 6c4009
	arg 2		x1
Packit 6c4009
	arg 3		x2
Packit 6c4009
	arg 4		x3
Packit 6c4009
	arg 5		x4
Packit 6c4009
	arg 6		x5
Packit 6c4009
	arg 7		x6
Packit 6c4009
Packit 6c4009
   The compiler is going to form a call by coming here, through PSEUDO, with
Packit 6c4009
   arguments
Packit 6c4009
	syscall number	in the DO_CALL macro
Packit 6c4009
	arg 1		x0
Packit 6c4009
	arg 2		x1
Packit 6c4009
	arg 3		x2
Packit 6c4009
	arg 4		x3
Packit 6c4009
	arg 5		x4
Packit 6c4009
	arg 6		x5
Packit 6c4009
	arg 7		x6
Packit 6c4009
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
# undef	DO_CALL
Packit 6c4009
# define DO_CALL(syscall_name, args)		\
Packit 6c4009
    mov x8, SYS_ify (syscall_name);		\
Packit 6c4009
    svc 0
Packit 6c4009
Packit 6c4009
#else /* not __ASSEMBLER__ */
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* List of system calls which are supported as vsyscalls.  */
Packit 6c4009
# define HAVE_CLOCK_GETRES_VSYSCALL	1
Packit 6c4009
# define HAVE_CLOCK_GETTIME_VSYSCALL	1
Packit 6c4009
# define HAVE_GETTIMEOFDAY_VSYSCALL	1
Packit 6c4009
Packit 6c4009
/* Previously AArch64 used the generic version without the libc_hidden_def
Packit 6c4009
   which lead in a non existent __send symbol in libc.so.  */
Packit 6c4009
# undef HAVE_INTERNAL_SEND_SYMBOL
Packit 6c4009
Packit 6c4009
# define SINGLE_THREAD_BY_GLOBAL		1
Packit 6c4009
Packit 6c4009
/* Define a macro which expands into the inline wrapper code for a system
Packit 6c4009
   call.  */
Packit 6c4009
# undef INLINE_SYSCALL
Packit 6c4009
# define INLINE_SYSCALL(name, nr, args...)				\
Packit 6c4009
  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);	\
Packit 6c4009
     if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
Packit 6c4009
       {								\
Packit 6c4009
	 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));		\
Packit 6c4009
	 _sys_result = (unsigned long) -1;				\
Packit 6c4009
       }								\
Packit 6c4009
     (long) _sys_result; })
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_DECL
Packit 6c4009
# define INTERNAL_SYSCALL_DECL(err) do { } while (0)
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_RAW
Packit 6c4009
# define INTERNAL_SYSCALL_RAW(name, err, nr, args...)		\
Packit 6c4009
  ({ long _sys_result;						\
Packit 6c4009
     {								\
Packit 6c4009
       LOAD_ARGS_##nr (args)					\
Packit 6c4009
       register long _x8 asm ("x8") = (name);			\
Packit 6c4009
       asm volatile ("svc	0	// syscall " # name     \
Packit 6c4009
		     : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory");	\
Packit 6c4009
       _sys_result = _x0;					\
Packit 6c4009
     }								\
Packit 6c4009
     _sys_result; })
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL
Packit 6c4009
# define INTERNAL_SYSCALL(name, err, nr, args...)		\
Packit 6c4009
	INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_AARCH64
Packit 6c4009
# define INTERNAL_SYSCALL_AARCH64(name, err, nr, args...)	\
Packit 6c4009
	INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_ERROR_P
Packit 6c4009
# define INTERNAL_SYSCALL_ERROR_P(val, err) \
Packit 6c4009
  ((unsigned long) (val) >= (unsigned long) -4095)
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_ERRNO
Packit 6c4009
# define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
Packit 6c4009
Packit 6c4009
# define LOAD_ARGS_0()				\
Packit 6c4009
  register long _x0 asm ("x0");
Packit 6c4009
# define LOAD_ARGS_1(x0)			\
Packit 6c4009
  long _x0tmp = (long) (x0);			\
Packit 6c4009
  LOAD_ARGS_0 ()				\
Packit 6c4009
  _x0 = _x0tmp;
Packit 6c4009
# define LOAD_ARGS_2(x0, x1)			\
Packit 6c4009
  long _x1tmp = (long) (x1);			\
Packit 6c4009
  LOAD_ARGS_1 (x0)				\
Packit 6c4009
  register long _x1 asm ("x1") = _x1tmp;
Packit 6c4009
# define LOAD_ARGS_3(x0, x1, x2)		\
Packit 6c4009
  long _x2tmp = (long) (x2);			\
Packit 6c4009
  LOAD_ARGS_2 (x0, x1)				\
Packit 6c4009
  register long _x2 asm ("x2") = _x2tmp;
Packit 6c4009
# define LOAD_ARGS_4(x0, x1, x2, x3)		\
Packit 6c4009
  long _x3tmp = (long) (x3);			\
Packit 6c4009
  LOAD_ARGS_3 (x0, x1, x2)			\
Packit 6c4009
  register long _x3 asm ("x3") = _x3tmp;
Packit 6c4009
# define LOAD_ARGS_5(x0, x1, x2, x3, x4)	\
Packit 6c4009
  long _x4tmp = (long) (x4);			\
Packit 6c4009
  LOAD_ARGS_4 (x0, x1, x2, x3)			\
Packit 6c4009
  register long _x4 asm ("x4") = _x4tmp;
Packit 6c4009
# define LOAD_ARGS_6(x0, x1, x2, x3, x4, x5)	\
Packit 6c4009
  long _x5tmp = (long) (x5);			\
Packit 6c4009
  LOAD_ARGS_5 (x0, x1, x2, x3, x4)		\
Packit 6c4009
  register long _x5 asm ("x5") = _x5tmp;
Packit 6c4009
# define LOAD_ARGS_7(x0, x1, x2, x3, x4, x5, x6)\
Packit 6c4009
  long _x6tmp = (long) (x6);			\
Packit 6c4009
  LOAD_ARGS_6 (x0, x1, x2, x3, x4, x5)		\
Packit 6c4009
  register long _x6 asm ("x6") = _x6tmp;
Packit 6c4009
Packit 6c4009
# define ASM_ARGS_0
Packit 6c4009
# define ASM_ARGS_1	, "r" (_x0)
Packit 6c4009
# define ASM_ARGS_2	ASM_ARGS_1, "r" (_x1)
Packit 6c4009
# define ASM_ARGS_3	ASM_ARGS_2, "r" (_x2)
Packit 6c4009
# define ASM_ARGS_4	ASM_ARGS_3, "r" (_x3)
Packit 6c4009
# define ASM_ARGS_5	ASM_ARGS_4, "r" (_x4)
Packit 6c4009
# define ASM_ARGS_6	ASM_ARGS_5, "r" (_x5)
Packit 6c4009
# define ASM_ARGS_7	ASM_ARGS_6, "r" (_x6)
Packit 6c4009
Packit 6c4009
# undef INTERNAL_SYSCALL_NCS
Packit 6c4009
# define INTERNAL_SYSCALL_NCS(number, err, nr, args...)	\
Packit 6c4009
	INTERNAL_SYSCALL_RAW (number, err, nr, args)
Packit 6c4009
Packit 6c4009
#endif	/* __ASSEMBLER__ */
Packit 6c4009
Packit 6c4009
/* Pointer mangling is supported for AArch64.  */
Packit 6c4009
#if (IS_IN (rtld) || \
Packit 6c4009
     (!defined SHARED && (IS_IN (libc) \
Packit 6c4009
			  || IS_IN (libpthread))))
Packit 6c4009
# ifdef __ASSEMBLER__
Packit 6c4009
/* Note, dst, src, guard, and tmp are all register numbers rather than
Packit 6c4009
   register names so they will work with both ILP32 and LP64. */
Packit 6c4009
#  define PTR_MANGLE(dst, src, guard, tmp)                                \
Packit 6c4009
  LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \
Packit 6c4009
  PTR_MANGLE2 (dst, src, guard)
Packit 6c4009
/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
Packit 6c4009
#  define PTR_MANGLE2(dst, src, guard)\
Packit 6c4009
  eor x##dst, x##src, x##guard
Packit 6c4009
#  define PTR_DEMANGLE(dst, src, guard, tmp)\
Packit 6c4009
  PTR_MANGLE (dst, src, guard, tmp)
Packit 6c4009
#  define PTR_DEMANGLE2(dst, src, guard)\
Packit 6c4009
  PTR_MANGLE2 (dst, src, guard)
Packit 6c4009
# else
Packit 6c4009
extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
Packit 6c4009
#  define PTR_MANGLE(var) \
Packit 6c4009
  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
Packit 6c4009
#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
Packit 6c4009
# endif
Packit 6c4009
#else
Packit 6c4009
# ifdef __ASSEMBLER__
Packit 6c4009
/* Note, dst, src, guard, and tmp are all register numbers rather than
Packit 6c4009
   register names so they will work with both ILP32 and LP64. */
Packit 6c4009
#  define PTR_MANGLE(dst, src, guard, tmp)                             \
Packit 6c4009
  LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard));   \
Packit 6c4009
  PTR_MANGLE2 (dst, src, guard)
Packit 6c4009
/* Use PTR_MANGLE2 for efficiency if guard is already loaded.  */
Packit 6c4009
#  define PTR_MANGLE2(dst, src, guard)\
Packit 6c4009
  eor x##dst, x##src, x##guard
Packit 6c4009
#  define PTR_DEMANGLE(dst, src, guard, tmp)\
Packit 6c4009
  PTR_MANGLE (dst, src, guard, tmp)
Packit 6c4009
#  define PTR_DEMANGLE2(dst, src, guard)\
Packit 6c4009
  PTR_MANGLE2 (dst, src, guard)
Packit 6c4009
# else
Packit 6c4009
extern uintptr_t __pointer_chk_guard attribute_relro;
Packit 6c4009
#  define PTR_MANGLE(var) \
Packit 6c4009
  (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
Packit 6c4009
#  define PTR_DEMANGLE(var) PTR_MANGLE (var)
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#endif /* linux/aarch64/sysdep.h */