sched_getcpu.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 2007, 2011 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <tls.h>
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. #include <bits/kernel-features.h>
  20. /* For the calculation see asm/vsyscall.h. */
  21. #define VSYSCALL_ADDR_vgetcpu 0xffffffffff600800
  22. ENTRY (sched_getcpu)
  23. /* Align stack and create local variable for result. */
  24. sub $0x8, %rsp
  25. cfi_adjust_cfa_offset(8)
  26. movq %rsp, %rdi
  27. xorl %esi, %esi
  28. movl $VGETCPU_CACHE_OFFSET, %edx
  29. addq %fs:0, %rdx
  30. #ifdef SHARED
  31. movq __vdso_getcpu(%rip), %rax
  32. PTR_DEMANGLE (%rax)
  33. callq *%rax
  34. #else
  35. # ifdef __NR_getcpu
  36. movl $__NR_getcpu, %eax
  37. syscall
  38. # ifndef __ASSUME_GETCPU_SYSCALL
  39. cmpq $-ENOSYS, %rax
  40. jne 1f
  41. # endif
  42. # endif
  43. # ifndef __ASSUME_GETCPU_SYSCALL
  44. movq $VSYSCALL_ADDR_vgetcpu, %rax
  45. callq *%rax
  46. 1:
  47. # else
  48. # ifndef __NR_getcpu
  49. # error "cannot happen"
  50. # endif
  51. # endif
  52. #endif
  53. cmpq $-4095, %rax
  54. jae SYSCALL_ERROR_LABEL
  55. movl (%rsp), %eax
  56. L(pseudo_end):
  57. add $0x8, %rsp
  58. cfi_adjust_cfa_offset(-8)
  59. ret
  60. PSEUDO_END(sched_getcpu)