abort.c 955 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdlib.h>
  2. #include <signal.h>
  3. #include "syscall.h"
  4. #include "pthread_impl.h"
  5. #include "atomic.h"
  6. #include "lock.h"
  7. #include "ksigaction.h"
  8. hidden volatile int __abort_lock[1];
  9. _Noreturn void abort(void)
  10. {
  11. raise(SIGABRT);
  12. /* If there was a SIGABRT handler installed and it returned, or if
  13. * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
  14. * sigaction from installing a new SIGABRT handler, uninstall any
  15. * handler that may be present, and re-raise the signal to generate
  16. * the default action of abnormal termination. */
  17. __block_all_sigs(0);
  18. LOCK(__abort_lock);
  19. __syscall(SYS_rt_sigaction, SIGABRT,
  20. &(struct k_sigaction){.handler = SIG_DFL}, 0, _NSIG/8);
  21. __syscall(SYS_tkill, __pthread_self()->tid, SIGABRT);
  22. __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
  23. &(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8);
  24. /* Beyond this point should be unreachable. */
  25. a_crash();
  26. raise(SIGKILL);
  27. _Exit(127);
  28. }