sched_getcpu.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include <tls.h>
  16. #define _ERRNO_H 1
  17. #include <bits/errno.h>
  18. #include <bits/kernel-features.h>
  19. /* For the calculation see asm/vsyscall.h. */
  20. #define VSYSCALL_ADDR_vgetcpu 0xffffffffff600800
  21. ENTRY (sched_getcpu)
  22. /* Align stack and create local variable for result. */
  23. sub $0x8, %rsp
  24. cfi_adjust_cfa_offset(8)
  25. movq %rsp, %rdi
  26. xorl %esi, %esi
  27. movl $VGETCPU_CACHE_OFFSET, %edx
  28. addq %fs:0, %rdx
  29. #ifdef SHARED
  30. movq __vdso_getcpu(%rip), %rax
  31. PTR_DEMANGLE (%rax)
  32. callq *%rax
  33. #else
  34. # ifdef __NR_getcpu
  35. movl $__NR_getcpu, %eax
  36. syscall
  37. # ifndef __ASSUME_GETCPU_SYSCALL
  38. cmpq $-ENOSYS, %rax
  39. jne 1f
  40. # endif
  41. # endif
  42. # ifndef __ASSUME_GETCPU_SYSCALL
  43. movq $VSYSCALL_ADDR_vgetcpu, %rax
  44. callq *%rax
  45. 1:
  46. # else
  47. # ifndef __NR_getcpu
  48. # error "cannot happen"
  49. # endif
  50. # endif
  51. #endif
  52. cmpq $-4095, %rax
  53. jae SYSCALL_ERROR_LABEL
  54. movl (%rsp), %eax
  55. L(pseudo_end):
  56. add $0x8, %rsp
  57. cfi_adjust_cfa_offset(-8)
  58. ret
  59. PSEUDO_END(sched_getcpu)