userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER, but these threads can't do much since they start with permissions on no kernel objects other than their own thread object. Rather than do some run-time synchronization to have some other thread grant the necessary permissions, we introduce macros to conveniently assign object permissions to these threads when they are brought up at boot by the kernel. The tables generated here are constant and live in ROM when possible. Example usage: K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry, NULL, NULL, NULL, 0, K_USER, K_NO_WAIT); K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe); Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
493852bac3
commit
877f82e847
4 changed files with 63 additions and 2 deletions
|
@ -181,6 +181,32 @@ struct _k_object {
|
|||
u32_t data;
|
||||
} __packed;
|
||||
|
||||
struct _k_object_assignment {
|
||||
struct k_thread *thread;
|
||||
void * const *objects;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Grant a static thread access to a list of kernel objects
|
||||
*
|
||||
* For threads declared with K_THREAD_DEFINE(), grant the thread access to
|
||||
* a set of kernel objects. These objects do not need to be in an initialized
|
||||
* state. The permissions will be granted when the threads are initialized
|
||||
* in the early boot sequence.
|
||||
*
|
||||
* All arguments beyond the first must be pointers to kernel objects.
|
||||
*
|
||||
* @param name_ Name of the thread, as passed to K_THREAD_DEFINE()
|
||||
*/
|
||||
#define K_THREAD_ACCESS_GRANT(name_, ...) \
|
||||
static void * const _CONCAT(_object_list_, name_)[] = \
|
||||
{ __VA_ARGS__, NULL }; \
|
||||
static __used __in_section_unique(object_access) \
|
||||
const struct _k_object_assignment \
|
||||
_CONCAT(_object_access_, name_) = \
|
||||
{ (&_k_thread_obj_ ## name_), \
|
||||
(_CONCAT(_object_list_, name_)) }
|
||||
|
||||
#define K_OBJ_FLAG_INITIALIZED BIT(0)
|
||||
#define K_OBJ_FLAG_PUBLIC BIT(1)
|
||||
|
||||
|
@ -195,6 +221,9 @@ struct _k_object {
|
|||
*/
|
||||
void _k_object_init(void *obj);
|
||||
#else
|
||||
|
||||
#define K_THREAD_ACCESS_GRANT(thread, ...)
|
||||
|
||||
static inline void _k_object_init(void *obj)
|
||||
{
|
||||
ARG_UNUSED(obj);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue