《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
957 B

10 years ago
  1. #include <defs.h>
  2. #include <stdio.h>
  3. #include <intr.h>
  4. #include <kmonitor.h>
  5. static bool is_panic = 0;
  6. /* *
  7. * __panic - __panic is called on unresolvable fatal errors. it prints
  8. * "panic: 'message'", and then enters the kernel monitor.
  9. * */
  10. void
  11. __panic(const char *file, int line, const char *fmt, ...) {
  12. if (is_panic) {
  13. goto panic_dead;
  14. }
  15. is_panic = 1;
  16. // print the 'message'
  17. va_list ap;
  18. va_start(ap, fmt);
  19. cprintf("kernel panic at %s:%d:\n ", file, line);
  20. vcprintf(fmt, ap);
  21. cprintf("\n");
  22. va_end(ap);
  23. panic_dead:
  24. intr_disable();
  25. while (1) {
  26. kmonitor(NULL);
  27. }
  28. }
  29. /* __warn - like panic, but don't */
  30. void
  31. __warn(const char *file, int line, const char *fmt, ...) {
  32. va_list ap;
  33. va_start(ap, fmt);
  34. cprintf("kernel warning at %s:%d:\n ", file, line);
  35. vcprintf(fmt, ap);
  36. cprintf("\n");
  37. va_end(ap);
  38. }
  39. bool
  40. is_kernel_panic(void) {
  41. return is_panic;
  42. }