diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index 9a88baeb5bdf55..07428d18ca8bd4 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 2dfcaee9af4c8f..9e7602bfbd87af 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 00000000000000..47ce077304f7ae --- /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; +}