Skip to content

Commit 41f6011

Browse files
Andrew Boienashif
authored andcommitted
userspace: remove APPLICATION_MEMORY feature
This was never a long-term solution, more of a gross hack to get test cases working until we could figure out a good end-to-end solution for memory domains that generated appropriate linker sections. Now that we have this with the app shared memory feature, and have converted all tests to remove it, delete this feature. To date all userspace APIs have been tagged as 'experimental' which sidesteps deprecation policies. Signed-off-by: Andrew Boie <[email protected]>
1 parent 525065d commit 41f6011

File tree

52 files changed

+152
-701
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+152
-701
lines changed

CMakeLists.txt

Lines changed: 3 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,9 @@ zephyr_cc_option(-Wpointer-arith)
341341

342342
# Declare MPU userspace dependencies before the linker scripts to make
343343
# sure the order of dependencies are met
344-
if(CONFIG_APP_SHARED_MEM AND CONFIG_USERSPACE)
344+
if(CONFIG_USERSPACE)
345+
if(CONFIG_APP_SHARED_MEM)
345346
set(APP_SMEM_DEP app_smem_linker)
346-
endif()
347-
if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE)
348-
if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_ARC AND CONFIG_APPLICATION_MEMORY)
349-
set(ALIGN_SIZING_DEP app_sizing_prebuilt linker_app_sizing_script)
350347
endif()
351348
if(CONFIG_ARM)
352349
set(PRIV_STACK_DEP priv_stacks_prebuilt)
@@ -745,101 +742,6 @@ endforeach()
745742

746743
get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)
747744

748-
if(CONFIG_APPLICATION_MEMORY)
749-
# Objects default to being in kernel space, and then we exclude
750-
# certain items.
751-
set(kernel_object_file_list
752-
${ZEPHYR_LIBS_PROPERTY}
753-
kernel
754-
)
755-
list(
756-
REMOVE_ITEM
757-
kernel_object_file_list
758-
app
759-
)
760-
761-
# The zephyr libraries in zephyr/lib/ and zephyr/test/ belong in
762-
# userspace.
763-
764-
# NB: The business logic for determing what source files are in
765-
# kernel space and what source files are in user space is
766-
# fragile. Fix ASAP.
767-
#
768-
# The intended design is that certain directories are designated as
769-
# containing userspace code and others for kernel space code. The
770-
# implementation we have however is not working on directories of
771-
# code, it is working on zephyr libraries. It is exploiting the fact
772-
# that zephyr libraries follow a naming scheme as described in
773-
# extensions.cmake:zephyr_library_get_current_dir_lib_name
774-
#
775-
# But code from test/ and lib/ that is placed in the "zephyr"
776-
# library (with zephyr_sources()) will not be in a library that is
777-
# prefixed with lib__ or test__ and will end up in the wrong address
778-
# space.
779-
set(application_space_dirs
780-
lib
781-
tests
782-
)
783-
foreach(f ${kernel_object_file_list})
784-
foreach(app_dir ${application_space_dirs})
785-
if(${f} MATCHES "^${app_dir}__") # Begins with ${app_dir}__, e.g. lib__libc
786-
list(
787-
REMOVE_ITEM
788-
kernel_object_file_list
789-
${f}
790-
)
791-
endif()
792-
endforeach()
793-
endforeach()
794-
795-
# Create a list ks, with relative paths to kernel space libs.
796-
foreach(f ${kernel_object_file_list})
797-
get_target_property(target_name ${f} NAME)
798-
get_target_property(target_binary_dir ${f} BINARY_DIR)
799-
800-
string(REPLACE
801-
${PROJECT_BINARY_DIR}
802-
""
803-
fixed_path
804-
${target_binary_dir}
805-
)
806-
807-
# Append / if not empty
808-
if(fixed_path)
809-
set(fixed_path "${fixed_path}/")
810-
endif()
811-
812-
# Cut off leading / if present
813-
if(fixed_path MATCHES "^/.+")
814-
string(SUBSTRING ${fixed_path} 1 -1 fixed_path)
815-
endif()
816-
817-
set(fixed_path "${fixed_path}lib${target_name}.a")
818-
819-
if(CMAKE_GENERATOR STREQUAL "Ninja")
820-
# Ninja invokes the linker from the root of the build directory
821-
# (APPLICATION_BINARY_DIR) instead of from the build/zephyr
822-
# directory (PROJECT_BINARY_DIR). So for linker-defs.h to get
823-
# the correct path we need to prefix with zephyr/.
824-
set(fixed_path "zephyr/${fixed_path}")
825-
endif()
826-
827-
list(APPEND ks ${fixed_path})
828-
endforeach()
829-
830-
# We are done constructing kernel_object_file_list, now we inject
831-
# this list into the linker script through the define
832-
# KERNELSPACE_OBJECT_FILES
833-
set(def -DKERNELSPACE_OBJECT_FILES=)
834-
foreach(f ${ks})
835-
set(def "${def} ${f}")
836-
endforeach()
837-
set_property(GLOBAL APPEND PROPERTY
838-
PROPERTY_LINKER_SCRIPT_DEFINES
839-
${def}
840-
)
841-
endif() # CONFIG_APPLICATION_MEMORY
842-
843745
if (CONFIG_CODE_DATA_RELOCATION)
844746
set(CODE_RELOCATION_DEP code_relocation_source_lib)
845747
endif() # CONFIG_CODE_DATA_RELOCATION
@@ -1244,52 +1146,7 @@ if(CONFIG_APP_SHARED_MEM AND CONFIG_USERSPACE)
12441146
)
12451147
endif()
12461148

1247-
if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE)
1248-
1249-
if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_ARC AND CONFIG_APPLICATION_MEMORY)
1250-
1251-
construct_add_custom_command_for_linker_pass(linker_app_sizing custom_command)
1252-
add_custom_command(
1253-
${custom_command}
1254-
)
1255-
1256-
add_custom_target(
1257-
linker_app_sizing_script
1258-
DEPENDS
1259-
linker_app_sizing.cmd
1260-
${OFFSETS_H_TARGET}
1261-
${APP_SMEM_DEP}
1262-
${CODE_RELOCATION_DEP}
1263-
)
1264-
1265-
set_property(TARGET
1266-
linker_app_sizing_script
1267-
PROPERTY INCLUDE_DIRECTORIES
1268-
${ZEPHYR_INCLUDE_DIRS}
1269-
)
1270-
1271-
# For systems with MPUs, the size of the application data section must
1272-
# be determined so that MPU alignment requirements can be met.
1273-
# Create a app_sizing_prebuilt target so we can do this before the
1274-
# other ELF files are built
1275-
set(GEN_APP_ALIGN $ENV{ZEPHYR_BASE}/scripts/gen_alignment_script.py)
1276-
add_executable( app_sizing_prebuilt misc/empty_file.c)
1277-
target_link_libraries(app_sizing_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd ${zephyr_lnk} ${CODE_RELOCATION_DEP})
1278-
set_property(TARGET app_sizing_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_app_sizing.cmd)
1279-
add_dependencies( app_sizing_prebuilt linker_app_sizing_script ${OFFSETS_LIB} ${CODE_RELOCATION_DEP} )
1280-
1281-
add_custom_command(
1282-
TARGET app_sizing_prebuilt
1283-
POST_BUILD
1284-
COMMAND ${PYTHON_EXECUTABLE} ${GEN_APP_ALIGN}
1285-
--output ./include/generated/app_data_alignment.ld
1286-
--kernel $<TARGET_FILE:app_sizing_prebuilt>
1287-
VERBATIM
1288-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/
1289-
)
1290-
endif()
1291-
1292-
if(CONFIG_ARM)
1149+
if(CONFIG_USERSPACE AND CONFIG_ARM)
12931150
construct_add_custom_command_for_linker_pass(linker_priv_stacks custom_command)
12941151
add_custom_command(
12951152
${custom_command}
@@ -1317,8 +1174,6 @@ if(CONFIG_ARM)
13171174
add_dependencies( priv_stacks_prebuilt ${ALIGN_SIZING_DEP} linker_priv_stacks_script ${OFFSETS_LIB})
13181175
endif()
13191176

1320-
endif()
1321-
13221177
# FIXME: Is there any way to get rid of empty_file.c?
13231178
add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c)
13241179
target_link_libraries(${ZEPHYR_PREBUILT_EXECUTABLE} ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk} ${CODE_RELOCATION_DEP})

arch/arc/core/mpu/arc_mpu.c

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -447,51 +447,19 @@ void arc_core_mpu_configure_user_context(struct k_thread *thread)
447447
/* for kernel threads, no need to configure user context */
448448
if (!(thread->base.user_options & K_USER)) {
449449
#if defined(CONFIG_APP_SHARED_MEM) && CONFIG_ARC_MPU_VER == 3
450-
/*
451-
* APP_SHARED_MEM is handled here, all privileged threads have the right
452-
* to access it. APPLICATION_MEMORY will be handled as a static memory region
453-
*/
450+
/* APP_SHARED_MEM is handled here, all privileged threads have
451+
* the right to access it.
452+
*/
454453
base = (u32_t)&_app_smem_start;
455454
size = (u32_t)&_app_smem_size;
456-
_region_init(_get_region_index_by_type(THREAD_APP_DATA_REGION)
457-
, base, size, _get_region_attr_by_type(THREAD_APP_DATA_REGION));
455+
_region_init(_get_region_index_by_type(THREAD_APP_DATA_REGION),
456+
base, size,
457+
_get_region_attr_by_type(THREAD_APP_DATA_REGION));
458458
#endif
459459
return;
460460
}
461461

462462
arc_core_mpu_configure(THREAD_STACK_USER_REGION, base, size);
463-
464-
/* configure app data portion */
465-
#ifdef CONFIG_APPLICATION_MEMORY
466-
#if CONFIG_ARC_MPU_VER == 2
467-
/*
468-
* _app_ram_size is guaranteed to be power of two, and
469-
* _app_ram_start is guaranteed to be aligned _app_ram_size
470-
* in linker template
471-
*/
472-
base = (u32_t)&__app_ram_start;
473-
size = (u32_t)&__app_ram_size;
474-
475-
/* set up app data region if exists, otherwise disable */
476-
if (size > 0) {
477-
arc_core_mpu_configure(THREAD_APP_DATA_REGION, base, size);
478-
}
479-
#elif CONFIG_ARC_MPU_VER == 3
480-
/*
481-
* ARC MPV v3 doesn't support MPU region overlap.
482-
* Application memory should be a static memory, defined in mpu_config
483-
*
484-
* here, need to clear THREAD_APP_DATA_REGION for user thread as it will
485-
* be set by kernel thread to to access app_shared mem. For user thread
486-
* the handling of app_shared mem is done by
487-
* THREAD_DOMAIN_PARTITION_REGION
488-
*/
489-
#if defined(CONFIG_APP_SHARED_MEM)
490-
_region_init(_get_region_index_by_type(THREAD_APP_DATA_REGION)
491-
, 0, 0, 0);
492-
#endif
493-
#endif
494-
#endif
495463
}
496464

497465
/**

arch/arm/core/cortex_m/mpu/arm_core_mpu.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ void _arch_configure_static_mpu_regions(void)
6565
* MPU regions.
6666
*/
6767
const struct k_mem_partition static_regions[] = {
68-
#if defined(CONFIG_APPLICATION_MEMORY)
69-
{
70-
.start = (u32_t)&__app_ram_start,
71-
.size = (u32_t)&__app_ram_end - (u32_t)&__app_ram_start,
72-
.attr = K_MEM_PARTITION_P_RW_U_RW,
73-
},
74-
#endif /* CONFIG_APPLICATION_MEMORY */
7568
#if defined(CONFIG_COVERAGE_GCOV) && defined(CONFIG_USERSPACE)
7669
{
7770
.start = (u32_t)&__gcov_bss_start,
@@ -105,13 +98,6 @@ void _arch_configure_static_mpu_regions(void)
10598
* initialization.
10699
*/
107100
const struct k_mem_partition dyn_region_areas[] = {
108-
#if defined(CONFIG_APPLICATION_MEMORY)
109-
/* Dynamic areas are also allowed in Application Memory. */
110-
{
111-
.start = (u32_t)&__app_ram_start,
112-
.size = (u32_t)&__app_ram_end - (u32_t)&__app_ram_start,
113-
},
114-
#endif /* CONFIG_APPLICATION_MEMORY */
115101
{
116102
.start = _MPU_DYNAMIC_REGIONS_AREA_START,
117103
.size = _MPU_DYNAMIC_REGIONS_AREA_SIZE,

arch/x86/core/crt0.S

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,6 @@ __csSet:
314314

315315
call _x86_data_copy
316316

317-
#ifdef CONFIG_APPLICATION_MEMORY
318-
movl $__app_data_ram_start, %edi /* DATA in RAM (dest) */
319-
movl $__app_data_rom_start, %esi /* DATA in ROM (src) */
320-
movl $__app_data_num_words, %ecx /* Size of DATA in quad bytes */
321-
322-
call _x86_data_copy
323-
#endif /* CONFIG_APPLICATION_MEMORY */
324-
325317
#ifdef CONFIG_APP_SHARED_MEM
326318
movl $_app_smem_start, %edi /* DATA in RAM (dest) */
327319
movl $_app_smem_rom_start, %esi /* DATA in ROM (src) */
@@ -348,12 +340,6 @@ __csSet:
348340
call _x86_bss_zero
349341
#endif /* CONFIG_COVERAGE_GCOV */
350342

351-
#ifdef CONFIG_APPLICATION_MEMORY
352-
movl $__app_bss_start, %edi /* load app BSS start address */
353-
movl $__app_bss_num_words, %ecx /* number of quad bytes */
354-
call _x86_bss_zero
355-
#endif
356-
357343
#ifdef CONFIG_GDT_DYNAMIC
358344
/* activate RAM-based Global Descriptor Table (GDT) */
359345
lgdt %ds:_gdt

arch/x86/core/x86_mmu.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
MMU_BOOT_REGION((u32_t)&_image_rom_start, (u32_t)&_image_rom_size,
2121
MMU_ENTRY_READ | MMU_ENTRY_USER);
2222

23-
#ifdef CONFIG_APPLICATION_MEMORY
24-
/* User threads by default can read/write app-level memory. */
25-
MMU_BOOT_REGION((u32_t)&__app_ram_start, (u32_t)&__app_ram_size,
26-
MMU_ENTRY_WRITE | MMU_ENTRY_USER | MMU_ENTRY_EXECUTE_DISABLE);
27-
#endif
2823
#ifdef CONFIG_APP_SHARED_MEM
2924
MMU_BOOT_REGION((u32_t)&_app_smem_start, (u32_t)&_app_smem_size,
3025
MMU_ENTRY_WRITE | MMU_ENTRY_USER | MMU_ENTRY_EXECUTE_DISABLE);

boards/arc/em_starterkit/arc_mpu_regions.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@
1111

1212
#ifdef CONFIG_USERSPACE
1313
static struct arc_mpu_region mpu_regions[] = {
14-
#if CONFIG_ARC_MPU_VER == 3 && defined(CONFIG_APPLICATION_MEMORY)
15-
/* Region ICCM */
16-
MPU_REGION_ENTRY("IMAGE ROM",
17-
(u32_t) _image_rom_start,
18-
(u32_t) _image_rom_size,
19-
REGION_FLASH_ATTR),
20-
MPU_REGION_ENTRY("APP MEMORY",
21-
(u32_t) __app_ram_start,
22-
(u32_t) __app_ram_size,
23-
REGION_RAM_ATTR),
24-
MPU_REGION_ENTRY("KERNEL MEMORY",
25-
(u32_t) __kernel_ram_start,
26-
(u32_t) __kernel_ram_size,
27-
AUX_MPU_RDP_KW | AUX_MPU_RDP_KR),
28-
29-
#else
3014
#if DT_ICCM_SIZE > 0
3115
/* Region ICCM */
3216
MPU_REGION_ENTRY("ICCM",
@@ -49,7 +33,6 @@ static struct arc_mpu_region mpu_regions[] = {
4933
AUX_MPU_RDP_KW | AUX_MPU_RDP_KR |
5034
AUX_MPU_RDP_KE | AUX_MPU_RDP_UE),
5135
#endif
52-
#endif /* ARC_MPU_VER == 3 */
5336
/* Region Peripheral */
5437
MPU_REGION_ENTRY("PERIPHERAL",
5538
0xF0000000,

boards/arc/nsim_em/arc_mpu_regions.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111

1212
#ifdef CONFIG_USERSPACE
1313
static struct arc_mpu_region mpu_regions[] = {
14-
#if CONFIG_ARC_MPU_VER == 3 && defined(CONFIG_APPLICATION_MEMORY)
14+
#if CONFIG_ARC_MPU_VER == 3
1515
/* Region ICCM */
1616
MPU_REGION_ENTRY("IMAGE ROM",
1717
(u32_t) _image_rom_start,
1818
(u32_t) _image_rom_size,
1919
REGION_FLASH_ATTR),
20-
MPU_REGION_ENTRY("APP MEMORY",
21-
(u32_t) __app_ram_start,
22-
(u32_t) __app_ram_size,
23-
REGION_RAM_ATTR),
2420
MPU_REGION_ENTRY("KERNEL MEMORY",
2521
(u32_t) __kernel_ram_start,
2622
(u32_t) __kernel_ram_size,

doc/reference/kernel/usermode/kernelobjects.rst

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,8 @@ call APIs, several conditions must be met on how the kernel object is declared:
5656
in a special table of kernel object metadata. Kernel objects may be members
5757
of arrays or embedded within other data structures.
5858

59-
* Kernel objects must be located in memory reserved for the kernel. If
60-
:option:`CONFIG_APPLICATION_MEMORY` is used, all declarations of kernel
61-
objects inside application code must be prefixed with the :c:macro:`__kernel`
62-
attribute so that they are placed in the right memory sections. The APIs for
63-
statically declaring and initializing kernel objects (such as
64-
:c:macro:`K_SEM_DEFINE()`) automatically do this. However, uninitialized
65-
kernel objects need to be tagged like this:
66-
67-
.. code-block:: c
68-
69-
__kernel struct k_sem my_sem;
59+
* Kernel objects must be located in memory reserved for the kernel. They
60+
must not be located in any memory partitions that are user-accessible.
7061

7162
* Any memory reserved for a kernel object must be used exclusively for that
7263
object. Kernel objects may not be members of a union data type.
@@ -232,7 +223,7 @@ are embedded within some larger struct and initialized statically.
232223
...
233224
};
234225
235-
__kernel struct foo my_foo = {
226+
struct foo my_foo = {
236227
.sem = _K_SEM_INITIALIZER(my_foo.sem, 0, 1),
237228
...
238229
};
@@ -274,7 +265,7 @@ Configuration Options
274265
Related configuration options:
275266

276267
* :option:`CONFIG_USERSPACE`
277-
* :option:`CONFIG_APPLICATION_MEMORY`
268+
* :option:`CONFIG_APP_SHARED_MEM`
278269
* :option:`CONFIG_MAX_THREAD_BYTES`
279270

280271
API Reference

0 commit comments

Comments
 (0)