kernel: fix errno access for user mode
The errno "variable" is required to be thread-specific. It gets defined to a macro which dereferences a pointer returned by a kernel function. In user mode, we cannot simply read/write the thread struct. We do not have thread-local storage mechanism, so for now use the lowest address of the thread stack to store this value, since this is guaranteed to be read/writable by a user thread. The downside of this approach is potential stack corruption if the stack pointer goes down this far but does not exceed the location, since a fault won't be generated in this case. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
89f87ec56e
commit
7f4d006959
6 changed files with 69 additions and 5 deletions
|
@ -538,9 +538,17 @@ struct k_thread {
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_ERRNO
|
||||
#ifdef CONFIG_USERSPACE
|
||||
/* Set to the lowest area in the thread stack since this needs to
|
||||
* be directly read/writable by user mode. Not ideal, but best we
|
||||
* can do until we have thread-local storage
|
||||
*/
|
||||
int *errno_location;
|
||||
#else
|
||||
/** per-thread errno variable */
|
||||
int errno_var;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_THREAD_STACK_INFO)
|
||||
/** Stack Info */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue