test_panic.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "freertos/xtensa_context.h"
  14. #include "esp_private/panic_internal.h"
  15. extern void esp_panic_handler(panic_info_t *info);
  16. extern volatile bool g_override_illegal_instruction;
  17. void __real_esp_panic_handler(panic_info_t *info);
  18. /* Memprot test specific IllegalInstruction exception handler:
  19. * when testing the protection against a code execution, sample code
  20. * is being injected into various memory regions which produces
  21. * EXCCAUSE_ILLEGAL on execution attempt. Such a result is expected
  22. * but it causes system reboot in the standard panic handler.
  23. * The following variant of panic handling simply returns back to the
  24. * next instruction and continues normal execution.
  25. *
  26. * NOTE: if EXCCAUSE_ILLEGAL comes from a different source than the testing code
  27. * the behavior is undefined
  28. * */
  29. void __wrap_esp_panic_handler(panic_info_t *info)
  30. {
  31. XtExcFrame *frm = (XtExcFrame *)info->frame;
  32. if ( frm->exccause == EXCCAUSE_ILLEGAL && g_override_illegal_instruction == true ) {
  33. frm->pc = frm->a0;
  34. return;
  35. } else {
  36. __real_esp_panic_handler(info);
  37. }
  38. }