2017-03-29 20:05:44 +08:00
|
|
|
.. _mpu_stack_guard_test:
|
|
|
|
|
|
|
|
MPU Stack Guard Test
|
|
|
|
####################
|
|
|
|
|
|
|
|
Overview
|
|
|
|
********
|
|
|
|
|
|
|
|
This is a simple application that demonstrates basic thread stack guarding on
|
|
|
|
the supported platforms.
|
|
|
|
A thread spawned by the main task recursively calls a function that fills the
|
|
|
|
thread stack up to where it overwrites a preposed canary.
|
|
|
|
If the MPU is enabled and the Stack Guard feature is present the test succeeds
|
|
|
|
because an MEM Faults exception prevents the canary from being overwritten.
|
|
|
|
If the MPU is disabled the test fails because the canary is overwritten.
|
|
|
|
|
|
|
|
Building and Running
|
|
|
|
********************
|
|
|
|
|
|
|
|
This project outputs to the console.
|
|
|
|
To build the test with the MPU disabled:
|
|
|
|
|
2017-11-10 23:30:36 +08:00
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/mpu/mpu_stack_guard_test
|
2018-08-25 03:38:15 +08:00
|
|
|
:board: frdm_k64f
|
2017-11-10 23:30:36 +08:00
|
|
|
:goals: build flash
|
|
|
|
:compact:
|
2017-03-29 20:05:44 +08:00
|
|
|
|
|
|
|
To build the test with the MPU enabled and the stack guard feature present:
|
|
|
|
|
2017-11-10 23:30:36 +08:00
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/mpu/mpu_stack_guard_test
|
2018-08-25 03:38:15 +08:00
|
|
|
:board: frdm_k64f
|
2017-11-10 23:30:36 +08:00
|
|
|
:conf: prj_stack_guard.conf
|
|
|
|
:goals: build flash
|
|
|
|
:compact:
|
2017-03-29 20:05:44 +08:00
|
|
|
|
|
|
|
Sample Output
|
|
|
|
=============
|
|
|
|
|
2017-06-27 15:49:28 +08:00
|
|
|
With the MPU enabled but the stack guard feature disabled:
|
2017-03-29 20:05:44 +08:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2018-08-25 03:38:15 +08:00
|
|
|
***** Booting Zephyr OS v1.13.0-rc1-14-gd47fada *****
|
|
|
|
STACK_ALIGN 0x8
|
2017-06-27 15:49:28 +08:00
|
|
|
MPU STACK GUARD Test
|
2018-08-25 03:38:15 +08:00
|
|
|
Canary Initial Value = 0xf0cacc1a threads 0x20000ff8
|
|
|
|
Canary = 0x20000128 Test not passed.
|
|
|
|
***** BUS FAULT *****
|
|
|
|
Instruction bus error
|
|
|
|
NXP MPU error, port 3
|
|
|
|
Mode: Supervisor, Instruction Address: 0x20001030
|
|
|
|
Type: Read, Master: 0, Regions: 0x8800
|
|
|
|
***** Hardware exception *****
|
|
|
|
Current thread ID = 0x20000ff8
|
|
|
|
Faulting instruction address = 0x20001030
|
|
|
|
Fatal fault in essential thread! Spinning...
|
2017-06-27 15:49:28 +08:00
|
|
|
|
|
|
|
With the MPU enabled and the stack guard feature enabled:
|
2017-03-29 20:05:44 +08:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2018-08-25 03:38:15 +08:00
|
|
|
***** Booting Zephyr OS v1.13.0-rc1-14-gd47fada *****
|
|
|
|
STACK_ALIGN 0x20
|
2017-06-27 15:49:28 +08:00
|
|
|
MPU STACK GUARD Test
|
2018-08-25 03:38:15 +08:00
|
|
|
Canary Initial Value = 0xf0cacc1a threads 0x20001100
|
|
|
|
***** BUS FAULT *****
|
2017-06-27 15:49:28 +08:00
|
|
|
Stacking error
|
2018-08-25 03:38:15 +08:00
|
|
|
NXP MPU error, port 3
|
|
|
|
Mode: Supervisor, Data Address: 0x200011b0
|
|
|
|
Type: Write, Master: 0, Regions: 0x8400
|
|
|
|
***** Hardware exception *****
|
|
|
|
Current thread ID = 0x20001100
|
|
|
|
Faulting instruction address = 0x0
|
|
|
|
Fatal fault in thread 0x20001100! Aborting.
|