Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / sched_getcpu.S
blob0fd47f2ac0879e9783163cd9e7c9bfe8071a8edc
1 /* Copyright (C) 2007-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <tls.h>
20 #define _ERRNO_H        1
21 #include <bits/errno.h>
22 #include <kernel-features.h>
24 /* For the calculation see asm/vsyscall.h.  */
25 #define VSYSCALL_ADDR_vgetcpu   0xffffffffff600800
28 ENTRY (sched_getcpu)
29         /* Align stack and create local variable for result.  */
30         sub     $0x8, %rsp
31         cfi_adjust_cfa_offset(8)
33         movq    %rsp, %rdi
34         xorl    %esi, %esi
35         movl    $VGETCPU_CACHE_OFFSET, %edx
36         addq    %fs:0, %rdx
38 #ifdef SHARED
39         movq    __vdso_getcpu(%rip), %rax
40         PTR_DEMANGLE (%rax)
41         callq   *%rax
42 #else
43 # ifdef __NR_getcpu
44         movl    $__NR_getcpu, %eax
45         syscall
46 #  ifndef __ASSUME_GETCPU_SYSCALL
47         cmpq    $-ENOSYS, %rax
48         jne     1f
49 #  endif
50 # endif
51 # ifndef __ASSUME_GETCPU_SYSCALL
52         movq    $VSYSCALL_ADDR_vgetcpu, %rax
53         callq   *%rax
55 # else
56 #  ifndef __NR_getcpu
57 #   error "cannot happen"
58 #  endif
59 # endif
60 #endif
62         /* Local variable is result if the call is successful.  */
63         movl    (%rsp), %edx
64         /* Restore stack pointer before we might jump to
65         SYSCALL_ERROR_LABEL which returns to the caller.  */
66         add     $0x8, %rsp
67         cfi_adjust_cfa_offset(-8)
69         cmpq    $-4095, %rax
70         jae     SYSCALL_ERROR_LABEL
72         movl    %edx, %eax
73         ret
74 PSEUDO_END(sched_getcpu)