Skip to content

Commit 35b26e9

Browse files
dcpleungcfriedt
authored andcommitted
tests: mem_protect/mem_map: fix mapped code execution test
The mapped code execution test uses the simple k_mem_phys_addr() to do virtual to physical address translation. And this requires the virtual address to be inside the kernel permanent mapping (i.e. between __kernel_ram_start and __kernel_ram_end). With demand paging, the translation is no longer static and it can be mapped into any physical address. So a simple memory mapping in the test would map an incorrect physical address which may not even contain the said function. It has been working when demand paging is not enabled is due to the custom sections is immediately after the text section, so that the simple address translation still works. But a custom linker script (i.e. board config) may make that not true anymore. So fix this by putting transplanted_function() into snippets-text-sections.ld such that this would appear inside .text section. Signed-off-by: Daniel Leung <[email protected]>
1 parent a9849a7 commit 35b26e9

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

tests/kernel/mem_protect/mem_map/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ target_include_directories(app PRIVATE
1212
FILE(GLOB app_sources src/*.c)
1313
target_sources(app PRIVATE ${app_sources})
1414

15-
zephyr_linker_sources(SECTIONS custom-sections.ld)
15+
zephyr_linker_sources(TEXT_SECTIONS custom-sections.ld)
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* SPDX-License-Identifier: Apache-2.0 */
22

3-
SECTION_DATA_PROLOGUE(TEST_MEM_MAP,,SUBALIGN(CONFIG_MMU_PAGE_SIZE))
4-
{
3+
. = ALIGN(CONFIG_MMU_PAGE_SIZE);
4+
__test_mem_map_start = .;
5+
56
/* transplanted_function() must be first */
67
KEEP(*(".test_mem_map.transplanted_function*"));
78
KEEP(*(".test_mem_map.*"));
89

9-
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
10-
11-
PROVIDE(__test_mem_map_start = ADDR(TEST_MEM_MAP));
12-
PROVIDE(__test_mem_map_end = __test_mem_map_start + SIZEOF(TEST_MEM_MAP));
10+
. = ALIGN(CONFIG_MMU_PAGE_SIZE);
11+
__test_mem_map_end = .;

0 commit comments

Comments
 (0)