Browse Source

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 <ederson.desouza@intel.com>
pull/70512/head
Ederson de Souza 1 year ago committed by Fabio Baltieri
parent
commit
67bb6db3f8
  1. 10
      include/zephyr/llext/symbol.h
  2. 2
      kernel/mutex.c
  3. 10
      scripts/build/gen_syscalls.py
  4. 1
      subsys/logging/log_msg.c

10
include/zephyr/llext/symbol.h

@ -83,16 +83,6 @@ struct llext_symtable {
struct llext_symbol Z_GENERIC_SECTION(".exported_sym") __used \ struct llext_symbol Z_GENERIC_SECTION(".exported_sym") __used \
symbol_##x = {STRINGIFY(x), (void *)&x} 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)
/** /**
* @} * @}
*/ */

2
kernel/mutex.c

@ -196,7 +196,6 @@ int z_impl_k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
return -EAGAIN; return -EAGAIN;
} }
EXPORT_SYSCALL(k_mutex_lock);
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
static inline int z_vrfy_k_mutex_lock(struct k_mutex *mutex, static inline int z_vrfy_k_mutex_lock(struct k_mutex *mutex,
@ -282,7 +281,6 @@ k_mutex_unlock_return:
return 0; return 0;
} }
EXPORT_SYSCALL(k_mutex_unlock);
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
static inline int z_vrfy_k_mutex_unlock(struct k_mutex *mutex) static inline int z_vrfy_k_mutex_unlock(struct k_mutex *mutex)

10
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 */ table_template = """/* auto-generated by gen_syscalls.py, don't edit */
#include <zephyr/llext/symbol.h>
/* Weak handler functions that get replaced by the real ones unless a system /* Weak handler functions that get replaced by the real ones unless a system
* call is not implemented due to kernel configuration. * 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] = { const _k_syscall_handler_t _k_syscall_table[K_SYSCALL_LIMIT] = {
\t%s \t%s
}; };
/* Export syscalls for extensions */
%s
""" """
list_template = """/* auto-generated by gen_syscalls.py, don't edit */ 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);" 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]) % 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, fp.write(table_template % (weak_defines,
",\n\t".join(table_entries))) ",\n\t".join(table_entries),
exported_symbols))
# Listing header emitted to stdout # Listing header emitted to stdout
ids_emit.sort() ids_emit.sort()

1
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); z_log_msg_finalize(msg, source, out_desc, data);
} }
EXPORT_SYSCALL(z_log_msg_static_create);
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
static inline void z_vrfy_z_log_msg_static_create(const void *source, static inline void z_vrfy_z_log_msg_static_create(const void *source,

Loading…
Cancel
Save