abort.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (C) 1991 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. /* Hacked up for uClibc by Erik Andersen */
  16. #include <signal.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include <signal.h>
  22. #include <errno.h>
  23. /* Our last ditch effort to commit suicide */
  24. #if defined(__i386__)
  25. #define ABORT_INSTRUCTION asm ("hlt")
  26. #elif defined(__ia64__)
  27. #define ABORT_INSTRUCTION asm ("break 0")
  28. #elif defined(__mc68000__)
  29. #define ABORT_INSTRUCTION asm (".long 0xffffffff")
  30. #elif defined(__mips__)
  31. #define ABORT_INSTRUCTION asm ("break 255")
  32. #elif defined(__s390__)
  33. #define ABORT_INSTRUCTION asm (".word 0")
  34. #elif defined(__sparc__)
  35. #define ABORT_INSTRUCTION asm ("unimp 0xf00")
  36. #elif defined(__x86_64__)
  37. #define ABORT_INSTRUCTION asm ("hlt")
  38. #else
  39. #define ABORT_INSTRUCTION
  40. #endif
  41. typedef void (*vfuncp) (void);
  42. extern vfuncp __uClibc_cleanup;
  43. extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
  44. static int been_there_done_that = 0;
  45. /* Cause an abnormal program termination with core-dump. */
  46. void abort(void)
  47. {
  48. sigset_t sigset;
  49. /* Unmask SIGABRT to be sure we can get it */
  50. if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
  51. sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
  52. }
  53. /* __uClibc_cleanup NULLs itself out after being called */
  54. if (__uClibc_cleanup) {
  55. __uClibc_cleanup();
  56. }
  57. while (1) {
  58. /* Try to suicide with a SIGABRT. */
  59. if (been_there_done_that == 0) {
  60. been_there_done_that++;
  61. raise(SIGABRT);
  62. }
  63. /* Still here? Try to remove any signal handlers. */
  64. if (been_there_done_that == 1) {
  65. struct sigaction act;
  66. been_there_done_that++;
  67. memset (&act, '\0', sizeof (struct sigaction));
  68. act.sa_handler = SIG_DFL;
  69. __sigfillset (&act.sa_mask);
  70. act.sa_flags = 0;
  71. sigaction (SIGABRT, &act, NULL);
  72. }
  73. /* Still here? Try to suicide with an illegal instruction */
  74. if (been_there_done_that == 2) {
  75. been_there_done_that++;
  76. ABORT_INSTRUCTION;
  77. }
  78. /* Still here? Try to at least exit */
  79. if (been_there_done_that == 3) {
  80. been_there_done_that++;
  81. _exit (127);
  82. }
  83. /* Still here? We're screwed. Sleepy time. Good night */
  84. while (1)
  85. /* Try for ever and ever. */
  86. ABORT_INSTRUCTION;
  87. }
  88. }