panic.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * linux/lib/vsprintf.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
  7. /*
  8. * Wirzenius wrote this portably, Torvalds fucked it up :-)
  9. */
  10. #include <common.h>
  11. #include <hang.h>
  12. #if !defined(CONFIG_PANIC_HANG)
  13. #include <command.h>
  14. #endif
  15. #include <linux/delay.h>
  16. #include <stdio.h>
  17. static void panic_finish(void) __attribute__ ((noreturn));
  18. static void panic_finish(void)
  19. {
  20. putc('\n');
  21. #if defined(CONFIG_PANIC_HANG)
  22. hang();
  23. #else
  24. flush(); /* flush the panic message before reset */
  25. do_reset(NULL, 0, 0, NULL);
  26. #endif
  27. while (1)
  28. ;
  29. }
  30. void panic_str(const char *str)
  31. {
  32. puts(str);
  33. panic_finish();
  34. }
  35. void panic(const char *fmt, ...)
  36. {
  37. #if CONFIG_IS_ENABLED(PRINTF)
  38. va_list args;
  39. va_start(args, fmt);
  40. vprintf(fmt, args);
  41. va_end(args);
  42. #endif
  43. panic_finish();
  44. }
  45. void __assert_fail(const char *assertion, const char *file, unsigned int line,
  46. const char *function)
  47. {
  48. /* This will not return */
  49. panic("%s:%u: %s: Assertion `%s' failed.", file, line, function,
  50. assertion);
  51. }