hwasan_setjmp_riscv64.S 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===-- hwasan_setjmp_riscv64.S -------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of HWAddressSanitizer.
  10. // setjmp interceptor for risc-v.
  11. // HWAddressSanitizer runtime.
  12. //===----------------------------------------------------------------------===//
  13. #include "sanitizer_common/sanitizer_asm.h"
  14. #include "builtins/assembly.h"
  15. #if HWASAN_WITH_INTERCEPTORS && defined(__riscv) && (__riscv_xlen == 64)
  16. #include "sanitizer_common/sanitizer_platform.h"
  17. // We want to save the context of the calling function.
  18. // That requires
  19. // 1) No modification of the link register by this function.
  20. // 2) No modification of the stack pointer by this function.
  21. // 3) (no modification of any other saved register, but that's not really going
  22. // to occur, and hence isn't as much of a worry).
  23. //
  24. // There's essentially no way to ensure that the compiler will not modify the
  25. // stack pointer when compiling a C function.
  26. // Hence we have to write this function in assembly.
  27. .section .text
  28. .file "hwasan_setjmp_riscv64.S"
  29. .global __interceptor_setjmp
  30. ASM_TYPE_FUNCTION(__interceptor_setjmp)
  31. __interceptor_setjmp:
  32. CFI_STARTPROC
  33. addi x11, x0, 0
  34. tail __interceptor_sigsetjmp
  35. CFI_ENDPROC
  36. ASM_SIZE(__interceptor_setjmp)
  37. .global __interceptor_sigsetjmp
  38. ASM_TYPE_FUNCTION(__interceptor_sigsetjmp)
  39. __interceptor_sigsetjmp:
  40. CFI_STARTPROC
  41. sd ra, 0<<3(x10)
  42. sd s0, 1<<3(x10)
  43. sd s1, 2<<3(x10)
  44. sd s2, 3<<3(x10)
  45. sd s3, 4<<3(x10)
  46. sd s4, 5<<3(x10)
  47. sd s5, 6<<3(x10)
  48. sd s6, 7<<3(x10)
  49. sd s7, 8<<3(x10)
  50. sd s8, 9<<3(x10)
  51. sd s9, 10<<3(x10)
  52. sd s10, 11<<3(x10)
  53. sd s11, 12<<3(x10)
  54. sd sp, 13<<3(x10)
  55. #if __riscv_float_abi_double
  56. fsd fs0, 14<<3(x10)
  57. fsd fs1, 15<<3(x10)
  58. fsd fs2, 16<<3(x10)
  59. fsd fs3, 17<<3(x10)
  60. fsd fs4, 18<<3(x10)
  61. fsd fs5, 19<<3(x10)
  62. fsd fs6, 20<<3(x10)
  63. fsd fs7, 21<<3(x10)
  64. fsd fs8, 22<<3(x10)
  65. fsd fs9, 23<<3(x10)
  66. fsd fs10, 24<<3(x10)
  67. fsd fs11, 25<<3(x10)
  68. #elif __riscv_float_abi_soft
  69. #else
  70. # error "Unsupported case"
  71. #endif
  72. // We always have the second argument to __sigjmp_save (savemask) set, since
  73. // the _setjmp function above has set it for us as `false`.
  74. // This function is defined in hwasan_interceptors.cc
  75. tail __sigjmp_save
  76. CFI_ENDPROC
  77. ASM_SIZE(__interceptor_sigsetjmp)
  78. .macro WEAK_ALIAS first second
  79. .weak \second
  80. .equ \second\(), \first
  81. .endm
  82. WEAK_ALIAS __interceptor_sigsetjmp, __sigsetjmp
  83. WEAK_ALIAS __interceptor_setjmp, _setjmp
  84. #endif
  85. // We do not need executable stack.
  86. NO_EXEC_STACK_DIRECTIVE