From d7119b889f8582e20f073a2f8369f176a724d8a5 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Tue, 18 Jul 2023 08:33:41 -0400 Subject: [PATCH] kernel: dynamic: declare dynamic stubs when disabled With some of the recent work to disable unnecessary system calls, there is a scenario where `z_impl_k_thread_stack_free()` is not defined and an undefined symbol error occurs. Safety was very concerned that dynamic thread stack code might touch other code that does not malloc, so add a separate file for the stack alloc and free stubs. Signed-off-by: Christopher Friedt --- include/zephyr/kernel.h | 1 + kernel/CMakeLists.txt | 10 +++++----- kernel/dynamic_disabled.c | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 kernel/dynamic_disabled.c diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index 9a88baeb5bd..07428d18ca8 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -289,6 +289,7 @@ __syscall k_thread_stack_t *k_thread_stack_alloc(size_t size, int flags); * @retval 0 on success. * @retval -EBUSY if the thread stack is in use. * @retval -EINVAL if @p stack is invalid. + * @retval -ENOSYS if dynamic thread stack allocation is disabled * * @see CONFIG_DYNAMIC_THREAD */ diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 2dfcaee9af4..9e7602bfbd8 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -123,11 +123,11 @@ target_sources_ifdef( userspace.c ) -target_sources_ifdef( - CONFIG_DYNAMIC_THREAD - kernel PRIVATE - dynamic.c - ) +if(${CONFIG_DYNAMIC_THREAD}) + target_sources(kernel PRIVATE dynamic.c) +else() + target_sources(kernel PRIVATE dynamic_disabled.c) +endif() target_include_directories(kernel PRIVATE ${ZEPHYR_BASE}/kernel/include diff --git a/kernel/dynamic_disabled.c b/kernel/dynamic_disabled.c new file mode 100644 index 00000000000..47ce077304f --- /dev/null +++ b/kernel/dynamic_disabled.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +k_thread_stack_t *z_impl_k_thread_stack_alloc(size_t size, int flags) +{ + ARG_UNUSED(size); + ARG_UNUSED(flags); + + return NULL; +} + +int z_impl_k_thread_stack_free(k_thread_stack_t *stack) +{ + ARG_UNUSED(stack); + + return -ENOSYS; +}