sched_getcpu.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. callq *%rax
  32. #else
  33. # ifdef __NR_getcpu
  34. movl $__NR_getcpu, %eax
  35. syscall
  36. # ifndef __ASSUME_GETCPU_SYSCALL
  37. cmpq $-ENOSYS, %rax
  38. jne 1f
  39. # endif
  40. # endif
  41. # ifndef __ASSUME_GETCPU_SYSCALL
  42. movq $VSYSCALL_ADDR_vgetcpu, %rax
  43. callq *%rax
  44. 1:
  45. # else
  46. # ifndef __NR_getcpu
  47. # error "cannot happen"
  48. # endif
  49. # endif
  50. #endif
  51. cmpq $-4095, %rax
  52. jae SYSCALL_ERROR_LABEL
  53. movl (%rsp), %eax
  54. L(pseudo_end):
  55. add $0x8, %rsp
  56. cfi_adjust_cfa_offset(-8)
  57. ret
  58. PSEUDO_END(sched_getcpu)