Skip to content

Commit

Permalink
kernel: dynamic: declare dynamic stubs when disabled
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cfriedt committed Jul 21, 2023
1 parent 43ffae2 commit e5e7992
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 5 additions & 5 deletions kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions kernel/dynamic_disabled.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2022, Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>

#include <zephyr/kernel.h>
#include <zephyr/kernel/thread_stack.h>

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;
}

0 comments on commit e5e7992

Please sign in to comment.