hwasan_setjmp_aarch64.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //===-- hwasan_setjmp_aarch64.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. //
  11. // HWAddressSanitizer runtime.
  12. //===----------------------------------------------------------------------===//
  13. #include "sanitizer_common/sanitizer_asm.h"
  14. #include "builtins/assembly.h"
  15. #if HWASAN_WITH_INTERCEPTORS && defined(__aarch64__)
  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_aarch64.S"
  29. .global __interceptor_setjmp
  30. ASM_TYPE_FUNCTION(__interceptor_setjmp)
  31. __interceptor_setjmp:
  32. CFI_STARTPROC
  33. BTI_C
  34. mov x1, #0
  35. b __interceptor_sigsetjmp
  36. CFI_ENDPROC
  37. ASM_SIZE(__interceptor_setjmp)
  38. #if SANITIZER_ANDROID
  39. // Bionic also defines a function `setjmp` that calls `sigsetjmp` saving the
  40. // current signal.
  41. .global __interceptor_setjmp_bionic
  42. ASM_TYPE_FUNCTION(__interceptor_setjmp_bionic)
  43. __interceptor_setjmp_bionic:
  44. CFI_STARTPROC
  45. BTI_C
  46. mov x1, #1
  47. b __interceptor_sigsetjmp
  48. CFI_ENDPROC
  49. ASM_SIZE(__interceptor_setjmp_bionic)
  50. #endif
  51. .global __interceptor_sigsetjmp
  52. ASM_TYPE_FUNCTION(__interceptor_sigsetjmp)
  53. __interceptor_sigsetjmp:
  54. CFI_STARTPROC
  55. BTI_C
  56. stp x19, x20, [x0, #0<<3]
  57. stp x21, x22, [x0, #2<<3]
  58. stp x23, x24, [x0, #4<<3]
  59. stp x25, x26, [x0, #6<<3]
  60. stp x27, x28, [x0, #8<<3]
  61. stp x29, x30, [x0, #10<<3]
  62. stp d8, d9, [x0, #14<<3]
  63. stp d10, d11, [x0, #16<<3]
  64. stp d12, d13, [x0, #18<<3]
  65. stp d14, d15, [x0, #20<<3]
  66. mov x2, sp
  67. str x2, [x0, #13<<3]
  68. // We always have the second argument to __sigjmp_save (savemask) set, since
  69. // the _setjmp function above has set it for us as `false`.
  70. // This function is defined in hwasan_interceptors.cc
  71. b __sigjmp_save
  72. CFI_ENDPROC
  73. ASM_SIZE(__interceptor_sigsetjmp)
  74. .macro WEAK_ALIAS first second
  75. .weak \second
  76. .equ \second\(), \first
  77. .endm
  78. #if SANITIZER_ANDROID
  79. WEAK_ALIAS __interceptor_sigsetjmp, sigsetjmp
  80. WEAK_ALIAS __interceptor_setjmp_bionic, setjmp
  81. #else
  82. WEAK_ALIAS __interceptor_sigsetjmp, __sigsetjmp
  83. #endif
  84. WEAK_ALIAS __interceptor_setjmp, _setjmp
  85. #endif
  86. // We do not need executable stack.
  87. NO_EXEC_STACK_DIRECTIVE
  88. GNU_PROPERTY_BTI_PAC