sanitizer_syscall_linux_x86_64.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //===-- sanitizer_syscall_linux_x86_64.inc ----------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // Implementations of internal_syscall and internal_iserror for Linux/x86_64.
  9. //
  10. //===----------------------------------------------------------------------===//
  11. #define SYSCALL(name) __NR_ ## name
  12. static uptr internal_syscall(u64 nr) {
  13. u64 retval;
  14. asm volatile("syscall" : "=a"(retval) : "a"(nr) : "rcx", "r11",
  15. "memory", "cc");
  16. return retval;
  17. }
  18. template <typename T1>
  19. static uptr internal_syscall(u64 nr, T1 arg1) {
  20. u64 retval;
  21. asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1) :
  22. "rcx", "r11", "memory", "cc");
  23. return retval;
  24. }
  25. template <typename T1, typename T2>
  26. static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2) {
  27. u64 retval;
  28. asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
  29. "S"((u64)arg2) : "rcx", "r11", "memory", "cc");
  30. return retval;
  31. }
  32. template <typename T1, typename T2, typename T3>
  33. static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3) {
  34. u64 retval;
  35. asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
  36. "S"((u64)arg2), "d"((u64)arg3) : "rcx", "r11", "memory", "cc");
  37. return retval;
  38. }
  39. template <typename T1, typename T2, typename T3, typename T4>
  40. static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
  41. u64 retval;
  42. asm volatile("mov %5, %%r10;"
  43. "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
  44. "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4) :
  45. "rcx", "r11", "r10", "memory", "cc");
  46. return retval;
  47. }
  48. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  49. static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
  50. T5 arg5) {
  51. u64 retval;
  52. asm volatile("mov %5, %%r10;"
  53. "mov %6, %%r8;"
  54. "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
  55. "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5) :
  56. "rcx", "r11", "r10", "r8", "memory", "cc");
  57. return retval;
  58. }
  59. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  60. typename T6>
  61. static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
  62. T5 arg5, T6 arg6) {
  63. u64 retval;
  64. asm volatile("mov %5, %%r10;"
  65. "mov %6, %%r8;"
  66. "mov %7, %%r9;"
  67. "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
  68. "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5),
  69. "r"((u64)arg6) : "rcx", "r11", "r10", "r8", "r9",
  70. "memory", "cc");
  71. return retval;
  72. }
  73. bool internal_iserror(uptr retval, int *rverrno) {
  74. if (retval >= (uptr)-4095) {
  75. if (rverrno)
  76. *rverrno = -retval;
  77. return true;
  78. }
  79. return false;
  80. }