Skip to content

Commit d7119b8

Browse files
committed
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 <[email protected]>
1 parent dcdebb6 commit d7119b8

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

include/zephyr/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ __syscall k_thread_stack_t *k_thread_stack_alloc(size_t size, int flags);
289289
* @retval 0 on success.
290290
* @retval -EBUSY if the thread stack is in use.
291291
* @retval -EINVAL if @p stack is invalid.
292+
* @retval -ENOSYS if dynamic thread stack allocation is disabled
292293
*
293294
* @see CONFIG_DYNAMIC_THREAD
294295
*/

kernel/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ target_sources_ifdef(
123123
userspace.c
124124
)
125125

126-
target_sources_ifdef(
127-
CONFIG_DYNAMIC_THREAD
128-
kernel PRIVATE
129-
dynamic.c
130-
)
126+
if(${CONFIG_DYNAMIC_THREAD})
127+
target_sources(kernel PRIVATE dynamic.c)
128+
else()
129+
target_sources(kernel PRIVATE dynamic_disabled.c)
130+
endif()
131131

132132
target_include_directories(kernel PRIVATE
133133
${ZEPHYR_BASE}/kernel/include

kernel/dynamic_disabled.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022, Meta
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/kernel/thread_stack.h>
11+
12+
k_thread_stack_t *z_impl_k_thread_stack_alloc(size_t size, int flags)
13+
{
14+
ARG_UNUSED(size);
15+
ARG_UNUSED(flags);
16+
17+
return NULL;
18+
}
19+
20+
int z_impl_k_thread_stack_free(k_thread_stack_t *stack)
21+
{
22+
ARG_UNUSED(stack);
23+
24+
return -ENOSYS;
25+
}

0 commit comments

Comments
 (0)