LinuxSignal.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef mozilla_LinuxSignal_h
  5. #define mozilla_LinuxSignal_h
  6. namespace mozilla {
  7. #if defined(__arm__)
  8. // Some (old) Linux kernels on ARM have a bug where a signal handler
  9. // can be called without clearing the IT bits in CPSR first. The result
  10. // is that the first few instructions of the handler could be skipped,
  11. // ultimately resulting in crashes. To workaround this bug, the handler
  12. // on ARM is a trampoline that starts with enough NOP instructions, so
  13. // that even if the IT bits are not cleared, only the NOP instructions
  14. // will be skipped over.
  15. template <void (*H)(int, siginfo_t*, void*)>
  16. __attribute__((naked)) void
  17. SignalTrampoline(int aSignal, siginfo_t* aInfo, void* aContext)
  18. {
  19. asm volatile (
  20. "nop; nop; nop; nop"
  21. : : : "memory");
  22. asm volatile (
  23. "b %0"
  24. :
  25. : "X"(H)
  26. : "memory");
  27. }
  28. # define MOZ_SIGNAL_TRAMPOLINE(h) (mozilla::SignalTrampoline<h>)
  29. #else // __arm__
  30. # define MOZ_SIGNAL_TRAMPOLINE(h) (h)
  31. #endif // __arm__
  32. } // namespace mozilla
  33. #endif // mozilla_LinuxSignal_h