diff --git a/include/kernel.h b/include/kernel.h index 02824d82e67..180c9ae9513 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -615,6 +615,22 @@ extern FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry, void *p1, void *p2, void *p3); +/** + * @brief Grant a thread access to a NULL-terminated set of kernel objects + * + * This is a convenience function. For the provided thread, grant access to + * the remaining arguments, which must be pointers to kernel objects. + * The final argument must be a NULL. + * + * The thread object must be initialized (i.e. running). The objects don't + * need to be. + * + * @param thread Thread to grant access to objects + * @param ... NULL-terminated list of kernel object pointers + */ +extern void __attribute__((sentinel)) + k_thread_access_grant(struct k_thread *thread, ...); + /** * @brief Put the current thread to sleep. * diff --git a/kernel/thread.c b/kernel/thread.c index 61513d6f2dc..465e034843d 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -692,6 +692,25 @@ void _k_thread_group_leave(u32_t groups, struct k_thread *thread) thread_data->init_groups &= groups; } +void k_thread_access_grant(struct k_thread *thread, ...) +{ +#ifdef CONFIG_USERSPACE + va_list args; + va_start(args, thread); + + while (1) { + void *object = va_arg(args, void *); + if (object == NULL) { + break; + } + k_object_access_grant(object, thread); + } + va_end(args); +#else + ARG_UNUSED(thread); +#endif +} + FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry, void *p1, void *p2, void *p3) {