mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests: add test for the mpu_noexec_ram pseudomodule
The Makefiles have been copied from the mpu_stack_guard test.
This commit is contained in:
parent
2c1a627118
commit
5bb3b3dfea
5
tests/mpu_noexec_ram/Makefile
Normal file
5
tests/mpu_noexec_ram/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += mpu_noexec_ram
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
10
tests/mpu_noexec_ram/README.md
Normal file
10
tests/mpu_noexec_ram/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# mpu_noexec_ram
|
||||
|
||||
Tests for the `mpu_noexec_ram` pseudomodule. As this module is currently
|
||||
only supported on Cortex M devices, the test case is a bit ARM specific.
|
||||
|
||||
## Output
|
||||
|
||||
With `USEMODULE += mpu_noexec_ram` in `Makefile` this application should
|
||||
execute a kernel panic from the `MEM MANAGE HANDLER`. Without this
|
||||
pseudomodule activated, it will run into a hard fault.
|
51
tests/mpu_noexec_ram/main.c
Normal file
51
tests/mpu_noexec_ram/main.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Sören Tempel <tempel@uni-bremen.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test application for the mpu_noexec_stack pseudo-module
|
||||
*
|
||||
* @author Sören Tempel <tempel@uni-bremen.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "mpu.h"
|
||||
|
||||
/* RIOT's MPU headers gracefully fail when no MPU is present.
|
||||
* Use this to catch if RIOT's features are correctly gating MPU use.
|
||||
*/
|
||||
#if !__MPU_PRESENT
|
||||
#error "(!__MPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#define JMPBUF_SIZE 3
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t buf[JMPBUF_SIZE];
|
||||
|
||||
/* Fill the buffer with invalid instructions */
|
||||
for (unsigned i = 0; i < JMPBUF_SIZE; i++) {
|
||||
buf[i] = UINT32_MAX;
|
||||
}
|
||||
|
||||
puts("Attempting to jump to stack buffer ...\n");
|
||||
__asm__ volatile ("BX %0"
|
||||
: /* no output operands */
|
||||
: "r" ((uint8_t*)&buf + 1)); /* LSB must be set for thumb2 */
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user