Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / sched_getcpu.S
blob4c3cebe88e758f18e2815afed04530c5cc6b5f8c
1 /* Copyright (C) 2007, 2011 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         cmpq    $-4095, %rax
63         jae     SYSCALL_ERROR_LABEL
65         movl    (%rsp), %eax
67 L(pseudo_end):
68         add     $0x8, %rsp
69         cfi_adjust_cfa_offset(-8)
70         ret
71 PSEUDO_END(sched_getcpu)