diff --git a/include/kernel.h b/include/kernel.h index 4508bbf20c5..a052b98df2b 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -427,6 +427,11 @@ extern void k_call_stacks_analyze(void); #define K_FP_REGS (1 << 1) #endif +/* This thread has dropped from supervisor mode to user mode and consequently + * has additional restrictions + */ +#define K_USER (1 << 2) + #ifdef CONFIG_X86 /* x86 Bitmask definitions for threads user options */ diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index 2b1bfb51ed1..fff2afe1682 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -516,4 +516,17 @@ static inline struct k_thread *_unpend_first_thread(_wait_q_t *wait_q) return thread; } +#ifdef CONFIG_USERSPACE +/** + * Indicate whether the currently running thread has been configured to be + * a user thread. + * + * @return nonzero if the current thread is a user thread, regardless of what + * mode the CPU is currently in + */ +static inline int _is_thread_user(void) +{ + return _current->base.user_options & K_USER; +} +#endif /* CONFIG_USERSPACE */ #endif /* _ksched__h_ */ diff --git a/kernel/userspace.c b/kernel/userspace.c index bc9f01f9d56..a5a5f81d066 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -10,6 +10,7 @@ #include #include #include +#include /** * Kernel object validation function @@ -84,13 +85,6 @@ static int test_thread_perms(struct _k_object *ko) return 1; } -static int _is_thread_user(void) -{ - /* STUB */ - - return 0; -} - void k_object_grant_access(void *object, struct k_thread *thread) { struct _k_object *ko = _k_object_find(object);