abort.c 917 B

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