test_panic.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "freertos/xtensa_context.h"
  7. #include "esp_private/panic_internal.h"
  8. extern void esp_panic_handler(panic_info_t *info);
  9. extern volatile bool g_override_illegal_instruction;
  10. void __real_esp_panic_handler(panic_info_t *info);
  11. void __real_esp_cpu_stall(int core_id);
  12. /* Memprot test specific IllegalInstruction exception handler:
  13. * when testing the protection against a code execution, sample code
  14. * is being injected into various memory regions which produces
  15. * EXCCAUSE_ILLEGAL on execution attempt. Such a result is expected
  16. * but it causes system reboot in the standard panic handler.
  17. * The following variant of panic handling simply returns back to the
  18. * next instruction and continues normal execution.
  19. *
  20. * NOTE: if EXCCAUSE_ILLEGAL comes from a different source than the testing code
  21. * the behavior is undefined
  22. * */
  23. void __wrap_esp_panic_handler(panic_info_t *info)
  24. {
  25. XtExcFrame *frm = (XtExcFrame *)info->frame;
  26. if (frm->exccause == EXCCAUSE_ILLEGAL && g_override_illegal_instruction == true) {
  27. frm->pc = frm->a0;
  28. return;
  29. } else {
  30. __real_esp_panic_handler(info);
  31. }
  32. }
  33. void __wrap_esp_cpu_stall(int core_id)
  34. {
  35. if (g_override_illegal_instruction == true) {
  36. return;
  37. } else {
  38. __real_esp_cpu_stall(core_id);
  39. }
  40. }