sched_getcpu.S 1.6 KB

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