2017-01-01 00:14:16 +00:00
|
|
|
/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
|
2012-11-09 17:53:51 +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
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <tls.h>
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
# include <nptl/pthreadP.h>
|
|
|
|
#endif
|
|
|
|
|
2014-11-24 09:33:45 +00:00
|
|
|
#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
|
2012-11-09 17:53:51 +00:00
|
|
|
|
|
|
|
# undef PSEUDO
|
|
|
|
# define PSEUDO(name, syscall_name, args) \
|
2014-05-25 17:00:00 +00:00
|
|
|
.section ".text"; \
|
2014-05-25 18:07:17 +00:00
|
|
|
ENTRY (__##syscall_name##_nocancel); \
|
|
|
|
.Lpseudo_nocancel: \
|
2014-05-25 17:00:00 +00:00
|
|
|
DO_CALL (syscall_name, args); \
|
2014-05-25 18:07:17 +00:00
|
|
|
.Lpseudo_finish: \
|
2014-05-25 17:00:00 +00:00
|
|
|
cmn x0, 4095; \
|
|
|
|
b.cs .Lsyscall_error; \
|
2014-05-25 18:07:17 +00:00
|
|
|
.subsection 2; \
|
2014-05-25 17:00:00 +00:00
|
|
|
.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
|
|
|
|
ENTRY (name); \
|
2014-05-25 18:15:14 +00:00
|
|
|
SINGLE_THREAD_P(16); \
|
|
|
|
cbz w16, .Lpseudo_nocancel; \
|
2014-05-25 18:57:53 +00:00
|
|
|
/* Setup common stack frame no matter the number of args. \
|
|
|
|
Also save the first arg, since it's basically free. */ \
|
|
|
|
stp x30, x0, [sp, -64]!; \
|
|
|
|
cfi_adjust_cfa_offset (64); \
|
|
|
|
cfi_rel_offset (x30, 0); \
|
|
|
|
DOCARGS_##args; /* save syscall args around CENABLE. */ \
|
2014-05-25 17:00:00 +00:00
|
|
|
CENABLE; \
|
2014-05-25 18:57:53 +00:00
|
|
|
mov x16, x0; /* save mask around syscall. */ \
|
2014-05-25 17:00:00 +00:00
|
|
|
UNDOCARGS_##args; /* restore syscall args. */ \
|
2014-05-25 18:57:53 +00:00
|
|
|
DO_CALL (syscall_name, args); \
|
|
|
|
str x0, [sp, 8]; /* save result around CDISABLE. */ \
|
|
|
|
mov x0, x16; /* restore mask for CDISABLE. */ \
|
2014-05-25 17:00:00 +00:00
|
|
|
CDISABLE; \
|
2014-05-25 18:57:53 +00:00
|
|
|
/* Break down the stack frame, restoring result at once. */ \
|
|
|
|
ldp x30, x0, [sp], 64; \
|
|
|
|
cfi_adjust_cfa_offset (-64); \
|
2014-05-25 17:00:00 +00:00
|
|
|
cfi_restore (x30); \
|
2014-05-25 18:07:17 +00:00
|
|
|
b .Lpseudo_finish; \
|
|
|
|
cfi_endproc; \
|
|
|
|
.size name, .-name; \
|
|
|
|
.previous
|
|
|
|
|
|
|
|
# undef PSEUDO_END
|
|
|
|
# define PSEUDO_END(name) \
|
|
|
|
SYSCALL_ERROR_HANDLER; \
|
|
|
|
cfi_endproc
|
2012-11-09 17:53:51 +00:00
|
|
|
|
2014-05-25 18:57:53 +00:00
|
|
|
# define DOCARGS_0
|
|
|
|
# define DOCARGS_1
|
|
|
|
# define DOCARGS_2 str x1, [sp, 16]
|
|
|
|
# define DOCARGS_3 stp x1, x2, [sp, 16]
|
|
|
|
# define DOCARGS_4 DOCARGS_3; str x3, [sp, 32]
|
|
|
|
# define DOCARGS_5 DOCARGS_3; stp x3, x4, [sp, 32]
|
|
|
|
# define DOCARGS_6 DOCARGS_5; str x5, [sp, 48]
|
2012-11-09 17:53:51 +00:00
|
|
|
|
|
|
|
# define UNDOCARGS_0
|
2014-05-25 18:57:53 +00:00
|
|
|
# define UNDOCARGS_1 ldr x0, [sp, 8]
|
|
|
|
# define UNDOCARGS_2 ldp x0, x1, [sp, 8]
|
|
|
|
# define UNDOCARGS_3 UNDOCARGS_1; ldp x1, x2, [sp, 16]
|
|
|
|
# define UNDOCARGS_4 UNDOCARGS_2; ldp x2, x3, [sp, 24]
|
|
|
|
# define UNDOCARGS_5 UNDOCARGS_3; ldp x3, x4, [sp, 32]
|
|
|
|
# define UNDOCARGS_6 UNDOCARGS_4; ldp x4, x5, [sp, 40]
|
2012-11-09 17:53:51 +00:00
|
|
|
|
2014-11-20 08:52:40 +00:00
|
|
|
# if IS_IN (libpthread)
|
2012-11-09 17:53:51 +00:00
|
|
|
# define CENABLE bl __pthread_enable_asynccancel
|
|
|
|
# define CDISABLE bl __pthread_disable_asynccancel
|
|
|
|
# define __local_multiple_threads __pthread_multiple_threads
|
2014-11-24 09:33:45 +00:00
|
|
|
# elif IS_IN (libc)
|
2012-11-09 17:53:51 +00:00
|
|
|
# define CENABLE bl __libc_enable_asynccancel
|
|
|
|
# define CDISABLE bl __libc_disable_asynccancel
|
|
|
|
# define __local_multiple_threads __libc_multiple_threads
|
2014-11-20 07:56:25 +00:00
|
|
|
# elif IS_IN (librt)
|
2012-11-09 17:53:51 +00:00
|
|
|
# define CENABLE bl __librt_enable_asynccancel
|
|
|
|
# define CDISABLE bl __librt_disable_asynccancel
|
|
|
|
# else
|
|
|
|
# error Unsupported library
|
|
|
|
# endif
|
|
|
|
|
2014-11-24 09:33:45 +00:00
|
|
|
# if IS_IN (libpthread) || IS_IN (libc)
|
2012-11-09 17:53:51 +00:00
|
|
|
# ifndef __ASSEMBLER__
|
|
|
|
extern int __local_multiple_threads attribute_hidden;
|
|
|
|
# define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
|
|
|
|
# else
|
2014-05-25 18:15:14 +00:00
|
|
|
# define SINGLE_THREAD_P(R) \
|
|
|
|
adrp x##R, __local_multiple_threads; \
|
|
|
|
ldr w##R, [x##R, :lo12:__local_multiple_threads]
|
2012-11-09 17:53:51 +00:00
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
/* There is no __local_multiple_threads for librt, so use the TCB. */
|
|
|
|
# ifndef __ASSEMBLER__
|
|
|
|
# define SINGLE_THREAD_P \
|
|
|
|
__builtin_expect (THREAD_GETMEM (THREAD_SELF, \
|
|
|
|
header.multiple_threads) == 0, 1)
|
|
|
|
# else
|
2014-05-25 18:15:14 +00:00
|
|
|
# define SINGLE_THREAD_P(R) \
|
2014-05-20 20:17:20 +00:00
|
|
|
mrs x##R, tpidr_el0; \
|
|
|
|
sub x##R, x##R, PTHREAD_SIZEOF; \
|
|
|
|
ldr w##R, [x##R, PTHREAD_MULTIPLE_THREADS_OFFSET]
|
2012-11-09 17:53:51 +00:00
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#elif !defined __ASSEMBLER__
|
|
|
|
|
|
|
|
/* For rtld, et cetera. */
|
|
|
|
# define SINGLE_THREAD_P 1
|
|
|
|
# define NO_CANCELLATION 1
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
# define RTLD_SINGLE_THREAD_P \
|
|
|
|
__builtin_expect (THREAD_GETMEM (THREAD_SELF, \
|
|
|
|
header.multiple_threads) == 0, 1)
|
|
|
|
#endif
|