From 67bb6db3f8e5329516f005f1335bb7a23a95b3eb Mon Sep 17 00:00:00 2001 From: Ederson de Souza Date: Fri, 15 Mar 2024 14:51:39 -0700 Subject: [PATCH] syscall: Export all emitted syscalls, enabling them for extensions Linkable loadable extensions can only use syscalls if they are exported via EXPORT_SYSCALL (or EXPORT_SYMBOL). Instead of enabling used syscalls one by one, this patch exports all of them automatically via `gen_syscalls.py`. If CONFIG_LLEXT=n, the section where the exported symbols live is discarded, so it should be a non-op when llext is not enabled. This patch also removes the now redundant EXPORT_SYSCALL macro. Note that EXPORT_SYMBOL is still useful on different situations (and is indeed used by the code generated by `gen_syscalls.py`). Signed-off-by: Ederson de Souza --- include/zephyr/llext/symbol.h | 10 ---------- kernel/mutex.c | 2 -- scripts/build/gen_syscalls.py | 10 +++++++++- subsys/logging/log_msg.c | 1 - 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/zephyr/llext/symbol.h b/include/zephyr/llext/symbol.h index 993e2c4a51..8691301ac0 100644 --- a/include/zephyr/llext/symbol.h +++ b/include/zephyr/llext/symbol.h @@ -83,16 +83,6 @@ struct llext_symtable { struct llext_symbol Z_GENERIC_SECTION(".exported_sym") __used \ symbol_##x = {STRINGIFY(x), (void *)&x} -/** - * @brief Export a system call to a table of symbols - * - * Takes a system call name and uses @a EXPORT_SYMBOL() to export the respective - * function. - * - * @param x System call to export - */ -#define EXPORT_SYSCALL(x) EXPORT_SYMBOL(z_impl_ ## x) - /** * @} */ diff --git a/kernel/mutex.c b/kernel/mutex.c index 808e06eda4..328a75ca9d 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c @@ -196,7 +196,6 @@ int z_impl_k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout) return -EAGAIN; } -EXPORT_SYSCALL(k_mutex_lock); #ifdef CONFIG_USERSPACE static inline int z_vrfy_k_mutex_lock(struct k_mutex *mutex, @@ -282,7 +281,6 @@ k_mutex_unlock_return: return 0; } -EXPORT_SYSCALL(k_mutex_unlock); #ifdef CONFIG_USERSPACE static inline int z_vrfy_k_mutex_unlock(struct k_mutex *mutex) diff --git a/scripts/build/gen_syscalls.py b/scripts/build/gen_syscalls.py index 68d0f15f48..3741707f80 100755 --- a/scripts/build/gen_syscalls.py +++ b/scripts/build/gen_syscalls.py @@ -52,6 +52,8 @@ noweak = ["z_mrsh_k_object_release", table_template = """/* auto-generated by gen_syscalls.py, don't edit */ +#include + /* Weak handler functions that get replaced by the real ones unless a system * call is not implemented due to kernel configuration. */ @@ -60,6 +62,8 @@ table_template = """/* auto-generated by gen_syscalls.py, don't edit */ const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT] = { \t%s }; +/* Export syscalls for extensions */ +%s """ list_template = """/* auto-generated by gen_syscalls.py, don't edit */ @@ -460,8 +464,12 @@ def main(): weak_defines += "\n".join(["extern uintptr_t %s(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, void *ssf);" % s for s in noweak]) + # Export symbols for emitted syscalls + exported_symbols = "\n".join("EXPORT_SYMBOL(%s);" % e for e in emit_list) + fp.write(table_template % (weak_defines, - ",\n\t".join(table_entries))) + ",\n\t".join(table_entries), + exported_symbols)) # Listing header emitted to stdout ids_emit.sort() diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index ef9b777eb6..6c1cc3c578 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -329,7 +329,6 @@ void z_impl_z_log_msg_static_create(const void *source, z_log_msg_finalize(msg, source, out_desc, data); } -EXPORT_SYSCALL(z_log_msg_static_create); #ifdef CONFIG_USERSPACE static inline void z_vrfy_z_log_msg_static_create(const void *source,